5845 Commits

Author SHA1 Message Date
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
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
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
bors 6f109d8a2d Auto merge of #155223 - teor2345:fndef-refactor, r=mati865
Refactor FnDecl and FnSig non-type fields into a new wrapper type





#### Why this Refactor?

This PR is part of an initial cleanup for the [arg splat experiment](https://github.com/rust-lang/rust/issues/153629), but it's a useful refactor by itself.

It refactors the non-type fields of `FnDecl`, `FnSig`, and `FnHeader` into a new packed wrapper types, based on this comment in the `splat` experiment PR:
https://github.com/rust-lang/rust/pull/153697#discussion_r3004637413

It also refactors some common `FnSig` creation settings into their own methods. I did this instead of creating a struct with defaults.

#### Relationship to `splat` Experiment

I don't think we can use functional struct updates (`..default()`) to create `FnDecl` and `FnSig`, because we need the bit-packing for the `splat` experiment.

Bit-packing will avoid breaking "type is small" assertions for commonly used types when `splat` is added.
This PR packs these types:
- ExternAbi: enum + `unwind` variants (38) -> 6 bits
- ImplicitSelfKind: enum variants (5) -> 3 bits
- lifetime_elision_allowed, safety, c_variadic: bool -> 1 bit

#### Minor Changes

Fixes some typos, and applies rustfmt to clippy files that got skipped somehow.
2026-04-18 23:46:37 +00:00
nataliakokoromyti 9064d17405 Do not suggest borrowing enclosing calls for nested where-clause obligations 2026-04-18 10:51:16 -07:00
Shoyu Vanilla ace3aa319c Make region equality emits Eq constraints 2026-04-18 22:02:01 +09:00
Jacob Pratt 92f640115a Rollup merge of #155364 - nnethercote:reduce-err-struct-visibilities, r=Kivooeo
Reduce diagnostic type visibilities.

Most diagnostic types are only used within their own crate, and so have a `pub(crate)` visibility. We have some diagnostic types that are unnecessarily `pub`. This is bad because (a) information hiding, and (b) if a `pub(crate)` type becomes unused the compiler will warn but it won't warn for a `pub` type.

This commit eliminates unnecessary `pub` visibilities for some diagnostic types, and also some related things due to knock-on effects. (I found these types with some ad hoc use of `grep`.)

r? @Kivooeo
2026-04-16 01:54:15 -04:00
Nicholas Nethercote 9b64d52d78 Reduce diagnostic type visibilities.
Most diagnostic types are only used within their own crate, and so have
a `pub(crate)` visibility. We have some diagnostic types that are
unnecessarily `pub`. This is bad because (a) information hiding, and (b)
if a `pub(crate)` type becomes unused the compiler will warn but it
won't warn for a `pub` type.

This commit eliminates unnecessary `pub` visibilities for some
diagnostic types, and also some related things due to knock-on effects.
(I found these types with some ad hoc use of `grep`.)
2026-04-16 07:42:17 +10:00
teor dafb6bb801 Refactor FnDecl and FnSig flags into packed structs 2026-04-16 07:08:08 +10:00
WilliamTakeshi dbb83b65b0 remove calls to AliasTyKind::def_id 2026-04-15 21:23:02 +02:00
Jacob Pratt 3002472a77 Rollup merge of #155301 - mejrs:dead, r=nnethercote
Delete unused `rustc_trait_selection` errors.

The first two of these are duplicated elsewhere in some form or another, apparently they became orphaned during various moves and refactors. The third is just never used.
2026-04-14 23:02:35 -04:00
mejrs c8c4f02d00 Delete unused rustc_trait_selection errors. 2026-04-14 19:33:36 +02:00
cijiugechu 28b0ef6683 Add FIXME 2026-04-15 00:29:50 +08:00
Jacob Pratt 2a0b5343df Rollup merge of #154939 - chenyukang:yukang-refactor-fn-pointer-cast-suggestion, r=davidtwco
Refactor: simplify report_selection_error

Split out `suggest_cast_to_fn_pointer` for better readability.
2026-04-13 20:12:05 -04:00
bors 17584a1819 Auto merge of #155253 - JonathanBrouwer:rollup-lERdTAB, r=JonathanBrouwer
Rollup of 19 pull requests

Successful merges:

 - rust-lang/rust#155162 (relnotes for 1.95)
 - rust-lang/rust#140763 (Change codegen of LLVM intrinsics to be name-based, and add llvm linkage support for `bf16(xN)` and `i1xN`)
 - rust-lang/rust#153604 (Fix thread::available_parallelism on WASI targets with threads)
 - rust-lang/rust#154193 (Implement EII for statics)
 - rust-lang/rust#154389 (Add more robust handling of nested query cycles)
 - rust-lang/rust#154435 (resolve: Some import resolution cleanups)
 - rust-lang/rust#155236 (Normalize individual predicate of `InstantiatedPredicates` inside `predicates_for_generics`)
 - rust-lang/rust#155243 (cg_ssa: transmute between scalable vectors)
 - rust-lang/rust#153941 (tests/debuginfo/basic-stepping.rs: Explain why all lines are not steppable)
 - rust-lang/rust#154587 (Add --verbose-run-make-subprocess-output flag to suppress verbose run-make output for passing tests)
 - rust-lang/rust#154624 (Make `DerefPure` dyn-incompatible)
 - rust-lang/rust#154929 (Add `const Default` impls for `LazyCell` and `LazyLock`)
 - rust-lang/rust#154944 (Small refactor of `arena_cache` query values)
 - rust-lang/rust#155055 (UI automation)
 - rust-lang/rust#155062 (Move tests from `tests/ui/issues/` to appropriate directories)
 - rust-lang/rust#155131 (Stabilize feature `uint_bit_width`)
 - rust-lang/rust#155147 (Stabilize feature `int_lowest_highest_one`)
 - rust-lang/rust#155174 (Improve emission of `UnknownDiagnosticAttribute` lint)
 - rust-lang/rust#155194 (Fix manpage version replacement and use verbose version)
2026-04-13 18:32:47 +00:00
yukang 270cc62257 refactor: simplify fn pointer cast suggestion logic 2026-04-13 23:55:22 +08:00
Adwin White 7aa3f3ce52 normalize each predicate inside predicates_for_generics 2026-04-13 21:03:51 +08:00
Jonathan Brouwer f8a8c9e244 Rollup merge of #155003 - malezjaa:update-thinvec, r=davidtwco
update thin-vec

With thin-vec v0.2.15 released, copy-pasted implementation of ExtractIf can be removed.
2026-04-13 14:02:35 +02:00
Takayuki Maeda dbf8681242 handle RTN projections in assoc type restriction diagnostics 2026-04-13 18:05:07 +09:00
cijiugechu b7bd207d63 Avoid projection-only constraint suggestions for inherent associated type mismatches 2026-04-13 12:36:46 +08:00
Jonathan Brouwer b36833d634 Rollup merge of #154804 - cijiugechu:fix/host-effect-hrtb-ice, r=adwinwhite
Fix ICE when reporting host-effect errors for const Fn HRTBs in next trait solver

Avoid leaking bound vars into the diagnostic selection path for HRTB host-effect predicates.

Closes rust-lang/rust#151894 .
2026-04-12 15:44:18 +02:00
cijiugechu 0b02f678c4 Handle leaked host-effect HRTBs before selection 2026-04-12 14:44:20 +08:00
Jacob Pratt 44bad026ce Rollup merge of #154661 - CoCo-Japan-pan:impl-restriction-check, r=jhpratt,Urgau
Semantic checks of `impl` restrictions

This PR implements semantic checks for `impl` restrictions proposed in the [Restrictions RFC](https://rust-lang.github.io/rfcs/3323-restrictions.html) (Tracking Issue rust-lang/rust#105077), and linked to a [GSOC idea/proposal](https://github.com/rust-lang/google-summer-of-code/tree/142433eb3b104b2f32bae0b9dfafb78a0a2ac579?tab=readme-ov-file#implementing-impl-and-mut-restrictions).

It lowers the resolved paths of `impl` restrictions from the AST to HIR and into `TraitDef`, and integrates the checks into the coherence phase by extending `check_impl`. As parsing (rust-lang/rust#152943) and path resolution (rust-lang/rust#153556) have already been implemented, this PR provides a working implementation of `impl` restrictions.

r? @Urgau
cc @jhpratt
2026-04-11 01:49:12 -04:00
Jana Dönszelmann 63c212e62b make typing_mode getter 2026-04-10 11:42:02 +02:00
Jana Dönszelmann 0e0d12ccb3 introduce TypingModeEqWrapper and make TypingMode !Eq 2026-04-10 11:40:01 +02:00
Jacob Pratt defee2995b Rollup merge of #153888 - MaximilianAzendorf:issue-153583, r=Kivooeo
Avoid stack overflow in FindExprBySpan

Fixes rust-lang/rust#153583.

Deeply nested `?` desugarings can build a very deep HIR expression spine.
When `FindExprBySpan` walks that expression during error reporting, the
recursive `visit_expr` traversal can overflow the stack before rustc emits the
actual diagnostic.

This wraps the recursive expression walk in `ensure_sufficient_stack`, which
lets the compiler report the expected E0277 instead of crashing.

Added a UI regression test for a deeply nested `?` chain.
2026-04-08 23:03:58 -04:00