5353 Commits

Author SHA1 Message Date
Nicholas Nethercote
200f56d605 Add itertools to [workspace.dependencies]. 2025-08-27 14:21:21 +10:00
Nicholas Nethercote
c50d2cc807 Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
Nicholas Nethercote
777e2d6a2a Add thin-vec to newly added [workspace.dependencies]. 2025-08-27 13:59:32 +10:00
Guillaume Gomez
2708b26a3b
Rollup merge of #145481 - mu001999-contrib:fix/closure-sugg, r=SparrowLii
Add parentheses for closure when suggesting calling closure

Fixes rust-lang/rust#145404
2025-08-26 16:34:11 +02:00
lcnr
d6a18e1867 change non-defining use error message 2025-08-25 14:20:18 +02:00
lcnr
14b0ba6a05 support non-defining uses in HIR typeck 2025-08-25 14:20:18 +02:00
bors
69b76df90c Auto merge of #145706 - lcnr:uniquification, r=BoxyUwU
change HIR typeck region uniquification handling approach

rust-lang/rust#144405 causes structural lookup of opaque types to not work during HIR typeck, so instead avoid uniquifying goals and instead only reprove them if MIR borrowck actually encounters an error.

This doesn't perfectly maintain the property that HIR typeck succeeding implies that MIR typeck succeeds, instead weakening this check to only guarantee that HIR typeck implies that MIR typeck succeeds modulo region uniquification. This means we still get the actually desirable ICEs if we MIR building is broken or we forget to check some property in HIR typeck, without having to deal with the fallout of uniquification in HIR typeck itself.

We report errors using the original obligation sources of HIR typeck so diagnostics aren't that negatively impacted either.

Here's the history of region uniquification while working on the new trait solver:
- rust-lang/rust#107981
- rust-lang/rust#110180
- rust-lang/rust#114117
- rust-lang/rust#130821
- rust-lang/rust#144405
- rust-lang/rust#145706 <- we're here 🎉

r? `@BoxyUwU`
2025-08-23 20:16:58 +00:00
Jacob Pratt
15eeddee1f
Rollup merge of #145641 - estebank:point-at-type-in-e0277, r=davidtwco
On E0277, point at type that doesn't implement bound

When encountering an unmet trait bound, point at local type that doesn't implement the trait:

```
error[E0277]: the trait bound `Bar<T>: Foo` is not satisfied
  --> $DIR/issue-64855.rs:9:19
   |
LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ;
   |                   ^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
   |
help: the trait `Foo` is not implemented for `Bar<T>`
  --> $DIR/issue-64855.rs:9:1
   |
LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ;
   | ^^^^^^^^^^^^^^^^^
```
2025-08-22 22:00:52 -04:00
Esteban Küber
049c32797b On E0277, point at type that doesn't implement bound
When encountering an unmet trait bound, point at local type that doesn't implement the trait:

```
error[E0277]: the trait bound `Bar<T>: Foo` is not satisfied
  --> $DIR/issue-64855.rs:9:19
   |
LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ;
   |                   ^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound
   |
help: the trait `Foo` is not implemented for `Bar<T>`
  --> $DIR/issue-64855.rs:9:1
   |
LL | pub struct Bar<T>(<Self as Foo>::Type) where Self: ;
   | ^^^^^^^^^^^^^^^^^
```
2025-08-22 17:55:15 +00:00
lcnr
17ac2fc96d change HIR typeck unification handling approach 2025-08-22 13:39:38 +02:00
Luca Versari
291da71b2a Add an experimental unsafe(force_target_feature) attribute.
This uses the feature gate for
https://github.com/rust-lang/rust/issues/143352, but is described in
https://github.com/rust-lang/rfcs/pull/3820 which is strongly tied to
the experiment.
2025-08-22 01:26:26 +02:00
bors
57e620e56b Auto merge of #145701 - jhpratt:rollup-a0kg33p, r=jhpratt
Rollup of 19 pull requests

