Commit Graph

54480 Commits

Author SHA1 Message Date
Jonathan Brouwer f540b27f90 Rollup merge of #153508 - JonathanBrouwer:improved_eager_format, r=GuillaumeGomez
Clean up the eager formatting API

For https://github.com/rust-lang/rust/issues/151366#event-22181360642

Previously eager formatting worked by throwing the arguments into a diag, formatting, then removing the args again. This is ugly so instead we now just do the formatting completely separately.
This PR has nice commits, so I recommend reviewing commit by commit.

r? @GuillaumeGomez
2026-03-07 01:42:37 +01:00
Jonathan Brouwer feeeea9ad1 Rollup merge of #153503 - bjorn3:cg_gcc_thin_lto_fallback, r=antoyo
Fallback to fat LTO for -Clto=thin in cg_gcc

Fallback to no LTO doesn't work in practice as Cargo asks rustc to produce LTO-only rlibs with -Clinker-plugin-lto without providing any indication if they will be used for thin or fat LTO, so we can't disable -Clinker-plugin-lto for ThinLTO when using cg_gcc.

r? @antoyo
2026-03-07 01:42:36 +01:00
Jonathan Brouwer 783c9d3de0 Rollup merge of #149937 - jyn514:linker-info, r=mati865
spliit out `linker-info` from `linker-messages`

*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/149937)*

Helps with https://github.com/rust-lang/rust/issues/136096.
2026-03-07 01:42:35 +01:00
Jonathan Brouwer 4e0b64408c Fix newly detected subdiagnostics using variables from parent 2026-03-06 19:00:25 +01:00
Jonathan Brouwer e58ddb5ae5 Fix variable_references logic to catch all variable references 2026-03-06 18:52:11 +01:00
Jonathan Brouwer 10eb844bac Remove eagerly_format_to_string from DiagCtxt 2026-03-06 18:52:11 +01:00
Jonathan Brouwer 8c87d0761f Remove eagerly_format from DiagCtxt 2026-03-06 18:52:11 +01:00
Jonathan Brouwer 43221b43b6 Remove eagerly_format from Diag 2026-03-06 18:52:11 +01:00
Jonathan Brouwer 828c0c0668 Remove remove_arg from diagnostics 2026-03-06 18:52:11 +01:00
Jonathan Brouwer c2f1e9d71d Remove stored args from diagnostics 2026-03-06 18:52:11 +01:00
Jonathan Brouwer 2b0552f0cb Add new eager formatting API 2026-03-06 18:52:11 +01:00
Jonathan Brouwer 03a8ae8b11 Rollup merge of #153483 - aytey:dyn_paren_impl_fn_return, r=fmease
Preserve parentheses around `Fn` trait bounds in pretty printer

The AST pretty printer was dropping parentheses around `Fn` trait bounds in `dyn`/`impl` types when additional `+` bounds were present. For example:

    dyn (FnMut(&mut T) -> &mut dyn ResourceLimiter) + Send + Sync

was pretty-printed as:

    dyn FnMut(&mut T) -> &mut dyn ResourceLimiter + Send + Sync

Without parens, `+ Send + Sync` binds to the inner `dyn ResourceLimiter` instead of the outer type, producing invalid Rust.

The parser already tracks parentheses via `PolyTraitRef.parens`, but `print_poly_trait_ref` never checked this field. This adds `popen()` and `pclose()` calls when `parens == Parens::Yes`.
2026-03-06 18:49:52 +01:00
Jonathan Brouwer 69dc318464 Rollup merge of #153452 - GuillaumeGomez:migrate-diag, r=JonathanBrouwer
Cleanup unused diagnostic emission methods

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

To remove `lint_level`, we need to remove all functions calling it. One of them is `TyCtxt::node_span_lint`, so removing it.

r? @JonathanBrouwer
2026-03-06 18:49:51 +01:00
Jonathan Brouwer 56c8de6364 Rollup merge of #153189 - JayanAXHF:refactor/check_attrs_reftor_1, r=JonathanBrouwer
refactor: move `check_align` to `parse_alignment`

Part of rust-lang/rust#153101

r? @JonathanBrouwer

