Commit Graph

48471 Commits

Author SHA1 Message Date
Matthias Krüger
bfd8abd8f3 Rollup merge of #141069 - chenyukang:yukang-fix-137486-suggest-mut, r=davidtwco
Suggest mut when possbile for temporary value dropped while borrowed

Fixes #137486
2025-06-12 22:09:41 +02:00
Matthias Krüger
ae7615039f Rollup merge of #134536 - Urgau:fn-ptr-option, r=compiler-errors,traviscross
Lint on fn pointers comparisons in external macros

This PR extends the recently stabilized `unpredictable_function_pointer_comparisons` lint ~~to also lint on `Option<{function pointer}>` and~~ as well as linting in external macros (as to catch `assert_eq!` and others).

```rust
assert_eq!(Some::<FnPtr>(func), Some(func as unsafe extern "C" fn()));
//~^ WARN function pointer comparisons

#[derive(PartialEq, Eq)]
struct A {
    f: fn(),
    //~^ WARN function pointer comparisons
}
```

Fixes https://github.com/rust-lang/rust/issues/134527
2025-06-12 22:09:41 +02:00
bors
573a015690 Auto merge of #138164 - jdonszelmann:attr-parsing-lint-infra, r=oli-obk
Infrastructure for lints during attribute parsing, specifically duplicate usages of attributes

r? `@oli-obk`

This PR adds a new field to OwnerInfo to buffer lints which are generated during attribute parsing and ast lowering in general. They can't be emitted at this stage because at that point there's no HIR yet, and early lints are already emitted.

