Commit Graph

5869 Commits

Author SHA1 Message Date
Nicholas Nethercote 2cf48841f1 Remove silly FmtPrinter<'tcx, 'tcx> instance.
This doesn't match any of the other uses.
2026-05-04 15:50:46 +10:00
Nicholas Nethercote 67ba480fdb Remove unused 'tcx lifetime from trait Print. 2026-05-04 14:04:55 +10:00
Jonathan Brouwer 43fbdfd2f4 Rollup merge of #153536 - zedddie:const-param-ty-unchecked-gate, r=BoxyUwU
Add `const_param_ty_unchecked` gate

Add `const_param_ty_unchecked` internal feature gate to skip `ConstParamTy_` trait enforcement on type. Provides an escape hatch for writing tests and examples that use const generics without needing to ensure all fields implement `ConstParamTy_`.

r? BoxyUwU
2026-05-03 19:23:52 +02:00
Jacob Pratt c3afa21a40 Rollup merge of #156065 - mejrs:spanculler, r=JonathanBrouwer
Remove unused spans from AttributeKind

Recently I noticed some spans in diagnostic attributes were never used. I went through and checked the other variants too.
2026-05-03 00:25:33 -04:00
Jacob Pratt b7c65513ba Rollup merge of #155940 - mejrs:filter, r=jdonszelmann
refactor rustc_on_unimplemented's filtering

Previously when you had a
```rust
pub struct Directive {
    pub is_rustc_attr: bool,
    pub condition: Option<OnUnimplementedCondition>,
    pub subcommands: ThinVec<Directive>,
    pub message: Option<(Span, FormatString)>,
    ...
}
```
that condition would control the emission of the message, label, notes etc. I've changed that to
```rust
pub struct Directive {
    pub is_rustc_attr: bool,
    pub filters: ThinVec<(Filter, Directive)>,
    pub message: Option<(Span, FormatString)>,
    ...
```

so that the message etc is always emitted, and there's a vec of tuples with (filter, directive) where the filter controls whether that directive is even emitted,  which i think is much clearer. That also makes it easier to not have to do the reverse iteration thing and this makes it so that notes are emitted in declaration order (with nonfiltered options always last).

The rename is because I plan on making it available to other diagnostic attributes at some point (very wip) so `OnUnimplementedCondition` and the like would have to be renamed anyway.
2026-05-03 00:25:32 -04:00
mejrs 061017274d rename "condition" to "filter" 2026-05-02 18:00:10 +02:00
mejrs 4a13f36265 Remove more spans from AttributeKind 2026-05-02 17:41:30 +02:00
Adwin White dbba04e032 use the new routine to eagerly normalize 2026-05-02 16:11:12 +08:00
Adwin White e82c3c80ef add a new normalization routine that can handle ambiguity 2026-05-02 16:11:12 +08:00
Guillaume Gomez e95df7d6d5 Rollup merge of #155749 - ShoyuVanilla:leakcheck-vis, r=lcnr
`-Znext-solver` Ignore region constraints from the nested goals in leakcheck

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/251
Fixes https://github.com/rust-lang/rust/issues/140577
Fixes https://github.com/rust-lang/rust/issues/153596
2026-05-02 04:12:05 +02:00
Shoyu Vanilla e43a1b5b44 -Znext-solver Ignore region constraints from the nested goals in leakcheck 2026-05-02 00:11:43 +09:00
Nicholas Nethercote 6d79bc6f01 Move feature* methods from parse mod to errors mod.
As the FIXME comment says, these no longer use `ParseSess` and so the
`parse` mod is not a good place for them. The `errors` mod is a better
home.
2026-04-30 12:02:33 +10:00
Jonathan Brouwer a0ef691e5a Rollup merge of #155861 - oli-obk:effect-bound-suggestions, r=jdonszelmann
Suggest `[const] Trait` bounds in more places

Right now we have some special logic in the const checker for emitting `[const] Trait` suggestions, but I'm trying to handle that similarly to how it is handled for normal `Trait` clauses. This is just a small step in how it will look on the UX side, which should make my follow-up PRs affect tests less and just be a refactoring
2026-04-29 23:51:35 +02:00
Shoyu Vanilla (Flint) dce5b97c52 Rollup merge of #155648 - ShoyuVanilla:maybe-stalled-on-couroutines, r=lcnr
`-Znext-solver` Propagate `stalled_on_coroutines` as a field in `Certainty::Maybe`

