1494 Commits

Author SHA1 Message Date
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
Jana Dönszelmann
92f2402096
port #[recursion_limit] to the new attribute parsing infrastructure 2025-09-08 14:57:28 -07:00
Guillaume Gomez
07f7d86f36
Rollup merge of #146102 - fmease:rm-dead-eff-code-iii, r=fee1-dead
Remove dead code stemming from an old effects desugaring

CC https://github.com/rust-lang/rust/pull/132374, https://github.com/rust-lang/rust/pull/133443.

r? fee1-dead
2025-09-02 17:08:58 +02:00
Guillaume Gomez
af315b0725
Rollup merge of #145783 - Erk-:et-cetera-span, r=compiler-errors
add span to struct pattern rest (..)

Struct pattern rest (`..`) did not retain span information compared to normal fields. This patch adds span information for it.

The motivation of this patch comes from when I implemented this PR for Clippy: https://github.com/rust-lang/rust-clippy/pull/15000#discussion_r2134145163

It is possible to get the span of the Et cetera in a bit roundabout way, but I thought this would be nicer.
2025-09-02 17:08:52 +02:00
Nicholas Nethercote
301655eafe Revert introduction of [workspace.dependencies].
This was done in #145740 and #145947. It is causing problems for people
using r-a on anything that uses the rustc-dev rustup package, e.g. Miri,
clippy.

This repository has lots of submodules and subtrees and various
different projects are carved out of pieces of it. It seems like
`[workspace.dependencies]` will just be more trouble than it's worth.
2025-09-02 19:12:54 +10:00
León Orell Valerian Liehr
6fc0cf4288
Remove dead code stemming from an old effects desugaring 2025-09-01 21:39:01 +02:00
Stuart Cook
2246dda682
Rollup merge of #145947 - nnethercote:workspace-members-2, r=Kobzol
Add more to the `[workspace.dependencies]` section in the top-level `Cargo.toml`

Following on from rust-lang/rust#145740.

r? `@Kobzol`
2025-08-29 12:54:12 +10:00
Nicholas Nethercote
20d03752c5 Add odht to [workspace.dependencies]. 2025-08-28 20:12:16 +10:00
Jonathan Brouwer
e8d08b5416
Port the #[link] attribute to the new parser 2025-08-27 20:25:16 +02:00
Jonathan Brouwer
aab5e0bf1f
Move NativeLibKind from rustc_session to rustc_hir 2025-08-27 20:24:59 +02:00
Nicholas Nethercote
c50d2cc807 Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
Nicholas Nethercote
82c4b9c51b Add bitflags to [workspace.dependencies]. 2025-08-27 13:59:32 +10:00
Nicholas Nethercote
777e2d6a2a Add thin-vec to newly added [workspace.dependencies]. 2025-08-27 13:59:32 +10:00
Sasha Pourcelot
a8e9ca195e Use attribute name in message for "outer attr used as inner attr" errors 2025-08-25 21:31:04 +02:00
Valdemar Erk
75d8687f2b add span to struct pattern rest (..) 2025-08-25 09:55:50 +02:00
Jana Dönszelmann
59ceb02d65
Port crate name to the new attribute system 2025-08-24 09:20:57 +02:00
Jana Dönszelmann
1c03ae19db
port attribute to the new parsing infrastructure 2025-08-23 12:31:07 +02:00
Jacob Pratt
566c13c88e
Rollup merge of #145726 - aapoalas:reborrow-lang-experiment, r=petrochenkov
Experiment: Reborrow trait

Tracking issue: rust-lang/rust#145612

Starting off really small here: just introduce the unstable feature and the feature gate, and one of the two traits that the Reborrow experiment deals with.

### Cliff-notes explanation

The `Reborrow` trait is conceptually a close cousin of `Copy` with the exception that it disables the source (`self`) for the lifetime of the target / result of the reborrow action. It can be viewed as a method of `fn reborrow(self: Self<'a>) -> Self<'a>` with the compiler adding tracking of the resulting `Self<'a>` (or any value derived from it that retains the `'a` lifetime) to keep the `self` disabled for reads and writes.

