Commit Graph

2182 Commits

Author SHA1 Message Date
Jamie Hill-Daniel 02bd3e86c0 Use Rustc prefix for rustc attrs in AttributeKind 2026-01-29 14:52:09 +00: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
Jamie Hill-Daniel 66b78b700b Port crate_type to attribute parser 2026-01-22 02:34:28 +00:00
Jamie Hill-Daniel e902d0512c Sort do-nothing attributes in check_attributes 2026-01-22 02:30:55 +00:00
Oscar Bray f6d76385e2 Port #![no_builtins] to the attribute parser. 2026-01-21 21:08:28 +00:00
Oscar Bray 54385b52b4 Port #![profiler_runtime] to the attribute parser. 2026-01-21 21:07:57 +00:00
Oscar Bray 1143cb2bb2 Port two panic attrs to the attr parser.
Ports #![panic_runtime] and #![needs_panic_runtime]
2026-01-21 21:07:19 +00:00
Oscar Bray 8c4e48e9b5 Port #![compiler_builtins] to the attribute parser. 2026-01-21 21:06:39 +00:00
Pavel Grigorenko 61ac56209d separate ast item for const block items 2026-01-21 18:26:57 +03:00
Jacob Pratt d37351bbe3 Rollup merge of #148637 - rustc_dyn_incompatible, r=lcnr
Replace `#[rustc_do_not_implement_via_object]` with `#[rustc_dyn_incompatible_trait]`

Background: `#[rustc_do_not_implement_via_object]` on a trait currently still allows `dyn Trait` to exist (if the trait is otherwise dyn-compatible), it just means that `dyn Trait` does not automatically implement `Trait` via the normal object candidate. For some traits, this means that `dyn Trait` does not implement `Trait` at all (e.g. `Unsize` and `Tuple`). For some traits, this means that `dyn Trait` implements `Trait`, but with different associated types (e.g. `Pointee`, `DiscriminantKind`). Both of these cases can can cause issues with codegen , as seen in https://github.com/rust-lang/rust/issues/148089 (and https://github.com/rust-lang/rust/issues/148089#issuecomment-3447803823 ), because codegen assumes that if `dyn Trait` does not implement `Trait` (including if `dyn Trait<Assoc = T>` does not implement `Trait` with `Assoc == T`), then `dyn Trait` cannot be constructed, so vtable accesses on `dyn Trait` are unreachable, but this is not the case if `dyn Trait` has multiple supertraits: one which is `#[rustc_do_not_implement_via_object]`, and one which we are doing the vtable access to call a method from.

This PR replaces `#[rustc_do_not_implement_via_object]` with `#[rustc_dyn_incompatible_trait]`, which makes the marked trait dyn-incompatible, making `dyn Trait` not well-formed, instead of it being well-formed but not implementing `Trait`. This resolves rust-lang/rust#148089 by making it not compile.

May fix rust-lang/rust#148615

The traits that are currently marked `#[rustc_do_not_implement_via_object]` are: `Sized`, `MetaSized`, `PointeeSized`, `TransmuteFrom`, `Unsize`, `BikeshedGuaranteedNoDrop`, `DiscriminantKind`, `Destruct`, `Tuple`, `FnPtr`, `Pointee`. Of these:
* `Sized` and `FnPtr` are already not dyn-compatible (`FnPtr: Copy`, which implies `Sized`)
* `MetaSized`
    * Removed `#[rustc_do_not_implement_via_object]`. Still dyn-compatible after this change. (Has a special-case in the trait solvers to ignore the object candidate for `dyn MetaSized`, since it `dyn MetaSized: MetSized` comes from the sized candidate that all `dyn Trait` get.)
* `PointeeSized`
    * Removed `#[rustc_do_not_implement_via_object]`. It doesn't seem to have been doing anything anyway ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=a395626c8bef791b87a2d371777b7841)), since `PointeeSized` is removed before trait solving(?).
