Commit Graph

72 Commits

Author SHA1 Message Date
Matthias Krüger
7420ae82a7
Rollup merge of #142058 - xizheyin:rustc-attr-parsing, r=jdonszelmann
Clean `rustc_attr_parsing/src/lib.rs` documentation

Improves the documentation clarity in `rustc_attr_parsing` by restructuring content with clearer section headers, simplifying explanations of attribute types, making technical descriptions more precise.

r? ``@oli-obk``
2025-06-06 00:58:46 +02:00
xizheyin
1e49ad3862 Clean rustc_attr_parsing documentation
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-05 17:11:46 +08:00
Matthias Krüger
c1e8fe760b
Rollup merge of #141271 - nnethercote:attr-streamline, r=jdonszelmann
Streamline some attr parsing APIs

r? ``@jdonszelmann``
2025-06-04 16:24:06 +02:00
Urgau
e33fe611f5 Add custom trait for emitting lint within cfg_matches 2025-05-26 21:51:09 +02:00
Jacob Pratt
761e5464dd
Rollup merge of #140539 - nnethercote:simplify-attribute_groups, r=jdonszelmann
Simplify `attribute_groups`

It's more complicated than it needs to be.

r? ``@jdonszelmann``
2025-05-26 03:38:16 +02:00
est31
f3245e48f9 Make #[cfg(version)] respect RUSTC_OVERRIDE_VERSION_STRING 2025-05-24 23:54:17 +02:00
Nicholas Nethercote
e5c78de85c Rename MetaItemParser::path_without_args as MetaItemParser::path.
And avoid the clone.
2025-05-21 04:53:31 +10:00
Nicholas Nethercote
2cd2d24967 Remove MetaItemParser::{path,deconstruct}.
They're equivalent, and `path` is unused, and `deconstruct` has only one
call site outside of `path`.
2025-05-21 04:53:31 +10:00
Nicholas Nethercote
ea3b3fdcc1 Remove MetaItemParser::{word,word_without_args,path_is}.
They are unused.
2025-05-21 04:53:31 +10:00
Nicholas Nethercote
a822e557cd Remove an unnecessary lifetime. 2025-05-21 04:53:24 +10:00
bohan
097b7a2ac7 collect doc alias as tips during resolution 2025-05-21 00:47:36 +08:00
Nicholas Nethercote
ee1c2d583a Remove MetaItemListParser::all_{word,path}_list, which are unused. 2025-05-20 11:58:11 +10:00
Nicholas Nethercote
354b1cbcca Avoid rustc_span:: qualifiers.
In several files they are entirely unnecessary, with the relevant names
already imported. And in a few I have added the necessary `use` item.
2025-05-20 09:20:27 +10:00
Nicholas Nethercote
1525f548bc Fix up some comments.
Some are too long (> 100 chars), some are too short, some are missing
full stops, some are missing upper-case letters at the start of
sentences.
2025-05-20 09:17:49 +10:00
Nicholas Nethercote
5b808b7da8 Simplify Accepts.
There only needs to be one `Fn` per symbol, not multiple.
2025-05-20 09:12:24 +10:00
Nicholas Nethercote
e139d268f0 Introduce some typedefs to improve readability. 2025-05-20 08:31:49 +10:00
Stuart Cook
599b08ada8
Rollup merge of #140874 - mejrs:rads, r=WaffleLapkin
make `rustc_attr_parsing` less dominant in the rustc crate graph

It has/had a glob re-export of `rustc_attr_data_structures`, which is a crate much lower in the graph, and a lot of crates were using it *just* (or *mostly*) for that re-export, while they can rely on `rustc_attr_data_structures` directly.