Successful merges:

 - rust-lang/rust#143383 (stabilize `const_array_each_ref`)
 - rust-lang/rust#144758 ([Doc] Add links to the various collections)
 - rust-lang/rust#144915 (Defer tail call ret ty equality to check_tail_calls)
 - rust-lang/rust#145256 (Add new `--test-codegen-backend` bootstrap option)
 - rust-lang/rust#145297 (fix(debuginfo): handle false positives in overflow check)
 - rust-lang/rust#145390 (Shorten some dependency chains in the compiler)
 - rust-lang/rust#145415 (std_detect: RISC-V: implement implication to "C")
 - rust-lang/rust#145525 (stdlib: Replace typedef -> type alias in doc comment)
 - rust-lang/rust#145590 (Prevent impossible combinations in `ast::ModKind`.)
 - rust-lang/rust#145593 (UnsafePinned::raw_get: sync signature with get)
 - rust-lang/rust#145621 (Fix some doc typos)
 - rust-lang/rust#145627 (Unconditionally-const supertraits are considered not dyn compatible)
 - rust-lang/rust#145642 (Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause)
 - rust-lang/rust#145650 (Fix JS search scripts path)
 - rust-lang/rust#145654 (Download CI GCC into the correct directory)
 - rust-lang/rust#145662 (Enforce correct number of arguments for `"x86-interrupt"` functions)
 - rust-lang/rust#145673 (Add flock support for cygwin)
 - rust-lang/rust#145674 (Enable triagebot `[review-changes-since]` feature)
 - rust-lang/rust#145678 (Fix typo in docstring)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-21 07:03:07 +00:00
Jacob Pratt
0af35f6a3b
Rollup merge of #145642 - xizheyin:145611, r=lcnr
Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause

Partially fix rust-lang/rust#145611, but we should do something make cycle in this situation ICE.

Instead of using a query, call `&tcx.resolutions(()).effective_visibilities`.

r? `````@lcnr`````

cc `````@compiler-errors`````
2025-08-21 01:12:22 -04:00
Jacob Pratt
64c43edffe
Rollup merge of #145627 - compiler-errors:const-supertrait-dyn-compat, r=fee1-dead
Unconditionally-const supertraits are considered not dyn compatible

Let's save some space in the design of const traits by making `dyn Trait` where `trait Trait: const Super` not dyn compatible.

Such a trait cannot satisfy `dyn Trait: Trait`; we could in the future make this dyn compatible but *NOT* implement `Trait`, but that's a bit weird and seems like it needs to be independently justified moving forward.

Fixes https://github.com/rust-lang/rust/issues/145198

r? fee1-dead
2025-08-21 01:12:21 -04:00
Michael Goulet
e57e5f02b8 Unconditionally-const supertraits are considered not dyn compatible 2025-08-20 15:41:42 +00:00
xizheyin
27e6726cb8
Do not use effective_visibilities query for Adt types of a local trait while proving a where-clause
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-08-20 18:29:01 +08:00
lcnr
8365ad17da handle opaque types before region inference 2025-08-20 11:04:38 +02:00
许杰友 Jieyou Xu (Joe)
4090d98b67
Rollup merge of #145537 - zachs18:metasized-negative-bound-fix, r=davidtwco
Do not consider a `T: !Sized` candidate to satisfy a `T: !MetaSized` obligation.

This example should fail to compile (and does under this PR, with the old and new solvers), but currently compiles successfully ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=6e0e5d0ae0cdf0571dea97938fb4a86d)), because (IIUC) the old solver's `lazily_elaborate_sizedness_candidate`/callers and the new solver's `TraitPredicate::fast_reject_assumption`/`match_assumption` consider a `T: _ Sized` candidate to satisfy a `T: _ MetaSized` obligation, for either polarity `_`, when that should only hold for positive polarity.

