Commit graph

845 commits

Author SHA1 Message Date
Esteban Küber
c73b3d20c6 Unify wording of resolve error
Remove "failed to resolve" and use the same format we use in other resolution errors "cannot find `name`".

```
error[E0433]: cannot find `nonexistent` in `existent`
  --> $DIR/custom_attr_multisegment_error.rs:5:13
   |
LL | #[existent::nonexistent]
   |             ^^^^^^^^^^^ could not find `nonexistent` in `existent`
```
2026-02-17 16:51:44 +00:00
Stuart Cook
1367126837
Rollup merge of #151783 - mu001999-contrib:impl/final-method, r=fee1-dead
Implement RFC 3678: Final trait methods

Tracking: https://github.com/rust-lang/rust/issues/131179

This PR is based on rust-lang/rust#130802, with some minor changes and conflict resolution.

Futhermore, this PR excludes final methods from the vtable of a dyn Trait.

And some excerpt from the original PR description:
> Implements the surface part of https://github.com/rust-lang/rfcs/pull/3678.
>
> I'm using the word "method" in the title, but in the diagnostics and the feature gate I used "associated function", since that's more accurate.

cc @joshtriplett
2026-02-17 13:02:21 +11:00
Jacob Pratt
d1f3c9eea8
Rollup merge of #152296 - jdonszelmann:port-rust-nonnull-guaranteed, r=jonathanbrouwer
Port `rust_nonnull_optimization_guaranteed` and `rustc_do_not_const_check` to the new attribute parser

r? @JonathanBrouwer another two of them :)
2026-02-16 04:28:57 -05:00
Jana Dönszelmann
12e6628977
Port rustc_nonnull_optimization_guaranteed to the new attribute parser 2026-02-16 09:46:04 +01:00
Folkert de Vries
981dacc34f
feature-gate c-variadic definitions and calls in const contexts 2026-02-15 19:54:25 +01:00
Jonathan Brouwer
1944af691e
Rollup merge of #152554 - JonathanBrouwer:remove_deprecated_safe, r=jdonszelmann
Remove `deprecated_safe` and its corresponding feature gate

This unimplements the feature gate for tracking issue https://github.com/rust-lang/rust/issues/94978
The author of that tracking issue and the MCP seem to no longer exist
Afaik we can just do this, but let me know if I'm wrong

