24914 Commits

Author SHA1 Message Date
usamoi febf9f5047 fix arch names in cfg pretty printer
(cherry picked from commit 05081b96c9)
2026-04-16 09:57:27 -07:00
bors 02c7f9bec0 Auto merge of #155115 - JonathanBrouwer:rollup-RePrRPQ, r=JonathanBrouwer
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#152901 (Introduce a `#[diagnostic::on_unknown]` attribute)
 - rust-lang/rust#155078 (Reject dangling attributes in where clauses)
 - rust-lang/rust#154449 (Invert dependency between `rustc_errors` and `rustc_abi`.)
 - rust-lang/rust#154646 (Add suggestion to `.to_owned()` used on `Cow` when borrowing)
 - rust-lang/rust#154993 (compiletest: pass -Zunstable-options for unpretty and no-codegen paths)
 - rust-lang/rust#155097 (Make `rustc_attr_parsing::SharedContext::emit_lint` take a `MultiSpan` instead of a `Span`)
2026-04-10 18:19:03 +00:00
Jonathan Brouwer 9c01701171 Rollup merge of #154646 - m4rch3n1ng:144792-cow-diag, r=davidtwco
Add suggestion to `.to_owned()` used on `Cow` when borrowing

fixes rust-lang/rust#144792
supersedes rust-lang/rust#144925 with the review comments addressed

the tests suggested from @Kivooeo from https://github.com/rust-lang/rust/pull/144925#discussion_r2252703007 didn't work entirely, because these tests failed due to error `[E0308]` mismatched types, which actually already provides a suggestion, that actually makes the code compile:

```
$ cargo check
error[E0308]: mismatched types
 --> src/main.rs:3:5
  |
1 | fn test_cow_suggestion() -> String {
  |                             ------ expected `std::string::String` because of return type
2 |     let os_string = std::ffi::OsString::from("test");
3 |     os_string.to_string_lossy().to_owned()
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `String`, found `Cow<'_, str>`
  |
  = note: expected struct `std::string::String`
               found enum `std::borrow::Cow<'_, str>`
help: try using a conversion method
  |
3 |     os_string.to_string_lossy().to_owned().to_string()
  |                                           ++++++++++++
```

now this suggestion is of course not good or efficient code, but via clippy with `-Wclippy::nursery` lint group you can actually get to the correct code, so i don't think this is too much of an issue:

<details>
<summary>the clippy suggestions</summary>

```
$ cargo clippy -- -Wclippy::nursery
warning: this `to_owned` call clones the `Cow<'_, str>` itself and does not cause its contents to become owned
 --> src/main.rs:3:5
  |
3 |     os_string.to_string_lossy().to_owned().to_string()
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/beta/index.html#suspicious_to_owned
  = note: `#[warn(clippy::suspicious_to_owned)]` on by default
help: depending on intent, either make the `Cow` an `Owned` variant
  |
3 |     os_string.to_string_lossy().into_owned().to_string()
  |                                 ++
help: or clone the `Cow` itself
  |
3 -     os_string.to_string_lossy().to_owned().to_string()
3 +     os_string.to_string_lossy().clone().to_string()
  |
$ # apply first suggestion
$ cargo c -- -Wclippy::nursery
warning: redundant clone
 --> src/main.rs:3:45
  |
3 |     os_string.to_string_lossy().into_owned().to_string()
  |                                             ^^^^^^^^^^^^ help: remove this
  |
note: this value is dropped without further use
 --> src/main.rs:3:5
  |
3 |     os_string.to_string_lossy().into_owned().to_string()
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/beta/index.html#redundant_clone
  = note: `-W clippy::redundant-clone` implied by `-W clippy::nursery`
  = help: to override `-W clippy::nursery` add `#[allow(clippy::redundant_clone)]`
```

</details>

the actual error that we are looking for is error `[E0515]`, cannot return value referencing local variable, which was only present in the original issue due to automatic type inference assuming you want to return a cloned `Cow<'_, str>`, which is of course not possible. this is why i took the original test functions and turned them into closures, where it's less obvious that it's trying to return the wrong type.