PS: jonathan i'm not sure about what to do with `check_align` now
2026-03-06 18:49:49 +01:00
Jonathan Brouwer 6be5b25aa9 Rollup merge of #152741 - arferreira:fix-invalid-suggestions-destructuring-drop, r=estebank,Kivooeo
Suppress invalid suggestions in destructuring assignment

Fixes rust-lang/rust#152694

When destructuring assignment hits a type with `Drop`, the compiler was emitting two broken suggestions: `ref *&mut String::new()` (invalid syntax) and `.clone()` on a temporary (useless).

Root cause: the suggestion logic didn't know these bindings were synthetic from assign desugaring. The fix reuses the existing `AssignDesugar` detection in `BindingFinder` to collect those spans and skip both suggestions.
2026-03-06 18:49:49 +01:00
Jonathan Brouwer 946e0f4924 Rollup merge of #152040 - JohnTitor:issue-151631, r=BoxyUwU
Do not emit ConstEvaluatable goals if type-const

Fixes rust-lang/rust#151631, fixes rust-lang/rust#151477
r? @fmease

I'd recommend reviewing commit-by-commit, the diff is less-readable to address a cyclic issue.
2026-03-06 18:49:48 +01:00
Jonathan Brouwer ac9bd09ec6 Rollup merge of #153495 - TaKO8Ki:fix-153236-offset-of-recovery, r=petrochenkov
Fix ICE in `offset_of!` error recovery

Fixes rust-lang/rust#153236.

`offset_of!` was changed in rust-lang/rust#148151 to lower through THIR as a sum of calls to the `offset_of` intrinsic. In the error-recovery case, when no valid field indices are recorded, that lowering synthesized `0` as a `u32` even though the overall `offset_of!` expression has type `usize`.

On 64-bit targets, const-eval then tried to write a 4-byte immediate into an 8-byte destination, which caused the ICE.
2026-03-06 18:49:48 +01:00
Jonathan Brouwer 6b42067e18 Rollup merge of #153485 - RalfJung:float-macros-const, r=tgross35
libcore float tests: replace macro shadowing by const-compatible macro

This lets us avoid https://github.com/rust-lang/rust/issues/153478.
However this means we generate 3 function items per assertion -- or rather, 3*8, since every assertion gets duplicated 8 times (4 float types, each in a const and a non-const variant). That's a lot; is it enough to be concerned about?
coretest already takes forever to build. In a quick test, build time increased from 29.8s to 30.8s, but that may also entirely be noise.

r? @tgross35
2026-03-06 18:49:48 +01:00
Jonathan Brouwer 77658bcda3 Rollup merge of #152593 - spirali:valtreekind-list, r=lcnr
Box in `ValTreeKind::Branch(Box<[I::Const]>)` changed to `List`

This is related to trait system refactoring. It fixes the FIXME in `ValTreeKind`

```
   // FIXME(mgca): Use a `List` here instead of a boxed slice
    Branch(Box<[I::Const]>),
```

It introduces `Interner::Consts`, changes `Branch(Box<[I::Const]>)` to `Branch(I::Consts)`, and updates all relevant places.

r? lcnr
2026-03-06 18:49:47 +01:00
Jonathan Brouwer 550527989e Rollup merge of #151280 - chenyukang:yukang-fix-149787, r=estebank
Fix incorrect trailing comma suggested in no_accessible_fields

Fixes rust-lang/rust#149787

r? @estebank

I think add new field for AST for it is too heavy change for this issue, here is a trivial fix with source_map, seems enough for it.
2026-03-06 18:49:46 +01:00
Jonathan Brouwer 46cedc33b8 Use eager formatting in #[derive(Subdiagnostic)] 2026-03-06 18:32:54 +01:00
bjorn3 15e839e006 Fallback to fat LTO for -Clto=thin in cg_gcc
Fallback to no LTO doesn't work in practice as Cargo asks rustc to
produce LTO-only rlibs with -Clinker-plugin-lto without providing any
indication if they will be used for thin or fat LTO, so we can't disable
-Clinker-plugin-lto for ThinLTO when using cg_gcc.
2026-03-06 15:22:17 +00:00
Jonathan Brouwer 8d96e603b1 Preserve the DiagLocation in diag_lint_level 2026-03-06 15:15:43 +01:00
Takayuki Maeda e62f17cfc4 use try_from_target_usize instead of try_from_uint 2026-03-06 22:31:01 +09:00
Takayuki Maeda ed12fe81b0 fix ICE in offset_of! error recovery 2026-03-06 22:19:23 +09:00
Yuki Okushi 1190845a3d Do not emit ConstEvaluatable goals if type-const 2026-03-06 21:51:31 +09:00
Ralf Jung 0fd3ac4c97 libcore float tests: replace macro shadowing by const-compatible macro 2026-03-06 12:07:25 +01:00
Andrew V. Teylu cb66c85555 Preserve parentheses around Fn trait bounds in pretty printer
The AST pretty printer was dropping parentheses around `Fn` trait
bounds in `dyn`/`impl` types when additional `+` bounds were present.
For example:

    dyn (FnMut(&mut T) -> &mut dyn ResourceLimiter) + Send + Sync