..instead of collecting them with a `ProofTreeVisitor`

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/270
2026-04-29 10:40:46 +09:00
Shoyu Vanilla 25c241c1b0 Propagate stalled_on_coroutines as a field in Certainty::Maybe 2026-04-29 02:28:38 +09:00
Oli Scherer 61e876fe76 Suggest various missing trait bounds on HostEffect clauses not being satisfied 2026-04-28 12:54:55 +02:00
Oli Scherer b465c5642b Handle hkl const closures 2026-04-28 10:36:32 +02:00
Jonathan Brouwer 76a502d358 Rollup merge of #155675 - zedddie:disallow-non_exhaustive-adt-const-params, r=BoxyUwU
Disallow non_exhaustive structs and enums with non_exhaustive variants from implementing `ConstParamTy`

tracking issue rust-lang/rust#154042

r? BoxyUwU
2026-04-27 19:54:48 +02:00
Jonathan Brouwer e8ad7f25e4 Rollup merge of #155702 - mejrs:itemkind_trait-fields, r=petrochenkov
Change `ItemKind::Trait` to a field variant.

This changes `ItemKind::Trait` from an octuple(!!) to an enum variant with fields. Their names were chosen to match up with existing usage and minimize renaming.

I'm leaning towards renaming `ident` to `name` as well; let me know if that's desired.
2026-04-27 19:54:46 +02:00
Jonathan Brouwer 2cd70607e7 Rollup merge of #155355 - erickt:trait-solver-hang, r=lcnr
Fix pathological performance in trait solver cycles with errors

Fuchsia's Starnix system has had a multi-year long bug where occasionally a typo could cause the rust compiler to take 10+ hours to report an error (see rust-lang/rust#136516 and rust-lang/rust#150907). This was particularly hard to trace down since Starnix's codebase is massive, over 384 thousand lines as of writing.

With the help of treereduce, cargo-minimize, and rustmerge, after about a month of running we reduced it down to a couple [lines of code], which only takes about 35 seconds to report an error on my machine. The bug also appears to happen with `-Z next-solver=no` and `-Z next-solver=coherence`, but does not occur with `-Z next-solver` or `-Z next-solver=globally`.

I used Gemini to help diagnose the problem and proposed solution (which is the one proposed in this patch):

1. The trait solver gets stuck in an exponential loop evaluating auto-trait bounds (like Send and Sync) on cyclic types that contain compilation errors (TyKind::Error).

2. Normally, if the solver detects a cycle, it prevents the result from being stored in the Global Cache because the result depends on the current evaluation stack. However, when an error is involved, the depth tracking gets pinned to a low value, forcing the solver to rely on the short-lived Provisional Cache. Since the provisional cache is cleared between high-level iterations of the fulfillment loop, the solver ends up re-discovering and re-evaluating the same large cycle thousands of times.

3. Allow global caching of results even if they appear stack-dependent, provided that the inference context is already "tainted by errors" (`self.infcx.tainted_by_errors().is_some()`). This violates the strict invariant that global cache entries shouldn't depend on the stack, but it is safe because the compilation is already guaranteed to fail due to the presence of errors. Prioritizing compiler responsiveness and termination over perfect correctness in error states is the correct trade-off here.

I added the reduction as the test case for this. However, I don't see an easy way to catch if this bug comes back. Should we add some way to timeout the test if it takes longer than 10 seconds to compile? That could be a source of flakes though.

I don't have any experience with the trait solver code, but I did try to review the code to the best of my ability. This approach seems a bit of a bandaid to the solution, but I don't see a better solution. We could try to teach the solver to not clear the provisional cache in this circumstance, but I suspect that'd be a pretty invasive change.

I'm guessing if this does cause problems, it might report an incorrect error, but I (and Gemini) were unable to come up with an example that reported a different error with and without this fix.

Resolves rust-lang/rust#150907

[lines of code]: https://gist.github.com/erickt/255bc4006292cac88de906bd6bd9220a
2026-04-27 14:44:18 +02:00
zedddie 33a1ed1f4b disallow non_exhaustive structs and enums with non_exhaustive variants from implementing ConstParamTy 2026-04-25 15:52:28 +02:00
bors 80729d7ce0 Auto merge of #155662 - mejrs:this_the_thing, r=petrochenkov
Permit `{This}` in diagnostic attribute format literals

My motivation was that yesterday I wanted to write something like this and reference `$name` in the string literal.

```rust
pub mod sym {
   // stuff here
}

macro_rules! my_macro {
    ($name:ident $(,)?) => {{
        #[diagnostic::on_unknown(
            message = "this is not present in symbol table",
            note = "you must add it to rustc_span::symbol::symbol!"
        )]
        use sym::$name as name;
        // ...
    }}
}
```

