Commit graph

45050 commits

Author SHA1 Message Date
Nicholas Nethercote
a28d5092e9 Improve keyword comments a little. 2025-03-24 18:43:37 +11:00
Nicholas Nethercote
9dd5340d3c Remove is_any_keyword methods.
They're dodgy, covering all the keywords, including weak ones, and
edition-specific ones without considering the edition. They have a
single use in rustfmt. This commit changes that use to
`is_reserved_ident`, which is a much more widely used alternative and is
good enough, judging by the lack of effect on the test suite.
2025-03-24 18:43:37 +11:00
Lukas Wirth
5950c862bd Slim rustc_parse_format dependencies down
`rustc_index` is only used for its size assertion macro, so demote it to a dev-dependency gated under testing instead
2025-03-23 07:30:18 +01:00
bors
756bff97ea Auto merge of #138841 - matthiaskrgr:rollup-bfkls57, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #138018 (rustdoc: Use own logic to print `#[repr(..)]` attributes in JSON output.)
 - #138294 (Mark some std tests as requiring `panic = "unwind"`)
 - #138468 (rustdoc js: add nonnull helper and typecheck src-script.js)
 - #138675 (Add release notes for 1.85.1)
 - #138765 (Fix Thread::set_name on cygwin)
 - #138786 (Move some driver code around)
 - #138793 (target spec check: better error when llvm-floatabi is missing)
 - #138822 (De-Stabilize `file_lock`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-22 23:59:01 +00:00
bors
b48576b4db Auto merge of #138831 - matthiaskrgr:rollup-3t0dqiz, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #138609 (Add stack overflow handler for cygwin)
 - #138639 (Clean UI tests 2 of n)
 - #138773 (catch_unwind intrinsic: document return value)
 - #138782 (test(ui): add tuple-struct-where-clause-suggestion ui test for #91520)
 - #138794 (expand: Do not report `cfg_attr` traces on macros as unused attributes)
 - #138801 (triagebot: add autolabel rules for D-* and L-*)
 - #138804 (Allow inlining for `Atomic*::from_ptr`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-22 20:52:30 +00:00
Matthias Krüger
7372f2812b
Rollup merge of #138793 - RalfJung:arm-floatabi, r=Noratrieb
target spec check: better error when llvm-floatabi is missing
2025-03-22 21:34:39 +01:00
Matthias Krüger
4457da3dc4
Rollup merge of #138786 - bjorn3:driver_code_move, r=compiler-errors
Move some driver code around

`--emit mir`, `#[rustc_symbol_name]` and `#[rustc_def_path]` now run before codegen and thus work even if codegen fails. This can help with debugging.
2025-03-22 21:34:39 +01:00
bors
d93f678fa5 Auto merge of #138830 - matthiaskrgr:rollup-gaxgfwl, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #138410 (Couple mir building cleanups)
 - #138490 (Forward `stream_position` in `Arc<File>` as well)
 - #138535 (Cleanup `LangString::parse`)
 - #138536 (stable_mir: Add `MutMirVisitor`)
 - #138673 (Fix build failure on Trusty)
 - #138750 (Make `crate_hash` not iterate over `hir_crate` owners anymore)
 - #138763 (jsondocck: Replace `jsonpath_lib` with `jsonpath-rust`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-22 14:03:50 +00:00
Matthias Krüger
66c3566b88
Rollup merge of #138794 - petrochenkov:cfgtracefix, r=jieyouxu
expand: Do not report `cfg_attr` traces on macros as unused attributes

Fixes https://github.com/rust-lang/rust/issues/138779
2025-03-22 12:00:50 +01:00
Matthias Krüger
fb09bd52a8
Rollup merge of #138750 - oli-obk:decouple-hir-queries, r=fee1-dead
Make `crate_hash` not iterate over `hir_crate` owners anymore

cc https://github.com/rust-lang/rust/issues/95004

One more direct usage of hir::Crate removed
2025-03-22 11:59:19 +01:00
Matthias Krüger
1cb17dd6f2
Rollup merge of #138536 - makai410:mut-mir-visitor, r=celinval
stable_mir: Add `MutMirVisitor`