```rs
#![feature(negative_bounds)]
#![feature(sized_hierarchy)]

use std::marker::MetaSized;

fn foo<T: !MetaSized>() {}

fn bar<T: !Sized + MetaSized>() {
    foo::<T>();
    //~^ ERROR the trait bound `T: !MetaSized` is not satisfied // error under this PR
}
```

Only observable with the internal-only `feature(negative_bounds)`, so might just be "wontfix".

This example is added as a test in this PR (as well as testing that `foo<()>` and `foo<str>` are disallowed for `fn foo<T: !MetaSized`).

cc `@davidtwco` for `feature(sized_hierarchy)`

Maybe similar to 91c53c9 from <https://github.com/rust-lang/rust/pull/143307>
2025-08-19 19:45:40 +08:00
许杰友 Jieyou Xu (Joe)
99de64bac7
Rollup merge of #145338 - lcnr:coroutine-witness-yikes, r=compiler-errors
actually provide the correct args to coroutine witnesses

rust-lang/rust#145194 accidentally provided all arguments of the closure to the witness, but the witness only takes the generic parameters of the defining scope: 216cdb7b22/compiler/rustc_hir_typeck/src/closure.rs (L164)

Fixes rust-lang/rust#145288
2025-08-19 19:45:30 +08:00
Zachary S
c7cd1b3b9d Do not consider a T: !Sized candidate to satisfy a T: !MetaSized obligation. 2025-08-17 13:37:32 -05:00
bors
425a9c0a0e Auto merge of #145284 - nnethercote:type_name-print-regions, r=lcnr
Print regions in `type_name`.

Currently they are skipped, which is a bit weird, and it sometimes causes malformed output like `Foo<>` and `dyn Bar<, A = u32>`.

Most regions are erased by the time `type_name` does its work. So all regions are now printed as `'_` in non-optional places. Not perfect, but better than the status quo.

`c_name` is updated to trim lifetimes from MIR pass names, so that the `PASS_NAMES` sanity check still works. It is also renamed as `simplify_pass_type_name` and made non-const, because it doesn't need to be const and the non-const implementation is much shorter.

The commit also renames `should_print_region` as `should_print_optional_region`, which makes it clearer that it only applies to some regions.

Fixes rust-lang/rust#145168.

r? `@lcnr`
2025-08-17 10:24:20 +00:00
Mu001999
5e8c2c3aec Add parentheses for closure when suggesting calling closure 2025-08-16 15:07:38 +08:00
Stuart Cook
8f1202cef2
Rollup merge of #145235 - compiler-errors:comment, r=BoxyUwU
Minor `[const]` tweaks

Self explanatory
2025-08-15 16:16:38 +10:00
Stuart Cook
1eeb8e8b15
Rollup merge of #122661 - estebank:assert-macro-span, r=petrochenkov
Change the desugaring of `assert!` for better error output

In the desugaring of `assert!`, we now expand to a `match` expression instead of `if !cond {..}`.

The span of incorrect conditions will point only at the expression, and not the whole `assert!` invocation.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091.rs:2:13
   |
LL |     assert!(1,1);
   |             ^ expected `bool`, found integer
```

We no longer mention the expression needing to implement the `Not` trait.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091-2.rs:15:13
   |
LL |     assert!(x, x);
   |             ^ expected `bool`, found `BytePos`
```

Now `assert!(val)` desugars to:

```rust
match val {
    true => {},
    _ => $crate::panic::panic_2021!(),
}
```

Fix #122159.
2025-08-15 16:16:29 +10:00
Nicholas Nethercote
8296ad0456 Print regions in type_name.
Currently they are skipped, which is a bit weird, and it sometimes
causes malformed output like `Foo<>` and `dyn Bar<, A = u32>`.

Most regions are erased by the time `type_name` does its work. So all
regions are now printed as `'_` in non-optional places. Not perfect, but
better than the status quo.