That is (as far as I can tell) impossible or at least very unergonomic. This adds the ability to just reference the name of the item the attribute is on. I imagine that's useful for use inside macros generally, so it's also added for some other attributes.

The affected attributes are all unstable, it is not implemented for diagnostic::on_unimplemented (will do in its own PR).

Note that `{This}` is already usable in `#[rustc_on_unimplemented]`, so this does not implement it but just enables some more.

This PR also migrates one lint away from AttributeLintKind, and improves the messages for that lint.
2026-04-24 20:46:55 +00:00
mejrs c2916be8d7 Permit {This} in diagnostic attribute format literals 2026-04-24 19:59:32 +02:00
mejrs 9515f52d61 Change ItemKind::Trait to have named fields. 2026-04-24 19:03:16 +02:00
Jonathan Brouwer a51a163574 Rollup merge of #155219 - nataliakokoromyti:fix-155088-borrow-suggestion-v2, r=JohnTitor
Do not suggest borrowing enclosing calls for nested where-clause obligations

In rust-lang/rust#155088, the compiler was blaming the whole call expr instead of the value that  actually failed the trait bound, so for foo(&[String::from("a")]) it was suggesting stuff like &foo(...). I changed the suggestion logic so it only emits borrow help if the expr it found actually matches the failed self type,  and used the same check for the “similar impl exists” help too. So now the compiler should give the normal error + required bound note.

Fix rust-lang/rust#155088
2026-04-24 18:19:17 +02:00
Guillaume Gomez 8c3864b6cc Rollup merge of #155561 - cijiugechu:fix/need-type-info-underscore-wording, r=adwinwhite
Use singular wording for single _ placeholders in type suggestions

While looking this part of code, I noticed this FIXME and fixed it :)
2026-04-23 14:42:48 +02:00
Guillaume Gomez abce9f98d7 Rollup merge of #155442 - CoCo-Japan-pan:impl-restriction-reorder, r=Urgau,fmease,jhpratt
Change keyword order for `impl` restrictions

Based on rust-lang/rust#155222, this PR reorders keywords in trait definitions to group restrictions with visibility. It changes the order from `pub(...) const unsafe auto impl(...) trait Foo {...}`  to `pub(...) impl(...) const unsafe auto trait Foo {...}`.

Tracking issue for restrictions: rust-lang/rust#105077

r? @Urgau
cc @jhpratt
2026-04-23 14:42:47 +02:00
Jonathan Brouwer 280345333a Rollup merge of #154819 - cijiugechu:fix-next-solver-inherent-iat-ice, r=jackh726
Fix ICE for inherent associated type mismatches

Avoid projection-only suggestions for inherent associated types.

Closes rust-lang/rust#154333
Closes rust-lang/rust#155204
2026-04-23 09:38:20 +02:00
bors cf1817bc6e Auto merge of #155634 - jhpratt:rollup-lo99oO5, r=jhpratt
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#155589 (Forbid `check-pass`/`build-pass`/`run-pass` directives in incremental tests)
 - rust-lang/rust#155610 (Add missing `dyn` keyword to `trait_alias` page of the Unstable Book)
 - rust-lang/rust#155615 (test cleanups for `ui/derives` and `ui/deriving`)
 - rust-lang/rust#154874 (Fix ICE for inherited const conditions on const closures)
 - rust-lang/rust#155605 (std: Update support for `wasm32-wasip3`)
 - rust-lang/rust#155613 (c-variadic: tweak `std` docs)
 - rust-lang/rust#155619 (Remove a bunch of unnecessary explicit lifetimes from the ast validator)
2026-04-22 06:20:12 +00:00
Jacob Pratt b622dd00fb Rollup merge of #154874 - cijiugechu:fix-const-closure-inherited-conditions, r=oli-obk
Fix ICE for inherited const conditions on const closures

Synchronize `evaluate_host_effect_for_fn_goal` with the behavior of `extract_fn_def_from_const_callable` in new solver.

Closes rust-lang/rust#153861 .
2026-04-22 01:53:41 -04:00
bors 1bfcb284f7 Auto merge of #155392 - WaffleLapkin:alias-termmm, r=BoxyUwU
`AliasTerm` refactor

follow up to https://github.com/rust-lang/rust/pull/154758
tracking issue: https://github.com/rust-lang/rust/issues/154941
2026-04-22 02:57:46 +00:00
zedddie 35bc5436d3 add const_param_ty_unchecked gate 2026-04-21 21:30:50 +02:00
Jonathan Brouwer 63b6bd933e Rollup merge of #155425 - nnethercote:rm-dup-Flags-methods, r=nikomatsakis
Remove duplicated `Flags` methods.

