2587 Commits

Author SHA1 Message Date
Jonathan Brouwer
21d3189779
Move validate_attr to rustc_attr_parsing 2025-08-22 08:37:19 +02:00
Jacob Pratt
f49d69093e
Rollup merge of #145604 - compiler-errors:static-closure, r=fmease
Gate static closures behind a parser feature

I'd like to gate `static ||` closures behind a feature gate, since we shouldn't allow people to take advantage of this syntax if it's currently unstable. Right now, since it's only rejected after ast lowering, it's accessible to macros.

Let's crater this to see if we can claw it back without breaking anyone's code.
2025-08-21 17:57:52 -04:00
Jacob Pratt
25b81bf5ad
Rollup merge of #145590 - nnethercote:ModKind-Inline, r=petrochenkov
Prevent impossible combinations in `ast::ModKind`.

`ModKind::Loaded` has an `inline` field and a `had_parse_error` field. If the `inline` field is `Inline::Yes` then `had_parse_error` must be `Ok(())`.

This commit moves the `had_parse_error` field into the `Inline::No` variant. This makes it impossible to create the nonsensical combination of `inline == Inline::Yes` and `had_parse_error = Err(_)`.

r? ```@Urgau```
2025-08-21 01:12:19 -04:00
bors
bec747418c Auto merge of #145348 - nnethercote:parse_token_tree-speedup-for-uom, r=petrochenkov
Sometimes skip over tokens in `parse_token_tree`.

r? `@petrochenkov`
2025-08-20 09:01:41 +00:00
bors
f605b57042 Auto merge of #145601 - jieyouxu:rollup-t5mbqhc, r=jieyouxu
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#145538 (bufreader::Buffer::backshift: don't move the uninit bytes)
 - rust-lang/rust#145542 (triagebot: Don't warn no-mentions on subtree updates)
 - rust-lang/rust#145549 (Update rust maintainers in openharmony.md)
 - rust-lang/rust#145550 (Avoid using `()` in `derive(From)` output.)
 - rust-lang/rust#145556 (Allow stability attributes on extern crates)
 - rust-lang/rust#145560 (Remove unused `PartialOrd`/`Ord` from bootstrap)
 - rust-lang/rust#145568 (ignore frontmatters in `TokenStream::new`)
 - rust-lang/rust#145571 (remove myself from some adhoc-groups and pings)
 - rust-lang/rust#145576 (Add change tracker entry for `--timings`)
 - rust-lang/rust#145578 (Add VEXos "linked files" support to `armv7a-vex-v5`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-08-19 23:52:06 +00:00
Michael Goulet
db0c825d2c Gate static coroutines behind a parser feature 2025-08-19 13:12:31 +00:00
Nicholas Nethercote
bfd5d59f97 Prevent impossible combinations in ast::ModKind.
`ModKind::Loaded` has an `inline` field and a `had_parse_error` field.
If the `inline` field is `Inline::Yes` then `had_parse_error` must be
`Ok(())`.

This commit moves the `had_parse_error` field into the `Inline::No`
variant. This makes it impossible to create the nonsensical combination
of `inline == Inline::Yes` and `had_parse_error = Err(_)`.
2025-08-19 21:57:31 +10:00
许杰友 Jieyou Xu (Joe)
b638266f23
Rollup merge of #145474 - fmease:paren-use-bounds-fix, r=fee1-dead
Properly recover from parenthesized use-bounds (precise capturing lists) plus small cleanups

Fixes https://github.com/rust-lang/rust/issues/145470.

First commit fixes the issue, second one performs some desperately needed cleanups.

The fix shouldn't be a breaking change because IINM the parser always ensures that all brackets are balanced (via a buffer of brackets). Meaning even though we used to accept `(use<>` as a valid precise capturing list, it was guaranteed that we would fail in the end.
2025-08-19 19:45:33 +08:00
Deadbeef
c335d5781d ignore frontmatters in TokenStream::new 2025-08-18 20:28:29 +08:00
León Orell Valerian Liehr
f8f7c27d4f
Clean up parsers related to generic bounds 2025-08-16 16:15:58 +02:00
León Orell Valerian Liehr
eb3e0d4c8a
Properly recover from parenthesized use-bounds (precise capturing) 2025-08-16 01:21:35 +02:00
Stuart Cook
dc047f1385
Rollup merge of #145378 - xizheyin:144968, r=davidtwco
Add `FnContext` in parser for diagnostic