`c_name` is updated to trim lifetimes from MIR pass names, so that the
`PASS_NAMES` sanity check still works. It is also renamed as
`simplify_pass_type_name` and made non-const, because it doesn't need
to be const and the non-const implementation is much shorter.

The commit also renames `should_print_region` as
`should_print_optional_region`, which makes it clearer that it only
applies to some regions.

Fixes #145168.
2025-08-14 21:13:06 +10:00
Guillaume Gomez
ad21c6d898
Rollup merge of #145266 - camsteffen:reduce-queries, r=petrochenkov
Reduce some queries around associated items
2025-08-14 11:39:38 +02:00
Guillaume Gomez
e7e3a37e9a
Rollup merge of #144949 - nnethercote:more-Printer-cleanups, r=davidtwco
More `Printer` cleanups

A sequel to rust-lang/rust#144776.

r? ```@davidtwco```
2025-08-13 18:42:59 +02:00
Cameron Steffen
d4eb0947f1 Cleanup assoc parent utils 2025-08-13 09:33:09 -05:00
lcnr
f979bf018f fn new_coroutine_witness_for_coroutine woops 2025-08-13 14:10:19 +02:00
Esteban Küber
c439a59dbd Change the desugaring of assert! for better error output
In the desugaring of `assert!`, we now expand to a `match` expression
instead of `if !cond {..}`.

The span of incorrect conditions will point only at the expression, and not
the whole `assert!` invocation.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091.rs:2:13
   |
LL |     assert!(1,1);
   |             ^ expected `bool`, found integer
```

We no longer mention the expression needing to implement the `Not` trait.

```
error[E0308]: mismatched types
  --> $DIR/issue-14091-2.rs:15:13
   |
LL |     assert!(x, x);
   |             ^ expected `bool`, found `BytePos`
```

`assert!(val)` now desugars to:

```rust
match val {
    true => {},
    _ => $crate::panic::panic_2021!(),
}
```

Fix #122159.

We make some minor changes to some diagnostics to avoid span overlap on
type mismatch or inverted "expected"/"found" on type errors.

We remove some unnecessary parens from core, alloc and miri.

address review comments
2025-08-12 16:30:48 +00:00
Cameron Steffen
bf266dc834 Propagate TraitImplHeader to hir 2025-08-11 17:05:42 -05:00
Stuart Cook
ad14de2375
Rollup merge of #145194 - compiler-errors:coro-witness-re, r=lcnr
Ignore coroutine witness type region args in auto trait confirmation

## The problem

Consider code like:

```
async fn process<'a>() {
    Box::pin(process()).await;
}

fn require_send(_: impl Send) {}

fn main() {
    require_send(process());
}
```

When proving that the coroutine `{coroutine@process}::<'?0>: Send`, we end up instantiating a nested goal `{witness@process}::<'?0>: Send` by synthesizing a witness type from the coroutine's args:

Proving a coroutine witness type implements an auto trait requires looking up the coroutine's witness types. The witness types are a binder that look like `for<'r> { Pin<Box<{coroutine@process}::<'r>>> }`. We instantiate this binder with placeholders and prove `Send` on the witness types. This ends up eventually needing to prove something like `{coroutine@process}::<'!1>: Send`. Repeat this process, and we end up in an overflow during fulfillment, since fulfillment does not use freshening.

This can be visualized with a trait stack that ends up looking like:
* `{coroutine@process}::<'?0>: Send`
  * `{witness@process}::<'?0>: Send`
    * `Pin<Box<{coroutine@process}::<'!1>>>: Send`
      * `{coroutine@process}::<'!1>: Send`
        * ...
          * `{coroutine@process}::<'!2>: Send`
            * `{witness@process}::<'!2>: Send`
              * ...
                * overflow!

The problem here specifically comes from the first step: synthesizing a witness type from the coroutine's args.

## Why wasn't this an issue before?

Specifically, before 63f6845e570305a92eaf855897768617366164d6, this wasn't an issue because we were instead extracting the witness from the coroutine type itself. It turns out that given some `{coroutine@process}::<'?0>`, the witness type was actually something like `{witness@process}::<'erased>`!