No method is planned to be surfaced to the user, however, as reborrowing cannot be seen in code (except for method calls [`a.foo()` reborrows `a`] and explicit reborrows [`&*a`]) and thus triggering user-code in it could be viewed as "spooky action at a distance". Furthermore, the added compiler tracking cannot be seen on the method itself, violating the Golden Rule. Note that the userland "reborrow" method is not True Reborrowing, but rather a form of a "Fancy Deref":
```rust
fn reborrow(&'short self: Self<'long>) -> Self<'short>;
```
The lifetime shortening is the issue here: a reborrowed `Self` or any value derived from it is bound to the method that called `reborrow`, since `&'short` is effectively a local variable. True Reborrowing does not shorten the lifetime of the result.

To avoid having to introduce new kinds of references, new kinds of lifetime annotations, or a blessed trait method, no method will be introduced at all. Instead, the `Reborrow` trait is intended to be a derived trait that effectively reborrows each field individually; `Copy` fields end up just copying, while fields that themselves `Reborrow` get disabled in the source, usually leading to the source itself being disabled (some differences may appear with structs that contain multiple reborrowable fields). The goal of the experiment is to determine how the actual implementation here will shape out, and what the "bottom case" for the recursive / deriving `Reborrow` is.

`Reborrow` has a friend trait, `CoerceShared`, which is equivalent to a `&'a mut T -> &'a T` conversion. This is needed as a different trait and different operation due to the different semantics it enforces on the source: a `CoerceShared` operation only disables the source for writes / exclusive access for the lifetime of the result. That trait is not yet introduced in this PR, though there is no particular reason why it could not be introduced.
2025-08-22 22:00:55 -04:00
Jacob Pratt
45d5109ad8
Rollup merge of #145573 - veluca93:unsafe-force-target-feature, r=davidtwco
Add an experimental unsafe(force_target_feature) attribute.

This uses the feature gate for https://github.com/rust-lang/rust/issues/143352, but is described in https://github.com/rust-lang/rfcs/pull/3820 which is strongly tied to the experiment.
2025-08-22 22:00:51 -04:00
Luca Versari
291da71b2a Add an experimental unsafe(force_target_feature) attribute.
This uses the feature gate for
https://github.com/rust-lang/rust/issues/143352, but is described in
https://github.com/rust-lang/rfcs/pull/3820 which is strongly tied to
the experiment.
2025-08-22 01:26:26 +02:00
Aapo Alasuutari
5af359162e Introduce Reborrow lang item and trait 2025-08-21 23:53:25 +03:00
Jana Dönszelmann
2158e2d4d7
refactor target checking, move out of context.rs and rename MaybeWarn to Policy 2025-08-21 13:15:30 +02:00
Jana Dönszelmann
9be8effb3f
impl IntoDiagArg for AttrPath 2025-08-21 13:15:30 +02:00
Josh Triplett
f3c8b7ad40 Split rustc_hir_id out of rustc_hir
Some crates depend on `rustc_hir` but only want `HirId` and similar id
types. `rustc_hir` is a heavy dependency, since it pulls in
`rustc_target`. Split these types out into their own crate
`rustc_hir_id`.

This allows `rustc_errors` to drop its direct dependency on `rustc_hir`.

(`rustc_errors` still depends on `rustc_hir` indirectly through
`rustc_lint_defs`; a subsequent commit will fix that.)
2025-08-20 15:01:13 -07:00
Josh Triplett
b65fab6299 Move IntoDiagArg earlier in the dependency chains
`rustc_errors` depends on numerous crates, solely to implement its
`IntoDiagArg` trait on types from those crates. Many crates depend on
`rustc_errors`, and it's on the critical path.

We can't swap things around to make all of those crates depend on
`rustc_errors` instead, because `rustc_errors` would end up in
dependency cycles.

Instead, move `IntoDiagArg` into `rustc_error_messages`, which has far
fewer dependencies, and then have most of these crates depend on
`rustc_error_messages`.