* `Pointee`, `DiscriminantKind`, `Unsize`, and `Tuple` being dyn-compatible without having `dyn Trait: Trait` (with same assoc tys) can be observed to cause codegen issues (https://github.com/rust-lang/rust/issues/148089) so should be made dyn-incompatible
* `Destruct`, `TransmuteFrom`, and `BikeshedGuaranteedNoDrop` I'm not sure if would be useful as object types, but they can be relaxed to being dyn-compatible later if it is determined they should be.

-----

<details> <summary> resolved </summary>

Questions before merge:

1. `dyn MetaSized: MetaSized` having both `SizedCandidate` and `ObjectCandidate`
    1. I'm not sure if the checks in compiler/rustc_trait_selection/src/traits/project.rs and compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs were "load-bearing" for `MetaSized` (which is the only trait that was previously `#[rustc_do_not_implement_via_object]` that is still dyn-compatible after this change). Is it fine to just remove them? Removing them (as I did in the second commit) doesn't change any UI test results.
    3. IIUC, `dyn MetaSized` could get its `MetaSized` implementation in two ways: the object candidate (the normal `dyn Trait: Trait`) that was supressed by `#[rustc_do_not_implement_via_object]`, and the `SizedCandidate` (that all `dyn Trait` get for `dyn Trait: MetaSized`). Given that `MetaSized` has no associated types or methods, is it fine that these both exist now? Or is it better to only have the `SizedCandidate` and leave these checks in (i.e. drop the second commit, and remove the FIXMEs)?
    4. Resolved: the trait solvers special-case `dyn MetaSized` to ignore the object candidate in preference to the sizedness candidate (technically the check is for any `is_sizedness_trait`, but only `MetaSized` gets this far (`Sized` is inherently dyn-incompatible, and `dyn PointeeSized` is ill-formed for other reasons)
4. Diagnostics improvements?
    1. The diagnostics are kinda bad. If you have a `trait Foo: Pointee {}`, you now get a note that reads like *Foo* "opted out of dyn-compatbility", when really `Pointee` did that.
    2. Resolved: can be improved later

  <details> <summary>diagnostic example</summary>

```rs
#![feature(ptr_metadata)]

trait C: std::ptr::Pointee {}

fn main() {
    let y: &dyn C;
}
```

```rs
error[E0038]: the trait `C` is not dyn compatible
  --> c.rs:6:17
   |
 6 |     let y: &dyn C;
   |                 ^ `C` is not dyn compatible
   |
note: for a trait to be dyn compatible it needs to allow building a vtable
      for more information, visit <https://doc.rust-lang.org/reference/items/traits.html#dyn-compatibility>
  --> /home/zachary/opt_mount/zachary/Programming/rust-compiler-2/library/core/src/ptr/metadata.rs:57:1
   |
57 | #[rustc_dyn_incompatible_trait]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...because it opted out of dyn-compatbility
   |
  ::: c.rs:3:7
   |
 3 | trait C: std::ptr::Pointee {}
   |       - this trait is not dyn compatible...

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0038`.
  ```

  </details> </details>

  Still investigating "3. `compiler/rustc_hir/src/attrs/encode_cross_crate.rs`: Should `DynIncompatibleTrait` attribute be encoded cross crate?"
2026-01-21 02:04:01 -05:00
Jacob Pratt 0b8a935e7d Rollup merge of #151428 - attrs3, r=JonathanBrouwer
Port variance attrs to attr parser.

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

Ports rustc_variance and rustc_variance_of_opaques to be parsed attributes.

Info: https://rustc-dev-guide.rust-lang.org/variance.html
2026-01-20 19:46:31 -05:00
Jacob Pratt 79be7a0e75 Rollup merge of #151340 - port_patchable_function_entry, r=JonathanBrouwer
Port `#[patchable_function_entry]` to attr parser

This is the last codegen attr (see rust-lang/rust#151335 and rust-lang/rust#151336)!

Tracking issue: rust-lang/rust#131229

currently this PR is rebased on rust-lang/rust#151336 to make CI pass for the last commit

to see the actual changes in this PR you can look [here](https://github.com/rust-lang/rust/pull/151340/changes/3e731f7e84301a898a36e46ee5e4845ff9bda98a..55111fb468808b733e97170a841217a67666ac33)
2026-01-20 19:46:30 -05:00
Oscar Bray 005fcea374 Port variance attrs to attr parser. 2026-01-20 19:32:24 +00:00
Zachary S c3205f98dd Replace #[rustc_do_not_implement_via_object] with #[rustc_dyn_incompatible_trait], which makes the marked trait dyn-incompatible.
Removes the attribute from `MetaSized` and `PointeeSized`, with a special case in the trait solvers for `MetaSized`.

`dyn MetaSized` is a perfectly cromulent type, and seems to only have had #[rustc_do_not_implement_via_object] so the builtin object
candidate does not overlap with the builtin MetaSized impl that all `dyn` types get.
Resolves this with a special case by checking `is_sizedness_trait` where the trait solvers previously checked `implement_via_object`.

`dyn PointeeSized` alone is rejected for other reasons (since `dyn PointeeSized` is considered to have no principal trait because `PointeeSized`
is removed at an earlier stage of the compiler), but `(dyn PointeeSized + Send)` is valid and equivalent to `dyn Send`.

Add suggestions from code review

Update compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs and tests

Co-authored-by: lcnr <rust@lcnr.de>
2026-01-20 12:54:40 -06:00
Edvin Bryntesson b65e1fdcb8 Port #[patchable_function_entry] to attr parser 2026-01-20 11:46:05 +01:00
Jonathan Brouwer b7f6e85fa0 Remove #[rustc_lint_diagnostics] 2026-01-19 17:40:42 +01:00
Jonathan Brouwer 0ee7d96253 Remove all allows for diagnostic_outside_of_impl and untranslatable_diagnostic throughout the codebase
This PR was mostly made by search&replacing
2026-01-19 17:39:49 +01:00
Jonathan Brouwer a77d6b838a Rollup merge of #151336 - port_rustc_codegen_attrs, r=JonathanBrouwer
Port rustc codegen attrs

Tracking issue: rust-lang/rust#131229

two more quick ones

r? @JonathanBrouwer
2026-01-19 12:33:42 +01:00
Edvin Bryntesson 3e731f7e84 Port #[rustc_offload_kernel] to attr parser 2026-01-19 10:40:42 +01:00
Edvin Bryntesson 03b8b68073 Port #[rustc_nounwind] to attr parser 2026-01-19 10:40:41 +01:00
Stuart Cook 82db63b7ca Rollup merge of #151328 - diag-case, r=Urgau
Fix capitalization of diag messages

Per https://rustc-dev-guide.rust-lang.org/diagnostics.html#diagnostic-output-style-guide
> Error, Warning, Note, and Help messages start with a lowercase letter and do not end with punctuation.
2026-01-19 15:28:02 +11:00
Jonathan Brouwer e668836c92 Fix capitalization of error messages 2026-01-18 22:40:55 +01:00
bors 9b37157ece Auto merge of #151339 - JonathanBrouwer:rollup-DYrRtnq, r=JonathanBrouwer
Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#151287 (Reorganizing `tests/ui/issues` 15 tests [2/N] )
 - rust-lang/rust#151309 (fix: thread creation failed on the wasm32-wasip1-threads target.)
 - rust-lang/rust#151335 (Port rustc allocator attributes to attribute parser)

r? @ghost
2026-01-18 21:30:40 +00:00
Edvin Bryntesson 9a931e8bf2 Port #[rustc_allocator_zeroed_variant] to attr parser 2026-01-18 20:13:13 +01:00
Edvin Bryntesson 21c9bd7692 Port #[rustc_allocator_zeroed] to attr parser 2026-01-18 20:12:08 +01:00
Edvin Bryntesson 9a7614da04 Port #[rustc_reallocator] to attr parser 2026-01-18 20:10:35 +01:00
Edvin Bryntesson 027a6f268f Port #[rustc_deallocator] to attr parser 2026-01-18 20:08:07 +01:00
Edvin Bryntesson 858fb40022 Port #[rustc_allocator] to attr parser 2026-01-18 20:06:15 +01:00
Jonathan Brouwer 3c2c533d2e Rollup merge of #151321 - no_main-attr, r=JonathanBrouwer
Port #![no_main] to the attribute parser.

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

r? @JonathanBrouwer
2026-01-18 18:26:06 +01:00
Jonathan Brouwer a5b6c4b0a0 Rollup merge of #151245 - list-crate-level, r=jdonszelmann
Explicitly list crate level attrs

r? @jdonszelmann
2026-01-18 18:26:04 +01:00
Oscar Bray ea77786cdb Port #![no_main] to the attribute parser. 2026-01-18 16:50:49 +00:00
Jacob Pratt 845316c093 Rollup merge of #151242 - master, r=JonathanBrouwer
Port #[needs_allocator] to attribute parser

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

Ports needs_allocator attribute to the new attribute parser.
Note: this is a deprecated and feature gated attribute.
2026-01-18 03:16:46 -05:00
Jonathan Brouwer fe63539778 Explicitly list crate level attrs 2026-01-17 14:18:11 +01:00
Oscar Bray ebfd22796f Port #[needs_allocator] to attribute parser 2026-01-17 12:05:21 +00:00
Keith-Cancel 4c93efae2b Fix ICE: When Trying to check visibility of a #[type_const], check RHS instead.
We want to evaluate the rhs of a type_const.

Also added an early return/guard in eval_in_interpreter which is used in functions like `eval_to_allocation_raw_provider`

Lastly add a debug assert to `thir_body()` if we have gotten there with a type_const something as gone wrong.

Get rid of a call to is_type_const() and instead use a match arm.

Change this is_type_const() check to a debug_assert!()

Change to use an if else statment instead.

Update type_const-pub.rs

Fix formatting.

Noticed that this is the same check as is_type_const() centralize it.

Add test case for pub type_const.
2026-01-16 20:30:58 -08:00
bors 22c74ba918 Auto merge of #151056 - mejrs:do_not_recommend, r=JonathanBrouwer
Port `diagnostic::do_not_recommend` to new attr parsing

r? @jdonszelmann
2026-01-15 19:35:19 +00:00
Jonathan Brouwer db10879fd1 Rollup merge of #151096 - rm-providers-deref, r=oli-obk
Remove `Deref`/`DerefMut` impl for `Providers`.

It's described as a "backwards compatibility hack to keep the diff small". Removing it requires only a modest amount of churn, and the resulting code is clearer without the invisible derefs.

r? @oli-obk
2026-01-14 11:05:42 +01:00
Nicholas Nethercote 3aa31788b5 Remove Deref/DerefMut impl for Providers.
It's described as a "backwards compatibility hack to keep the diff
small". Removing it requires only a modest amount of churn, and the
resulting code is clearer without the invisible derefs.
2026-01-14 15:55:59 +11:00
mejrs a1e2cea685 Port do_not_recommend to new attr parsing 2026-01-13 20:43:37 +01:00
Jonathan Brouwer abcbf72bab Port #[rustc_dump_predicates] 2026-01-13 15:25:28 +01:00
Jonathan Brouwer a4c34b421c Port #[rustc_dump_vtable] 2026-01-13 15:25:28 +01:00
Jonathan Brouwer 2a455409e3 Port #[rustc_dump_item_bounds] 2026-01-13 15:25:27 +01:00
Jonathan Brouwer cf4d480eff Port #[rustc_dump_def_parents] 2026-01-13 15:25:27 +01:00
Jonathan Brouwer 84d59d0731 Port #[rustc_dump_user_args] 2026-01-13 15:25:24 +01:00
Jonathan Brouwer a2994063d4 Rollup merge of #150943 - port_must_not_suspend, r=jdonszelmann,JonathanBrouwer
Port `#[must_not_suspend]` to attribute parser

Tracking issue: rust-lang/rust#131229

r? @JonathanBrouwer
2026-01-13 09:01:31 +01:00
Jonathan Brouwer e33f5aa634 Rollup merge of #150934 - move-doc-attr-checks, r=JonathanBrouwer
Move some checks from `check_doc_attrs` directly into `rustc_attr_parsing`

Part of https://github.com/rust-lang/rust/issues/149865.

I also used this opportunity to remove the `id_is_crate_root` method.

Once this is merged, I think I'll try to see if we can remove `target_id` as well.

r? @JonathanBrouwer
2026-01-13 09:01:31 +01:00
Edvin Bryntesson 418cff3ec0 Port #[must_not_suspend] to attribute parser 2026-01-12 18:16:37 +01:00
Jana Dönszelmann 6d0f23adad rename extern item to foreign item 2026-01-12 08:07:23 +01:00
Jana Dönszelmann 322bbdfaaf rename eii-extern-target 2026-01-12 08:07:23 +01:00
Matthias Krüger 565c663413 Rollup merge of #150964 - list_all_attrs, r=jdonszelmann
Completely list all unparsed attributes

Also introduce a `SPECIAL_ATTRIBUTES` list, since `cfg` was incorrectly being detected as an unparsed attribute in `check_attr`.

I will also update https://github.com/rust-lang/rust/issues/131229#issuecomment-2971351163

r? @jdonszelmann
2026-01-12 00:02:55 +01:00