Because this feature has been idle for 3+ years, and it is in the way to finish the attribute refactoring (https://github.com/rust-lang/rust/issues/131229#issuecomment-2971351163)
When someone wants to do work on it the feature gate can be re-added

r? @jdonszelmann
2026-02-13 13:35:03 +01:00
Stuart Cook
426921007e
Rollup merge of #152519 - scottmcm:fix-152501, r=fmease
Fix feature gating for new `try bikeshed` expressions

r? fmease
Fixes rust-lang/rust#152501
2026-02-13 15:19:13 +11:00
Jonathan Brouwer
42a3c864d2
Remove deprecated_safe and its corresponding feature gate 2026-02-12 22:16:28 +01:00
Scott McMurray
6afebcc4dd Fix feature gating for new try bikeshed expressions 2026-02-12 12:17:49 -08:00
mu001999
7077797f52 Parse and lower final for methods
Co-authored-by: Michael Goulet <michael@errs.io>
2026-02-12 15:12:29 +08:00
Keith-Cancel
73a991fb9d Allow provisional mgca syntax of type const <IDENT> = <EXPR> to be reconized.
Revert, but without type const.

Update symbol for feature err, then update suggestion output, and lastly update tests that change because of those.

Update these new tests with the correct syntax, and few existing tests with the new outputs the merge with main added.

Fix for tidyfmt and some errors when manually resolving a merge conflicts.

Update these tests to use update error messages and type const syntax.

Update comments and error message to use new syntax instead of old type_const attribute.

Remove the type_const attribute

update some more tests to use the new syntax.

Update these test cases.

update feature gate test

Change gate logic for `mgca_type_const_syntax` to work also if `min_generic_const_args` is enabled.

Create a new feature gate that checks for the feature before expansion.

Make rustfmt handle the `type const` syntax correctly.

Add a convience method to check if a RhsKind is type const.

Rename `Const` discriminant to `Body` for `ConstItemRhsKind`

Give the `TraitItemKind` flag an enum instead of a simple bool to better describe what the flag is for.

Update formatting for these match statements.

Update clippy test to use type const syntax.

Update test to use type const syntax.

update rustfmt to match ast items.

Update clippy to match ast and hir items.

Few more test cases that used old attribute, instead of 'type const'

Update to match the output from the feature gate checks.

tidyfmt adjustments.

Update the is_type_const, so I can constrain record!(..) in encoder.rs

Update conditional compilation test.

Move the feature gate to after expansion to allow for cfg(...) to work.

Update some more tests to use the new syntax.

Update type const tests in associated-const-bindings to use new syntax.

Don't check based off the attribute, but the item here.

Update some tests outside of the const_generics folder that were using #[type_const]

update the tests in associated consts that use #[type_const] to use type const

Update these mgca tests with the type const syntax.

Add a flag to TraitItemKind for detecting type const for now. Maybe later change ItemConstRhs to have optional consts but that touches a lot more lines of code.

Don't need into for these now that it's a query.

Add is_type_const query to handle foreign def ids.

update this test to use type const syntax.

Fix logic here, we only want to lower if there is expression in this case.

Update built-in macros to use ConstItemRhsKind

Update more instance of the old ConstItemRhs.

Rename ConstItemKind to ConstItemRhsKind, I noticed there is a typed called ConstantItemKind, so add the Rhs to the name to avoid confusion.

Update lower to use ConstItemKind

Add an other helper method to check if the rhs kinda has an expr.

Update item parse to use ConstItemKind enum.

Felt the field name could a be little clear when editing a few other things.

Change the ConstItem struct see know if we have a type const or regular const.

Make sure this syntax is properly feature gated.
2026-02-09 07:59:24 -08:00
Noah Lev
9a30ec8149 Implement MVP for opaque generic const arguments
This is meant to be the interim successor to generic const expressions.
Essentially, const item RHS's will be allowed to do arbitrary const
operations using generics. The limitation is that these const items will
be treated opaquely, like ADTs in nominal typing, such that uses of them
will only be equal if the same const item is referenced. In other words,
two const items with the exact same RHS will not be considered equal.

I also added some logic to check feature gates that depend on others
being enabled (like oGCA depending on mGCA).

= Coherence =

During coherence, OGCA consts should be normalized ambiguously because
they are opaque but eventually resolved to a real value. We don't want
two OGCAs that have the same value to be treated as distinct for
coherence purposes. (Just like opaque types.)

This actually doesn't work yet because there are pre-existing
fundamental issues with equate relations involving consts that need to
be normalized. The problem is that we normalize only one layer of the
const item and don't actually process the resulting anon const. Normally
the created inference variable should be handled, which in this case
would cause us to hit the anon const, but that's not happening.
Specifically, `visit_const` on `Generalizer` should be updated to be
similar to `visit_ty`.
2026-02-08 18:15:11 +00:00
Folkert de Vries
8aea4b1775
add unreachable_cfg_select_predicates lint
This is emitted on branches of a `cfg_select!` that are statically known
to be unreachable.
2026-02-07 02:19:42 +01:00
Jonathan Brouwer
011d7b0525
Rollup merge of #152090 - Ozzy1423:attrs5, r=JonathanBrouwer
Port reexport_test_harness_main to attr parser

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

I don't think I can use the parsed form in compiler/rustc_builtin_macros/src/test_harness.rs since that has to use the AST attrs?

r? @JonathanBrouwer
2026-02-05 08:32:50 +01:00
Jonathan Brouwer
76a49eeb6c
Rollup merge of #151952 - GuillaumeGomez:revert-error-to-future-warning, r=JonathanBrouwer
Revert doc attribute parsing errors to future warnings

Part of https://github.com/rust-lang/rust/issues/151865 (hopefully fixes it).

r? @JonathanBrouwer
2026-02-04 14:39:22 +01:00
Guillaume Gomez
7dbbab63e2 Emit a future error warning for duplicate doc attribute 2026-02-04 10:54:44 +01:00
Oscar Bray
f2fff8ee54 Port reexport_test_harness_main. 2026-02-04 07:59:01 +00:00
cezarbbb
dcdffe8d80 link modifier export-symbols: export all global symbols from selected uptream c static libraries 2026-02-04 09:26:21 +08:00
Jonathan Brouwer
70f1120363
Rollup merge of #151102 - zachs18:mut-ref-in-struct-pattern-shorthand-gate, r=JonathanBrouwer
Feature-gate `mut ref` patterns in struct pattern field shorthand

Tracking issue for `mut_ref` (and other parts of Match Ergonomics 2024): https://github.com/rust-lang/rust/issues/123076

https://github.com/rust-lang/rust/pull/123080 introduced `mut ref`[^1] patterns (for by-reference bindings where the binding itself is mutable), feature-gated behind the `mut_ref` feature, except for in struct pattern shorthand, where the feature gating was missing. Thus, `mut ref` patterns in struct pattern shorthand has been unintentionally stable for ~18 months (since 1.79.0 ([compiler explorer](https://rust.godbolt.org/z/4WTrvhboT))).

This PR adds feature-gating for `mut ref` patterns in struct pattern shorthand. Since this is reverting an accidental stabilization, this probably needs a crater run and a T-lang FCP?

Some alternative possibilities:

* Do nothing (let the inconsistency exist until `feature(mut_ref)` is stabilized)
* Document the existing behavior
* Do a FCW instead of fully feature-gating
* Stabilize `feature(mut_ref)`

CC https://github.com/rust-lang/rust/pull/123080#issuecomment-3746793632

CC @Nadrieril

[^1]: everything in this description also applies analogously to `mut ref mut` patterns.
2026-01-31 21:42:46 +01:00
Jamie Hill-Daniel
b226583d94 Treat unions as 'data types' in attr parsing diagnostics 2026-01-29 15:51:43 +00:00
Stuart Cook
b4f8dc726f
Rollup merge of #148718 - estebank:macro-spans, r=nnethercote
Do not mention `-Zmacro-backtrace` for std macros that are a wrapper around a compiler intrinsic
2026-01-27 12:50:50 +11:00
Esteban Küber
4a27be6972 Do not mention -Zmacro-backtrace for std macros that are a wrapper around a compiler intrinsic 2026-01-26 17:34:31 +00:00
Stuart Cook
e811f07736
Rollup merge of #151589 - Urgau:documentation-scope, r=GuillaumeGomez
Add a `documentation` remapping path scope for rustdoc usage

This PR adds a new remapping path scope for rustdoc usage: `documentation`, instead of rustdoc abusing the other scopes for it's usage.

Like remapping paths in rustdoc, this scope is unstable. (rustdoc doesn't even have yet an equivalent to [rustc `--remap-path-scope`](https://doc.rust-lang.org/nightly/rustc/remap-source-paths.html#--remap-path-scope)).

I also took the opportunity to add a bit of documentation in rustdoc book.
2026-01-26 14:36:22 +11:00
bors
75963ce795 Auto merge of #151065 - nagisa:add-preserve-none-abi, r=petrochenkov
abi: add a rust-preserve-none calling convention

This is the conceptual opposite of the rust-cold calling convention and is particularly useful in combination with the new `explicit_tail_calls` feature.

For relatively tight loops implemented with tail calling (`become`) each of the function with the regular calling convention is still responsible for restoring the initial value of the preserved registers. So it is not unusual to end up with a situation where each step in the tail call loop is spilling and reloading registers, along the lines of:

    foo:
        push r12
        ; do things
        pop r12
        jmp next_step

This adds up quickly, especially when most of the clobberable registers are already used to pass arguments or other uses.

I was thinking of making the name of this ABI a little less LLVM-derived and more like a conceptual inverse of `rust-cold`, but could not come with a great name (`rust-cold` is itself not a great name: cold in what context? from which perspective? is it supposed to mean that the function is rarely called?)
2026-01-25 02:49:32 +00:00
Simonas Kazlauskas
6db94dbc25 abi: add a rust-preserve-none calling convention
This is the conceptual opposite of the rust-cold calling convention and
is particularly useful in combination with the new `explicit_tail_calls`
feature.

For relatively tight loops implemented with tail calling (`become`) each
of the function with the regular calling convention is still responsible
for restoring the initial value of the preserved registers. So it is not
unusual to end up with a situation where each step in the tail call loop
is spilling and reloading registers, along the lines of:

    foo:
        push r12
        ; do things
        pop r12
        jmp next_step

This adds up quickly, especially when most of the clobberable registers
are already used to pass arguments or other uses.

I was thinking of making the name of this ABI a little less LLVM-derived
and more like a conceptual inverse of `rust-cold`, but could not come
with a great name (`rust-cold` is itself not a great name: cold in what
context? from which perspective? is it supposed to mean that the
function is rarely called?)
2026-01-24 19:23:17 +02:00
Matthias Krüger
0bb15457de
Rollup merge of #149174 - GrigorenkoPV:const_block_item, r=me,ytmimi
`const` blocks as a `mod` item

Tracking issue: rust-lang/rust#149226

This adds support for writing `const { ... }` as an item in a module. In the current implementation, this is a unique AST item that gets lowered to `const _: () = const { ... };` in HIR.

rustfmt support included.

TODO:
- `pub const { ... }` does not make sense (see rust-lang/rust#147136). Reject it. Should this be rejected by the parser or smth?
- Improve diagnostics (preferably they should not mention the fake `_` ident).
2026-01-24 15:35:08 +01:00
Urgau
91e3e2a37f Add the remapping path documentation scope for rustdoc usage 2026-01-24 15:33:21 +01:00
Jamie Hill-Daniel
66b78b700b Port crate_type to attribute parser 2026-01-22 02:34:28 +00:00
Oscar Bray
f6d76385e2 Port #![no_builtins] to the attribute parser. 2026-01-21 21:08:28 +00:00
Pavel Grigorenko
8439fda014 Sugar for const _: () = 2026-01-21 18:12:21 +03:00
bors
88ad3d44ca Auto merge of #151436 - jhpratt:rollup-Rp5KtGe, r=jhpratt
Rollup of 6 pull requests

Successful merges:

 - rust-lang/rust#150436 (`c_variadic`: impl `va_copy` and `va_end` as Rust intrinsics)
 - rust-lang/rust#151340 (Port `#[patchable_function_entry]` to attr parser)
 - rust-lang/rust#151351 (Deduplicate diagnostics for const trait supertraits)
 - rust-lang/rust#151424 (missing colon after the compile-flags directive)
 - rust-lang/rust#151428 (Port variance attrs to attr parser.)
 - rust-lang/rust#151429 (s390x: Support aligned stack datalayout)

Failed merges:

 - rust-lang/rust#151343 (Port some crate level attrs to the attribute parser)

r? @ghost
2026-01-21 03:21:23 +00:00
Oscar Bray
005fcea374 Port variance attrs to attr parser. 2026-01-20 19:32:24 +00:00
Jonathan Brouwer
6dc27bf7de
Update uitests 2026-01-19 21:50:29 +01:00
Jonathan Brouwer
f5a1fc75ad
Update uitests 2026-01-18 22:41:00 +01:00
Oscar Bray
ea77786cdb Port #![no_main] to the attribute parser. 2026-01-18 16:50:49 +00:00
Jonathan Brouwer
cbcd1c3eef
Rollup merge of #151036 - issue-151026, r=mati865
Better handle when trying to iterate on a `Range` of a type that isn't `Step`

Mention when a trait bound corresponds to an unstable trait.

Mention `Range` when `Step` bound is unment, and explain that only some std types impl `Iterator` for `Range`.

CC rust-lang/rust#151026
2026-01-14 11:05:40 +01:00
Zachary S
f809e332d8 Feature-gate mut ref patterns in struct field shorthand. 2026-01-13 22:46:44 -06:00
Zachary S
cd6c412838 Add test for feature-gating mut ref patterns in struct field shorthand. 2026-01-13 22:43:09 -06:00
Lukas Bergdoll
506762f3ff Explicitly export core and std macros
Currently all core and std macros are automatically added to the prelude
via #[macro_use]. However a situation arose where we want to add a new macro
`assert_matches` but don't want to pull it into the standard prelude for
compatibility reasons. By explicitly exporting the macros found in the core and
std crates we get to decide on a per macro basis and can later add them via
the rust_20xx preludes.
2026-01-13 08:47:48 +01:00
Esteban Küber
cafe91749f On unmet trait bound, mention if trait is unstable 2026-01-13 01:16:58 +00:00
Jana Dönszelmann
322bbdfaaf
rename eii-extern-target 2026-01-12 08:07:23 +01:00
Zachary S
5466c6b255 Move feature(multiple_supertrait_upcastable) to the actual feature gates section (from the internal feature gates section) and give it a tracking issue. 2026-01-08 14:57:32 -06:00
AprilNEA
4421270516
Merge associated_const_equality feature gate into MGCA
This removes `associated_const_equality` as a separate feature gate and makes it part of `min_generic_const_args` (mgca).

Key changes:
  - Remove `associated_const_equality` from unstable features, add to removed
  - Update all test files to use `min_generic_const_args` instead
  - Preserve the original "associated const equality is incomplete" error message by specially handling `sym::associated_const_equality` spans in `feature_gate.rs`
  - Rename FIXME(associated_const_equality) to FIXME(mgca)
2026-01-05 12:31:42 +08:00
Manuel Drehwald
c34ea6e56d remove llvm_enzyme and enzyme fallbacks from most places, enable the autodiff frontend on nightly 2025-12-19 11:02:57 -08:00
Edvin Bryntesson
b09a9d0062
add tests making sure to FCW warn on field, arm, and macro def 2025-12-16 22:45:56 +01:00
Edvin Bryntesson
52bcaabdb8
Port #[no_link] to use attribute parser 2025-12-16 22:45:32 +01:00
Stuart Cook
bd1e142ac0
Rollup merge of #148756 - JonathanBrouwer:link_section_targets2, r=jdonszelmann
Warn on codegen attributes on required trait methods

This PR turns applying the following attributes on required trait methods (that is, trait methods **without** a default implementation) into a FCW:
- `#[cold]`
- `#[link_section]`
- `#[linkage]` (unstable)
- `#[rustc_allow_const_fn_unstable]` (internal attribute)

These attributes already had no effect when applied to a required trait method, this PR only adds a warning.

Furthermore, it adds a comment in the code that the following codegen attributes are *inherited* when applied to a required trait method:
- `#[track_caller]`
- `#[align]` (unstable)

````@rustbot```` labels +I-lang-nominated
````@rust-lang/lang````

Two questions for the lang team:
- Is adding this warning ok?
- Does the current behaviour of these attributes align with that you would expect them to be?

Fixes https://github.com/rust-lang/rust/issues/147432
2025-12-16 14:40:40 +11:00
Matthias Krüger
185f7dc044
Rollup merge of #149949 - JonathanBrouwer:error_cleanup, r=jdonszelmann
Cleanup of attribute parsing errors

Removes the specific `UnknownMetaItem` and `IllFormedAttributeInputLint` errors.
Note that `IllFormedAttributeInputLint` is not a lint, contrary to its name

r? ``````@jdonszelmann``````
2025-12-14 20:04:56 +01:00
bors
3f4dc1e02d Auto merge of #146348 - jdonszelmann:eiiv3, r=lcnr,oli-obk
Externally implementable items

Supersedes https://github.com/rust-lang/rust/pull/140010
Tracking issue: https://github.com/rust-lang/rust/issues/125418

Getting started:

```rust
#![feature(eii)]

#[eii(eii1)]
pub fn decl1(x: u64)
// body optional (it's the default)
{
    println!("default {x}");
}

// in another crate, maybe
#[eii1]
pub fn decl2(x: u64) {
    println!("explicit {x}");
}

fn main() {
    decl1(4);
}
```

- tiny perf regression, underlying issue makes multiple things in the compiler slow, not just EII, planning to solve those separately.
- No codegen_gcc support, they don't have bindings for weak symbols yet but could
- No windows support yet for weak definitions

This PR merges the implementation of EII for just llvm + not windows, doesn't yet contain like a new panic handler implementation or alloc handler. With this implementation, it would support implementing the panic handler in terms of EII already since it requires no default implementation so no weak symbols

The PR has been open in various forms for about a year now, but I feel that having some implementation merged to build upon
2025-12-14 04:20:26 +00:00
Jonathan Brouwer
8fa10c0ed7
Add regression test for codegen attributes on required trait methods
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-12-13 20:19:20 +01:00