summary refs log tree commit diff
path: root/compiler/rustc_parse/src/lib.rs
AgeCommit message (Collapse)AuthorLines
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-3/+3
Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile.
2023-04-27Migrate trivially translatable `rustc_parse` diagnosticsclubby789-14/+3
2023-04-18Add `rustc_fluent_macro` to decouple fluent from `rustc_macros`Nilstrieb-1/+1
Fluent, with all the icu4x it brings in, takes quite some time to compile. `fluent_messages!` is only needed in further downstream rustc crates, but is blocking more upstream crates like `rustc_index`. By splitting it out, we allow `rustc_macros` to be compiled earlier, which speeds up `x check compiler` by about 5 seconds (and even more after the needless dependency on `serde_json` is removed from `rustc_data_structures`).
2023-03-11Simplify message pathsest31-1/+1
This makes it easier to open the messages file while developing on features. The commit was the result of automatted changes: for p in compiler/rustc_*; do mv $p/locales/en-US.ftl $p/messages.ftl; rmdir $p/locales; done for p in compiler/rustc_*; do sed -i "s#\.\./locales/en-US.ftl#../messages.ftl#" $p/src/lib.rs; done
2023-02-28refactor parse_token_trees to not return unmatched_delimsyukang-24/+1
2023-02-28no need to return unmatched_delims from tokentreesyukang-10/+6
2023-02-28rename unmatched_braces to unmatched_delimsyukang-5/+5
2023-02-28Exit when there are unmatched delims to avoid noisy diagnosticsyukang-3/+10
2023-02-22errors: generate typed identifiers in each crateDavid Wood-0/+4
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>
2022-11-22Split `MacArgs` in two.Nicholas Nethercote-4/+5
`MacArgs` is an enum with three variants: `Empty`, `Delimited`, and `Eq`. It's used in two ways: - For representing attribute macro arguments (e.g. in `AttrItem`), where all three variants are used. - For representing function-like macros (e.g. in `MacCall` and `MacroDef`), where only the `Delimited` variant is used. In other words, `MacArgs` is used in two quite different places due to them having partial overlap. I find this makes the code hard to read. It also leads to various unreachable code paths, and allows invalid values (such as accidentally using `MacArgs::Empty` in a `MacCall`). This commit splits `MacArgs` in two: - `DelimArgs` is a new struct just for the "delimited arguments" case. It is now used in `MacCall` and `MacroDef`. - `AttrArgs` is a renaming of the old `MacArgs` enum for the attribute macro case. Its `Delimited` variant now contains a `DelimArgs`. Various other related things are renamed as well. These changes make the code clearer, avoids several unreachable paths, and disallows the invalid values.
2022-11-11Recover from fn ptr tys with generic param listLeón Orell Valerian Liehr-0/+1
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