Fix gap in const stability checks around intrinsics
@N1ark managed to find a gap in our const stability checks around intrinsics. This PR fixes that gap.
Sadly the standard library already relies on the gap, so for now I added a `rustc_allow_const_fn_unstable` but that attribute usually needs some process to be approved.
Also fixes https://github.com/rust-lang/rust/issues/150961 by properly supporting & testing `rustc_do_not_const_check` on intrinsics.
Add regression test for unexpected type for constructor
Closesrust-lang/rust#162393.
This fails on eca445e5. I think it was fixed yesterday, acording to @malezjaa
regression test for valtree leaf const
Closesrust-lang/rust#162392. It no longer reproduces since nightly-2026-09-12.
Not sure if this is the right folder for this test.
Simplify the `G` in `Diag<'a, G>`
The `EmissionGuarantee` trait isn't necessary, and just complicates things. Details in individual commits.
r? @oli-obk
tidy: Sort multi-line types by treating `>` as a closing bracket
While tidying up some macros in the compiler, I noticed that `tidy-alphabetical-start` doesn't treat `>` as a closing bracket, so it gets confused when sorting lists where complex parameterized types have been broken across multiple lines.
This PR therefore changes tidy to treat `>` as a closing bracket, and adds some tests to verify the intended behaviour.
While we do have some places that sort lists of types, none of them happen to use multi-line types right now.
turn aligned-in-packed error into lint
Fixes https://github.com/rust-lang/rust/issues/80926:
The aligned-in-packed check ignores the fact that generics exist, so it can trivially be bypassed. Acknowledge that by downgrading the hard error to a lint. The lint also only fires for `repr(C)` types, because that's the only case where that is a problem: the type may not actually match what the C compiler for the target does, if that C compiler is MSVC. This is tied up with https://github.com/rust-lang/rfcs/pull/3845 and the general tension around `repr(C)` as a repr for predictable stable layout vs C compatibility. The error doesn't really help to make fixing the mess any easier though, so let's de-fang it.
Also fixes https://github.com/rust-lang/rfcs/issues/3060; see that issue for a usecase that's made unnecessarily hard by the status quo.
[Three years ago](https://github.com/rust-lang/rust/issues/80926#issuecomment-1716238277), the t-lang vibes seem to have been "yes let's downgrade this to a lint, that's kind of what it already is anyway".
Questions for t-lang:
- Are you still on-board with this?
- How should the lint be called? I went with `aligned_fields_in_packed`.
- When exactly should it fire? I currently require the outer packed type, the inner aligned type, and all the types in between to be `repr(C)`. For Rust types I see no reason at all to forbid this combination, we can just define whatever we want for the layout there and IMO the current behavior makes a lot of sense.
- What should the default lint level be? I went with "deny" since it was a hard error after all.
Cc @rust-lang/opsem
Implement semantic analysis for named `Fn` trait params
This PR can be reviewed commit by commit.
Every commit passes uitests individually.
The goal of this PR is to make the semantic of named fn trait parameters match those of `fn` pointers, which is what was decided on the RFC: https://github.com/rust-lang/rfcs/pull/3955.
This is achieved, which can be observed by the fact that the output of the `named-fn-trait-params.rs` test matches that of `fn-ptr-pattern.rs`.
This PR also marks the feature as complete.
Tracking issue: https://github.com/rust-lang/rust/issues/158499
fix tailcall indirect return
Fixesrust-lang/rust#162585
This branch should only be intended for arguments, but it also marked return values as being passed on the stack. It later caused codegen to panic because return values can't use `on_stack`.
Garbage-collect old incremental compilation sessions
## Summary
rustc cleans up old incremental-cache snapshots twice during a compilation: once at startup (after loading the previous cache), and then again after finishing and finalizing the new cache.
In rust-lang/rust#147821, we started skipping the current session during cleanup. But that means we're also skipping cleanup _after_ the session has finished, so we're keeping _both_ the previous and the completed snapshot on disk. (The snapshots don't accumulate indefinitely -- the "extra" snapshot gets removed when the next compilation starts, but that compilation then leaves another snapshot behind when it finishes.)
This PR modifies the logic to skip the current session while it is still active, but remove it once finalized.
Testing it locally for [Ruff](https://github.com/astral-sh/ruff) and [uv](https://github.com/astral-sh/uv), the target directory shrinks significantly... The query caches are almost exactly 50% smaller, and `target` as a whole is 27.3% smaller in Ruff and 31.1% smaller in uv.
Fix initialization cycle in `target_config`
There is an initialization cycle in `target_config`. Details in the final commit. The previous commits are precursors that support the changes in the final commit.
r? @nikic
cc @cuviper @RalfJung @Zalathar @Patryk27
Subtree sync for rustc_codegen_cranelift
Subtree update of `rustc_codegen_cranelift` to f6bcac9858.
This migrates from git-subtree to josh-sync.
Created using https://github.com/rust-lang/josh-sync.
r? @ghost
@rustbot label +A-codegen +A-cranelift +T-compiler +subtree-sync
Constify more Iterator and DoubleEndedIterator functions required for Range
Extracted from https://github.com/rust-lang/rust/pull/156216
Consitfies functions required for `const impl Iterator for Range`.
r? clarfonthey
We can just hardwire `'a` and `Visitor`/`MutVisitor`. This simplifies
the inputs for these macros from "leading thing + repeating elements" to
just "repeating elements".
The AST visitor code uses `($($extra_ty)?)` which expands to `()` in
some cases and `(T)` in others, which requires `allow(unused_parens)` to
avoid warnings.
This commit splits the two `impl_visitable!` macros into two rules: one
for the "no-extra" case and one for the "with-extra" case. There's a
small amount of duplication between the two rules but there are multiple
advantages.
- The `allow(unused_parens)` is removed.
- `impl_visitable!` callers can omit the extra param if it's `()`.
- When the extra argument might or might not be present, a more standard
`$(, $extra: $extra_ty)?` is now used.
- No weird `let ($($extra)?) = extra;` destructuring.
The `Visitable` derive also gets a tweak to avoid unnecessary parens
around extra args.
They fit the pattern.
Also remove `#[inline]` from `impl_visitable_list` for consistency. The
visitor is generic so the methods are monomorphized into the calling
crate and probably inlined anyway.
Currently various `Visitable` impls are defined within functions even
though `Visitable` is defined at the top level, which is weird and
requires `allow(non_local_definitions)`.
This commit uses `for_each_ast_visit_hook` to move them out. It also
renames a couple of the existing macros to give them simpler names.
There is currently a big list of `visit_*` methods in one macro call and
another list of `walk_*` method in another macro call. The previous
commit showed these can unintentionally get out of sync.
This commit introduces a higher-order macro that puts all the
information in a single place. This will make it impossible for the
`visit_*` and `walk_*` methods to get out of sync (as we saw in the
previous commit). It will also facilitate another cleanup in
the next commit.
`visit_test_binder_constraints` is the only `visit_foo`
method in `impl_visitable_calling_walkable!` without a corresponding
`walk_foo` method in `define_named_walk!`.
I confirmed with the original author (khyperia) that this is an
unintentional oversight.
Remove `CacheCell` and `CacheRefCell` aliases and directly use `Lock` and `RwLock`
Some changes from rust-lang/rust#158845 for benchmarking.
decided to change Mutex to `datastructures::sync::Lock`.
r? @petrochenkov