Fixes rust-lang/rust#144968

Inspired by https://github.com/rust-lang/rust/issues/144968#issuecomment-3156094581, I implemented `FnContext` to indicate whether a function should have a self parameter, for example, whether the function is a trait method, whether it is in an impl block. And I removed the outdated note.

I made two commits to show the difference.

cc ``@estebank`` ``@djc``

r? compiler
2025-08-15 16:16:41 +10:00
Jakub Beránek
01bd889098
Rollup merge of #145233 - joshtriplett:cfg-select-expr, r=jieyouxu
cfg_select: Support unbraced expressions

Tracking issue for `cfg_select`: rust-lang/rust#115585

When operating on expressions, `cfg_select!` can now handle expressions
without braces. (It still requires braces for other things, such as
items.)

Expand the test coverage and documentation accordingly.

---

I'm not sure whether deciding to extend `cfg_select!` in this way is T-lang or T-libs-api. I've labeled for both, with the request that both teams don't block on each other. :)
2025-08-14 21:48:42 +02:00
Jakub Beránek
18afb69767
Rollup merge of #137872 - estebank:extra-vert, r=compiler-errors
Include whitespace in "remove |" suggestion and make it hidden

Tweak error rendering of patterns with an extra `|` on either end.

Built on #137409. Only last commit is relevant.

? ``@compiler-errors``
2025-08-14 21:48:41 +02:00
xizheyin
3ce555f631 Add FnContext in parser for diagnostic
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-08-14 21:31:47 +08:00
Nicholas Nethercote
145b84721a Sometimes skip over tokens in parse_token_tree.
This sometimes avoids a lot of `bump` calls.
2025-08-14 15:31:29 +10:00
Stuart Cook
d862ae2fce
Rollup merge of #145238 - estebank:attr-overhaul, r=jdonszelmann
Tweak invalid builtin attribute output

 - Add link to reference/docs when possible
 - More accurate suggestions by supporting multiple alternative suggestions

```
error: malformed `crate_type` attribute input
  --> $DIR/crate-type-macro-call.rs:1:1
   |
LL | #![crate_type = foo!()]
   | ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html>
help: the following are the possible correct uses
   |
LL - #![crate_type = foo!()]
LL + #![crate_type = "bin"]
   |
LL - #![crate_type = foo!()]
LL + #![crate_type = "cdylib"]
   |
LL - #![crate_type = foo!()]
LL + #![crate_type = "dylib"]
   |
LL - #![crate_type = foo!()]
LL + #![crate_type = "lib"]
   |
   = and 4 other candidates
```
2025-08-12 20:37:53 +10:00
Cameron Steffen
5bc23ce255 Extract ast TraitImplHeader 2025-08-11 17:05:36 -05:00
Cameron Steffen
3aa0ac0a8a Tweak trait modifier errors 2025-08-11 16:58:21 -05:00
Cameron Steffen
fa733909ed Move trait impl modifier errors to parsing
This is a technically a breaking change for what can be parsed in
`#[cfg(false)]`.
2025-08-11 16:58:21 -05:00
Esteban Küber
625143bac3 Add link to docs on malformed attributes 2025-08-11 16:00:49 +00:00
Esteban Küber
189f264926 Allow attr entries to declare list of alternatives for List and NamedValueStr
Modify `AttributeTemplate` to support list of alternatives for list and name value attribute styles.

Suggestions now provide more correct suggested code:

```
error[E0805]: malformed `used` attribute input
  --> $DIR/used_with_multi_args.rs:3:1
   |
LL | #[used(compiler, linker)]
   | ^^^^^^------------------^
   |       |
   |       expected a single argument here
   |
help: try changing it to one of the following valid forms of the attribute
   |
LL - #[used(compiler, linker)]
LL + #[used(compiler)]
   |
LL - #[used(compiler, linker)]
LL + #[used(linker)]
   |
LL - #[used(compiler, linker)]
LL + #[used]
   |
```