r? davidtwco

(because you reviewed the last attempt)
(also, let me know if i should squash this down to one commit and add myself as the co-contributor)
2026-04-10 18:38:14 +02:00
Jonathan Brouwer c729f33e46 Rollup merge of #155078 - cijiugechu:fix/where-clause-trailing-attrs, r=petrochenkov
Reject dangling attributes in where clauses

Report `attribute without where predicates` for trailing outer attributes in where clauses.

Closes rust-lang/rust#155073 .
2026-04-10 18:38:12 +02:00
Jonathan Brouwer dbf9492774 Rollup merge of #152901 - weiznich:feature/on_unknown_item, r=jdonszelmann
Introduce a `#[diagnostic::on_unknown]` attribute

This PR introduces a `#[diagnostic::on_unknown]` attribute that allows crate authors to customize the error messages emitted by unresolved imports. The main usecase for this is using this attribute as part of a proc macro that expects a certain external module structure to exist or certain dependencies to be there.

For me personally the motivating use-case are several derives in diesel, that expect to refer to a `tabe` module. That is done either implicitly (via the name of the type with the derive) or explicitly by the user. This attribute would allow us to improve the error message in both cases:

* For the implicit case we could explicity call out our assumptions (turning the name into lower case, adding an `s` in the end)
+ point to the explicit variant as alternative
* For the explicit variant we would add additional notes to tell the user why this is happening and what they should look for to fix the problem (be more explicit about certain diesel specific assumptions of the module structure)

I assume that similar use-cases exist for other proc-macros as well, therefore I decided to put in the work implementing this new attribute. I would also assume that this is likely not useful for std-lib internal usage.

related rust-lang/rust#152900 and rust-lang/rust#128674
2026-04-10 18:38:11 +02:00
bors b6100ccf71 Auto merge of #155099 - JonathanBrouwer:rollup-nKbnTlV, r=JonathanBrouwer
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#155047 (Always exhaustively match on typing mode)
 - rust-lang/rust#155080 (Simplify `try_load_from_disk_fn`.)
 - rust-lang/rust#152384 (Restrict EII declarations to functions at lowering time)
 - rust-lang/rust#153796 (Fix ICE when combining #[eii] with #[core::contracts::ensures])
 - rust-lang/rust#154369 (Fix `pattern_from_macro_note` for bit-or expr)
 - rust-lang/rust#155027 ( Rename some more of our internal `#[rustc_*]` TEST attributes)
 - rust-lang/rust#155031 (delegation: fix unelided lifetime ICE, refactoring of GenericArgPosition)
 - rust-lang/rust#155040 (Fix code block whitespace handling in Markdown)
2026-04-10 14:43:38 +00:00
cijiugechu 3c6cf27ae4 Reject dangling attributes in where clauses 2026-04-10 21:45:26 +08:00
Jonathan Brouwer 3b8c7eccdc Rollup merge of #155031 - aerooneqq:delegation-generic-args-lowering-ice, r=petrochenkov
delegation: fix unelided lifetime ICE, refactoring of GenericArgPosition

This PR does two things:
- First it restores `lower_generic_args_of_path` as it was before rust-lang/rust#151864, as it turns out we should use `GenericArgPosition::Type` for generic args lowering for signature inheritance, as it will not cause lifetime inference and then ICEs during child args lowering,
- Next it refactors `GenericArgPosition` enum replacing `Value` and `MethodCall` with `Call(IsMethodCall)`, as the only place where we created `Value` or `MethodCall` variants was in `check_generic_arg_count_for_call`, where it was a match over `is_method_call`. Not sure it is needed, but seems cleaner to me.

Fixes rust-lang/rust#154178, part of rust-lang/rust#118212.

r? @petrochenkov
2026-04-10 15:33:14 +02:00
Jonathan Brouwer 6547a33a8b Rollup merge of #155027 - fmease:more-test-attr-renamings, r=JonathanBrouwer
Rename some more of our internal `#[rustc_*]` TEST attributes

Follow-up to https://github.com/rust-lang/rust/pull/153300.