Resolves: [rust-lang/project-stable-mir#81](https://github.com/rust-lang/project-stable-mir/issues/81).

I am unsure if we should add a `MutableBody` like Kani did.
Currently, I use `&mut Body` in `MutMirVisitor::visit_body()`.

r? ``````@celinval``````
2025-03-22 11:59:17 +01:00
Matthias Krüger
92acd148f8
Rollup merge of #138410 - bjorn3:misc_cleanups, r=compiler-errors
Couple mir building cleanups
2025-03-22 11:59:15 +01:00
bors
0ce1369bde Auto merge of #136974 - m-ou-se:fmt-options-64-bit, r=scottmcm
Reduce FormattingOptions to 64 bits

This is part of https://github.com/rust-lang/rust/issues/99012

This reduces FormattingOptions from 6-7 machine words (384 bits on 64-bit platforms, 224 bits on 32-bit platforms) to just 64 bits (a single register on 64-bit platforms).

Before:

```rust
pub struct FormattingOptions {
    flags: u32, // only 6 bits used
    fill: char,
    align: Option<Alignment>,
    width: Option<usize>,
    precision: Option<usize>,
}
```

After:

```rust
pub struct FormattingOptions {
    /// Bits:
    ///  - 0-20: fill character (21 bits, a full `char`)
    ///  - 21: `+` flag
    ///  - 22: `-` flag
    ///  - 23: `#` flag
    ///  - 24: `0` flag
    ///  - 25: `x?` flag
    ///  - 26: `X?` flag
    ///  - 27: Width flag (if set, the width field below is used)
    ///  - 28: Precision flag (if set, the precision field below is used)
    ///  - 29-30: Alignment (0: Left, 1: Right, 2: Center, 3: Unknown)
    ///  - 31: Always set to 1
    flags: u32,
    /// Width if width flag above is set. Otherwise, always 0.
    width: u16,
    /// Precision if precision flag above is set. Otherwise, always 0.
    precision: u16,
}
```
2025-03-22 10:56:14 +00:00
bors
db687889a5 Auto merge of #138719 - lcnr:concrete_opaque_types-closures, r=oli-obk
merge opaque types defined in nested bodies

A small step towards https://github.com/rust-lang/types-team/issues/129

r? `@oli-obk`
2025-03-22 06:55:52 +00:00
bors
48b36c9d59 Auto merge of #128320 - saethlin:link-me-maybe, r=compiler-errors
Avoid no-op unlink+link dances in incr comp

Incremental compilation scales quite poorly with the number of CGUs. This PR improves one reason for that.

The incr comp process hard-links all the files from an old session into a new one, then it runs the backend, which may just hard-link the new session files into the output directory. Then codegen hard-links all the output files back to the new session directory.

This PR (perhaps unimaginatively) fixes the silliness that ensues in the last step. The old `link_or_copy` implementation would be passed pairs of paths which are already the same inode, then it would blindly delete the destination and re-create the hard-link that it just deleted. This PR lets us skip both those operations. We don't skip the other two hard-links.

`cargo +stage1 b && touch crates/core/main.rs && strace -cfw -elink,linkat,unlink,unlinkat cargo +stage1 b` before and then after on `ripgrep-13.0.0`:
```
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 52.56    0.024950          25       978       485 unlink
 34.38    0.016318          22       727           linkat
 13.06    0.006200          24       249           unlinkat
------ ----------- ----------- --------- --------- ----------------
100.00    0.047467          24      1954       485 total
```
```
% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 42.83    0.014521          57       252           unlink
 38.41    0.013021          26       486           linkat
 18.77    0.006362          25       249           unlinkat