The `Flags` trait has two methods: `flags` and `outer_exclusive_binder`. Multiple types impl this trait and then also have duplicate inherent methods with the same names; these are all marked with "Think about removing this" comments. This is left over from things being moved into `rustc_type_ir`.

This commit removes those inherent methods. This requires adding `use Flags` to a number of files.

r? @lcnr
2026-04-21 20:42:51 +02:00
Jacob Pratt 545e7dc06c Rollup merge of #151194 - chenyukang:yukang-fix-150701-async-closure, r=wesleywiser
Fix wrong suggestion for returning async closure

Fixes rust-lang/rust#150701

r? @estebank
2026-04-21 08:22:15 -04:00
Waffle Lapkin be8bfb2d69 x fmt
I have no idea what caused this change, I don't think other commits
changed anything near these lines?..
2026-04-21 12:42:52 +02:00
Waffle Lapkin e8b6c9737e fix ty::UnevaluatedConst<I>>->AliasTerm<I> conversion 2026-04-21 12:28:25 +02:00
Waffle Lapkin 0ff2fe8eef add AliasTermTy::with_args to simplify a common-ish pattern 2026-04-21 12:28:24 +02:00
Waffle Lapkin d7986943e4 AliasTermTy refactor: fixup compiler 2026-04-21 12:28:22 +02:00
Jacob Pratt 03dc6a3a28 Rollup merge of #154933 - fru1tworld:fix-87211-ref-future-diagnostic, r=chenyukang
Suggest removing `&` when awaiting a reference to a future

Fixes rust-lang/rust#87211

When `.await`ing `&impl Future`, suggest removing the `&` instead of removing `.await`.
2026-04-20 20:50:22 -04:00
Jacob Pratt a8e1664fd8 Rollup merge of #154557 - Muhtasim-Rasheed:issue-147313-improve-help, r=chenyukang
Make E0284 generic argument suggestions more explicit

Closes rust-lang/rust#147313

Previously, when type annotations were missing for a function call, rust suggested: "consider specifying the generic argument". This PR improves the diagnostics:

- If only one generic type is missing:
  "consider specifying a concrete type for the generic type `<T>`" with the turbofish being "::\<SomeConcreteType>"
- If only one const generic is missing:
  "consider specifying a const for the const generic `<CONST>`" with the turbofish being "::<SOME_CONST>"

Multiple missing generics still produce the original more general suggestion
2026-04-20 20:50:21 -04:00
Jonathan Brouwer 515c670b35 Rollup merge of #152162 - chenyukang:yukang-fix-152064-unsized-closure-return, r=petrochenkov
Suggest returning a reference for unsized place from a closure

Fixes rust-lang/rust#152064

There are 3 similar note:
`the size for values of type str cannot be known at compilation time`
for different spans, maybe need more work to remove some of them.

This PR only adds a suggestion for using a reference.
2026-04-20 18:57:00 +02:00
cijiugechu ffcbfc1cf4 Use singular wording for single _ placeholders in type suggestions 2026-04-20 22:21:51 +08:00
Muhtasim-Rasheed b1786813df Make E0284 generic argument suggestions more explicit 2026-04-20 16:46:57 +06:00
fru1tworld e9856d7c15 Do not suggest removing param & when expr also has & 2026-04-20 18:42:24 +09:00
Nicholas Nethercote e192eec395 Remove duplicated Flags methods.
The `Flags` trait has two methods: `flags` and `outer_exclusive_binder`.
Multiple types impl this trait and then also have duplicate inherent
methods with the same names; these are all marked with "Think about
removing this" comments. This is left over from things being moved into
`rustc_type_ir`.

This commit removes those inherent methods. This requires adding `use
Flags` to a number of files.
2026-04-20 10:13:53 +10:00
Adwin White 6279106e72 fix all errors 2026-04-20 00:18:28 +08:00
Adwin White 3e1e35b5d1 make common normalization routines take Unnormalized 2026-04-20 00:08:14 +08:00
CoCo-Japan-pan 614994fb8b Update HIR pretty printing 2026-04-19 15:58:02 +09:00
yukang eedf870de9 Suggest returning a reference for unsized place from a closure 2026-04-19 13:15:41 +08:00
yukang ae05a49f33 Fix wrong suggestion for returning async closure 2026-04-19 12:32:26 +08:00