314 Commits

Author SHA1 Message Date
Matthias Krüger
d182d8e874 Rollup merge of #148000 - JonathanBrouwer:wipnew2, r=jdonszelmann
Improvements to attribute suggestions

Changes in commit 1:
- Add `AcceptContext::suggestions`, which retrieves the suggestions for the currently parsing attribute
- This happens to fix a bug in the way `#[macro_export`]. Closes https://github.com/rust-lang/rust/pull/147987

Changes in commit 2:
- Add a check to the suggestions function so the suggestions for attributes in cfg_attr are nicer. Fixes https://github.com/rust-lang/rust/issues/147693

This is also part (but not all) of the changes needed to unblock https://github.com/rust-lang/rust/pull/147945

r? `@jdonszelmann`
2025-10-25 12:57:39 +02:00
Jonathan Brouwer
24502dd2d2 Improve suggestions for cfg_attr
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-10-22 21:57:13 +02:00
Jonathan Brouwer
9735524533 Add AcceptContext::suggestions
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-10-22 21:43:50 +02:00
Jonathan Brouwer
ebd3220b20 Remove unused field style from AttributeKind::CrateName
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-10-22 15:45:59 +02:00
Matthias Krüger
2b582ea0ba Rollup merge of #147532 - JonathanBrouwer:cfg_attr2, r=jdonszelmann
Port `#[cfg_attr]` to the new attribute parsing infrastructure

This work in progress, not ready for review.
PR mostly for ci/perf runs
2025-10-18 15:09:03 +02:00
Matthias Krüger
d7b9e66728 Rollup merge of #147716 - zhetaicheleba:master, r=jdonszelmann
Fix some comments

Fix some comments
2025-10-15 23:41:05 +02:00
Matthias Krüger
c607de5508 Rollup merge of #147676 - jdonszelmann:span-is-doc-comment, r=GuillaumeGomez
Return spans out of `is_doc_comment` to reduce reliance on `.span()` on attributes

r? `@GuillaumeGomez`
2025-10-15 23:41:03 +02:00
Jonathan Brouwer
7113d58c8e Port #[cfg_attr] to the new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-10-15 22:18:18 +02:00
Jonathan Brouwer
e0c190f681 Move parse_cfg_attr to rustc_attr_parsing
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-10-15 22:18:18 +02:00
Jonathan Brouwer
52cc311828 Rename some functions
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-10-15 22:18:17 +02:00
zhetaicheleba
07df2adbdf Fix some comments
Signed-off-by: zhetaicheleba <taicheleba@outlook.com>
2025-10-15 14:23:28 +08:00
Jana Dönszelmann
047c37cf23 convert rustc_main to the new attribute parsing infrastructure 2025-10-14 17:55:00 +02:00
Jana Dönszelmann
3941b42993 return spans out of is_doc_comment to reduce reliance on .span() on attrs 2025-10-14 15:36:09 +02:00
Jonathan Brouwer
c050bfbf6f Fix double error for #[no_mangle] on consts 2025-10-08 17:46:33 +02:00
Jonathan Brouwer
730221e654 Fix double error for #[no_mangle] on closures 2025-10-08 17:46:33 +02:00
Jana Dönszelmann
1dbe831e47 sort attribute targets for more consistent error messages 2025-10-08 08:32:03 +02:00
Jonathan Brouwer
4787834eda Fix target list of link_section
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-10-06 23:04:09 +02:00
usamoi
21dd997aec support link modifier as-needed for raw-dylib-elf 2025-10-06 08:56:40 +08:00
bors
981353ca16 Auto merge of #147345 - Kivooeo:tidy-flt-fix, r=Kobzol
Tidy: revert `flt` to `ftl`

As was explained here https://github.com/rust-lang/rust/pull/147191#issuecomment-3353801210, this reverting this change because `flt` is incorrect format

Also maybe there is existed PR for that? I didn't found one

Follow up https://github.com/rust-lang/rust/pull/147191