r? JonathanBrouwer or jdonszelmann
2026-04-10 15:33:13 +02:00
Jonathan Brouwer ad68deab08 Rollup merge of #154369 - ver-nyan:fix-bit_or-pat_macro-msg, r=JohnTitor
Fix `pattern_from_macro_note` for bit-or expr

This is a continuation of issue https://github.com/rust-lang/rust/issues/99380 (and pr https://github.com/rust-lang/rust/pull/124488) but covers bit-or pattern.

Essentially a `pat1 | pat2`, or any bit-or pattern used in a `$e:expr` was not firing the `.pattern_from_macro_note` diagnostic bc `ast::Expr::is_approximately_pattern()` did not cover bit-or.

The cover for bit-or is only added in `lower_expr_within_pat()`, otherwise doing it in `is_approximately_pattern()` would result in the suggestion `if (i + 2) = 2 => if let (i + 2) = 2` from `suggest_pattern_match_with_let()` (which is the only other place `ast::Expr::is_approximately_pattern()` is used from what i see).

resolves https://github.com/rust-lang/rust/issues/99380
refs https://github.com/rust-lang/rust/pull/124488
2026-04-10 15:33:13 +02:00
Jonathan Brouwer 45223feeba Rollup merge of #153796 - GokhanKabar:fix-ice-missing-tokens-eii-attr-expansion, r=jdonszelmann
Fix ICE when combining #[eii] with #[core::contracts::ensures]

Fixes rust-lang/rust#153745

Builtin attribute macros like #[eii] generate AST items programmatically without collected tokens. When another attribute macro was present on the same item, the compiler would panic in TokenStream::from_ast() trying to tokenize the generated items during subsequent attribute expansion.

Generate fake token streams (via pretty-print and re-parse) for Item and ForeignItem nodes that lack collected tokens, following the existing pattern used for Crate and out-of-line modules.
2026-04-10 15:33:12 +02:00
Jonathan Brouwer 5b16a31a0e Rollup merge of #152384 - enthropy7:fix-eii-root-resolution-clean, r=jdonszelmann
Restrict EII declarations to functions at lowering time

We tighten EII declaration resolution so that `lower_path_simple_eii` only accepts function‑like items (`Fn, AssocFn, Ctor(_, Fn)`) as valid EII targets. If name resolution points at something else (like a const with the same name), we now emit a direct error (“`externally implementable items must refer to a function`”) at the declaration site, which prevents bad `DefIds` from ever reaching `compare_eii_function_types` and turning into an ICE

this is more robust and root-cause oriented fix to rust-lang/rust#152337 issue and an alternate of my more simple PR rust-lang/rust#152365

test included
2026-04-10 15:33:11 +02:00
Jonathan Brouwer 610eaec233 Rollup merge of #155047 - jdonszelmann:lint-against-eq-typing-mode, r=lcnr
Always exhaustively match on typing mode

r? @lcnr

Unimplements Eq/PartialEq for TypingMode, adds TypingModeEqWrapper for the few cases where we need it (mainly in the query system), and adds a new rustc internal lint to detect cases where we non-exhaustively match on typing mode.
2026-04-10 15:33:10 +02:00
Jana Dönszelmann 18d118a7b7 fixup rustdoc,clippy,rustfmt 2026-04-10 15:10:04 +02:00
Jana Dönszelmann d5d0153254 make all typing-mode conditional code an exhaustive match 2026-04-10 15:01:37 +02:00
bors 8317fef204 Auto merge of #152996 - mu001999-contrib:feat/extend-import-self, r=petrochenkov
Replacing `self` overwriting with proper resolution

Reference PR:

- https://github.com/rust-lang/reference/pull/2221