was pretty-printed as:

    dyn FnMut(&mut T) -> &mut dyn ResourceLimiter + Send + Sync

Without parens, `+ Send + Sync` binds to the inner `dyn ResourceLimiter`
instead of the outer type, producing invalid Rust.

The parser already tracks parentheses via `PolyTraitRef.parens`, but
`print_poly_trait_ref` never checked this field. This adds `popen()`
and `pclose()` calls when `parens == Parens::Yes`.

Signed-off-by: Andrew V. Teylu <andrew.teylu@vector.com>
2026-03-06 10:38:47 +00:00
bors ff086354c9 Auto merge of #153316 - nnethercote:rm-with_related_context, r=oli-obk
Remove `tls::with_related_context`.

This function gets the current `ImplicitCtxt` and checks that its `tcx` matches the passed-in `tcx`. It's an extra bit of sanity checking: when you already have a `tcx`, and you need access to the non-`tcx` parts of `ImplicitCtxt`, check that your `tcx` matches the one in `ImplicitCtxt`.

However, it's only used in two places: `start_query` and `current_query_job`. The non-checked alternatives (`with_context`, `with_context_opt`) are used in more places, including some where a `tcx` is available. And things would have to go catastrophically wrong for the check to fail -- e.g. if we somehow end up with multiple `TyCtxt`s. In my opinion it's just an extra case to understand in `tls.rs` that adds little value.

This commit removes it. This avoids the need for `tcx` parameters in a couple of places. The commit also adjusts how `start_query` sets up its `ImplicitCtxt` to more closely match how similar functions do it, i.e. with `..icx.clone()` for the unchanged fields.

r? @oli-obk
2026-03-06 10:21:32 +00:00
Jynn Nelson 20404bf4a6 Split out linker-info from linker-messages
- Hide common linker output behind `linker-info`
- Add tests
- Account for different capitalization on windows-gnu when removing
  "warning" prefix
- Add some more comments
- Add macOS deployment-target test
- Ignore linker warnings from trying to statically link glibc

  I don't know what's going on in `nofile-limit.rs` but I want no part
  of it.

- Use a fake linker so tests are platform-independent
2026-03-06 10:38:21 +01:00
Guillaume Gomez c98094bd32 Remove TyCtxt::node_span_lint usage from rustc_hir_typeck 2026-03-05 23:53:54 +01:00
Guillaume Gomez e1ee66935e Remove TyCtxt::node_span_lint usage from rustc_hir_analysis 2026-03-05 23:53:54 +01:00
Guillaume Gomez 140ad033e7 Remove TyCtxt::node_span_lint usage from rustc_codegen_ssa 2026-03-05 23:53:54 +01:00
Guillaume Gomez 6e47be7ad9 Remove last use of rustc_middle::lint_level function in rustc_lint 2026-03-05 23:53:54 +01:00
Guillaume Gomez a0b24e39b9 Remove unused LintContext::opt_span_lint method 2026-03-05 23:53:53 +01:00
Guillaume Gomez 1f62cd2942 Remove unused LintContext::span_lint method 2026-03-05 23:53:53 +01:00
Guillaume Gomez 9dc456a366 Remove usage of LintContext::span_lint in clippy 2026-03-05 23:53:53 +01:00
Ada Bohm f8998e9ad9 as_slice removed 2026-03-05 20:10:44 +01:00
JayanAXHF 2093158de7 refactor: move check_align to parse_alignment
* refactor: move `check_align` from check_attrs.rs to `parse_alignment`