This allows `rustc_errors` to drop dependencies on several crates,
including the large `rustc_target`.

(This doesn't fully reduce dependency chains yet, as `rustc_errors`
still depends on `rustc_hir` which depends on `rustc_target`. That will
get fixed in a subsequent commit.)
2025-08-20 15:01:13 -07:00
Stuart Cook
d92e1fe8d7
Rollup merge of #145206 - scrabsha:push-uxovoqzrxnlx, r=jdonszelmann
Port `#[custom_mir(..)]` to the new attribute system

r? ``````````@jdonszelmann``````````
2025-08-18 15:31:10 +10:00
bors
2e2642e641 Auto merge of #145304 - m-ou-se:simplify-panic, r=oli-obk
Revert "Partially outline code inside the panic! macro".

This reverts https://github.com/rust-lang/rust/pull/115670

Without any tests/benchmarks that show some improvement, it's hard to know whether the change had any positive effect. (And if it did, whether that effect is still achieved today.)
2025-08-16 10:15:46 +00:00
Sasha Pourcelot
51bccdd1ab Port #[custom_mir(..)] to the new attribute system 2025-08-15 11:19:29 +02:00
Jonathan Brouwer
5245c39972
Remove the old target checking logic 2025-08-14 18:18:42 +02:00
Jonathan Brouwer
744d39ebe6
Allow attribute parsers to specify a list of allowed targets
Every acceptor gets an `ALLOWED_TARGETS` specification which can specify per target whether it is allowed, warned, or errored.
2025-08-14 18:11:56 +02:00
Jonathan Brouwer
106731f714
Improved Target type
- Added a few more variants which are needed for various attributes
- Previously a trait method with default block had the same target representation as a method in a `impl trait for` block, this has been changed (See `MethodKind`)
- Added `plural_name` for more precision on the form of the name
2025-08-14 18:11:47 +02:00
Guillaume Gomez
44d3217c20
Rollup merge of #145323 - scrabsha:push-pqwvmznzzmpr, r=jdonszelmann
Port the `#[linkage]` attribute to the new attribute system

r? `@jdonszelmann`
2025-08-14 11:39:39 +02:00
Sasha Pourcelot
d435197afc Port the #[linkage] attribute to the new attribute system 2025-08-13 21:01:37 +02:00
Guillaume Gomez
bd6fb63596
Rollup merge of #145153 - joshtriplett:macro-kinds-plural, r=petrochenkov
Handle macros with multiple kinds, and improve errors

(I recommend reviewing this commit-by-commit.)

Switch to a bitflags `MacroKinds` to support macros with more than one kind

Review everything that uses `MacroKind`, and switch anything that could refer to more than one kind to use `MacroKinds`.

Add a new `SyntaxExtensionKind::MacroRules` for `macro_rules!` macros, using the concrete `MacroRulesMacroExpander` type, and have it track which kinds it can handle. Eliminate the separate optional `attr_ext`, now that a `SyntaxExtension` can handle multiple macro kinds.

This also avoids the need to downcast when calling methods on `MacroRulesMacroExpander`, such as `get_unused_rule`.

Integrate macro kind checking into name resolution's `sub_namespace_match`, so that we only find a macro if it's the right type, and eliminate the special-case hack for attributes.

This allows detecting and report macro kind mismatches early, and more precisely, improving various error messages. In particular, this eliminates the case in `failed_to_match_macro` to check for a function-like invocation of a macro with no function-like rules.

Instead, macro kind mismatches now result in an unresolved macro, and we detect this case in `unresolved_macro_suggestions`, which now carefully distinguishes between a kind mismatch and other errors.

This also handles cases of forward-referenced attributes and cyclic attributes.

----

In this PR, I've minimally fixed up `rustdoc` so that it compiles and passes tests. This is just the minimal necessary fixes to handle the switch to `MacroKinds`, and it only works for macros that don't actually have multiple kinds. This will panic (with a `todo!`) if it encounters a macro with multiple kinds.

rustdoc needs further fixes to handle macros with multiple kinds, and to handle attributes and derive macros that aren't proc macros. I'd appreciate some help from a rustdoc expert on that.