So why do we end up with a witness type with `'erased` in its args? This is due to the fact that opaque type inference erases all regions from the witness. This is actually explicitly part of opaque type inference -- changing this to actually visit the witness types actually replicates this overflow even with 63f6845e570305a92eaf855897768617366164d6 reverted:

ca77504943/compiler/rustc_borrowck/src/type_check/opaque_types.rs (L303-L313)

To better understand this difference and how it avoids a cycle, if you look at the trait stack before 63f6845e570305a92eaf855897768617366164d6, we end up with something like:

* `{coroutine@process}::<'?0>: Send`
  * `{witness@process}::<'erased>: Send` **<-- THIS CHANGED**
    * `Pin<Box<{coroutine@process}::<'!1>>>: Send`
      * `{coroutine@process}::<'!1>: Send`
        * ...
          * `{coroutine@process}::<'erased>: Send` **<-- THIS CHANGED**
            * `{witness@process}::<'erased>: Send` **<-- THIS CHANGED**
              * coinductive cycle! 🎉

## So what's the fix?

This hack replicates the behavior in opaque type inference to erase regions from the witness type, but instead erasing the regions during auto trait confirmation. This is kinda a hack, but is sound. It does not need to be replicated in the new trait solver, of course.

---

I hope this explanation makes sense.

We could beta backport this instead of the revert https://github.com/rust-lang/rust/pull/145193, but then I'd like to un-revert that on master in this PR along with landing this this hack. Thoughts?

r? lcnr
2025-08-11 18:22:33 +10:00
Stuart Cook
4e87b74810
Rollup merge of #144156 - compiler-errors:dtorck-upvars, r=lcnr
Check coroutine upvars in dtorck constraint

Fix rust-lang/rust#144155.

This PR fixes an unsoundness where we were not considering coroutine upvars as drop-live if the coroutine interior types (witness types) had nothing which required drop.

In the case that the coroutine does not have any interior types that need to be dropped, then we don't need to treat all of the upvars as use-live; instead, this PR uses the same logic as closures, and descends into the upvar types to collect anything that must be drop-live. The rest of this PR is reworking the comment to explain the behavior here.

r? `@lcnr` or reassign 😸

---

Just some thoughts --- a proper fix for this whole situation would be to consider `TypingMode` in the `needs_drop` function, and just calling `coroutine_ty.needs_drop(tcx, typing_env)` in the dtorck constraint check.

During MIR building, we should probably use a typing mode that stalls the local coroutines and considers them to be unconditionally drop, or perhaps just stall *all* coroutines in analysis mode. Then in borrowck mode, we can re-check `needs_drop` but descend into witness types properly. https://github.com/rust-lang/rust/pull/144158 implements this experimentally.

