Commit Graph

48659 Commits

Author SHA1 Message Date
Matthias Krüger
d7e10f083c Rollup merge of #142805 - estebank:underscore-import, r=compiler-errors
Emit a single error when importing a path with `_`

When encountering `use _;`, `use _::*'` or similar, do not emit two errors for that single mistake. This also side-steps the issue of resolve errors suggesting adding a crate named `_` to `Cargo.toml`.

Fix rust-lang/rust#142662.
2025-06-24 20:46:04 +02:00
Matthias Krüger
03c2197d6c Rollup merge of #142799 - petrochenkov:expnop, r=bjorn3
rustc_session: Add a structure for keeping both explicit and default sysroots

Also avoid creating and cloning sysroot unnecessarily.

Implements the suggestion from https://github.com/rust-lang/rust/pull/142089#discussion_r2132204079.
r? ``@bjorn3``
2025-06-24 20:46:04 +02:00
Matthias Krüger
9f384c414c Rollup merge of #142657 - tgross35:nonoptional-fragment-specifiers-cleanup, r=petrochenkov
mbe: Clean up code with non-optional `NonterminalKind`

Since [rust-lang/rust#128425], the fragment specifier is unconditionally required in all
editions. This means `NonTerminalKind` no longer needs to be optional,
as we can reject this code during the expansion of `macro_rules!` rather
than handling it throughout the code. Do this cleanup here.

[rust-lang/rust#128425]: https://github.com/rust-lang/rust/pull/128425
2025-06-24 20:46:03 +02:00
Matthias Krüger
27819a009d Rollup merge of #142645 - Urgau:usage-non_upper_case_globals, r=fmease
Also emit suggestions for usages in the `non_upper_case_globals` lint

This PR adds suggestions for all the usages of the renamed item in the warning of the  `non_upper_case_globals` lint.

Fixes https://github.com/rust-lang/rust/issues/124061
2025-06-24 20:46:03 +02:00
Esteban Küber
904652b2d0 Suggest cloning Arc moved into closure
```
error[E0382]: borrow of moved value: `x`
  --> $DIR/moves-based-on-type-capture-clause-bad.rs:9:20
   |
LL |     let x = "Hello world!".to_string();
   |         - move occurs because `x` has type `String`, which does not implement the `Copy` trait
LL |     thread::spawn(move || {
   |                   ------- value moved into closure here
LL |         println!("{}", x);
   |                        - variable moved due to use in closure
LL |     });
LL |     println!("{}", x);
   |                    ^ value borrowed here after move
   |
   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning the value before moving it into the closure
   |
LL ~     let value = x.clone();
LL ~     thread::spawn(move || {
LL ~         println!("{}", value);
   |
```
2025-06-24 18:44:41 +00:00
bendn
3583423536 suggest declaring modules when file found but module not defined 2025-06-25 01:12:15 +07:00
Michael Goulet
1c9f7955d4 Check CoerceUnsized impl validity before coercing 2025-06-24 17:48:09 +00:00
Esteban Küber
d82fb1e72d Emit a single error when importing a path with _
When encountering `use _;`, `use _::*'` or similar, do not emit two errors for that single mistake. This also side-steps the issue of resolve errors suggesting adding a crate named `_` to `Cargo.toml`.
2025-06-24 16:21:26 +00:00
Jieyou Xu
db11e74723 Don't include current rustc version string in feature removed help
The version string is difficult to properly normalize out, and removing
it isn't a huge deal (the user can query version info easily through
`rustc --version` or `cargo --version`).

The normalization options were all non-ideal:

- Per-test version string normalization is nasty to maintain, and we
  need to maintain `n` copies of it.
- Centralized compiletest normalization (with a directive opt-out) is
  also not ideal, because `cfg(version(..))` tests can't have those
  accidentally normalized out (and you'd have to remember to opt-out).
2025-06-24 23:32:09 +08:00
Guillaume Gomez
e8dd3c356c Rollup merge of #142944 - nnethercote:stats-tweaks, r=lqd
Stats output tweaks

Some improvements to `-Zinput-stats` and `-Zmeta-stat` inspired by the new `-Zmacro-stats`.

r? `@lqd`
2025-06-24 15:39:42 +02:00
Guillaume Gomez
4b52c9d8ea Rollup merge of #142742 - dpaoliello:arm64eclinking, r=bjorn3
[win][aarch64] Fix linking statics on Arm64EC, take 2

Arm64EC builds recently started to fail due to the linker not finding a symbol:
```
symbols.o : error LNK2001: unresolved external symbol #_ZN3std9panicking11EMPTY_PANIC17hc8d2b903527827f1E (EC Symbol)
          C:\Code\hello-world\target\arm64ec-pc-windows-msvc\debug\deps\hello_world.exe : fatal error LNK1120: 1 unresolved externals
```

It turns out that `EMPTY_PANIC` is a new static variable that was being exported then imported from the standard library, but when exporting LLVM didn't prepend the name with `#` (as only functions are prefixed with this character), whereas Rust was prefixing with `#` when attempting to import it.

The fix is to have Rust not prefix statics with `#` when importing.

Adding tests discovered another issue: we need to correctly mark static exported from dylibs with `DATA`, otherwise MSVC's linker assumes they are functions and complains that there is no exit thunk for them.

Fixes rust-lang/rust#138541

Resurrects rust-lang/rust#140176 now that rust-lang/rust#141061 is merged, which removes the incompatibility with `__rust_no_alloc_shim_is_unstable`.

r? ``@wesleywiser``

CC ``@bjorn3``
2025-06-24 15:39:39 +02:00
Guillaume Gomez
0377330be4 Rollup merge of #142704 - tgross35:remove-concat_idents, r=fee1-dead
Remove the deprecated unstable `concat_idents!` macro

In [rust-lang/rust#137653], the lang and libs-API teams did a joint FCP to deprecate
and eventually remove the long-unstable `concat_idents!` macro. The
deprecation is landing in 1.88, so do the removal here (target version
1.90).

This macro has been superseded by the more recent `${concat(...)}`
metavariable expression language feature, which avoids some of the
limitations of `concat_idents!`. The metavar expression is unstably
available under the [`macro_metavar_expr_concat`] feature.

History is mildly interesting here: `concat_idents!` goes back to 2011
when it was introduced with 513276e595 ("Add #concat_idents[] and
#ident_to_str[]"). The syntax looks a bit different but it still works
about the same:

    let asdf_fdsa = "<.<";
    assert(#concat_idents[asd,f_f,dsa] == "<.<");

    assert(#ident_to_str[use_mention_distinction]
           == "use_mention_distinction");

(That test existed from introduction until its removal here.)

Closes: https://github.com/rust-lang/rust/issues/29599

[rust-lang/rust#137653]: https://github.com/rust-lang/rust/pull/137653
[`macro_metavar_expr_concat`]: https://github.com/rust-lang/rust/issues/124225
2025-06-24 15:39:38 +02:00
Vadim Petrochenkov
0be37cab97 rustc_session: Add a structure for keeping both explicit and default sysroots
Also avoid creating and cloning sysroot unnecessarily.
2025-06-24 16:00:04 +03:00
Folkert de Vries
943d37958b Error on invalid signatures for interrupt ABIs 2025-06-24 14:40:11 +02:00
bjorn3
16c041d973 Merge commit '8c848e0604b5d26fad120914f822f564fe05c52a' into sync_cg_clif-2025-06-24 2025-06-24 11:32:02 +00:00
Trevor Gross
0e4de4ceb0 Remove the deprecated concat_idents! macro
In [137653], the lang and libs-API teams did a joint FCP to deprecate
and eventually remove the long-unstable `concat_idents!` macro. The
deprecation is landing in 1.88, so do the removal here (target version
1.90).

This macro has been superseded by the more recent `${concat(...)}`
metavariable expression language feature, which avoids some of the
limitations of `concat_idents!`. The metavar expression is unstably
available under the [`macro_metavar_expr_concat`] feature.

History is mildly interesting here: `concat_idents!` goes back to 2011
when it was introduced with 513276e595 ("Add #concat_idents[] and
about the same:

    let asdf_fdsa = "<.<";
    assert(#concat_idents[asd,f_f,dsa] == "<.<");

    assert(#ident_to_str[use_mention_distinction]
           == "use_mention_distinction");

(That test existed from introduction until its removal here.)

Closes: https://www.github.com/rust-lang/rust/issues/29599

[137653]: https://www.github.com/rust-lang/rust/pull/137653
[`macro_metavar_expr_concat`]: https://www.github.com/rust-lang/rust/issues/124225
2025-06-24 11:07:16 +00:00
Guillaume Gomez
7b864ac190 Rollup merge of #142933 - compiler-errors:refactor-solver-api, r=lcnr
Simplify root goal API of solver a bit

Root goal API is more easily distinguished between proof tree and non-proof tree, rather than `eval_goal` vs `eval_goal_raw`.

r? lcnr
2025-06-24 11:20:10 +02:00
Guillaume Gomez
69cc875438 Rollup merge of #142695 - GrigorenkoPV:attributes/rustc_skip_during_method_dispatch, r=jdonszelmann
Port `#[rustc_skip_during_method_dispatch]` to the new attribute system

Part of rust-lang/rust#131229

r? ``@jdonszelmann``
2025-06-24 11:20:07 +02:00
bjorn3
77232fb935 Fix normalization in linker-warning
Ensure rustc_codegen_cranelift doesn't get normalized to rustc. And
handle -Cpanic=abort.
2025-06-24 09:06:47 +00:00
Trevor Gross
cd5de49eaa mbe: Use TokenTree as the fallback for invalid fragment specifiers
`tt` should match more, so use this for both missing and invalid
fragment specifiers.

Also remove one unneeded instance of `String`.
2025-06-24 04:37:54 -04:00
Trevor Gross
b9e9be38c0 mbe: Clean up code with non-optional NonterminalKind
Since [1], the fragment specifier is unconditionally required in all
editions. This means `NonTerminalKind` no longer needs to be optional,
as we can reject this code during the expansion of `macro_rules!` rather
than handling it throughout the code. Do this cleanup here.

[1]: https://github.com/rust-lang/rust/pull/128425
2025-06-24 04:37:36 -04:00
Trevor Gross
be927caf06 mbe: Unnest nested matches with let-else and let chains
Non-functional change to simplify control flow.
2025-06-24 04:37:32 -04:00
Camille GILLOT
068f3ac20b Update test. 2025-06-24 04:05:27 +00:00
Nicholas Nethercote
b2a57e6b42 Tweak -Zinput-stats and -Zmeta-stats output.
To make it match `-Zmacro-stats`, and work better if you have enabled it
for multiple crates.
- Print each crate's name.
- Print a `===` banner at the start and end for separation.
2025-06-24 13:07:14 +10:00
Nicholas Nethercote
1e7e1732ca Reverse order of -Zinput-stats and -Zmeta-stats output.
Currently they have the largest items at the end. I believe the
rationale is that it saves you scrolling up through terminal output
because the important stuff is at the bottom. But it's also surprising
and a bit confusing, and I think the obvious order (big things at the
top) is better.
2025-06-24 13:05:53 +10:00
Nicholas Nethercote
8b1abd6578 Make stats code nicer.
Taking inspiration from `-Zmacro-stats`:
- Use "{prefix}" consistently.
- Use names for column widths.
- Write output in a single `eprint!` call, in an attempt to minimize
  interleaving of output from different rustc processes.
- Use `repeat` for the long `---` banners.
2025-06-24 13:05:51 +10:00
Michael Goulet
92e60e98af Apply fast path to old solver too 2025-06-24 01:42:28 +00:00
Michael Goulet
b8ef88517d Introduce trivial WF functions, use it in fast path 2025-06-24 01:42:28 +00:00
Nicholas Nethercote
c3200c3bb5 Tweak -Zmacro-stats measurement.
It currently reports net size, i.e. size(output) - size(input). After
some use I think this is sub-optimal, and it's better to just report
size(output). Because for derive macros the input size is always 1, and
for attribute macros it's almost always 1.
2025-06-24 08:42:14 +10:00
Michael Goulet
abd15858a1 Simplify API of solver a bit 2025-06-23 22:09:11 +00:00
Michael Goulet
df426cf289 Uplift find_const_ty_from_env 2025-06-23 21:00:23 +00:00
Michael Goulet
00f369abc2 Add note to find_const_ty_from_env 2025-06-23 21:00:09 +00:00
Jubilee
b7a9cd871c Rollup merge of #142923 - folkertdev:min-function-alignment-no-attributes, r=workingjubilee
fix `-Zmin-function-alignment` on functions without attributes

tracking issue: https://github.com/rust-lang/rust/issues/82232
related: https://github.com/rust-lang/rust/pull/142854

The minimum function alignment was skipped on functions without attributes (because the logic was in a loop that only runs if there is at least one attribute). The underlying reason we didn't catch this before is that in our testing we generally apply `#[no_mangle]` to functions that are tested. I've added a test now that deliberately has no attributes.

r? `@workingjubilee`
2025-06-23 12:48:23 -07:00
Jubilee
8ba8f1ef4c Rollup merge of #142873 - Urgau:issue-139830, r=BoxyUwU
Don't suggest changing a  method inside a expansion

Fixes https://github.com/rust-lang/rust/issues/139830
r? compiler
2025-06-23 12:48:22 -07:00
Pavel Grigorenko
aa80a2b62c Port #[rustc_skip_during_method_dispatch] to the new attribute system 2025-06-23 22:48:20 +03:00
Jubilee
8ba69d0f95 Rollup merge of #142784 - Kobzol:timings-codegen, r=nnethercote
Add codegen timing section

And since we now start and end the sections also using separate functions, also add some light checking if we're generating the sections correctly.

I'm integrating `--timings` into Cargo, and I realized that the codegen timings would be quite useful for that. Frontend can be computed simply as `[start of compilation, start of codegen]` for now.

r? `@nnethercote`
2025-06-23 12:48:20 -07:00
Daniel Paoliello
2602653424 [Arm64EC] Only decorate functions with # 2025-06-23 12:38:35 -07:00
bjorn3
ba5556d239 Add #[loop_match] for improved DFA codegen
Co-authored-by: Folkert de Vries <folkert@folkertdev.nl>
2025-06-23 20:43:04 +02:00
Folkert de Vries
8147646531 fix -Zmin-function-alignment without attributes
the minimum function alignment was skipped on functions without attributes. That is because in our testing we generally apply `#[no_mangle]` to functions that are tested. I've added a test now that deliberately has no attributes
2025-06-23 20:26:04 +02:00
Ralf Jung
7c6b50cd5b unsupported_calling_conventions: print which ABI this is about 2025-06-23 09:40:00 -07:00
Jubilee Young
267ecd132b Clarify note in rustc_ast_lowering still applies
Co-authored-by: Ralf Jung <post@ralfj.de>
2025-06-23 09:40:00 -07:00
Jubilee Young
b34c52043f compiler: Remove unsupported_fn_ptr_calling_conventions lint 2025-06-23 09:39:59 -07:00
Jubilee Young
e93a99b324 hir_analysis: Avoid repeating unsupported ABI errors 2025-06-23 09:39:23 -07:00
Jubilee Young
2f4a55b41d compiler: plug unsupported ABI leakage from the AST
We modify rustc_ast_lowering to prevent all unsupported ABIs
from leaking through the HIR without being checked for target support.
Previously ad-hoc checking on various HIR items required making sure
we check every HIR item which could contain an `extern "{abi}"` string.
This is a losing proposition compared to gating the lowering itself.

As a consequence, unsupported ABI strings will now hard-error instead of
triggering the FCW `unsupported_fn_ptr_calling_conventions`.
This FCW was upgraded to warn in dependencies in Rust 1.87 which was
released on 2025 May 17, and it is now 2025 June, so it has become
active within a stable Rust version.

As we already had errored on these ABIs in most other positions, and
have warned for fn ptrs, this breakage has had reasonable foreshadowing.

However, this does cause errors for usages of `extern "{abi}"` that were
theoretically writeable within source but could not actually be applied
in any useful way by Rust programmers without either warning or error.
For instance, trait declarations without impls were never checked.
These are the exact kinds of leakages that this new approach prevents.

A deprecation cycle is not useful for these marginal cases as upon impl,
even default impls within traits, different HIR objects would be used.
Details of our HIR analysis meant that those objects did get checked.

We choose to error twice if an ABI is also barred by a feature gate
on the presumption that usage of a target-incorrect ABI is intentional.

Co-authored-by: Ralf Jung <post@ralfj.de>
2025-06-23 09:39:23 -07:00
Jakub Beránek
6083850ba8 Skip late_lint_mod_inner if all built-in lints can be skipped 2025-06-23 17:35:49 +02:00
Jakub Beránek
637bf919eb Fix doc comment 2025-06-23 17:35:49 +02:00
Guillaume Gomez
3b5525bc42 Improve code and documentation 2025-06-23 16:12:49 +02:00
Guillaume Gomez
78cbcaffea Update tests to work with new DocFragment field and redundant_explicit_links new API 2025-06-23 16:02:34 +02:00
Guillaume Gomez
7e683cc4d1 Do not emit redundant_explicit_links rustdoc lint if the doc comment comes from expansion 2025-06-23 16:02:33 +02:00
Jana Dönszelmann
6cee0a6ead Rollup merge of #142892 - jdonszelmann:fix-142891, r=oli-obk
Fix ICE on debug builds where lints are delayed on the crate root

r? ``@oli-obk``

Closes rust-lang/rust#142891

thanks to ``@JonathanBrouwer`` for finding it!
2025-06-23 12:39:09 +02:00