------ ----------- ----------- --------- --------- ----------------
100.00    0.033904          34       987           total
```

This reduces the number of hard-links that are causing perf troubles, noted in https://github.com/rust-lang/rust/issues/64291 and https://github.com/rust-lang/rust/issues/137560
2025-03-21 21:03:49 +00:00
Vadim Petrochenkov
0ac2801f25 expand: Do not report cfg_attr traces on macros as unused attributes 2025-03-21 18:25:29 +03:00
Ralf Jung
b2d7271858 target spec check: better error when llvm-floatabi is missing 2025-03-21 16:08:48 +01:00
Matthias Krüger
7c2475e9aa
Rollup merge of #138717 - jdonszelmann:pin-macro, r=WaffleLapkin
Add an attribute that makes the spans from a macro edition 2021, and fix pin on edition 2024 with it

Fixes a regression, see issue below. This is a temporary fix, super let is the real solution.

Closes #138596
2025-03-21 15:48:57 +01:00
Matthias Krüger
0c594da55f
Rollup merge of #138627 - EnzymeAD:autodiff-cleanups, r=oli-obk
Autodiff cleanups

Splitting out some cleanups to reduce the size of my batching PR and simplify ``@haenoe`` 's [PR](https://github.com/rust-lang/rust/pull/138314).

r? ``@oli-obk``

Tracking:

- https://github.com/rust-lang/rust/issues/124509
2025-03-21 15:48:55 +01:00
Matthias Krüger
c354a97bd9
Rollup merge of #138570 - folkertdev:naked-function-target-feature-gate, r=Amanieu
add `naked_functions_target_feature` unstable feature

tracking issue: https://github.com/rust-lang/rust/issues/138568

tagging https://github.com/rust-lang/rust/pull/134213 https://github.com/rust-lang/rust/issues/90957

This PR puts `#[target_feature(/* ... */)]` on `#[naked]` functions behind its own feature gate, so that naked functions can be stabilized. It turns out that supporting `target_feature` on naked functions is tricky on some targets, so we're splitting it out to not block stabilization of naked functions themselves. See the tracking issue for more information and workarounds.

Note that at the time of writing, the `target_features` attribute is ignored when generating code for naked functions.

r? ``@Amanieu``
2025-03-21 15:48:52 +01:00
Matthias Krüger
f7f287077b
Rollup merge of #138364 - BLANKatGITHUB:compiler, r=RalfJung
ports the compiler test cases to new rust_intrinsic format

pr is part of #132735
2025-03-21 15:48:51 +01:00
bjorn3
cd929bfccb Fix lint name in unused linker_messages warning 2025-03-21 13:59:29 +00:00
bjorn3
41f1ed11c2 Move some calls to before calling codegen_crate
`--emit mir`, `#[rustc_symbol_name]` and `#[rustc_def_path]` now run
before codegen and thus work even if codegen fails. This can help with
debugging.
2025-03-21 13:23:07 +00:00
bjorn3
7d3965e0cd Move make_input call 2025-03-21 13:21:53 +00:00
Matthias Krüger
5ba395a98b
Rollup merge of #138754 - oli-obk:push-vtqtnwluyxop, r=compiler-errors
Handle spans of `~const`, `const`  and `async` trait bounds in macro expansion

r? `@compiler-errors`

`visit_span` is actually only used in one place (the `transcribe::Marker`), and all of this syntax is unstable, so while it would still be nice to write a test for it, I wager there's lots more interesting things in `transcribe::Marker` to write tests for. And the worst is some diagnostics being weird or incremental being not as incremental as it could be
2025-03-21 06:56:49 +01:00
Matthias Krüger
1135a63286
Rollup merge of #138724 - fmease:list-stems-bear-no-name, r=nnethercote
Check attrs: Don't try to retrieve the name of list stems

Fixes #138723.

r? nnethercote or compiler
2025-03-21 06:56:47 +01:00
Matthias Krüger
7c1b128383
Rollup merge of #138713 - RalfJung:memory-hook-pointers, r=oli-obk
interpret memory access hooks: also pass through the Pointer used for the access

In some ongoing work on the Miri side, we need the absolute address that the memory access occurred at. That is non-trivial to obtain since we don't have an `ecx`. So pass through the `Pointer` used for the access, which contains the address, and which is available everywhere we are calling these hooks.

r? `@oli-obk`
2025-03-21 06:56:47 +01:00
bors
eda7820be5 Auto merge of #138747 - matthiaskrgr:rollup-68x44rw, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #138435 (Add support for postfix yield expressions)
 - #138685 (Use `Option<Ident>` for lowered param names.)
 - #138700 (Suggest `-Whelp` when pass `--print lints` to rustc)
 - #138727 (Do not rely on `type_var_origin` in `OrphanCheckErr::NonLocalInputType`)
 - #138729 (Clean up `FnCtxt::resolve_coroutine_interiors`)
 - #138731 (coverage: Add LLVM plumbing for expansion regions)
 - #138732 (Use `def_path_str` for def id arg in `UnsupportedOpInfo`)
 - #138735 (Remove `llvm` and `llvms` triagebot ping aliases for `icebreakers-llvm` ping group)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-20 22:35:15 +00:00