This is a pretty involved fix, and conflicts with some in-flight changes (rust-lang/rust#144157) that I have around removing coroutine witnesses altogether. I'm happy to add a FIXME to rework this whole approach, but I don't want to block this quick fix since it's obviously more correct than the status-quo.
2025-08-11 18:22:31 +10:00
Michael Goulet
b5cee774ac Remove unnecessary UnsatisfiedConst reporting logic 2025-08-11 01:46:42 +00:00
Esteban Küber
48816e7493 Do not point at macro invocation when providing inference context 2025-08-10 21:55:02 +00:00
Stuart Cook
b30fe4bb8b
Rollup merge of #145147 - fee1-dead-contrib:push-mxxpmlpmzmsz, r=compiler-errors
rename `TraitRef::from_method` to `from_assoc`

also add a note to `GenericArgs::truncate_to`
2025-08-10 19:45:53 +10:00
Michael Goulet
b4aa629186 Ignore coroutine witness type region args in auto trait confirmation 2025-08-10 02:21:48 +00:00
bors
41ede7bd9b Auto merge of #145146 - fee1-dead-contrib:push-zmqrkurlzrxy, r=nnethercote
remove `P`

Previous work: rust-lang/rust#141603
MCP: https://github.com/rust-lang/compiler-team/issues/878

cc `@nnethercote`
2025-08-09 23:27:55 +00:00
Deadbeef
ad1113f87e remove P 2025-08-09 15:47:01 +08:00
Deadbeef
2736d66a1f rename TraitRef::from_method to from_assoc
also add a note to `GenericArgs::truncate_to`
2025-08-09 14:22:01 +08:00
Stuart Cook
d88a309114
Rollup merge of #145134 - camsteffen:indirect-assoc-parent, r=cjgillot
Reduce indirect assoc parent queries

Simplify some code that uses multiple queries to get the parent of an associated item.
2025-08-09 13:58:55 +10:00
Cameron Steffen
eec8585f65 Reduce indirect assoc parent queries 2025-08-08 17:28:19 -05:00
Michael Goulet
d47150111d Check coroutine upvars and in dtorck constraint 2025-08-08 18:53:18 +00:00
Esteban Küber
99196657fc Use tcx.short_string() in more diagnostics
`TyCtxt::short_string` ensures that user visible type paths aren't overwhelming on the terminal output, and properly saves the long name to disk as a side-channel. We already use these throughout the compiler and have been using them as needed when users find cases where the output is verbose. This is a proactive search of some cases to use `short_string`.

We add support for shortening the path of "trait path only".

Every manual use of `short_string` is a bright marker that that error should be using structured diagnostics instead (as they have proper handling of long types without the maintainer having to think abou tthem).

When we don't actually print out a shortened type we don't need the "use `--verbose`" note.

On E0599 show type identity to avoid expanding the receiver's generic parameters.

Unify wording on `long_ty_path` everywhere.
2025-08-07 21:18:00 +00:00
Nicholas Nethercote
b8adda6194 Rename some Printer methods.
I find these name clearer, and starting them all with `print_` makes
things more consistent.
2025-08-06 12:58:20 +10:00
Nicholas Nethercote
d76eef481e Simplify multiple things.
- `same_path` can just be a `bool`.
- `expected` and `found` are only needed inside the block.
- Neaten a comment.
2025-08-05 19:11:37 +10:00
Nicholas Nethercote
b0c36dd4c7 Rename most of the printers.
Three of them are named `AbsolutePathPrinter`, which is confusing, so
give those names that better indicate how they are used. And then there
is `SymbolPrinter` and `SymbolMangler`, which are renamed as
`LegacySymbolMangler` and `V0SymbolMangler`, better indicating their
similarity.
2025-08-05 19:11:37 +10:00
Samuel Tardieu
a1e41a0227
Rollup merge of #144776 - nnethercote:Printer-cleanups, r=cjgillot
`Printer` cleanups

The trait `Printer` is implemented by six types, and the sub-trait `PrettyPrinter` is implemented by three of those types. The traits and the impls are complex and a bit of a mess. This PR starts to clean them up.

r? ``@davidtwco``
2025-08-05 03:51:34 +02:00
Stuart Cook
7307dc0ca1
Rollup merge of #144694 - compiler-errors:with-self-ty, r=SparrowLii
Distinguish prepending and replacing self ty in predicates

There are two kinds of functions called `with_self_ty`:
1. Prepends the `Self` type onto an `ExistentialPredicate` which lacks it in its internal representation.
2. Replaces the `Self` type of an existing predicate, either for diagnostics purposes or in the new trait solver when normalizing that self type.

This PR distinguishes these two because I often want to only grep for one of them. Namely, let's call it `with_replaced_self_ty` when all we're doing is replacing the self type.
2025-08-04 14:58:09 +10:00
Nicholas Nethercote
2434d8cecf Remove unused arg from path_append_impl.
None of the impls use it.
2025-08-03 19:58:59 +10:00