cc `@GuillaumeGomez`
2025-10-05 15:55:18 +00:00
Stuart Cook
d97e346ac7 Rollup merge of #147262 - JonathanBrouwer:fix-link, r=jieyouxu
Make #[link="dl"] an FCW rather than an error

Fixes https://github.com/rust-lang/rust/issues/147254
I forgot to implement the T-lang decision in https://github.com/rust-lang/rust/pull/143193#issuecomment-3138479942, this implements that decision

r? ``@jdonszelmann``
Can be reviewed commit-by-commit
This needs a beta backport
2025-10-05 22:15:06 +11:00
Kivooeo
67bc030833 change flt back to ftl 2025-10-04 18:18:58 +00:00
Matthias Krüger
3f7b8c5198 Rollup merge of #147117 - iximeow:ixi/illumos-used-attr, r=Noratrieb
interpret `#[used]` as `#[used(compiler)]` on illumos

helps rust-lang/rust#146169 not be as painful: fixes the illumos regression in rust-lang/rust#140872, but `#[used(linker)]` is still erroneous on illumos generally.

illumos' `ld` does not support a flag like either SHF_GNU_RETAIN or SHF_SUNW_NODISCARD, so there is no way to communicate `#[used(linker)]` for that target. Setting `USED_LINKER` to try results in LLVM setting SHF_SUNW_NODISCARD for Solaris-like targets, which is an unknown section header flag for illumos `ld` and prevents sections from being merged that otherwise would.

As a motivating example, the `inventory` crate produces `#[used]` items to merge into `.init_array`. Because those items have an unknown section header flag they are not merged with the default `.init_array` with `frame_dummy`, and end up never executed.

Downgrading `#[used]` to `#[used(compiler)]` on illumos keeps so-attributed items as preserved as they had been before https://github.com/rust-lang/rust/pull/140872. As was the case before that change, because rustc passes `-z ignore` to illumos `ld`, it's possible that `used` sections are GC'd at link time. https://github.com/rust-lang/rust/issues/146169 describes this unfortunate circumstance.

----