bors
78948ac259 Auto merge of #138515 - petrochenkov:cfgtrace, r=nnethercote
expand: Leave traces when expanding `cfg_attr` attributes

Currently `cfg_trace` just disappears during expansion, but after this PR `#[cfg_attr(some tokens)]` will leave a `#[cfg_attr_trace(some tokens)]` attribute instead of itself in AST after expansion (the new attribute is built-in and inert, its inner tokens are the same as in the original attribute).
This trace attribute can then be used by lints or other diagnostics, #133823 has some examples.

Tokens in these trace attributes are set to an empty token stream, so the traces are non-existent for proc macros and cannot affect any user-observable behavior.
This is also a weakness, because if a proc macro processes some code with the trace attributes, they will be lost, so the traces are best effort rather than precise.

The next step is to do the same thing with `cfg` attributes (`#[cfg(TRUE)]` currently remains in both AST and tokens after expanding, it should be replaced with a trace instead).

The idea belongs to `@estebank.`
2025-03-20 19:24:48 +00:00
Oli Scherer
ff46ea8253 Handle spans of ~const, const and async trait bounds in macro expansion 2025-03-20 16:56:47 +00:00
Oli Scherer
485c14f373 Make crate_hash not iterate over hir_crate owners anymore 2025-03-20 16:20:41 +00:00
Ralf Jung
b9f59f6107 interpret memory access hooks: also pass through the Pointer used for the access 2025-03-20 17:00:45 +01:00
Matthias Krüger
55fa3f77fd
Rollup merge of #138732 - compiler-errors:did, r=jieyouxu
Use `def_path_str` for def id arg in `UnsupportedOpInfo`

We could alternatively just omit the def path from the label, but I think it's fine to keep around

Fixes #138730
2025-03-20 15:36:26 +01:00
Matthias Krüger
0d37f36341
Rollup merge of #138731 - Zalathar:llvm-expansion, r=jieyouxu
coverage: Add LLVM plumbing for expansion regions

This is currently unused, but paves the way for future work on expansion regions without having to worry about the FFI parts.

The span conversion refactoring is only loosely related, but I've included it here because it would conflict with the main changes in `fill_region_tables`, and is pretty straightforward on its own.
2025-03-20 15:36:25 +01:00
Matthias Krüger
b00c6881b9
Rollup merge of #138729 - compiler-errors:gen, r=lcnr
Clean up `FnCtxt::resolve_coroutine_interiors`

Random cleanups before I make a PR that stalls generator obligations.

r? lcnr
2025-03-20 15:36:22 +01:00
Matthias Krüger
3e04973891
Rollup merge of #138727 - compiler-errors:ty-var-origin, r=fmease
Do not rely on `type_var_origin` in `OrphanCheckErr::NonLocalInputType`

The ordering of ty var unification means that we may end up with a root variable whose ty var origin is from another item's params.

Let's not rely on this by just unifying the infer vars with the params of the impl + resolving. It's kinda goofy but it's clearer IMO.

Fixes #132826.

r? `@fmease` or `@lcnr`
2025-03-20 15:36:20 +01:00
Matthias Krüger
28fc422f30
Rollup merge of #138700 - xizheyin:issue-138612, r=Nadrieril
Suggest `-Whelp` when pass `--print lints` to rustc

Closes #138612
2025-03-20 15:36:19 +01:00
Matthias Krüger
915576935a
Rollup merge of #138685 - nnethercote:use-Option-Ident-for-lowered-param-names, r=compiler-errors
Use `Option<Ident>` for lowered param names.

Parameter patterns are lowered to an `Ident` by `lower_fn_params_to_names`, which is used when lowering bare function types, trait methods, and foreign functions. Currently, there are two exceptional cases where the lowered param can become an empty `Ident`.

- If the incoming pattern is an empty `Ident`. This occurs if the parameter is anonymous, e.g. in a bare function type.

- If the incoming pattern is neither an ident nor an underscore. Any such parameter will have triggered a compile error (hence the `span_delayed_bug`), but lowering still occurs.

This commit replaces these empty `Ident` results with `None`, which eliminates a number of `kw::Empty` uses, and makes it impossible to fail to check for these exceptional cases.