instead of the prior "masking" of the lack of this feature by suggesting pipe-separated lists:

```
error[E0805]: malformed `used` attribute input
  --> $DIR/used_with_multi_args.rs:3:1
   |
LL | #[used(compiler, linker)]
   | ^^^^^^------------------^
   |       |
   |       expected a single argument here
   |
help: try changing it to one of the following valid forms of the attribute
   |
LL - #[used(compiler, linker)]
LL + #[used(compiler|linker)]
   |
LL - #[used(compiler, linker)]
LL + #[used]
   |
```
2025-08-11 16:00:49 +00:00
Josh Triplett
38df15805b cfg_select: Support unbraced expressions
When operating on expressions, `cfg_select!` can now handle expressions
without braces. (It still requires braces for other things, such as
items.)

Expand the test coverage and documentation accordingly.
2025-08-10 16:18:01 -07:00
bors
41ede7bd9b Auto merge of #145146 - fee1-dead-contrib:push-zmqrkurlzrxy, r=nnethercote
remove `P`

Previous work: rust-lang/rust#141603
MCP: https://github.com/rust-lang/compiler-team/issues/878

cc `@nnethercote`
2025-08-09 23:27:55 +00:00
Deadbeef
ad1113f87e remove P 2025-08-09 15:47:01 +08:00
Michael Goulet
b2d524c43d Recover for PAT = EXPR {} 2025-08-08 18:46:09 +00:00
Guillaume Gomez
48d57564cf
Rollup merge of #144956 - fmease:gate-const-trait-syntax, r=BoxyUwU
Gate const trait syntax

Missed this during my review of rust-lang/rust#143879, huge apologies!
Fixes [after beta backport] https://github.com/rust-lang/rust/issues/144958.

cc ``@fee1-dead``
r? ``@BoxyUwU`` or anyone
2025-08-06 21:29:30 +02:00
Guillaume Gomez
d180873be8
Rollup merge of #144195 - Kivooeo:bad-attr, r=fmease,compiler-errors
Parser: Recover from attributes applied to types and generic args

r? compiler

Add clearer error messages for invalid attribute usage in types or generic types

fixes rust-lang/rust#135017
fixes rust-lang/rust#144132
2025-08-06 21:29:26 +02:00
León Orell Valerian Liehr
092c6f3a18
Gate const trait syntax 2025-08-05 14:52:02 +02:00
Kivooeo
d09cf616f7 Added checks for attribute in type case 2025-08-05 07:10:31 +05:00
Esteban Küber
2db126d651 Include whitespace in "remove |" suggestion and make it hidden 2025-08-04 18:06:18 +00:00
Jana Dönszelmann
5712d50648
Rollup merge of #144712 - nnethercote:dedup-num-types, r=fmease
Deduplicate `IntTy`/`UintTy`/`FloatTy`.

There are identical definitions in `rustc_type_ir` and `rustc_ast`. This commit removes them and places a single definition in `rustc_ast_ir`. This requires adding `rust_span` as a dependency of `rustc_ast_ir`, but means a bunch of silly conversion functions can be removed.

r? `@fmease`
2025-07-31 17:19:39 +02:00
Nicholas Nethercote
704f2ca172 Tidy up Cargo.toml files.
- Add some missing `tidy-alphabetical-*` markers.
- Remove some unnecessary blank lines.
2025-07-31 19:58:04 +10:00
Michael Goulet
51cd9b564f Consider operator's span when computing binop expr span 2025-07-31 02:28:11 +00:00
Stuart Cook
b76cb79e79
Rollup merge of #144589 - compiler-errors:postfix-yield-after-cast, r=petrochenkov
Account for `.yield` in illegal postfix operator message

Fixes rust-lang/rust#144527
2025-07-29 23:50:37 +10:00
Scott Schafer
aa9767290e
feat: Right align line numbers 2025-07-28 16:32:11 -06:00
Michael Goulet
2db97b2f7d Account for .yield in illegal postfix operator message 2025-07-28 16:09:59 +00:00
bors
d242a8bd5a Auto merge of #144469 - Kivooeo:chains-cleanup, r=SparrowLii
Some `let chains` clean-up