As a follow-up PR to https://github.com/rust-lang/rust/pull/146972 ([step 1](https://github.com/rust-lang/rust/pull/152996#issuecomment-4011548479)), after this PR:
~~1. Trailing `self` can appear in paths (as the consensus in https://github.com/rust-lang/rust/pull/146972#issuecomment-3719825627)~~ (in future)
~~2. [E0429](https://doc.rust-lang.org/stable/error_codes/E0429.html#error-code-e0429) will be no longer emitted, `use ...::self [as target];` will be equivalent to `use ...::{self [as target]};`~~ (in future)
3. Things like `struct S {}; use S::{self as Other};` will be rejected

---

This PR used to add a new lint `redundant_self`, which would lint `use ...::self [as target];` and `use ...::{self [as target]};`, and fixes all warnings emitted by this lint.

But this lint and clippy lint [unnecessary_self_imports](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_self_imports) have some overlap. And `use std::io::self;` is not equivalent to `use std::io` in fact for now, the new lint will also cause the following known issue:
> Removing `::{self}` will cause any non-module items at the same path to also be imported. This might cause a naming conflict (https://github.com/rust-lang/rustfmt/issues/3568).

So I removed this lint, and I think what it does should be done by extending the clippy lint `unnecessary_self_imports`.

r? petrochenkov
2026-04-10 11:30:02 +00:00
León Orell Valerian Liehr cb4a7f4f19 Rename #[rustc_symbol_name] to #[rustc_dump_symbol_name] 2026-04-10 12:14:39 +02:00
León Orell Valerian Liehr 0a597064ba Rename #[rustc_def_path] to #[rustc_dump_def_path] 2026-04-10 12:14:23 +02:00
León Orell Valerian Liehr dda1ea0c43 Rename #[rustc_hidden_type_of_opaques] to #[rustc_dump_hidden_type_of_opaques] 2026-04-10 12:14:07 +02:00
León Orell Valerian Liehr 7025605b8c Rename #[rustc_dump_layout]'s abi option to backend_repr
Moreover, dereference `ty_layout.align` for `#[rustc_dump_layout(align)]`
to render `align: Align($N bytes)` instead of `align: AbiAlign { abi: Align($N bytes) }`
which contains the same amount of information but it more concise and legible.
2026-04-10 12:13:52 +02:00
León Orell Valerian Liehr 357f670fde Rename #[rustc_layout] to #[rustc_dump_layout] 2026-04-10 12:13:48 +02:00
Jana Dönszelmann 2facd34bc8 add #[rustc_must_match_exhaustively] 2026-04-10 11:43:27 +02:00
Georg Semmler 97da8195de Rename the attribute to on_unknown 2026-04-10 09:01:20 +02:00
Georg Semmler 6e5fc9075c Introduce a #[diagnostic::on_unknown_item] attribute
This PR introduces a `#[diagnostic::on_unknown_item]` attribute that
allows crate authors to customize the error messages emitted by
unresolved imports. The main usecase for this is using this attribute as
part of a proc macro that expects a certain external module structure to
exist or certain dependencies to be there.

For me personally the motivating use-case are several derives in diesel,
that expect to refer to a `tabe` module. That is done either
implicitly (via the name of the type with the derive) or explicitly by
the user. This attribute would allow us to improve the error message in
both cases:

* For the implicit case we could explicity call out our
assumptions (turning the name into lower case, adding an `s` in the end)
+ point to the explicit variant as alternative
* For the explicit variant we would add additional notes to tell the
user why this is happening and what they should look for to fix the
problem (be more explicit about certain diesel specific assumptions of
the module structure)

I assume that similar use-cases exist for other proc-macros as well,
therefore I decided to put in the work implementing this new attribute.
I would also assume that this is likely not useful for std-lib internal
usage.
2026-04-10 08:55:02 +02:00
aerooneqq 9e8069fef1 Fix unelided lifetime ICE, refactoring of GenericArgPosition 2026-04-10 09:53:31 +03:00
Jacob Pratt c305a1a5e9 Rollup merge of #155071 - Fayti1703:alloc/no-thread-local, r=Kivooeo
Deny `#[global_allocator]` + `#[thread_local]`

This forbids using `#[thread_local]` on `static` items that are also `#[global_allocator]`s.

Fixes rust-lang/rust#85517.
2026-04-10 00:00:03 -04:00
Jacob Pratt d788fbfb58 Rollup merge of #155015 - jakubadamw:issues-104037-112623-113899, r=Kivooeo
Add tests for three fixed issues (an LLVM crash, an ICE and poor codegen)

Closes rust-lang/rust#104037.
Closes rust-lang/rust#112623.
Closes rust-lang/rust#113899.
2026-04-10 00:00:01 -04:00
Jacob Pratt 5a6abf3425 Rollup merge of #154677 - Darksonn:hwasan-tagged-globals, r=davidtwco
hwaddress: automatically add `-Ctarget-feature=+tagged-globals`

Note that since HWAddressSanitizer is/should be a target modifier, we do not have to worry about whether this LLVM target feature changes the ABI.

Fixes: rust-lang/rust#148185
2026-04-09 23:59:59 -04:00
Jacob Pratt d831599f3a Rollup merge of #151377 - xonx4l:main_termination, r=lcnr
Fix linker error by resolving regions for main return type obligations

This PR fix linker error by resolving regions for main return type obligations as discussed in https://github.com/rust-lang/rust/issues/148421

Added a final check . Now the compiler double-checks the lifetimes for main right away. If they don't work it stops and gives the user a clean compiler error instead of a linker crash.

Fixes https://github.com/rust-lang/rust/issues/148421.
2026-04-09 23:59:58 -04:00
bors dd82fd2034 Auto merge of #155056 - JonathanBrouwer:revert-lint-port, r=lqd,mati865
Revert "Port lint attributes to attribute parser"

This PR reverts the following two PRs:
- https://github.com/rust-lang/rust/pull/154808
- https://github.com/rust-lang/rust/pull/152369

This was not a clean revert, I manually solved several merge conflicts.

Closes https://github.com/rust-lang/rust/issues/154878
Closes https://github.com/rust-lang/rust/issues/154800
Closes https://github.com/rust-lang/rust/issues/155008
Re-opens https://github.com/rust-lang/rust/issues/132218 (this was never closed, oops)

r? @ghost
2026-04-09 23:54:22 +00:00
Fayti1703 dbe7a4e13a Improve diagnostic for global_allocator + thread_local 2026-04-10 00:45:37 +02:00
Fayti1703 9614f285a7 Update ui test for deny global_allocator + thread_local 2026-04-10 00:33:44 +02:00
Fayti1703 b65574d782 Add (failing) ui test for denying global_allocator + thread_local 2026-04-10 00:33:00 +02:00
Jonathan Brouwer 9c3661d63e Regression test for issue 155008
Co-authored-by: Edvin Bryntesson <epost@edvinbryntesson.se>
2026-04-09 20:36:36 +02:00
Jonathan Brouwer 77cc66c13c Regression test for issue 154800
Co-authored-by: Edvin Bryntesson <epost@edvinbryntesson.se>
2026-04-09 20:36:35 +02:00
Jonathan Brouwer ea86990ee6 Regression test for issue 154878
Co-authored-by: Edvin Bryntesson <epost@edvinbryntesson.se>
2026-04-09 20:34:37 +02:00
bors f5eca4fcfa Auto merge of #155052 - JonathanBrouwer:rollup-TlewACE, r=JonathanBrouwer
Rollup of 2 pull requests

Successful merges:

 - rust-lang/rust#155042 (Update cargo submodule)
 - rust-lang/rust#154930 (Revert performing basic const checks in typeck on stable)
2026-04-09 17:10:53 +00:00
Jonathan Brouwer 65745a1b95 Revert #152369 because of multiple regressions
The regressions are documented in the PR comments.
This reverts commit 2972b5e, reversing changes made to f908263.
2026-04-09 18:53:59 +02:00
Jonathan Brouwer db99e16ae3 Rollup merge of #154930 - oli-obk:revert-const-check, r=chenyukang
Revert performing basic const checks in typeck on stable

Revert rust-lang/rust#149375, it caused a (desirable, but unintended) change where we now emit errors about constants in dead code. This was due to mir never seeing dead code, so no const checks being run on it. But typeck sees all written code and will check it.

We'll land this again, with a proper types FCP and everything

fixes https://github.com/rust-lang/rust/issues/153765

see [#t-types/nominated > #153765: 1.95 beta regression: trait method calls in dead c…](https://rust-lang.zulipchat.com/#narrow/channel/326866-t-types.2Fnominated/topic/.23153765.3A.201.2E95.20beta.20regression.3A.20trait.20method.20calls.20in.20dead.20c.E2.80.A6/with/580203072) for discussions
2026-04-09 18:11:27 +02:00
mu001999 eb00f7806e Bless other tests 2026-04-09 23:27:38 +08:00
mu001999 16260d657f Add test for trailing self 2026-04-09 22:54:52 +08:00
xonx dbc08cfd57 main-termination 2026-04-09 14:37:09 +00:00
bors a87c9b9603 Auto merge of #154368 - aerooneqq:delegation-force-lowering-later, r=petrochenkov
delegation: fix cycles during delayed lowering



This PR forces lowering of delayed owners after `hir_crate_items`, as some diagnostics use `hir_crate_items` which results in query cycle which is then hangs calling `def_path_str` again and again. Fixes rust-lang/rust#154169. Part of rust-lang/rust#118212.

r? @petrochenkov
2026-04-09 13:26:48 +00:00
aerooneqq dac2e3eedf Fix cycles during delayed lowering 2026-04-09 15:13:50 +03:00
Oli Scherer d37d2be395 Revert performing basic const checks in typeck on stable 2026-04-09 11:36:46 +02:00
Jacob Adam fc9f492049 Add a codegen test for a missed optimisation with spare niches 2026-04-09 09:42:47 +01:00
Jacob Adam 12e847f75c Add a test for a const evaluator ICE on a self-receiver type mismatch 2026-04-09 09:42:47 +01:00
Jacob Adam f493cab3e3 Add a test for an LLVM crash "Vector elements must have same size" 2026-04-09 09:42:11 +01:00
Jacob Pratt a2d7d8c8da Rollup merge of #154955 - cijiugechu:fix-rustdoc-pattern-type-implementors, r=notriddle
Fix pattern types rendering in rustdoc

Closes rust-lang/rust#150889 .

`core` was rendering local pattern-type impls through `clean_ty`, which formatted `rustc_hir::TyPat` with derived Debug, while inlined docs go through `clean_middle_ty` and get the pretty-printed `rustc_middle::ty::Pattern`.
Lower local HIR pattern types before formatting so both paths share the same canonical pattern printer and stop exposing `TyPat { ... }` in implementors.

#### Current result:
<img width="1133" height="738" alt="截屏2026-04-07 22 47 26" src="https://github.com/user-attachments/assets/bb5f8942-30b1-400a-a0a0-f581da5bb59f" />
2026-04-09 02:31:08 -04:00
Jacob Pratt 9ebe418dc6 Rollup merge of #153038 - pthariensflame:syncview-rename, r=Amanieu
core::sync: rename `Exclusive` to `SyncView` and make improvements

This PR implements the renaming of `core::sync::Exclusive` to `SyncView` as decided in rust-lang/rust#98407.  To preserve the ability to search for the old name, it adds `Exclusive` as a `doc_alias`.

It also makes the following additional changes:

- Converting the `get_mut` method to being an instance of `AsMut::as_mut`.  In the process, it makes both the new `impl AsMut` and the existing `impl AsRef` `const`, and it also renames `get_pin_mut` to `as_pin_mut` for consistency.  This direction follows a suggestion from rust-lang/rust#98407.
- Adding an `as_pin` method that can only be used when the wrapped type implements `Sync`, to complete the square of access methods.
- Making as many of the existing `impl`s `const` as possible; this involved making the existing `impl Default` no longer derived.
- Adding `impl`s for `AsyncFnOnce`, `AsyncFnMut`, and `AsyncFn`, akin to the existing `impls` for `FnOnce`, `FnMut`, and `Fn`.

It does not yet do the following, which may be desirable:

- Fixing/improving the documentation to address the concern pointed out in rust-lang/rust#146245.

It previously did the following, but this was removed after discussion:
- Adding an `impl` for (`const`) `Iterator`, which felt in line with the existing `impl`s for `Future` and `Coroutine`.
2026-04-09 02:31:08 -04:00