Note: the `FIXME` comment in `is_unwrap_or_empty_symbol` is removed. It actually should have been removed in #138482, the precursor to this PR. That PR changed the lowering of wild patterns to `_` symbols instead of empty symbols, which made the mentioned underscore check load-bearing.

r? ``@compiler-errors``
2025-03-20 15:36:17 +01:00
Matthias Krüger
d752721636
Rollup merge of #138435 - eholk:prefix-yield, r=oli-obk
Add support for postfix yield expressions

We've been having a discussion about whether we want postfix yield, or want to stick with prefix yield, or have both. I figured it's easy enough to support both for now and let us play around with them while the feature is still experimental.

This PR treats `yield x` and `x.yield` as semantically equivalent. There was a suggestion to make `yield x` have a `()` type (so it only works in coroutines with `Resume = ()`. I think that'd be worth trying, either in a later PR, or before this one merges, depending on people's opinions.

#43122
2025-03-20 15:36:15 +01:00
bors
d8e44b722a Auto merge of #133889 - compiler-errors:inh-unstable, r=Nadrieril
Consider fields to be inhabited if they are unstable

Fixes #133885 with a simple heuristic

r? Nadrieril

Not totally certain if this needs T-lang approval or a crater run.
2025-03-20 14:31:34 +00:00
bors
4e2b096ed6 Auto merge of #137930 - nnethercote:use-Wunused-crate-dependencies, r=jieyouxu,Nadrieril
Use `Wunused-crate-dependencies` for the compiler

An implementation of https://github.com/rust-lang/compiler-team/issues/844.

r? `@jieyouxu`
2025-03-20 04:20:13 +00:00
Michael Goulet
e6004ccb50 Use def_path_str for def id arg in UnsupportedOpInfo 2025-03-20 03:22:46 +00:00
Zalathar
2e36990881 coverage: Convert and check span coordinates without a local file ID
For expansion region support, we will want to be able to convert and check
spans before creating a corresponding local file ID.

If we create local file IDs eagerly, but some expansion turns out to have no
successfully-converted spans, LLVM will complain about that expansion's file ID
having no regions.
2025-03-20 13:29:32 +11:00
Michael Goulet
b14de91c5e Pre cleanups 2025-03-20 02:20:06 +00:00
Michael Goulet
220851cc75 Do not rely on type_var_origin in OrphanCheckErr::NonLocalInputType 2025-03-20 02:17:14 +00:00
Zalathar
d07ef5b0e1 coverage: Add LLVM plumbing for expansion regions
This is currently unused, but paves the way for future work on expansion
regions without having to worry about the FFI parts.
2025-03-20 12:40:36 +11:00
León Orell Valerian Liehr
b5069da9df
Check attrs: Don't try to retrieve the name of list stems 2025-03-19 23:29:35 +01:00
Nicholas Nethercote
e2320b32c5 Convert rustc_serialize integration tests to unit tests.
Because (a) the vast majority of compiler tests are unit tests, and (b)
this works better with `unused_crate_dependencies`.
2025-03-20 08:59:50 +11:00
Nicholas Nethercote
8121958fda Use -Wunused_crate_dependencies for compiler crates.
It's very useful. There are some false positives involving integration
tests in `rustc_pattern_analysis` and `rustc_serialize`. There is also a
false positive involving `rustc_driver_impl`'s
`rustc_randomized_layouts` feature. And I removed a `rustc_span` mention
in a doc comment in `rustc_log` because it wasn't integral to the
comment but caused a dev-dependency.
2025-03-20 08:59:43 +11:00
bors
2947be7af8 Auto merge of #138714 - matthiaskrgr:rollup-8uwbpwv, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #135394 (`MaybeUninit` inherent slice methods part 2)
 - #137051 (Implement default methods for `io::Empty` and `io::Sink`)
 - #138001 (mir_build: consider privacy when checking for irrefutable patterns)
 - #138540 (core/slice: Mark some `split_off` variants unstably const)
 - #138589 (If a label is placed on the block of a loop instead of the header, suggest moving it to the header.)
 - #138594 (Fix next solver handling of shallow trait impl check)
 - #138613 (Remove E0773 "A builtin-macro was defined more than once.")

Failed merges:

 - #138602 (Slim `rustc_parse_format` dependencies down)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-19 21:44:19 +00:00