This also adds the generic `S: Stage` to attribute parsers. Currently we don't emit any lints during early attribute parsing, but if we ever want to that logic will be different. That's because there we don't have hir ids yet, while at the same time still having access to node ids and early lints. Even though that logic isn't completely there in this PR (no worries, we don't use it), that's why the parameter is there.

With this PR, we also add 2 associated consts  to `SingleAttributeParser`. Those determine what logic should be applied when finding a duplicate attribute.

This PR was getting pretty large, so the first code using this logic is in rust-lang/rust#138165. This code is all new things that weren't possible before so it also doesn't break any behaviour. However, some of it will be dead code right now. I recommend reviewing both before merging, though in some sense that doubles the size of the review again, and the other PR might be more controversial. Let me know how you want to do this `@oli-obk`
2025-06-12 19:48:49 +00:00
Folkert de Vries
5f73ce2b7e add extern "custom" functions 2025-06-12 20:27:10 +02:00
Matthias Krüger
94e8a2448f Rollup merge of #141474 - mejrs:diagnostic_mode, r=compiler-errors
Add `ParseMode::Diagnostic` and fix multiline spans in diagnostic attribute lints

Best viewed commit by commit.

The first commit is a test, the commits following that are small refactors to `rustc_parse_format`. Originally I wanted to do a much larger change (doing these smaller fixes first would have that made easier to review), but ended up doing something else instead.

An observable change from this is that the diagnostic attribute no longer tries to parse align/fill/width/etc parameters. For an example (see also test changes), a string like `"{Self:!}"` no longer says "missing '}'", instead it says that format parameters are not allowed. It'll now also format the string as if the user wrote just `"{Self}"`
2025-06-12 20:03:36 +02:00
Matthias Krüger
25914399ab Rollup merge of #141162 - mejrs:gated, r=fee1-dead
refactor  `AttributeGate` and `rustc_attr!` to emit notes during feature checking

First commit changes the following:

- `AttributeGate ` from an enum with (four) tuple fields to (five) named fields
- adds a `notes` fields that is emitted as notes in the `PostExpansionVisitor` pass
- removes the `this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date` note if the feature gate is `rustc_attrs`.
- various phrasing changes and touchups
- and finally, the reason why I went down this path to begin with: tell people they can use the diagnostic namespace when they hit the rustc_on_unimplemented feature gate 🙈

Second commit removes unused machinery for deprecated attributes
2025-06-12 20:03:35 +02:00
Ralf Jung
62418f4c56 intrinsics: rename min_align_of to align_of 2025-06-12 17:50:25 +02:00
Oli Scherer
488ebeecbe Remove lower_arg_ty as all callers were passing None 2025-06-12 15:04:09 +00:00
bors
6c8138de8f Auto merge of #142127 - compiler-errors:nested-goals-certainty, r=lcnr
Apply nested goals certainty to `InspectGoals` for normalizes-to

...so that normalizes-to goals don't have `Certainty::Yes` even if they have nested goals which don't hold.

r? lcnr
2025-06-12 11:29:20 +00:00
xizheyin
b8066f94fd Tracking the old name of renamed unstable library attribute
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-12 19:24:11 +08:00
Nicholas Nethercote
376cbc3787 Introduce -Zmacro-stats.
It collects data about macro expansions and prints them in a table after
expansion finishes. It's very useful for detecting macro bloat,
especially for proc macros.

Details:
- It measures code snippets by pretty-printing them and then measuring
  lines and bytes. This required a bunch of additional pretty-printing
  plumbing, in `rustc_ast_pretty` and `rustc_expand`.
- The measurement is done in `MacroExpander::expand_invoc`.
- The measurements are stored in `ExtCtxt::macro_stats`.
2025-06-12 21:17:17 +10:00
Deadbeef
ae8ca1f858 early linting: avoid redundant calls to check_id 2025-06-12 19:01:19 +08:00
Jana Dönszelmann
2e7e52e07c detect when variants have the same name as an associated function 2025-06-12 12:26:27 +02:00
Stypox
781baafbe4 Add documentation for init_logger_with_additional_layer 2025-06-12 12:11:15 +02:00
Oli Scherer
de4e7adc96 Don't hardcode the intrinsic return types twice in the compiler 2025-06-12 09:57:06 +00:00
Deadbeef
5f0dd44b3b avoid &mut P<T> in visit_expr etc methods 2025-06-12 17:36:03 +08:00
Jana Dönszelmann
e2afe04e2e remove 'static in some places 2025-06-12 09:57:38 +02:00
Trevor Gross
841f7ce69a Make missing_fragment_specifier an unconditional error
This was attempted in [1] then reverted in [2] because of fallout.
Recently, this was made an edition-dependent error in [3].

Make missing fragment specifiers an unconditional error again.

[1]: https://github.com/rust-lang/rust/pull/75516
[2]: https://github.com/rust-lang/rust/pull/80210
[3]: https://github.com/rust-lang/rust/pull/128006
2025-06-12 07:57:12 +00:00
Jana Dönszelmann
e6a5f281ec add error message for unused duplicate 2025-06-12 09:56:47 +02:00
Jana Dönszelmann
6072207a11 introduce new lint infra
lint on duplicates during attribute parsing
To do this we stuff them in the diagnostic context to be emitted after
hir is constructed
2025-06-12 09:56:47 +02:00
Jonathan Dönszelmann
4e1b6d13a2 Start using new diagnostic logic on all existing single parsers 2025-06-12 09:42:45 +02:00
Jana Dönszelmann
28bf61b9b3 introduce duplicate attribute diagnostic logic 2025-06-12 09:42:45 +02:00
Urgau
fafc0f249f Report the unpredictable_function_pointer_comparisons lint in macro 2025-06-12 07:33:56 +02:00
Nicholas Nethercote
bdfe1b9fb0 Overhaul the thousands module.
It currently only inserts separators into `usize`s, because that's all
that has been needed so far. `-Zmacro-stats` will need `isize` and `f64`
handling, so this commit adds that.
2025-06-12 15:26:06 +10:00
Nicholas Nethercote
fb73893e51 Add some useful Path/PathSegment equality operations.
They will be used in a subsequent commit.
2025-06-12 15:26:06 +10:00
Matthias Krüger
240776176b Rollup merge of #142352 - workingjubilee:c-int-width-is-an-integer, r=wesleywiser
compiler: Make `c_int_width` an integer

Because it is.

That's all I got.
2025-06-12 03:14:54 +02:00
Matthias Krüger
78d83952e4 Rollup merge of #142318 - Urgau:cleanup-rust-src-remap, r=jieyouxu
Cleanup `rust-src` remapping and real dir

When remapping, `bootstrap` sets `CFG_VIRTUAL_RUST_SOURCE_BASE_DIR` to indicate what the base build dir (`/` of this repo) was remapped to, ie. `/rustc/...`.

It is therefore impossible when stripping `/rustc/...` from a remapped path to be inside the our `library/` directory, nevertheless we have code that assumed it was possible and helpfully tried to correct it. I don't why this was done, but it's not necessary.

~~The normalization in compiletest of `$SRC_DIR_REAL` was also slightly wrong, it ate the `library` part for no reason.~~ EDIT: there is a reason, it affects too much tests otherwise

r? `@jieyouxu`
2025-06-12 03:14:53 +02:00
Matthias Krüger
75c186bf43 Rollup merge of #142261 - folkertdev:unstable-attr-correct-edition, r=compiler-errors
use correct edition when warning for unsafe attributes

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

If an attribute is re-emitted by a macro, the incorrect edition was used to emit warnings for unsafe attributes.

This logic was introduced in https://github.com/rust-lang/rust/pull/139718

cc `@compiler-errors` `@ehuss`
2025-06-12 03:14:52 +02:00
Matthias Krüger
2d9513b98c Rollup merge of #142157 - Enselic:trivial-anon-const-use-cases, r=compiler-errors
rustc_resolve: Improve `resolve_const_param_in_non_trivial_anon_const` wording

In some contexts, const expressions are OK. Add a `here` to the error message to clarify this.

Closes rust-lang/rust#79429 which has 15 x 👍
2025-06-12 03:14:51 +02:00
Matthias Krüger
bdf7b74517 Rollup merge of #142040 - jswrenn:transmute-ty-region-generic, r=compiler-errors
transmutability: shift abstraction boundary

Previously, `rustc_transmute`'s layout representations were genericized over `R`, a reference. Now, it's instead genericized over representations of type and region. This allows us to move reference transmutability logic from `rustc_trait_selection` to `rustc_transmutability` (and thus unit test it independently of the compiler), and — in a follow-up PR — will make it possible to support analyzing function pointer transmutability with minimal surgery.

r? `@compiler-errors`
2025-06-12 03:14:49 +02:00
Matthias Krüger
9f6e81c202 Rollup merge of #141307 - b-naber:closure-body, r=celinval
Add method to retrieve body of closure in stable-mir

fixes https://github.com/rust-lang/project-stable-mir/issues/85

r? `@celinval`
2025-06-12 03:14:49 +02:00
Celina G. Val
f52c6eee02 Another round of tidy / warning fixes 2025-06-11 16:56:01 -07:00
beetrees
eb472e77cd Apply ABI attributes on return types in rustc_codegen_cranelift 2025-06-12 00:47:01 +01:00
Camille GILLOT
a5ff3cc3f5 Do not clone Arc when hashing span. 2025-06-11 23:44:22 +00:00
Matthias Krüger
f417620160 Rollup merge of #142369 - jdonszelmann:attr-docs, r=fmease
Improve some attribute docs and rename groups

r? `@nnethercote`

Some naming here got changed at some point, and this feels more consistent. The docs changes were a direct response to `@mejrs` trying to implement a new parsers and running into this.
2025-06-11 22:58:29 +02:00
Matthias Krüger
e78b619cad Rollup merge of #142362 - Veykril:push-rzmrsswqourz, r=oli-obk
Add expectation for `{` when parsing lone coroutine qualifiers

Fixes https://github.com/rust-lang/rust/issues/80931
2025-06-11 22:58:28 +02:00
Matthias Krüger
e2846d6b75 Rollup merge of #142356 - Stypox:fix-enter_trace_span, r=RalfJung
Fix enter_trace_span!() using wrong $crate paths

This is a followup to rust-lang/rust#140972, where I made a silly mistake and forgot to update `$crate::interpret::tracing_utils::...` to `$crate::interpret::util::...` inside the macro after moving the referenced code from `tracing_utils.rs` to `util.rs`. Sorry about this.

r? `@RalfJung`
2025-06-11 22:58:28 +02:00
Matthias Krüger
b29c9a3588 Rollup merge of #142305 - GuillaumeGomez:remove-visit_id-EarlyContextAndPass, r=oli-obk
Remove unneeded `check_id` calls as they are already called in `visit_id` in `EarlyContextAndPass` type

Follow-up from [this message](https://github.com/rust-lang/rust/pull/142240/files#r2137474724).

Since `check_id` is already called in `visit_id` which is supposed to be called for each item with an ID, we don't need to manually call `check_id`.

r? `@oli-obk`
2025-06-11 22:58:26 +02:00
Celina G. Val
4aa62ea9e9 Use rustc_thread_pool instead of rustc-rayon-core 2025-06-11 12:26:42 -07:00
sayantn
d56fcd968d Simplify implementation of Rust intrinsics by using type parameters in the cache 2025-06-12 00:32:42 +05:30
Celina G. Val
0b9b1df006 Fix format and tidy for code moved from rayon 2025-06-11 11:12:32 -07:00
bors
e703dff8fe Auto merge of #142358 - matthiaskrgr:rollup-fxe6m7k, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#141967 (Configure bootstrap backport nominations through triagebot)
 - rust-lang/rust#142042 (Make E0621 missing lifetime suggestion verbose)
 - rust-lang/rust#142272 (tests: Change ABIs in tests to more future-resilient ones)
 - rust-lang/rust#142282 (Only run `citool` tests on the `auto` branch)
 - rust-lang/rust#142297 (Implement `//@ needs-target-std` compiletest directive)
 - rust-lang/rust#142298 (Make loongarch-none target maintainers more easily pingable)
 - rust-lang/rust#142306 (Dont unwrap and re-wrap typing envs)
 - rust-lang/rust#142324 (Remove unneeded `FunctionCx` from some codegen methods)
 - rust-lang/rust#142328 (feat: Add `bit_width` for unsigned integer types)

Failed merges:

 - rust-lang/rust#141639 (Expose discriminant values in stable_mir)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-11 17:51:57 +00:00
Celina G. Val
35c5144394 Move rayon-core to rustc_thread_pool files as is
This commit literally copied the directory rayon-core from
revision `5fadf44`. Link:
https://github.com/rust-lang/rustc-rayon/tree/5fadf44/rayon-core
2025-06-11 10:43:59 -07:00
Jubilee Young
86493f75a5 compiler: Avoid reporting unsupported_calling_conventions in deps 2025-06-11 09:55:41 -07:00
Jana Dönszelmann
ce0438684d consistently rename (old) attribute groups 2025-06-11 18:46:57 +02:00
Jana Dönszelmann
34241e5397 document attribute parsers better 2025-06-11 18:46:57 +02:00
Lukas Wirth
edc405d383 Add expectation for { when parsing lone coroutine qualifiers 2025-06-11 17:11:58 +02:00
Boxy
fe04ae7faf stabilize gai 2025-06-11 15:30:15 +01:00
Matthias Krüger
b1c668ca03 Rollup merge of #142324 - scottmcm:less-functioncx, r=workingjubilee
Remove unneeded `FunctionCx` from some codegen methods

No changes; just removing the `self` that wasn't needed.

r? workingjubilee
cc https://github.com/rust-lang/rust/pull/138759#issuecomment-2920860686
2025-06-11 13:48:13 +02:00
Matthias Krüger
9ef19ddfd8 Rollup merge of #142306 - compiler-errors:nit-reveal-param-env-query, r=lcnr
Dont unwrap and re-wrap typing envs

Just a tiny tweak to make the query less awkward.

r? lcnr
2025-06-11 13:48:12 +02:00