----

r? ````````@petrochenkov````````
2025-08-13 18:43:01 +02:00
Josh Triplett
0b855bcdc9 Switch to a bitflags MacroKinds to support macros with more than one kind
Review everything that uses `MacroKind`, and switch anything that could
refer to more than one kind to use `MacroKinds`.

Add a new `SyntaxExtensionKind::MacroRules` for `macro_rules!` macros,
using the concrete `MacroRulesMacroExpander` type, and have it track
which kinds it can handle. Eliminate the separate optional `attr_ext`,
now that a `SyntaxExtension` can handle multiple macro kinds.

This also avoids the need to downcast when calling methods on
`MacroRulesMacroExpander`, such as `get_unused_rule`.

Integrate macro kind checking into name resolution's
`sub_namespace_match`, so that we only find a macro if it's the right
type, and eliminate the special-case hack for attributes.
2025-08-12 09:24:45 -07:00
Mara Bos
08acba3071 Revert "Partially outline code inside the panic! macro".
Without any tests/benchmarks that show some improvement, it's hard to
know whether the change had any positive effect at all. (And if it did,
whether that effect is still achieved today.)
2025-08-12 12:52:39 +02:00
Stuart Cook
9fd7702305
Rollup merge of #145155 - scrabsha:push-tkvwkolzooyq, r=jdonszelmann
Port `#[allow_internal_unsafe]` to the new attribute system (attempt 2)

This is a slightly modified version of ae1487aa9922de7642c448cc0908584026699e1c, which caused a performance regression (reverted in https://github.com/rust-lang/rust/pull/145086#issue-3303428759). The diff between this PR and the previous one can be seen in 027a1def.

r? ```````@jdonszelmann``````` 💖
2025-08-12 20:37:51 +10:00
Cameron Steffen
bf266dc834 Propagate TraitImplHeader to hir 2025-08-11 17:05:42 -05:00
Sasha Pourcelot
6603fe1caa Port #[allow_internal_unsafe] to the new attribute system (attempt 2) 2025-08-11 15:01:52 +02:00
bors
8712e45675 Auto merge of #144873 - cjgillot:implications, r=lqd
Implement `stability_implications` without a visitor.

Since https://github.com/rust-lang/rust/pull/143845, the `Annotator` visitor was a no-op when the crate is not staged_api. This PR avoids using a visitor altogether, making `stability_implications` truly a no-op in most cases.
2025-08-10 05:44:53 +00:00
Jana Dönszelmann
866bc26475
Revert "Port #[allow_internal_unsafe] to the new attribute system"
This reverts commit 4f7a6ace9e2f2192af7b5d32f4b1664189e0e143.
2025-08-08 11:54:20 +02:00
Trevor Gross
8f519761a5
Rollup merge of #144857 - scrabsha:push-pwtyrnmqkrtr, r=jdonszelmann
Port `#[allow_internal_unsafe]` to the new attribute system

Related to https://github.com/rust-lang/rust/issues/131229#issue-2565886367.

r? ````@jdonszelmann````
2025-08-07 19:36:35 -05:00
Sasha Pourcelot
4f7a6ace9e Port #[allow_internal_unsafe] to the new attribute system 2025-08-07 15:47:21 +02:00
Stuart Cook
995ca3e532
Rollup merge of #143808 - JonathanBrouwer:should_panic_parser, r=jdonszelmann
Port `#[should_panic]` to the new attribute parsing infrastructure

Ports `#[should_panic]` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971351163

r? ```@jdonszelmann```
2025-08-07 20:49:40 +10:00
Jonathan Brouwer
f7ad4065fe
Port #[should_panic] to the new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-06 21:37:51 +02:00
Camille GILLOT
d5f2260bd3 Add doc-comment. 2025-08-04 23:07:15 +00:00
Sasha Pourcelot
904e2af3a9 Port #[coroutine] to the new attribute system
Related to https://github.com/rust-lang/rust/issues/131229#issue-2565886367.
2025-08-04 18:37:40 +02:00