summary refs log tree commit diff
path: root/compiler/rustc_parse/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2022-10-10Fix compiler docsGuillaume Gomez-1/+2
2022-09-27Move rustc_parse diagnostic structs to separate moduleXiretza-0/+2
2022-09-26remove cfg(bootstrap)Pietro Albini-1/+0
2022-09-15Only enable the let_else feature on bootstrapest31-1/+1
On later stages, the feature is already stable. Result of running: rg -l "feature.let_else" compiler/ src/librustdoc/ library/ | xargs sed -s -i "s#\\[feature.let_else#\\[cfg_attr\\(bootstrap, feature\\(let_else\\)#"
2022-08-29Revert let_chains stabilizationNilstrieb-0/+1
This reverts commit 326646074940222d602f3683d0559088690830f4. This is the revert against master, the beta revert was already done in #100538.
2022-08-22Use `AttrVec` in more places.Nicholas Nethercote-2/+2
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-08-12Adjust cfgsMark Rousskov-1/+0
2022-07-24Update doc comments that refer to config parameterDaniel Bevenius-2/+2
This commit updates the source_file_to_parser and the maybe_source_file_to_parse function's doc comments which currently refer to a config parameter. The doc comments have been updated to refer to the 'session' parameter similar to the doc comment for try_file_to_source_file, which also takes a &Session parameter.
2022-07-16Stabilize `let_chains`Caio-1/+1
2022-06-27various: add `rustc_lint_diagnostics` to diag fnsDavid Wood-0/+1
The `rustc_lint_diagnostics` attribute is used by the diagnostic translation/struct migration lints to identify calls where non-translatable diagnostics or diagnostics outwith impls are being created. Any function used in creating a diagnostic should be annotated with this attribute so this commit adds the attribute to many more functions. Signed-off-by: David Wood <david.wood@huawei.com>
2022-06-13remove unnecessary `to_string` and `String::new`Takayuki Maeda-1/+1
2022-05-22rustc_parse: Move AST -> TokenStream conversion logic to `rustc_ast`Vadim Petrochenkov-111/+6
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-1/+0
2022-05-11ast: Introduce some traits to get AST node properties genericallyVadim Petrochenkov-5/+25
And use them to avoid constructing some artificial `Nonterminal` tokens during expansion
2022-03-28Rollup merge of #95301 - nnethercote:rm-NtTT, r=petrochenkovDylan DPC-1/+0
Remove `Nonterminal::NtTT`. It's only needed for macro expansion, not as a general element in the AST. This commit removes it, adds `NtOrTt` for the parser and macro expansion cases, and renames the variants in `NamedMatch` to better match the new type. r? `@petrochenkov`
2022-03-27Make fatal DiagnosticBuilder yield neverMichael Goulet-0/+1
2022-03-28Remove `Nonterminal::NtTT`.Nicholas Nethercote-1/+0
It's only needed for macro expansion, not as a general element in the AST. This commit removes it, adds `NtOrTt` for the parser and macro expansion cases, and renames the variants in `NamedMatch` to better match the new type.
2022-03-20Take &mut Diagnostic in emit_diagnostic.Camille GILLOT-4/+4
Taking a Diagnostic by move would break the usual pattern `diag.label(..).emit()`.
2022-03-03Associate multiple with a crate too.Felix S. Klock II-1/+1
2022-02-284 - Make more use of `let_chains`Caio-1/+2
Continuation of #94376. cc #53667
2022-02-16Adopt let_else in even more placesest31-0/+1
2021-11-28expand: Turn `ast::Crate` into a first class expansion targetVadim Petrochenkov-0/+6
And stop creating a fake `mod` item for the crate root when expanding a crate.
2021-09-20Add some more tracingOli Scherer-0/+3
2021-09-10Keep a parent LocalDefId in SpanData.Camille GILLOT-1/+1
2021-09-08Bump stage0 compiler to 1.56Mark Rousskov-2/+0
2021-08-27Path remapping: Make behavior of diagnostics output dependent on presence of ↵Michael Woerister-1/+1
--remap-path-prefix.
2021-08-25Use if-let guards in the codebaseLéo Lanteri Thauvin-13/+12
2021-08-21Remove `Session.used_attrs` and move logic to `CheckAttrVisitor`Aaron Hill-1/+43
Instead of updating global state to mark attributes as used, we now explicitly emit a warning when an attribute is used in an unsupported position. As a side effect, we are to emit more detailed warning messages (instead of just a generic "unused" message). `Session.check_name` is removed, since its only purpose was to mark the attribute as used. All of the callers are modified to use `Attribute.has_name` Additionally, `AttributeType::AssumedUsed` is removed - an 'assumed used' attribute is implemented by simply not performing any checks in `CheckAttrVisitor` for a particular attribute. We no longer emit unused attribute warnings for the `#[rustc_dummy]` attribute - it's an internal attribute used for tests, so it doesn't mark sense to treat it as 'unused'. With this commit, a large source of global untracked state is removed.
2021-08-18Remove box syntax from rustc_parseest31-1/+0
2021-06-04replaced feature-gate use with cfg_attrmarcusdunn-1/+1
2021-05-31Remove unused feature gatesbjorn3-1/+0
2021-05-24remove cfg(bootstrap)Pietro Albini-1/+0
2021-05-05Use local and remapped paths where appropriateAndy Wang-2/+4
2021-04-11Implement token-based handling of attributes during expansionAaron Hill-38/+37
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-03-19stabilize or_patternsmark-1/+1
2021-03-14Bump recursion_limit in a few placesAaron Hill-0/+1
This is needed to get rustdoc to succeed on `dist-x86_64-linux-alt`
2021-02-27Combine HasAttrs and HasTokens into AstLikeAaron Hill-1/+1
When token-based attribute handling is implemeneted in #80689, we will need to access tokens from `HasAttrs` (to perform cfg-stripping), and we will to access attributes from `HasTokens` (to construct a `PreexpTokenStream`). This PR merges the `HasAttrs` and `HasTokens` traits into a new `AstLike` trait. The previous `HasAttrs` impls from `Vec<Attribute>` and `AttrVec` are removed - they aren't attribute targets, so the impls never really made sense.
2021-02-01Box the biggest ast::ItemKind variantsDániel Buga-0/+2
2021-01-22Refactor token collection to capture trailing token immediatelyAaron Hill-1/+1
2021-01-10Auto merge of #80789 - Aaron1011:fix/stmt-empty, r=petrochenkovbors-1/+10
Synthesize a `TokenStream` for `StmtKind::Empty` Fixes #80760
2021-01-09Synthesize a `TokenStream` for `StmtKind::Empty`Aaron Hill-1/+10
Fixes #80760
2021-01-08rustc_ast_pretty: Remove `PrintState::insert_extra_parens`Vadim Petrochenkov-2/+1
It's no longer necessary after #79472
2021-01-07rustc_parse: Better spans for synthesized token streamsVadim Petrochenkov-12/+8
2020-12-29Remove pretty-print/reparse hack, and add derive-specific hackAaron Hill-359/+31
2020-11-28Auto merge of #78296 - Aaron1011:fix/stmt-tokens, r=petrochenkovbors-14/+9
Properly handle attributes on statements We now collect tokens for the underlying node wrapped by `StmtKind` nstead of storing tokens directly in `Stmt`. `LazyTokenStream` now supports capturing a trailing semicolon after it is initially constructed. This allows us to avoid refactoring statement parsing to wrap the parsing of the semicolon in `parse_tokens`. Attributes on item statements (e.g. `fn foo() { #[bar] struct MyStruct; }`) are now treated as item attributes, not statement attributes, which is consistent with how we handle attributes on other kinds of statements. The feature-gating code is adjusted so that proc-macro attributes are still allowed on item statements on stable. Two built-in macros (`#[global_allocator]` and `#[test]`) needed to be adjusted to support being passed `Annotatable::Stmt`.
2020-11-26Properly handle attributes on statementsAaron Hill-14/+9
We now collect tokens for the underlying node wrapped by `StmtKind` instead of storing tokens directly in `Stmt`. `LazyTokenStream` now supports capturing a trailing semicolon after it is initially constructed. This allows us to avoid refactoring statement parsing to wrap the parsing of the semicolon in `parse_tokens`. Attributes on item statements (e.g. `fn foo() { #[bar] struct MyStruct; }`) are now treated as item attributes, not statement attributes, which is consistent with how we handle attributes on other kinds of statements. The feature-gating code is adjusted so that proc-macro attributes are still allowed on item statements on stable. Two built-in macros (`#[global_allocator]` and `#[test]`) needed to be adjusted to support being passed `Annotatable::Stmt`.
2020-11-26Auto merge of #79338 - Aaron1011:fix/token-reparse-cache, r=petrochenkovbors-3/+35
Cache pretty-print/retokenize result to avoid compile time blowup Fixes #79242 If a `macro_rules!` recursively builds up a nested nonterminal (passing it to a proc-macro at each step), we will end up repeatedly pretty-printing/retokenizing the same nonterminals. Unfortunately, the 'probable equality' check we do has a non-trivial cost, which leads to a blowup in compilation time. As a workaround, we cache the result of the 'probable equality' check, which eliminates the compilation time blowup for the linked issue. This commit only touches a single file (other than adding tests), so it should be easy to backport. The proper solution is to remove the pretty-print/retokenize hack entirely. However, this will almost certainly break a large number of crates that were relying on hygiene bugs created by using the reparsed `TokenStream`. As a result, we will definitely not want to backport such a change.
2020-11-23Cache pretty-print/retokenize result to avoid compile time blowupAaron Hill-3/+35
Fixes #79242 If a `macro_rules!` recursively builds up a nested nonterminal (passing it to a proc-macro at each step), we will end up repeatedly pretty-printing/retokenizing the same nonterminals. Unfortunately, the 'probable equality' check we do has a non-trivial cost, which leads to a blowup in compilation time. As a workaround, we cache the result of the 'probable equality' check, which eliminates the compilation time blowup for the linked issue. This commit only touches a single file (other than adding tests), so it should be easy to backport. The proper solution is to remove the pretty-print/retokenize hack entirely. However, this will almost certainly break a large number of crates that were relying on hygiene bugs created by using the reparsed `TokenStream`. As a result, we will definitely not want to backport such a change.
2020-11-22Stabilise `then`varkor-1/+0
2020-11-09Do not collect tokens for doc commentsVadim Petrochenkov-6/+1