Commit graph

256659 commits

Author SHA1 Message Date
bors 003a902792 Auto merge of #125958 - BoxyUwU:remove_const_ty, r=lcnr
Remove the `ty` field from type system `Const`s

Fixes #125556
Fixes #122908

Part of the work on `adt_const_params`/`generic_const_param_types`/`min_generic_const_exprs`/generally making the compiler nicer. cc rust-lang/project-const-generics#44

Please review commit-by-commit otherwise I wasted a lot of time not just squashing this into a giant mess (and also it'll be SO much nicer because theres a lot of fluff changes mixed in with other more careful changes if looking via File Changes

---

Why do this?
- The `ty` field keeps causing ICEs and weird behaviour due to it either being treated as "part of the const" or it being forgotten about leading to ICEs.
- As we move forward with `adt_const_params` and a potential `min_generic_const_exprs` it's going to become more complex to actually lower the correct `Ty<'tcx>`
- It muddles the idea behind how we check `Const` arguments have the correct type. By having the `ty` field it may seem like we ought to be relating it when we relate two types, or that its generally important information about the `Const`.
- Brings the compiler more in line with `a-mir-formality` as that also tracks the type of type system `Const`s via `ConstArgHasType` bounds in the env instead of on the `Const` itself.
- A lot of stuff is a lot nicer when you dont have to pass around the type of a const lol. Everywhere we construct `Const` is now significantly nicer 😅

See #125671's description for some more information about the `ty` field

---

General summary of changes in this PR:

- Add `Ty` to `ConstKind::Value` as otherwise there is no way to implement `ConstArgHasType` to ensure that const arguments are correctly typed for the parameter when we stop creating anon consts for all const args. It's also just incredibly difficult/annoying to thread the correct `Ty` around to a bunch of ctfe functions otherwise.
-  Fully implement `ConstArgHasType` in both the old and new solver. Since it now has no reliance on the `ty` field it serves its originally intended purpose of being able to act as a double check that trait vs impls have correctly typed const parameters. It also will now be able to be responsible for checking types of const arguments to parameters under `min_generic_const_exprs`.
- Add `Ty` to `mir::Const::Ty`. I dont have a great understanding of why mir constants are setup like this to be honest. Regardless they need to be able to determine the type of the const and the easiest way to make this happen was to simply store the `Ty` along side the `ty::Const`. Maybe we can do better here in the future but I'd have to spend way more time looking at everywhere we use `mir::Const`.
- rustdoc has its own `Const` which also has a `ty` field. It was relatively easy to remove this.

---

r? `@lcnr` `@compiler-errors`
2024-06-06 03:41:23 +00:00
bors d0ccb5413e Auto merge of #122505 - oli-obk:visit_nested_body2, r=tmiasko
Don't walk the bodies of free constants for reachability.

follow-up to #122371

cc #119214

This avoids codegening items (e.g. functions) that are only used during const eval, but do not reach their final constant value (e.g. via function pointers).

r? `@tmiasko`
2024-06-06 01:33:14 +00:00
Boxy 3a6b606ad9 remove const arg windows debug info tests 2024-06-05 22:39:42 +01:00
Michael Goulet 2e082677a6 Fix function-names.rs test 2024-06-05 22:25:42 +01:00
Boxy f74119a2e4 Bless tests and handle tests/crashes 2024-06-05 22:25:42 +01:00
Boxy 7fa98d0c01 ty::Expr reviews 2024-06-05 22:25:42 +01:00
Boxy 56092a345b Misc fixes (pattern type lowering, cfi, pretty printing) 2024-06-05 22:25:42 +01:00
Boxy a454da3b1c Misc fixes to cranelift/clippy/miri 2024-06-05 22:25:42 +01:00
Boxy 432c11feb6 Remove Type from rustdoc Const 2024-06-05 22:25:42 +01:00
Boxy 60a5bebbe5 Add Ty to mir::Const::Ty 2024-06-05 22:25:41 +01:00
Boxy 8d6705cdb8 Fully implement ConstArgHasType 2024-06-05 22:25:41 +01:00
Boxy a9702a6668 Add Ty to ConstKind::Value 2024-06-05 22:25:41 +01:00
Boxy 58feec9b85 Basic removal of Ty from places (boring) 2024-06-05 22:25:38 +01:00
bors 72fdf913c5 Auto merge of #126038 - matthiaskrgr:rollup-h4rm3x2, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #124840 (resolve: mark it undetermined if single import is not has any bindings)
 - #125622 (Winnow private method candidates instead of assuming any candidate of the right name will apply)
 - #125648 (Remove unused(?) `~/rustsrc` folder from docker script)
 - #125672 (Add more ABI test cases to miri (RFC 3391))
 - #125800 (Fix `mut` static task queue in SGX target)
 - #125871 (Orphanck[old solver]: Consider opaque types to never cover type parameters)
 - #125893 (Handle all GVN binops in a single place.)
 - #126008 (Port `tests/run-make-fulldeps/issue-19371` to ui-fulldeps)
 - #126032 (Update description of the `IsTerminal` example)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-05 20:53:32 +00:00
bors 7ebd2bdbf6 Auto merge of #126037 - matthiaskrgr:rollup-7pz1nhr, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #124746 (`rustc --explain E0582` additional example)
 - #125407 (Detect when user is trying to create a lending `Iterator` and give a custom explanation)
 - #125505 (Add intra-doc-links to rustc_middle crate-level docs.)
 - #125792 (Don't drop `Unsize` candidate in intercrate mode)
 - #125819 (Various `HirTyLowerer` cleanups)
 - #125861 (rustc_codegen_ssa: fix `get_rpath_relative_to_output` panic when lib only contains file name)
 - #125911 (delete bootstrap build before switching to bumped rustc)
 - #125921 (coverage: Carve out hole spans in a separate early pass)
 - #125940 (std::unix::fs::get_path: using fcntl codepath for netbsd instead.)
 - #126022 (set `has_unconstrained_ty_var` when generalizing aliases in bivariant contexts)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-05 18:40:07 +00:00
Matthias Krüger fa58891f99
Rollup merge of #126032 - ChrisDenton:update-docs, r=joboet
Update description of the `IsTerminal` example

The example code prompts for input if stdin is a terminal.
2024-06-05 18:21:15 +02:00
Matthias Krüger 1c17449ae3
Rollup merge of #126008 - Zalathar:fulldeps-19371, r=jieyouxu
Port `tests/run-make-fulldeps/issue-19371` to ui-fulldeps

This test can run as an ordinary `tests/ui-fulldeps` test, with the help of some additional header variable substitutions to supply a sysroot and linker.

---

Unlike #125973, this test appears to be testing something vaguely useful and breakable, which is why I didn't just delete it.
2024-06-05 18:21:15 +02:00
Matthias Krüger 33c02c3712
Rollup merge of #125893 - cjgillot:gvn-newops, r=oli-obk
Handle all GVN binops in a single place.

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->

Addresses https://github.com/rust-lang/rust/pull/125359/files#r1608185319
r? ``@oli-obk``
2024-06-05 18:21:14 +02:00
Matthias Krüger 9c8e46d08a
Rollup merge of #125871 - fmease:fix-orphanck-opaques, r=lcnr
Orphanck[old solver]: Consider opaque types to never cover type parameters

This fixes an oversight of mine in #117164. The change itself has already been FCP'ed.

This only affects the old solver, the next solver already correctly rejects the added test since #117164.

r? ``@lcnr``
2024-06-05 18:21:14 +02:00
Matthias Krüger fcc0b641e9
Rollup merge of #125800 - fortanix:raoul/rte-99-fix_mut_static_task_queue, r=jethrogb
Fix `mut` static task queue in SGX target

[PR 125046](https://github.com/rust-lang/rust/pull/125046) prevents mutable references to statics with `#[linkage]`. Such a construct was used with the tests for the `x86_64-fortanix-unknown-sgx` target. This PR fixes this and cleans up code a bit in 5 steps. Each step passes CI:

- The `mut` static is removed, and `Task` explicitly implements `Send`
- Renaming of the `task_queue::lock` function
- Pass function for `Thread` as `Send` to `Thread::imp` and update when `Packet<'scope, T>` implements `Sync`
- Storing `Task::p` as a type that implements `Send`
- Letting the compiler auto implement `Send` for `Task`

cc: ``@jethrogb``
2024-06-05 18:21:13 +02:00
Matthias Krüger dd2e1a3b34
Rollup merge of #126022 - lcnr:generalize-alias-bivariant, r=compiler-errors
set `has_unconstrained_ty_var` when generalizing aliases in bivariant contexts

this previously prevented the `regression-31157` benchmark from building

r? `@compiler-errors`
2024-06-05 18:21:12 +02:00
Matthias Krüger 36cab1260d
Rollup merge of #125672 - Lokathor:update-miri-result-ffi, r=RalfJung
Add more ABI test cases to miri (RFC 3391)

Part of https://github.com/rust-lang/rust/issues/110503

cc `@RalfJung`
2024-06-05 18:21:12 +02:00
Matthias Krüger 808ad606f1
Rollup merge of #125940 - devnexen:unix_fs_netbsd_get_path, r=cuviper
std::unix::fs::get_path: using fcntl codepath for netbsd instead.

on netbsd, procfs is not as central as on linux/solaris thus can be perfectly not mounted.
Thus using fcntl with F_GETPATH, the kernel deals with MAXPATHLEN internally too.
2024-06-05 18:21:12 +02:00
Matthias Krüger edba40122a
Rollup merge of #125648 - lqd:rustsrc, r=pietroalbini
Remove unused(?) `~/rustsrc` folder from docker script

Every time I run a docker image, the script creates an empty `~/rustsrc` folder. It doesn't seem to be referenced anywhere else, so I'd like to remove it.

Incidentally, this also documents DIST_TRY_BUILD as I fail to find it from a simple search any time I look for it to eg enable tests on try builds.
2024-06-05 18:21:12 +02:00
Matthias Krüger 79bb336b9c
Rollup merge of #125921 - Zalathar:buckets, r=oli-obk
coverage: Carve out hole spans in a separate early pass

When extracting spans from MIR for use in coverage instrumentation, we sometimes need to identify *hole spans* (currently just closures), and carve up the other spans so that they don't overlap with holes.

This PR simplifies the main coverage-span-refiner by extracting the hole-carving process into a separate early pass. That pass produces a series of independent buckets, and we run the span-refiner on each bucket separately.

There is almost no difference in the resulting mappings, other than in some edge cases involving macros.
2024-06-05 18:21:11 +02:00
Matthias Krüger 9abf8b105e
Rollup merge of #125622 - oli-obk:define_opaque_types15, r=compiler-errors
Winnow private method candidates instead of assuming any candidate of the right name will apply

partially reverts https://github.com/rust-lang/rust/pull/60721

My original motivation was just to avoid the `delay_span_bug` (by attempting to thread the `ErrorGuaranteed` through to here). But then I realized that the error message is wrong. It refers to the `Foo<A>::foo` instead of `Foo<B>::foo`. This is almost invisible, because both functions are the same, but on different lines, so `-Zui-testing` makes it so the test is the same no matter which of these two functions is referenced.

But there's a much more obvious bug: If `Foo<B>` does not have a `foo` method at all, but `Foo<A>` has a private `foo` method, then we'll refer to that one. This has now been fixed, and we report a normal `method not found` error.

The way this is done is by creating a list of all possible private functions (just like we create a list of the public functions that can actually be called), and then winnowing it by analyzing where bounds and `Self` types to see if any of the found methods can actually apply (again, just like with the list of public functions).

I wonder if there is room for doing the same thing with unstable functions instead of running all of method resolution twice.

r? ``@compiler-errors`` for method resolution stuff
2024-06-05 18:21:11 +02:00
Matthias Krüger ebc66fd04d
Rollup merge of #125911 - onur-ozkan:wipe-broken-cache, r=albertlarsan68
delete bootstrap build before switching to bumped rustc

Technically, wiping bootstrap builds can increase the build time. But in practice, trying to manually resolve post-bump issues and even accidentally removing the entire build directory will result in a much greater loss of time. After all, the bootstrap build process is not a particularly lengthy operation.

Workaround for #125578
2024-06-05 18:21:11 +02:00
Matthias Krüger 69a8c139f1
Rollup merge of #124840 - bvanjoi:fix-124490, r=petrochenkov
resolve: mark it undetermined if single import is not has any bindings

- Fixes #124490
- Fixes #125013

This issue arises from incorrect resolution updates, for example:

```rust
mod a {
    pub mod b {
        pub mod c {}
    }
}

use a::*;

use b::c;
use c as b;

fn main() {}
```

1. In the first loop, binding `(root, b)` is refer to `root:🅰️:b` due to `use a::*`.
    1. However, binding `(root, c)` isn't defined by `use b::c` during this stage because `use c as b` falls under the `single_imports` of `(root, b)`, where the `imported_module` hasn't been computed yet. This results in marking the `path_res` for `b` as `Indeterminate`.
    2. Then, the `imported_module` for `use c as b` will be recorded.
2. In the second loop, `use b::c` will be processed again:
    1. Firstly, it attempts to find the `path_res` for `(root, b)`.
    2. It will iterate through the `single_imports` of `use b::c`, encounter `use c as b`, attempt to resolve `c` in `root`, and ultimately return `Err(Undetermined)`, thus passing the iterator.
    3. Use the binding `(root, b)` -> `root:🅰️:b` introduced by `use a::*` and ultimately return `root:🅰️:b` as the `path_res` of `b`.
    4. Then define the binding `(root, c)` -> `root:🅰️🅱️:c`.
3. Then process `use c as b`, update the resolution for `(root, b)` to refer to `root:🅰️🅱️:c`, ultimately causing inconsistency.

In my view, step `2.2` has an issue where it should exit early, similar to the behavior when there's no `imported_module`. Therefore, I've added an attribute called `indeterminate` to `ImportData`. This will help us handle only those single imports that have at least one determined binding.

r? ``@petrochenkov``
2024-06-05 18:21:11 +02:00
Matthias Krüger e2ea7d82b1
Rollup merge of #125861 - name1e5s:fix/rpath_null_panic, r=michaelwoerister
rustc_codegen_ssa: fix `get_rpath_relative_to_output` panic when lib only contains file name

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->

When compiles program with `-C rpath=yes` but with no output filename specified, or with filename ONLY, we will get an ICE for now. Fix it by treat empty `output` path in `get_rpath_relative_to_output`  as current dir.

Before this patch:

```bash
rustc -C prefer_dynamic=yes -C rpath=yes -O h.rs  # ICE, no output filename specified
rustc -o hello -C prefer_dynamic=yes -C rpath=yes -O h.rs # ICE, output filename has no path
rustc -o ./hello -C prefer_dynamic=yes -C rpath=yes -O h.rs # Works
```

All those examples work after the patch.

Close #119571.
Close #125785.
2024-06-05 18:21:10 +02:00
Matthias Krüger 94c19c6522
Rollup merge of #125819 - oli-obk:localize, r=fmease
Various `HirTyLowerer` cleanups

Previously there was some ad-hoc specialization going on, because you could call `allows_infer`, which basically was deciding between whether the trait object was backed by `FnCtxt` or by `ItemCtxt`. I moved all the different logic into dedicated methods on `HirTyLowerer` and removed `allows_infer`

best reviewed commit-by-commit
2024-06-05 18:21:10 +02:00
Matthias Krüger e1745122ae
Rollup merge of #125792 - compiler-errors:dont-drop-upcast-cand, r=lcnr
Don't drop `Unsize` candidate in intercrate mode

Fixes #125767
2024-06-05 18:21:09 +02:00
Matthias Krüger efc3fdc74d
Rollup merge of #125505 - aDotInTheVoid:middle-idl, r=pnkfelix
Add intra-doc-links to rustc_middle crate-level docs.

Makes it slightly faster to find these modules, as you don't need to hunt for them in the big list.
2024-06-05 18:21:09 +02:00
Matthias Krüger 49f950434b
Rollup merge of #125407 - pacak:no-lending-iterators, r=pnkfelix
Detect when user is trying to create a lending `Iterator` and give a custom explanation

The scope for this diagnostic is to detect lending iterators specifically and it's main goal is to help beginners to understand that what they are trying to implement might not be possible for `Iterator` trait specifically.

I ended up to changing the wording from originally proposed in the ticket because it might be misleading otherwise: `Data` might have a lifetime parameter but it can be unrelated to items user is planning to return.

Fixes https://github.com/rust-lang/rust/issues/125337
2024-06-05 18:21:08 +02:00
Matthias Krüger 28deff4244
Rollup merge of #124746 - OliverKillane:E0582-explain-assoc-types-improvement, r=pnkfelix
`rustc --explain E0582` additional example

## Context
*From #124744*

Expands the example for E0582, an error ensuring that lifetime in a function's return type is sufficiently constrained (e.g. actually tied to some input type), to show an additional example where one sees the lifetime occurring syntactically among the relevant function input types, but is nonetheless rejected by rustc because a syntactic occurrence is not always sufficient.
2024-06-05 18:21:08 +02:00
Oli Scherer a0358f44b3 Also support generic constants 2024-06-05 15:40:11 +00:00
Oli Scherer 22d0073d47 Don't walk the bodies of free constants for reachability. 2024-06-05 15:40:11 +00:00
Oli Scherer 50b07aa899 add reachability test for const bodies 2024-06-05 15:40:11 +00:00
bors c1dba09f26 Auto merge of #126005 - weihanglo:update-cargo, r=weihanglo
Update cargo

9 commits in 7a6fad0984d28c8330974636972aa296b67c4513..34a6a87d8a2330d8c9d578f927489689328a652d
2024-05-31 22:26:03 +0000 to 2024-06-04 15:31:01 +0000
- Silence the warning about forgetting the vendoring (rust-lang/cargo#13886)
- fix(vendor): Ensure sort happens for vendor (rust-lang/cargo#14004)
- fix(add): Avoid escaping double-quotes by using string literals (rust-lang/cargo#14006)
- refactor(source): Split `RecursivePathSource` out of `PathSource` (rust-lang/cargo#13993)
- doc: Add README for resolver-tests (rust-lang/cargo#13977)
- Allows the default git/gitoxide configuration to be obtained from the ENV and config (rust-lang/cargo#13687)
- refactor: Transition direct assertions from cargo-test-support to snapbox (rust-lang/cargo#13980)
- Fix: Skip deserialization of unrelated fields with overlapping name (rust-lang/cargo#14000)
- chore(deps): update alpine docker tag to v3.20 (rust-lang/cargo#13996)

r? ghost
2024-06-05 15:39:16 +00:00
Chris Denton e704858b0b
Update description of the IsTerminal example 2024-06-05 14:28:42 +00:00
Ben Kimock b710404f3b Update the interpreter to handle the new cases 2024-06-05 09:04:37 -04:00
bors db8aca4812 Auto merge of #126016 - workingjubilee:rollup-nh6ehbz, r=workingjubilee
Rollup of 12 pull requests

Successful merges:

 - #123168 (Add `size_of` and `size_of_val` and `align_of` and `align_of_val` to the prelude)
 - #125273 (bootstrap: implement new feature `bootstrap-self-test`)
 - #125683 (Rewrite `suspicious-library`, `resolve-rename` and `incr-prev-body-beyond-eof` `run-make` tests in `rmake.rs` format)
 - #125815 (`rustc_parse` top-level cleanups)
 - #125903 (rustc_span: Inline some hot functions)
 - #125906 (Remove a bunch of redundant args from `report_method_error`)
 - #125920 (Allow static mut definitions with #[linkage])
 - #125982 (Make deleting on LinkedList aware of the allocator)
 - #125995 (Use inline const blocks to create arrays of `MaybeUninit`.)
 - #125996 (Closures are recursively reachable)
 - #126003 (Add a co-maintainer for the two ARMv4T targets)
 - #126004 (Add another test for hidden types capturing lifetimes that outlive but arent mentioned in substs)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-06-05 11:32:18 +00:00
lcnr a8e091de4a bivariant alias: set has_unconstrained_ty_var 2024-06-05 11:48:03 +02:00
Oli Scherer c8a331ac52 Unify optional param info with object lifetime default boolean into an enum that exhaustively supports all call sites 2024-06-05 09:16:55 +00:00
Oli Scherer 4146b8280a Remove some unnecessary explicit lifetimes 2024-06-05 09:16:55 +00:00
Oli Scherer 78706740d5 Remove allows_infer now that every use of it is delegated to HirTyLowerer 2024-06-05 09:16:55 +00:00
Oli Scherer 6a2e15a6f0 Only collect infer vars to error about in case infer vars are actually forbidden 2024-06-05 09:16:55 +00:00
Oli Scherer abd308b886 Remove an Option and instead eagerly create error lifetimes 2024-06-05 09:16:55 +00:00
Oli Scherer 9d387d14e0 Simplify some code paths and remove an unused field
`ct_infer` and `lower_ty` will correctly result in an error constant or type respectively, as they go through a `HirTyLowerer` method (just like `HirTyLowerer::allow_infer` is a method implemented by both implementors
2024-06-05 08:43:37 +00:00
Oli Scherer dc020ae5d8 Use a LocalDefId for HirTyLowerer::item_def_id, since we only ever (can) use it for local items 2024-06-05 08:43:37 +00:00
Jubilee f12fe3a33e
Rollup merge of #126004 - compiler-errors:captures-soundness-test, r=lcnr
Add another test for hidden types capturing lifetimes that outlive but arent mentioned in substs

Another test to make sure future implementations of https://github.com/rust-lang/rust/pull/116040 don't have any subtle unsoundness 🤔

r? types
2024-06-05 01:14:35 -07:00