Not sure if this kind of clean-up is welcoming because of size, but I decided to try out one

r? compiler
2025-07-28 05:25:23 +00:00
Kivooeo
b8eb046e6e use let chains in mir, resolve, target 2025-07-28 06:10:36 +05:00
Jonathan Brouwer
a2b3d81034
Call is_parsed_attribute rather than keeping track of a list of parsed attributes manually 2025-07-24 22:53:09 +02:00
León Orell Valerian Liehr
6dc41520e9
Rollup merge of #144358 - JonathanBrouwer:fix-stability-malformed, r=oli-obk
Stop using the old `validate_attr` logic for stability attributes

I think this was accidentally missed when implementing the stability attributes?

r? `````@oli-obk`````
cc `````@jdonszelmann`````
2025-07-24 15:08:28 +02:00
bors
29a58723b0 Auto merge of #144360 - matthiaskrgr:rollup-b6ej0mm, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#144173 (Remove tidy checks for `tests/ui/issues/`)
 - rust-lang/rust#144234 (Fix broken TLS destructors on 32-bit win7)
 - rust-lang/rust#144239 (Clean `rustc/parse/src/lexer` to improve maintainability)
 - rust-lang/rust#144256 (Don't ICE on non-TypeId metadata within TypeId)
 - rust-lang/rust#144290 (update tests/ui/SUMMARY.md)
 - rust-lang/rust#144292 (mbe: Use concrete type for `get_unused_rule`)
 - rust-lang/rust#144298 (coverage: Enlarge empty spans during MIR instrumentation, not codegen)
 - rust-lang/rust#144311 (Add powerpc64le-unknown-linux-musl to CI rustc targets)
 - rust-lang/rust#144315 (bootstrap: add package.json and package-lock.json to dist tarball)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-23 16:59:13 +00:00
Matthias Krüger
80342618e1
Rollup merge of #144239 - xizheyin:clean-lexer, r=fee1-dead
Clean `rustc/parse/src/lexer` to improve maintainability

This PR refactors the lexer code to improve maintainability and eliminate code duplication.
In the first commit, I improve the error handling:
- rename `make_unclosed_delims_error` to more appropriate `make_mismatched_closing_delims_errors`
- changes return type from Option<Diag> to `Vec<Diag>` to avoid lengthy vec processing at `lex_token_trees`
- use `splice` instead of `extend` to make the logic clearer, since `errs` sounds more generic and better suited as a return value

In the second commit, I replace the magic number 5 with UNCLOSED_DELIMITER_SHOW_LIMIT constant.

In the third commit, I moves `eof_err` function below parsing logic for better code flow.

In the forth one, I extract `calculate_spacing` function to eliminate duplicate spacing logic between `bump` and `bump_minimal` functions.

r? compiler
2025-07-23 15:59:30 +02:00
Jonathan Brouwer
af06bb925f
Stop using the old validate_attr logic for stability attributes 2025-07-23 14:31:50 +02:00
Jonathan Brouwer
a460b46d0f
Ports #[macro_use] and #[macro_escape] to the new attribute parsing infrastructure 2025-07-23 13:33:23 +02:00
xizheyin
2832517ba1
Clean code for rustc_parse/src/lexer
1. Rename `make_unclosed_delims_error` and return `Vec<Diag>`
2. change magic number `unclosed_delimiter_show_limit` to const
3. move `eof_err` below parsing logic
4. Add `calculate_spacing` for `bump` and `bump_minimal`

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-22 18:38:33 +08:00
许杰友 Jieyou Xu (Joe)
ef4a7fb1b7
Rollup merge of #144080 - jieyouxu:realign, r=BoxyUwU
Mitigate `#[align]` name resolution ambiguity regression with a rename

Mitigates beta regression rust-lang/rust#143834 after a beta backport.

### Background on the beta regression

The name resolution regression arises due to rust-lang/rust#142507 adding a new feature-gated built-in attribute named `#[align]`. However, unfortunately even [introducing new feature-gated unstable built-in attributes can break user code](https://www.github.com/rust-lang/rust/issues/134963) such as

