about summary refs log tree commit diff
path: root/compiler/rustc_ast/src/attr
AgeCommit message (Collapse)AuthorLines
2025-08-09remove `P`Deadbeef-3/+2
2025-07-12Port `#[automatically_derived]` to the new attribute parsing infrastructureJonathan Brouwer-0/+5
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-06-21Remove style() from AttributeExt traitDavid Tolnay-9/+3
2025-06-21Add AttributeExt::doc_resolution_scopeDavid Tolnay-0/+21
2025-05-27Reduce `P<T>` to a typedef of `Box<T>`.Nicholas Nethercote-1/+1
Keep the `P` constructor function for now, to minimize immediate churn. All the `into_inner` calls are removed, which is nice.
2025-04-22Auto merge of #139897 - nnethercote:rm-OpenDelim-CloseDelim, r=petrochenkovbors-4/+1
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-21Remove `token::{Open,Close}Delim`.Nicholas Nethercote-4/+1
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-17Replace infallible `name_or_empty` methods with fallible `name` methods.Nicholas Nethercote-11/+22
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-13Improve `-Z crate-attr` diagnosticsjyn-1/+1
- Show the `#![ ... ]` in the span (to make it clear that it should not be included in the CLI argument) - Show more detailed errors when the crate has valid token trees but invalid syntax. Previously, `crate-attr=feature(foo),feature(bar)` would just say "invalid crate attribute" and point at the comma. Now, it explicitly says that the comma was unexpected, which is useful when using `--error-format=short`. It also fixes the column to show the correct span. - Recover from parse errors. Previously we would abort immediately on syntax errors; now we go on to try and type-check the rest of the crate. The new diagnostic code also happens to be slightly shorter.
2025-04-03Allow boolean literals in `check-cfg`clubby789-0/+8
2025-02-28Remove `NtPath`.Nicholas Nethercote-5/+3
2025-02-28Remove `NtMeta`.Nicholas Nethercote-2/+10
Note: there was an existing code path involving `Interpolated` in `MetaItem::from_tokens` that was dead. This commit transfers that to the new form, but puts an `unreachable!` call inside it.
2025-01-26rustc_ast: replace some len-checks + indexing with slice patterns etc. 🧹Yotam Ofek-1/+1
2025-01-15allowed_through_unstable_modules: support showing a deprecation message when ↵Ralf Jung-0/+2
the unstable module name is used
2024-12-18Rollup merge of #134161 - nnethercote:overhaul-token-cursors, r=spastorino许杰友 Jieyou Xu (Joe)-39/+30
Overhaul token cursors Some nice cleanups here. r? `````@davidtwco`````
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-18Remove `Peekable<TokenStreamIter>` uses.Nicholas Nethercote-18/+9
Currently there are two ways to peek at a `TokenStreamIter`. - Wrap it in a `Peekable` and use that traits `peek` method. - Use `TokenStreamIter`'s inherent `peek` method. Some code uses one, some use the other. This commit converts all places to the inherent method. This eliminates mixing of `TokenStreamIter` and `Peekable<TokenStreamIter>` and some use of `impl Iterator` and `dyn Iterator`.
2024-12-18Rename `RefTokenTreeCursor`.Nicholas Nethercote-27/+27
Because `TokenStreamIter` is a much better name for a `TokenStream` iterator. Also rename the `TokenStream::trees` method as `TokenStream::iter`, and some local variables.
2024-12-15Add hir::AttributeJonathan Dönszelmann-59/+204
2024-12-15Rename `value` field to `expr` to simplify later commits' diffsOli Scherer-4/+4
2024-12-02Change `AttrArgs::Eq` into a struct variantOli Scherer-5/+7
2024-11-21Introduce `InvisibleOrigin` on invisible delimiters.Nicholas Nethercote-2/+2
It's not used meaningfully yet, but will be needed to get rid of interpolated tokens.
2024-11-05Add documentation on `ast::Attribute`Guillaume Gomez-0/+46
2024-10-19Do not run lints that cannot emitblyxyas-1/+1
Before this change, adding a lint was a difficult matter because it always had some overhead involved. This was because all lints would run, no matter their default level, or if the user had #![allow]ed them. This PR changes that
2024-10-06Rename NestedMetaItem to MetaItemInnercodemountains-24/+24
2024-10-01Implement boolean lit support in cfg predicatesUrgau-0/+10
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-6/+6
2024-07-29Reformat `use` declarations.Nicholas Nethercote-13/+13
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-10Rework `Attribute::get_tokens`.Nicholas Nethercote-13/+10
Returning `Vec<TokenTree>` works better for the call sites than returning `TokenStream`.
2024-07-07Rename `Attribute::tokens` (the inherent method).Nicholas Nethercote-1/+2
To distinguish it from the `HasTokens` method.
2024-07-02Change `AttrTokenStream::to_tokenstream` to `to_token_trees`.Nicholas Nethercote-6/+8
I.e. change the return type from `TokenStream` to `Vec<TokenTree>`. Most of the callsites require a `TokenStream`, but the recursive call used to create `target_tokens` requires a `Vec<TokenTree>`. It's easy to convert a `Vec<TokenTree>` to a `TokenStream` (just call `TokenStream::new`) but it's harder to convert a `TokenStream` to a `Vec<TokenTree>` (either iterate/clone/collect, or use `Lrc::into_inner` if appropriate). So this commit changes the return value to simplify that `target_tokens` call site.
2024-06-25Extra panic cases.Nicholas Nethercote-1/+8
Just some extra sanity checking, making explicit some values not possible in code working with token trees -- we shouldn't be seeing explicit delimiter tokens, because they should be represented as `TokenTree::Delimited`.
2024-06-06Change comment to FIXMEcarbotaniuman-1/+3
2024-06-06Fix buildcarbotaniuman-7/+7
2024-06-06Parse unsafe attributescarbotaniuman-8/+25
2024-05-21Move `#[do_not_recommend]` to the `#[diagnostic]` namespaceGeorg Semmler-0/+11
This commit moves the `#[do_not_recommend]` attribute to the `#[diagnostic]` namespace. It still requires `#![feature(do_not_recommend)]` to work.
2024-05-13Remove a `Span` from `TokenKind::Interpolated`.Nicholas Nethercote-1/+1
This span records the declaration of the metavariable in the LHS of the macro. It's used in a couple of error messages. Unfortunately, it gets in the way of the long-term goal of removing `TokenKind::Interpolated`. So this commit removes it, which degrades a couple of (obscure) error messages but makes things simpler and enables the next commit.
2024-04-24Rename `NestedMetaItem::name_value_literal`.Nicholas Nethercote-2/+3
It's a highly misleading name, because it's completely different to `MetaItem::name_value_literal`. Specifically, it doesn't match `MetaItemKind::NameValue` (e.g. `#[foo = 3]`), it matches `MetaItemKind::List` (e.g. `#[foo(3)]`).
2024-04-24Remove `MetaItemKind::value_str`.Nicholas Nethercote-8/+4
`MetaItem::value_str` is good enough. And this makes `MetaItem::value_str` more like `MetaItem::meta_item_list` and `name_value_literal`.
2024-04-04Rename ModSep to PathSepLeón Orell Valerian Liehr-3/+3
2023-12-11Add spacing information to delimiters.Nicholas Nethercote-3/+3
This is an extension of the previous commit. It means the output of something like this: ``` stringify!(let a: Vec<u32> = vec![];) ``` goes from this: ``` let a: Vec<u32> = vec![] ; ``` With this PR, it now produces this string: ``` let a: Vec<u32> = vec![]; ```
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-1/+1
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-11-16More detail when expecting expression but encountering bad macro argumentEsteban Küber-1/+1
Partially address #71039.
2023-10-13Format all the let chains in compilerMichael Goulet-3/+1
2023-10-12Use `TokenStream::token_alone` in one place.Nicholas Nethercote-4/+4
2023-09-12`#[diagnostic::on_unimplemented]` without filtersGeorg Semmler-0/+16
This commit adds support for a `#[diagnostic::on_unimplemented]` attribute with the following options: * `message` to customize the primary error message * `note` to add a customized note message to an error message * `label` to customize the label part of the error message Co-authored-by: León Orell Valerian Liehr <me@fmease.dev> Co-authored-by: Michael Goulet <michael@errs.io>
2023-08-03Remove `MacDelimiter`.Nicholas Nethercote-8/+6
It's the same as `Delimiter`, minus the `Invisible` variant. I'm generally in favour of using types to make impossible states unrepresentable, but this one feels very low-value, and the conversions between the two types are annoying and confusing. Look at the change in `src/tools/rustfmt/src/expr.rs` for an example: the old code converted from `MacDelimiter` to `Delimiter` and back again, for no good reason. This suggests the author was confused about the types.
2023-07-27Make `TokenTree::uninterpolate` take `&self` and return a `Cow`.Nicholas Nethercote-7/+7
Making it similar to `Token::uninterpolate`. This avoids some more token tree cloning.
2023-07-27Use `TokenStream::trees` instead of `into_trees` for attributes.Nicholas Nethercote-14/+13
This avoids cloning some token trees. A couple of `clone` calls were inserted, but only on some paths, and the next commit will remove them.
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-3/+3