rel: attribute parser rework
* fix: fix error messages
* test: fix test
* fix: fix invalid error message
* ops(test): Fix CI
2026-03-05 18:46:00 +00:00
Jonathan Brouwer 11c4beac1e Rollup merge of #153453 - kpreid:fix-153388, r=fmease,estebank
Fix ICEs due to incomplete typechecking on struct literals with syntax errors.

Fixes rust-lang/rust#153388.
Followup to rust-lang/rust#153227.

Today I have learned that when we don’t emit a diagnostic *specifically from typeck*, we need to call `self.infcx.set_tainted_by_errors()` to signal that the type checking is incomplete despite the lack of error.

r? fmease
2026-03-05 19:42:01 +01:00
Jonathan Brouwer 4a5a2165d2 Rollup merge of #153435 - aerooneqq:delegation_res_def_id_ice, r=petrochenkov
Fix obtaining def_id from unresolved segment

This PR fixes ICE when trying to obtain `def_id` from an unresolved segment, part of rust-lang/rust#118212, fixes rust-lang/rust#153389.

r? @petrochenkov
2026-03-05 19:42:01 +01:00
Jonathan Brouwer e26f208680 Rollup merge of #153422 - nnethercote:tcx-comment, r=bjorn3
Add a comment explaining the 'tcx lifetime.

I wrote this after thinking about where the `'tcx` lifetime actually comes from.

r? @bjorn3
2026-03-05 19:42:00 +01:00
Jonathan Brouwer 1e70647450 Rollup merge of #153386 - nnethercote:minor-query-cleanups, r=petrochenkov
Minor query cleanups

Details in individual commits.

r? @petrochenkov
2026-03-05 19:42:00 +01:00
Jonathan Brouwer 31c5680a50 Rollup merge of #153378 - Zalathar:for-each, r=fee1-dead
Rename `QueryCache::iter` to `for_each`

Methods that perform internal iteration are typically named `for_each`.
2026-03-05 19:41:59 +01:00
Jonathan Brouwer 9632fd893d Rollup merge of #152906 - lapla-cogito:issue_152653, r=BoxyUwU
Make `const_lit_matches_ty` check literal suffixes for exact type match

`const_lit_matches_ty` ignored literal suffixes. This let the `try_lower_anon_const_lit` fast path produce a mistyped `ty::Const::Value`, bypassing the type mismatch error that typeck would otherwise report.
2026-03-05 19:41:59 +01:00
Jonathan Brouwer 77f0241206 Rollup merge of #153436 - eggyal:shlex-not-shell_words, r=ChrisDenton
Use shlex instead of shell-words

In rust-lang/rust#152712, the [`shell-words`] crate was introduced as a new dependency of `rustc_llvm` in order for its build script to parse the output of `llvm-config --quote-paths` and thereby handle paths containing whitespace; however, as [noted by bjorn3], that build script already transitively depends upon the [`shlex`] crate (via the [`cc`] crate) which provides similar functionality.

This patch is based off (the already-approved) rust-lang/rust#153419, which would otherwise conflict.

[`cc`]: https://crates.io/crates/cc
[noted by bjorn3]: https://github.com/rust-lang/rust/pull/152712#issuecomment-3994130008
[`shell-words`]: https://crates.io/crates/shell-words
[`shlex`]: https://crates.io/crates/shlex

r? ChrisDenton
2026-03-05 19:41:58 +01:00
Kevin Reid 072bd694ad Fix ICEs due to incomplete typechecking on struct literals with syntax errors. 2026-03-05 09:50:13 -08:00
Zalathar 743d442845 Rename QueryCache::iter to for_each
Methods that perform internal iteration are typically named `for_each`.
2026-03-05 23:39:59 +11:00
bors 64b72a1fa5 Auto merge of #150447 - WaffleLapkin:maybe-dangling-semantics, r=RalfJung
Implement `MaybeDangling` compiler support



Tracking issue: https://github.com/rust-lang/rust/issues/118166



cc @RalfJung
2026-03-05 12:21:27 +00:00
Guillaume Gomez 25c7798004 Create new Diagnostic type for panic calls without literals 2026-03-05 12:12:31 +01:00