Previous graph:
![graph_1](https://github.com/user-attachments/assets/f4a5f13c-4222-4903-b56d-28c83511fcbd)

Graph with this PR:
![graph_2](https://github.com/user-attachments/assets/1e053d9c-75cc-402b-84df-86229c98277a)

The first commit keeps the re-export, and just changes the dependency if possible. The second commit is the "breaking change" which removes the re-export, and "explicitly" adds the `rustc_attr_data_structures` dependency where needed. It also switches over some src/tools/*.

The second commit is actually a lot more involved than I expected. Please let me know if it's a better idea to back it out and just keep the first commit.
2025-05-19 13:24:54 +10:00
mejrs
178e09ed37 Remove rustc_attr_data_structures re-export from rustc_attr_parsing 2025-05-18 18:14:43 +02:00
Pietro Albini
2ce08ca5d6
update cfg(bootstrap) 2025-05-12 15:33:37 +02:00
Nicholas Nethercote
603766cd72 Avoid some unwraps.
By using `@` patterns more.

Also, use `Symbol` more in a couple of errors to avoid some unnecessary
conversions to strings. This even removes a lifetime.
2025-05-07 12:56:44 +10:00
Nicholas Nethercote
d81472f266 Eliminate word_or_empty methods.
To get rid of the `Ident::empty` uses.

This requires introducing `PathParser::word_sym`, as an alternative to
`PathParser::word`.
2025-05-07 12:56:41 +10:00
Nicholas Nethercote
298c56f4ba Simplify LazyAttrTokenStream.
This commit does the following.
- Changes it from `Lrc<Box<dyn ToAttrTokenStream>>` to
  `Lrc<LazyAttrTokenStreamInner>`.
- Reworks `LazyAttrTokenStreamImpl` as `LazyAttrTokenStreamInner`, which
  is a two-variant enum.
- Removes the `ToAttrTokenStream` trait and the two impls of it.

The recursion limit must be increased in some crates otherwise rustdoc
aborts.
2025-04-30 07:10:56 +10:00
bors
8f43b85954 Auto merge of #140282 - matthiaskrgr:rollup-g6ze4jj, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #137653 (Deprecate the unstable `concat_idents!`)
 - #138957 (Update the index of Option to make the summary more comprehensive)
 - #140006 (ensure compiler existance of tools on the dist step)
 - #140143 (Move `sys::pal::os::Env` into `sys::env`)
 - #140202 (Make #![feature(let_chains)] bootstrap conditional in compiler/)
 - #140236 (norm nested aliases before evaluating the parent goal)
 - #140257 (Some drive-by housecleaning in `rustc_borrowck`)
 - #140278 (Don't use item name to look up associated item from trait item)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-25 12:27:16 +00:00
Matthias Krüger
c43022f8cb
Rollup merge of #140229 - nnethercote:pre-DelimArgs-spacing, r=petrochenkov
`DelimArgs` tweaks

r? `@petrochenkov`
2025-04-25 00:54:01 +02:00
est31
7493e1cdf6 Make #![feature(let_chains)] bootstrap conditional in compiler/ 2025-04-23 16:40:30 +02:00
Nicholas Nethercote
7fe6bc57f5 Use clone to clone DelimArgs in two places. 2025-04-23 20:10:49 +10:00
bors
fae7785b60 Auto merge of #139897 - nnethercote:rm-OpenDelim-CloseDelim, r=petrochenkov
Remove `token::{Open,Close}Delim`

By replacing them with `{Open,Close}{Param,Brace,Bracket,Invisible}`.

PR #137902 made `ast::TokenKind` more like `lexer::TokenKind` by
replacing the compound `BinOp{,Eq}(BinOpToken)` variants with fieldless
variants `Plus`, `Minus`, `Star`, etc. This commit does a similar thing
with delimiters. It also makes `ast::TokenKind` more similar to
`parser::TokenType`.

This requires a few new methods:
- `TokenKind::is_{,open_,close_}delim()` replace various kinds of
  pattern matches.
- `Delimiter::as_{open,close}_token_kind` are used to convert
  `Delimiter` values to `TokenKind`.

Despite these additions, it's a net reduction in lines of code. This is
because e.g. `token::OpenParen` is so much shorter than
`token::OpenDelim(Delimiter::Parenthesis)` that many multi-line forms
reduce to single line forms. And many places where the number of lines
doesn't change are still easier to read, just because the names are
shorter, e.g.:
```
-   } else if self.token != token::CloseDelim(Delimiter::Brace) {
+   } else if self.token != token::CloseBrace {
```

r? `@petrochenkov`
2025-04-22 01:15:06 +00:00
Nicholas Nethercote
bf8ce32558 Remove token::{Open,Close}Delim.
By replacing them with `{Open,Close}{Param,Brace,Bracket,Invisible}`.

PR #137902 made `ast::TokenKind` more like `lexer::TokenKind` by
replacing the compound `BinOp{,Eq}(BinOpToken)` variants with fieldless
variants `Plus`, `Minus`, `Star`, etc. This commit does a similar thing
with delimiters. It also makes `ast::TokenKind` more similar to
`parser::TokenType`.

This requires a few new methods:
- `TokenKind::is_{,open_,close_}delim()` replace various kinds of
  pattern matches.
- `Delimiter::as_{open,close}_token_kind` are used to convert
  `Delimiter` values to `TokenKind`.

Despite these additions, it's a net reduction in lines of code. This is
because e.g. `token::OpenParen` is so much shorter than
`token::OpenDelim(Delimiter::Parenthesis)` that many multi-line forms
reduce to single line forms. And many places where the number of lines
doesn't change are still easier to read, just because the names are
shorter, e.g.:
```
-   } else if self.token != token::CloseDelim(Delimiter::Brace) {
+   } else if self.token != token::CloseBrace {
```
2025-04-21 07:35:56 +10:00
Mara Bos
5f4d676e70 Remove #[rustc_macro_edition_2021].
It was only temporarily used by pin!(), which no longer needs it.
2025-04-20 11:15:46 +02:00
Matthias Krüger
540fb228af
Rollup merge of #139615 - nnethercote:rm-name_or_empty, r=jdonszelmann
Remove `name_or_empty`

Another step towards #137978.

r? ``@jdonszelmann``
2025-04-18 05:16:29 +02:00
bors
883f9f72e8 Auto merge of #139949 - matthiaskrgr:rollup-pxc5tsx, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #138632 (Stabilize `cfg_boolean_literals`)
 - #139416 (unstable book; document `macro_metavar_expr_concat`)
 - #139782 (Consistent with treating Ctor Call as Struct in liveness analysis)
 - #139885 (document RUSTC_BOOTSTRAP, RUSTC_OVERRIDE_VERSION_STRING, and -Z allow-features in the unstable book)
 - #139904 (Explicitly annotate edition for `unpretty=expanded` and `unpretty=hir` tests)
 - #139932 (transmutability: Refactor tests for simplicity)
 - #139944 (Move eager translation to a method on Diag)
 - #139948 (git: ignore `60600a6fa403216bfd66e04f948b1822f6450af7` for blame purposes)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-17 11:21:54 +00:00
Matthias Krüger
0de803c38d
Rollup merge of #138632 - clubby789:stabilize-cfg-boolean-lit, r=davidtwco,Urgau,traviscross
Stabilize `cfg_boolean_literals`

Closes #131204
`@rustbot` labels +T-lang +I-lang-nominated
This will end up conflicting with the test in #138293 so whichever doesn't land first will need updating

--

# Stabilization Report

## General design

### What is the RFC for this feature and what changes have occurred to the user-facing design since the RFC was finalized?

[RFC 3695](https://github.com/rust-lang/rfcs/pull/3695), none.

### What behavior are we committing to that has been controversial? Summarize the major arguments pro/con.

None

### Are there extensions to this feature that remain unstable? How do we know that we are not accidentally committing to those?

None

## Has a call-for-testing period been conducted? If so, what feedback was received?

Yes; only positive feedback was received.

## Implementation quality

### Summarize the major parts of the implementation and provide links into the code (or to PRs)

Implemented in [#131034](https://github.com/rust-lang/rust/pull/131034).

### Summarize existing test coverage of this feature

- [Basic usage, including `#[cfg()]`, `cfg!()` and `#[cfg_attr()]`](6d71251cf9/tests/ui/cfg/true-false.rs)
- [`--cfg=true/false` on the command line being accessible via `r#true/r#false`](6d71251cf9/tests/ui/cfg/raw-true-false.rs)
- [Interaction with the unstable `#[doc(cfg(..))]` feature](https://github.com/rust-lang/rust/tree/6d71251/tests/rustdoc-ui/cfg-boolean-literal.rs)
- [Denying `--check-cfg=cfg(true/false)`](https://github.com/rust-lang/rust/tree/6d71251/tests/ui/check-cfg/invalid-arguments.rs)
- Ensuring `--cfg false` on the command line doesn't change the meaning of `cfg(false)`: `tests/ui/cfg/cmdline-false.rs`
- Ensuring both `cfg(true)` and `cfg(false)` on the same item result in it being disabled: `tests/ui/cfg/both-true-false.rs`

### What outstanding bugs in the issue tracker involve this feature? Are they stabilization-blocking?

The above mentioned issue; it should not block as it interacts with another unstable feature.

### What FIXMEs are still in the code for that feature and why is it ok to leave them there?

None

### Summarize contributors to the feature by name for recognition and assuredness that people involved in the feature agree with stabilization
- `@clubby789` (RFC)
- `@Urgau` (Implementation in rustc)

### Which tools need to be adjusted to support this feature. Has this work been done?

`rustdoc`'s  unstable`#[doc(cfg(..)]` has been updated to respect it. `cargo` has been updated with a forward compatibility lint to enable supporting it in cargo once stabilized.

## Type system and execution rules

### What updates are needed to the reference/specification? (link to PRs when they exist)

A few lines to be added to the reference for configuration predicates, specified in the RFC.
2025-04-17 06:25:15 +02:00
Nicholas Nethercote
2fef0a30ae Replace infallible name_or_empty methods with fallible name methods.
I'm removing empty identifiers everywhere, because in practice they
always mean "no identifier" rather than "empty identifier". (An empty
identifier is impossible.) It's better to use `Option` to mean "no
identifier" because you then can't forget about the "no identifier"
possibility.

Some specifics:
- When testing an attribute for a single name, the commit uses the
  `has_name` method.
- When testing an attribute for multiple names, the commit uses the new
  `has_any_name` method.
- When using `match` on an attribute, the match arms now have `Some` on
  them.

In the tests, we now avoid printing empty identifiers by not printing
the identifier in the `error:` line at all, instead letting the carets
point out the problem.
2025-04-17 09:50:52 +10:00
Matthias Krüger
9842698be5
Rollup merge of #139084 - petrochenkov:transpaque, r=davidtwco
hygiene: Rename semi-transparent to semi-opaque

"Semi-transparent" is just too damn long for a name, especially when used multiple times on a single line, it bothered me when working on #139083.

An optimist sees a macro as semi-opaque, a pessimist sees it as semi-transparent.
Or is it the other way round?
2025-04-17 00:14:24 +02:00
clubby789
984c51f6a1 Stabilize cfg_boolean_literals 2025-04-03 18:10:48 +00:00
Nicholas Nethercote
1830245a22 Remove recursion_limit increases.
These are no longer needed now that `Nonterminal` is gone.
2025-04-02 16:25:27 +11:00
Nicholas Nethercote
4c0cbaeb9e Remove TokenStream::flattened and InvisibleOrigin::FlattenToken.
They are no longer needed.

This does slightly worsen the error message for a single test, but that
test contains code that is so badly broken that I'm not worried about
it.
2025-04-02 16:16:51 +11:00
Nicholas Nethercote
bb495d6d3e Remove NtBlock, Nonterminal, and TokenKind::Interpolated.
`NtBlock` is the last remaining variant of `Nonterminal`, so once it is
gone then `Nonterminal` can be removed as well.
2025-04-02 16:07:02 +11:00
Vadim Petrochenkov
54bb849aff hygiene: Rename semi-transparent to semi-opaque
The former is just too long, see the examples in `hygiene.rs`
2025-03-31 15:41:48 +03:00
Nicholas Nethercote
867da30cc7 Avoid kw::Empty when dealing with rustc_allowed_through_unstable_modules.
The existing code produces `Some(kw::Empty)` for these invalid forms:

- a non-name-value, e.g. `#[rustc_allowed_through_unstable_modules]`

- a non-string arg, e.g. `#[rustc_allowed_through_unstable_modules = 3]`

The new code avoids the `kw::Empty` and is a little shorter. It will
produce `None` in those cases, which means E0789 won't be produced if
the `stable` attribute is missing for these invalid forms. This doesn't
matter, because these invalid forms will trigger an "malformed
`rustc_allowed_through_unstable_modules` attribute" anyway.
2025-03-25 16:48:03 +11:00
Matthias Krüger
7c2475e9aa
Rollup merge of #138717 - jdonszelmann:pin-macro, r=WaffleLapkin
Add an attribute that makes the spans from a macro edition 2021, and fix pin on edition 2024 with it

Fixes a regression, see issue below. This is a temporary fix, super let is the real solution.

Closes #138596
2025-03-21 15:48:57 +01:00
Nicholas Nethercote
8121958fda Use -Wunused_crate_dependencies for compiler crates.
It's very useful. There are some false positives involving integration
tests in `rustc_pattern_analysis` and `rustc_serialize`. There is also a
false positive involving `rustc_driver_impl`'s
`rustc_randomized_layouts` feature. And I removed a `rustc_span` mention
in a doc comment in `rustc_log` because it wasn't integral to the
comment but caused a dev-dependency.
2025-03-20 08:59:43 +11:00
Jana Dönszelmann
7c085f7ffd
add rustc_macro_edition_2021 2025-03-19 17:37:35 +01:00
bors
249cb84316 Auto merge of #138414 - matthiaskrgr:rollup-9ablqdb, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #137314 (change definitely unproductive cycles to error)
 - #137701 (Convert `ShardedHashMap` to use `hashbrown::HashTable`)
 - #138269 (uefi: fs: Implement FileType, FilePermissions and FileAttr)
 - #138331 (Use `RUSTC_LINT_FLAGS` more)
 - #138345 (Some autodiff cleanups)
 - #138387 (intrinsics: remove unnecessary leading underscore from argument names)
 - #138390 (fix incorrect tracing log)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-12 17:27:43 +00:00
Matthias Krüger
d93ef397ce
Rollup merge of #138331 - nnethercote:use-RUSTC_LINT_FLAGS-more, r=onur-ozkan,jieyouxu
Use `RUSTC_LINT_FLAGS` more

An alternative to the failed #138084.

Fixes #138106.

r? ````@jieyouxu````
2025-03-12 17:59:08 +01:00
bors
aaa2d47dae Auto merge of #138083 - nnethercote:rm-NtItem-NtStmt, r=petrochenkov
Remove `NtItem` and `NtStmt`

Another piece of #124141.

r? `@petrochenkov`
2025-03-12 14:18:36 +00:00
Nicholas Nethercote
0b2d7062c4 Introduce sym::dummy and Ident::dummy.
The idea is to identify cases of symbols/identifiers that are not
expected to be used. There isn't a perfectly sharp line between "dummy"
and "not dummy", but I think it's useful nonetheless.
2025-03-12 09:35:11 +11:00
Nicholas Nethercote
ff0a5fe975 Remove #![warn(unreachable_pub)] from all compiler/ crates.
It's no longer necessary now that `-Wunreachable_pub` is being passed.
2025-03-11 13:14:21 +11:00
许杰友 Jieyou Xu (Joe)
063ef18fdc Revert "Use workspace lints for crates in compiler/ #138084"
Revert <https://github.com/rust-lang/rust/pull/138084> to buy time to
consider options that avoids breaking downstream usages of cargo on
distributed `rustc-src` artifacts, where such cargo invocations fail due
to inability to inherit `lints` from workspace root manifest's
`workspace.lints` (this is only valid for the source rust-lang/rust
workspace, but not really the distributed `rustc-src` artifacts).

This breakage was reported in
<https://github.com/rust-lang/rust/issues/138304>.

This reverts commit 48caf81484, reversing
changes made to c6662879b2.
2025-03-10 18:12:47 +08:00
Matthias Krüger
d88752a4b5
Rollup merge of #138160 - jdonszelmann:move-find-attr2, r=oli-obk
depend more on attr_data_structures and move find_attr! there

r?  ``@oli-obk``

This should be an easy one. It just moves some imports around. This is necessary for other changes that I'm working on not to have import cycles. However, it's an easy one to just merge on its own.
2025-03-09 10:34:52 +01:00