```rs
macro_rules! align {
    () => {
        /* .. */
    };
}

pub(crate) use align; // `use` here becomes ambiguous
```

### Mitigation approach

This PR renames `#[align]` to `#[rustc_align]` to mitigate the beta regression by:

1. Undoing the introduction of a new built-in attribute with a common name, i.e. `#[align]`.
2. Renaming `#[align]` to `#[rustc_align]`. The renamed attribute being `rustc_align` will not introduce new stable breakages, as attributes beginning with `rustc` are reserved and perma-unstable. This does mean existing nightly code using `fn_align` feature will additionally need to specify `#![feature(rustc_attrs)]`.

This PR is very much a short-term mitigation to alleviate time pressure from having to fully fix the current limitation of inevitable name resolution regressions that would arise from adding any built-in attributes. Long-term solutions are discussed in [#t-lang > namespacing macro attrs to reduce conflicts with new adds](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/namespacing.20macro.20attrs.20to.20reduce.20conflicts.20with.20new.20adds/with/529249622).

### Alternative mitigation options

[Various mitigation options were considered during the compiler triage meeting](https://github.com/rust-lang/rust/issues/143834#issuecomment-3084415277), and those consideration are partly reproduced here:

- Reverting the PR doesn't seem very minimal/trivial, and carries risks of its own.
- Rename to a less-common but aim-to-stabilization name is itself not safe nor convenient, because (1) that risks introducing new regressions (i.e. ambiguity against the new name), and (2) lang would have to FCP the new name hastily for the mitigation to land timely and have a chance to be backported. This also makes the path towards stabilization annoying.
- Rename the attribute to a rustc attribute, which will be perma-unstable and does not cause new ambiguities in stable code.
    - This alleviates the time pressure to address *this* regression, or for lang to have to rush an FCP for some new name that can still break user code.
    - This avoids backing out a whole implementation.

### Review advice

This PR is best reviewed commit-by-commit.

- Commit 1 adds a test `tests/ui/attributes/fn-align-nameres-ambiguity-143834.rs` which demonstrates the current name resolution regression re. `align`. This test fails against current master.
- Commit 2 carries out the renames and test reblesses. Notably, commit 2 will cause `tests/ui/attributes/fn-align-nameres-ambiguity-143834.rs` to change from fail (nameres regression) to pass.

This PR, if the approach still seems acceptable, will need a beta-backport to address the beta regression.
2025-07-22 00:54:28 +08:00
Jieyou Xu
69b71e4410
Mitigate #[align] name resolution ambiguity regression with a rename
From `#[align]` -> `#[rustc_align]`. Attributes starting with `rustc`
are always perma-unstable and feature-gated by `feature(rustc_attrs)`.

See regression RUST-143834.

For the underlying problem where even introducing new feature-gated
unstable built-in attributes can break user code such as

```rs
macro_rules! align {
    () => {
        /* .. */
    };
}

pub(crate) use align; // `use` here becomes ambiguous
```

refer to RUST-134963.

Since the `#[align]` attribute is still feature-gated by
`feature(fn_align)`, we can rename it as a mitigation. Note that
`#[rustc_align]` will obviously mean that current unstable user code
using `feature(fn_aling)` will need additionally `feature(rustc_attrs)`,
but this is a short-term mitigation to buy time, and is expected to be
changed to a better name with less collision potential.

See
<https://rust-lang.zulipchat.com/#narrow/channel/238009-t-compiler.2Fmeetings/topic/.5Bweekly.5D.202025-07-17/near/529290371>
where mitigation options were considered.
2025-07-19 01:42:30 +08:00
Matthias Krüger
61285e211b
Rollup merge of #138554 - xizheyin:issue-138401, r=chenyukang
Distinguish delim kind to decide whether to emit unexpected closing delimiter

Fixes #138401
2025-07-18 19:14:42 +02:00
xizheyin
181c1bda0e
Deduplicate unmatched_delims in rustc_parse to reduce confusion
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-18 20:34:58 +08:00