as it turns out, `tests/ui/attributes/used_with_archive.rs` had broken on `x86_64-unknown-illumos`, and this patch fixes it. the trials and tribulations of tier 2 :(

r? ````@Noratrieb```` probably?
2025-10-04 17:11:11 +02:00
Jonathan Brouwer
1c85a1dc2e Make #[link="dl"] a warning rather than an error 2025-10-04 11:22:56 +02:00
iximeow
c721fa2438 interpret #[used] as #[used(compiler)] on illumos
illumos' `ld` does not support a flag like either SHF_GNU_RETAIN or
SHF_SUNW_NODISCARD, so there is no way to communicate `#[used(linker)]`
for that target. Setting `USED_LINKER` to try results in LLVM setting
SHF_SUNW_NODISCARD for Solaris-like targets, which is an unknown section
header flag for illumos `ld` and prevents sections from being merged
that otherwise would.

As a motivating example, the `inventory` crate produces
`#[used]` items to merge into `.init_array`. Because those items have an
unknown section header flag they are not merged with the default
`.init_array` with `frame_dummy`, and end up never executed.

Downgrading `#[used]` to `#[used(compiler)]` on illumos keeps
so-attributed items as preserved as they had been before
https://github.com/rust-lang/rust/pull/140872. As was the case before
that change, because rustc passes `-z ignore` to illumos `ld`, it's
possible that `used` sections are GC'd at link time.
https://github.com/rust-lang/rust/issues/146169 describes this
unfortunate circumstance.
2025-10-03 22:03:24 +00:00
bors
8d603ef287 Auto merge of #147231 - CrooseGit:dev/reucru01/extend_rustc_force_inline, r=saethlin
Extending `#[rustc_force_inline]` to be applicable to inherent methods

`#[rustc_force_inline]` is an internal-only attribute similar to `#[inline(always)]` but which emits an error if inlining cannot occur. rustc_force_inline uses the MIR inliner to do this and has limitations on where it can be applied to ensure that an error is always emitted if inlining can't happen (e.g. it can't be applied to trait methods because calls to those can't always be resolved).

`#[rustc_force_inline]` is motivated by AArch64 pointer authentication intrinsics where it is vital for the security properties of these intrinsics that they do not exist in standalone functions that could be used as gadgets in an exploit (if they could, then you could sign whatever pointers you want, for example, which is bad, but if you force inlining, then you can't jump to a reusable function containing only these instructions).

Since its initial implementation, `#[rustc_force_inline]` could only be applied to free functions. This can be relaxed to also allow inherent methods while still preserving the desired properties. In a work-in-progress patch for manual pointer authentication intrinsics, it is useful to introduce types with inherent methods that would need to be force inlined.

r? `@saethlin`
2025-10-02 21:43:10 +00:00
Reuben Cruise
5bf5e71160 Extends rustc_force_inline to inherent methods
- Changes parser to allow application to inherent methods.
- Adds tests to confirm extended functionality works just as the existing.
2025-10-02 11:30:11 +01:00
Matthias Krüger
ac7beab527 Rollup merge of #146535 - joshtriplett:mbe-unsafe-attr, r=petrochenkov
mbe: Implement `unsafe` attribute rules

This implements `unsafe attr` rules for declarative `macro_rules!` attributes, as specified in [RFC 3697](https://github.com/rust-lang/rfcs/pull/3697).

An invocation of an attribute that uses an `unsafe attr` rule requires the `unsafe(attr(...))` syntax.

An invocation of an attribute that uses an ordinary `attr` rule must *not* use the `unsafe(attr(...))` syntax.

`unsafe` is only supported on an `attr` rule, not any other kind of `macro_rules!` rule.

Tracking issue for `macro_rules!` attributes: https://github.com/rust-lang/rust/issues/143547
2025-10-02 10:27:49 +02:00
Josh Triplett
6bff1abf9d mbe: Support unsafe attribute rules 2025-10-01 16:19:39 -07:00
Stuart Cook
08616a1745 Rollup merge of #147101 - yotamofek:pr/iter-eq-and-eq-by, r=jdonszelmann
Use `Iterator::eq` and (dogfood) `eq_by` in compiler and library

Now that rust-lang/rust#137122 has landed, we can replace stuff that looks like:
```rust
let a: &[T];
let b: &[T];
let eq = a.len() == b.len() && a.iter().zip(b).all(|(a,b)| a == b)
```
with the much simpler `a.iter().eq(b)`, without losing the perf benefit of the different-length-fast-path.
Also dogfooded `Iterator::eq_by` (cc rust-lang/rust#64295 ) while I'm at it.

First commit (4d1b6fad230f8a5ccceccc7562eadc4ea50059da) should be very straightforward to review, second one (049a4606cb3906787aedf508ee8eea09c2bb3b9a) is slightly more creative, but IMHO a nice cleanup.
2025-09-29 21:06:45 +10:00
Yotam Ofek
68a7c25078 Use Iterator::eq and (dogfood) eq_by in compiler and library 2025-09-29 08:08:05 +03:00
Jana Dönszelmann
b3631e1174 improve empty attribute diagnostic 2025-09-27 19:32:14 +02:00
Matthias Krüger
d09bb02eb5 Rollup merge of #146704 - jdonszelmann:port-debug-visualizer, r=petrochenkov
port `#[debugger_visualizer]` to the new attribute system
2025-09-26 18:11:09 +02:00
Stuart Cook
fab06469ee Rollup merge of #146667 - calebzulawski:simd-mono-lane-limit, r=lcnr,RalfJung
Add an attribute to check the number of lanes in a SIMD vector after monomorphization

Allows std::simd to drop the `LaneCount<N>: SupportedLaneCount` trait and maintain good error messages.

Also, extends rust-lang/rust#145967 by including spans in layout errors for all ADTs.

r? ``@RalfJung``

cc ``@workingjubilee`` ``@programmerjake``
2025-09-25 20:31:53 +10:00
Caleb Zulawski
f5c6c9542e Add an attribute to check the number of lanes in a SIMD vector after monomorphization
Unify zero-length and oversized SIMD errors
2025-09-23 20:47:34 -04:00
Jana Dönszelmann
9acc63a48c port #[debugger_visualizer] to the new attribute system 2025-09-21 21:30:16 -07:00
Jonathan Brouwer
6abcadc235 Port #[macro_export] to the new attribute parsing infrastructure
Co-authored-by: Anne Stijns <anstijns@gmail.com>
2025-09-21 10:42:47 -04:00
Jana Dönszelmann
205189c8c7 port #[rustc_coherence_is_core] to the new attribute parsing infrastructure 2025-09-17 10:02:23 -07:00
Stuart Cook
6ad98750e0 Rollup merge of #145660 - jbatez:darwin_objc, r=jdonszelmann,madsmtm,tmandry
initial implementation of the darwin_objc unstable feature

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

This feature makes it possible to reference Objective-C classes and selectors using the same ABI used by native Objective-C on Apple/Darwin platforms. Without it, Rust code interacting with Objective-C must resort to loading classes and selectors using costly string-based lookups at runtime. With it, these references can be loaded efficiently at dynamic load time.

r? ```@tmandry```

try-job: `*apple*`
try-job: `x86_64-gnu-nopt`
2025-09-17 14:56:44 +10:00
Jana Dönszelmann
f56eb06047 merge crate-level into ALLOWED_TARGETS 2025-09-13 22:37:20 -07:00
Jo Bates
1ebf69d1b1 initial implementation of the darwin_objc unstable feature 2025-09-13 16:06:22 -07:00
Jana Dönszelmann
147e97ae68 Rollup merge of #146389 - jdonszelmann:no-std, r=oli-obk
Convert `no_std` and `no_core` to the new attribute infrastructure

r? ```@oli-obk```

Also added a test for these, since we didn't have any and I was kind of surprised new diagnostics didn't break anything hehe
2025-09-13 02:40:44 +02:00
Jana Dönszelmann
dbd3ef1332 fixup no_{core,std} handling code 2025-09-10 11:45:24 -07:00
Matthias Krüger
422c76adae Rollup merge of #146178 - folkertdev:static-align, r=jdonszelmann,ralfjung,traviscross
Implement `#[rustc_align_static(N)]` on `static`s

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

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

#[rustc_align_static(64)]
static SO_ALIGNED: u64 = 0;
```

We need a different attribute than `rustc_align` because unstable attributes are tied to their feature (we can't have two unstable features use the same unstable attribute). Otherwise this uses all of the same infrastructure as `#[rustc_align]`.

r? `@traviscross`
2025-09-10 14:17:38 +02:00
Jana Dönszelmann
0db2eb7734 port #[no_std] to the new attribute parsing infrastructure 2025-09-09 15:16:02 -07:00
Jana Dönszelmann
b262cae857 port #[no_core] to the new attribute parsing infrastructure 2025-09-09 15:16:02 -07:00
Folkert de Vries
cbacd00f10 allow #[rustc_align_static(N)] on statics
We need a different attribute than `rustc_align` because unstable attributes are
tied to their feature (we can't have two unstable features use the same
unstable attribute). Otherwise this uses all of the same infrastructure
as `#[rustc_align]`.
2025-09-09 21:54:54 +02:00
Jana Dönszelmann
6087d89004 fixup limit handling code 2025-09-08 15:07:12 -07:00
Jana Dönszelmann
b82171de5f port #[pattern_complexity_limit] to the new attribute parsing infrastructure 2025-09-08 14:57:28 -07:00
Jana Dönszelmann
5dbe099dd3 port #[type_length_limit] to the new attribute parsing infrastructure 2025-09-08 14:57:28 -07:00
Jana Dönszelmann
a38288bbe0 port #[move_size_limit] to the new attribute parsing infrastructure 2025-09-08 14:57:28 -07:00