about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/parser/attr.rs
AgeCommit message (Collapse)AuthorLines
2023-08-02Move `TokenCursor::num_next_calls` into `Parser` and rename it.Nicholas Nethercote-3/+3
It's more of a `Parser`-level concern than a `TokenCursor`-level concern. Also, `num_bump_calls` is a more accurate name, because it's incremented in `Parser::bump`.
2023-06-27Simplify some conditionsMaybe Waffle-10/+7
2023-04-16fix clippy::toplevel_ref_arg and ::manual_mapMatthias Krüger-3/+3
2023-02-22errors: generate typed identifiers in each crateDavid Wood-9/+10
Instead of loading the Fluent resources for every crate in `rustc_error_messages`, each crate generates typed identifiers for its own diagnostics and creates a static which are pulled together in the `rustc_driver` crate and provided to the diagnostic emitter. Signed-off-by: David Wood <david.wood@huawei.com>
2023-02-21Use `ThinVec` in various AST types.Nicholas Nethercote-2/+5
This commit changes the sequence parsers to produce `ThinVec`, which triggers numerous conversions.
2022-12-10compiler: remove unnecessary imports and qualified pathsKaDiWa-1/+0
2022-11-28Rename `NestedMetaItem::[Ll]iteral` as `NestedMetaItem::[Ll]it`.Nicholas Nethercote-1/+1
We already use a mix of `Literal` and `Lit`. The latter is better because it is shorter without causing any ambiguity.
2022-11-28Rename `ast::Lit` as `ast::MetaItemLit`.Nicholas Nethercote-4/+5
2022-11-22`rustc_parse`: remove `ref` patternsMaybe Waffle-6/+6
2022-11-21Match crate and slug namesmejrs-6/+6
2022-11-16Use `token::Lit` in `ast::ExprKind::Lit`.Nicholas Nethercote-2/+2
Instead of `ast::Lit`. Literal lowering now happens at two different times. Expression literals are lowered when HIR is crated. Attribute literals are lowered during parsing. This commit changes the language very slightly. Some programs that used to not compile now will compile. This is because some invalid literals that are removed by `cfg` or attribute macros will no longer trigger errors. See this comment for more details: https://github.com/rust-lang/rust/pull/102944#issuecomment-1277476773
2022-10-23Migrate all diagnosticsNilstrieb-14/+14
2022-09-27Implement IntoDiagnosticArg for rustc_ast::token::Token(Kind)Xiretza-3/+1
2022-09-27Rework "inner attribute not permitted" errorsXiretza-56/+51
2022-09-27Remove error condition in parse_attributeXiretza-25/+12
This function is only ever called when the `#` has already been consumed, no need to produce an error message here.
2022-09-27Migrate more rustc_parse diagnostics to diagnostic structsXiretza-10/+7
2022-09-14make `mk_attr_id` part of `ParseSess`SparrowLii-2/+15
2022-09-09Rename `{Create,Lazy}TokenStream` as `{To,Lazy}AttrTokenStream`.Nicholas Nethercote-1/+1
`To` is better than `Create` for indicating that this is a non-consuming conversion, rather than creating something out of nothing. And the addition of `Attr` is because the current names makes them sound like they relate to `TokenStream`, but really they relate to `AttrTokenStream`.
2022-09-09Rename `AttrAnnotatedToken{Stream,Tree}`.Nicholas Nethercote-1/+1
These two type names are long and have long matching prefixes. I find them hard to read, especially in combinations like `AttrAnnotatedTokenStream::new(vec![AttrAnnotatedTokenTree::Token(..)])`. This commit renames them as `AttrToken{Stream,Tree}`.
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-2/+0
by module
2022-08-22Use `AttrVec` in more places.Nicholas Nethercote-4/+4
In some places we use `Vec<Attribute>` and some places we use `ThinVec<Attribute>` (a.k.a. `AttrVec`). This results in various points where we have to convert between `Vec` and `ThinVec`. This commit changes the places that use `Vec<Attribute>` to use `AttrVec`. A lot of this is mechanical and boring, but there are some interesting parts: - It adds a few new methods to `ThinVec`. - It implements `MapInPlace` for `ThinVec`, and introduces a macro to avoid the repetition of this trait for `Vec`, `SmallVec`, and `ThinVec`. Overall, it makes the code a little nicer, and has little effect on performance. But it is a precursor to removing `rustc_data_structures::thin_vec::ThinVec` and replacing it with `thin_vec::ThinVec`, which is implemented more efficiently.
2022-06-13remove unnecessary `to_string` and `String::new`Takayuki Maeda-4/+3
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-4/+4
2022-05-02fix most compiler/ doctestsElliot Roberts-3/+4
2022-04-28rustc_ast: Harmonize delimiter naming with `proc_macro::Delimiter`Vadim Petrochenkov-4/+4
2022-04-06Stop flagging certain inner attrs as outer onesLeón Orell Valerian Liehr-11/+15
2022-03-30Spellchecking some commentsYuri Astrakhan-1/+1
This PR attempts to clean up some minor spelling mistakes in comments
2022-03-17Rollup merge of #94731 - TaKO8Ki:const-generic-expr-recovery, ↵Dylan DPC-1/+1
r=davidtwco,oli-obk Suggest adding `{ .. }` around a const function call with arguments closes #91020
2022-03-15use `format_args_capture` in some parts of rustc_parseTakayuki Maeda-2/+2
2022-03-10replace `self.clone()` with `self.create_snapshot_for_diagnostic()`Takayuki Maeda-1/+1
2022-02-23rustc_errors: take `self` by value in `DiagnosticBuilder::cancel`.Eduard-Mihai Burtescu-4/+4
2022-02-23Replace `&mut DiagnosticBuilder`, in signatures, with `&mut Diagnostic`.Eduard-Mihai Burtescu-2/+2
2021-12-04Do not add `;` to expected tokens list when it's wrongMichael Howell-2/+2
There's a few spots where semicolons are checked for to do error recovery, and should not be suggested (or checked for other stuff). Fixes #87647
2021-09-02Provide more context on incorrect inner attributeEsteban Kuber-21/+119
Suggest changing an inner attribute into an outer attribute if followed by an item.
2021-07-02Recover from a misplaced inner doc commentAaron Hill-1/+8
Fixes #86781
2021-06-10Add support for using qualified paths with structs in expression and patternRyan Levick-1/+0
position.
2021-04-11Implement token-based handling of attributes during expansionAaron Hill-2/+20
This PR modifies the macro expansion infrastructure to handle attributes in a fully token-based manner. As a result: * Derives macros no longer lose spans when their input is modified by eager cfg-expansion. This is accomplished by performing eager cfg-expansion on the token stream that we pass to the derive proc-macro * Inner attributes now preserve spans in all cases, including when we have multiple inner attributes in a row. This is accomplished through the following changes: * New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced. These are very similar to a normal `TokenTree`, but they also track the position of attributes and attribute targets within the stream. They are built when we collect tokens during parsing. An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when we invoke a macro. * Token capturing and `LazyTokenStream` are modified to work with `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which is created during the parsing of a nested AST node to make the 'outer' AST node aware of the attributes and attribute target stored deeper in the token stream. * When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`), we tokenize and reparse our target, capturing additional information about the locations of `#[cfg]` and `#[cfg_attr]` attributes at any depth within the target. This is a performance optimization, allowing us to perform less work in the typical case where captured tokens never have eager cfg-expansion run.
2021-02-13Address review commentsAaron Hill-1/+1
2021-02-13Require passing an `AttrWrapper` to `collect_tokens_trailing_token`Aaron Hill-5/+7
This is a pure refactoring split out from #80689. It represents the most invasive part of that PR, requiring changes in every caller of `parse_outer_attributes` In order to eagerly expand `#[cfg]` attributes while preserving the original `TokenStream`, we need to know the range of tokens that corresponds to every attribute target. This is accomplished by making `parse_outer_attributes` return an opaque `AttrWrapper` struct. An `AttrWrapper` must be converted to a plain `AttrVec` by passing it to `collect_tokens_trailing_token`. This makes it difficult to accidentally construct an AST node with attributes without calling `collect_tokens_trailing_token`, since AST nodes store an `AttrVec`, not an `AttrWrapper`. As a result, we now call `collect_tokens_trailing_token` for attribute targets which only support inert attributes, such as generic arguments and struct fields. Currently, the constructed `LazyTokenStream` is simply discarded. Future PRs will record the token range corresponding to the attribute target, allowing those tokens to be removed from an enclosing `collect_tokens_trailing_token` call if necessary.
2021-02-07expand/resolve: Turn `#[derive]` into a regular macro attributeVadim Petrochenkov-4/+2
2021-01-13Set tokens on AST node in `collect_tokens`Aaron Hill-12/+4
A new `HasTokens` trait is introduced, which is used to move logic from the callers of `collect_tokens` into the body of `collect_tokens`. In addition to reducing duplication, this paves the way for PR #80689, which needs to perform additional logic during token collection.
2020-11-26rustc_parse: restore pub vis on parse_attributeCaleb Cartwright-2/+4
2020-11-19resolve/expand: Misc cleanupVadim Petrochenkov-7/+6
2020-11-09Do not collect tokens for doc commentsVadim Petrochenkov-99/+74
2020-10-22Only call `collect_tokens` when we have an attribute to parseAaron Hill-26/+32
2020-10-22Don't create an empty `LazyTokenStream`Aaron Hill-3/+3
2020-10-21Unconditionally capture tokens for attributes.Aaron Hill-51/+78
This allows us to avoid synthesizing tokens in `prepend_attr`, since we have the original tokens available. We still need to synthesize tokens when expanding `cfg_attr`, but this is an unavoidable consequence of the syntax of `cfg_attr` - the user does not supply the `#` and `[]` tokens that a `cfg_attr` expands to.
2020-10-19Rewrite `collect_tokens` implementations to use a flattened bufferAaron Hill-1/+14
Instead of trying to collect tokens at each depth, we 'flatten' the stream as we go allong, pushing open/close delimiters to our buffer just like regular tokens. One capturing is complete, we reconstruct a nested `TokenTree::Delimited` structure, producing a normal `TokenStream`. The reconstructed `TokenStream` is not created immediately - instead, it is produced on-demand by a closure (wrapped in a new `LazyTokenStream` type). This closure stores a clone of the original `TokenCursor`, plus a record of the number of calls to `next()/next_desugared()`. This is sufficient to reconstruct the tokenstream seen by the callback without storing any additional state. If the tokenstream is never used (e.g. when a captured `macro_rules!` argument is never passed to a proc macro), we never actually create a `TokenStream`. This implementation has a number of advantages over the previous one: * It is significantly simpler, with no edge cases around capturing the start/end of a delimited group. * It can be easily extended to allow replacing tokens an an arbitrary 'depth' by just using `Vec::splice` at the proper position. This is important for PR #76130, which requires us to track information about attributes along with tokens. * The lazy approach to `TokenStream` construction allows us to easily parse an AST struct, and then decide after the fact whether we need a `TokenStream`. This will be useful when we start collecting tokens for `Attribute` - we can discard the `LazyTokenStream` if the parsed attribute doesn't need tokens (e.g. is a builtin attribute). The performance impact seems to be neglibile (see https://github.com/rust-lang/rust/pull/77250#issuecomment-703960604). There is a small slowdown on a few benchmarks, but it only rises above 1% for incremental builds, where it represents a larger fraction of the much smaller instruction count. There a ~1% speedup on a few other incremental benchmarks - my guess is that the speedups and slowdowns will usually cancel out in practice.
2020-09-10Attach tokens to `NtMeta` (`ast::AttrItem`)Aaron Hill-1/+1
An `AttrItem` does not have outer attributes, so we only capture tokens when parsing a `macro_rules!` matcher
2020-08-30mv compiler to compiler/mark-0/+304