about summary refs log tree commit diff
path: root/compiler/rustc_expand/src/mbe
AgeCommit message (Collapse)AuthorLines
2023-04-09Fix some clippy::complexityNilstrieb-1/+1
2023-03-17Suggest surrounding the macro with `{}` to interpret as a statementMu42-6/+18
2023-03-15unequal → not equalgimbles-1/+1
2023-03-10Add note when matching token with nonterminalNilstrieb-3/+9
The current error message is _really_ confusing.
2023-03-03Match end user facing unmatched backticks in compiler/est31-1/+1
2023-02-20Remove a redundant function argumentOli Scherer-4/+2
2023-02-03Rename `Cursor`/`CursorRef` as `TokenTreeCursor`/`RefTokenTreeCursor`.Nicholas Nethercote-6/+6
This makes it clear they return token trees, and makes for a nice comparison against `TokenCursor` which returns tokens.
2023-01-30Replace some `_ == _ || _ == _`s with `matches!(_, _ | _)`sMaybe Waffle-1/+1
2023-01-20preserve delim spans during `macro_rules!` expansion if ableLukas Markeffsky-6/+18
2023-01-20Auto merge of #106090 - WaffleLapkin:dereffffffffff, r=Nilstriebbors-44/+42
Remove some `ref` patterns from the compiler Previous PR: https://github.com/rust-lang/rust/pull/105368 r? `@Nilstrieb`
2023-01-17Remove double spaces after dots in commentsMaybe Waffle-2/+2
2023-01-17`rustc_expand`: remove `ref` patternsMaybe Waffle-44/+42
2023-01-05Shrink `ParseResult` in the hot path.Nilstrieb-30/+81
A recent PR increased the size, which caused regressions. This uses the existing generic infrastructure to differentiate between the hot path and the diagnostics path.
2023-01-01Merge multiple mutable borrows of immutable binding errorsEsteban Küber-2/+2
Fix #53466.
2022-12-28Rollup merge of #105570 - Nilstrieb:actual-best-failure, r=compiler-errorsMatthias Krüger-15/+44
Properly calculate best failure in macro matching Previously, we used spans. This was not good. Sometimes, the span of the token that failed to match may come from a position later in the file which has been transcribed into a token stream way earlier in the file. If precisely this token fails to match, we think that it was the best match because its span is so high, even though other arms might have gotten further in the token stream. We now try to properly use the location in the token stream. This needs a little cleanup as the `best_failure` field is getting out of hand but it should be mostly good to go. I hope I didn't violate too many abstraction boundaries..
2022-12-25fix more clippy::style findingsMatthias Krüger-5/+1
match_result_ok obfuscated_if_else single_char_add writeln_empty_string collapsible_match iter_cloned_collect unnecessary_mut_passed
2022-12-20rustc: Remove needless lifetimesJeremy Stucki-1/+1
2022-12-18don't restuct references just to reborrowMatthias Krüger-3/+3
2022-12-12Properly calculate best failure in macro matchingNilstrieb-15/+44
Previously, we used spans. This was not good. Sometimes, the span of the token that failed to match may come from a position later in the file which has been transcribed into a token stream way earlier in the file. If precisely this token fails to match, we think that it was the best match because its span is so high, even though other arms might have gotten further in the token stream. We now try to properly use the location in the token stream.
2022-11-22Rollup merge of #104638 - Nilstrieb:macro-diagnostics, r=compiler-errorsManish Goregaokar-236/+266
Move macro_rules diagnostics to diagnostics module This will make it easier to add more diagnostics in the future in a centralized place.
2022-11-22Split `MacArgs` in two.Nicholas Nethercote-1/+1
`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-20Move macro_rules diagnostics to diagnostics moduleNilstrieb-236/+266
2022-11-19Cleanup macro matching recoveryNilstrieb-1/+0
The retry has been implemented already.
2022-11-15Only do parser recovery on retried macro matchingNilstrieb-8/+27
This prevents issues with eager parser recovery during macro matching.
2022-11-15Rollup merge of #103439 - Nilstrieb:help-me-with-my-macro, r=estebankMatthias Krüger-11/+76
Show note where the macro failed to match When feeding the wrong tokens, it used to fail with a very generic error that wasn't very helpful. This change tries to help by noting where specifically the matching went wrong. ```rust macro_rules! uwu { (a a a b) => {}; } uwu! { a a a c } ``` ```diff error: no rules expected the token `c` --> macros.rs:5:14 | 1 | macro_rules! uwu { | ---------------- when calling this macro ... 4 | uwu! { a a a c } | ^ no rules expected this token in macro call | +note: while trying to match `b` + --> macros.rs:2:12 + | +2 | (a a a b) => {}; + | ^ ```
2022-11-14Show a note where a macro failed to matchNilstrieb-11/+76
This shows a small note on what the macro matcher was currently processing to aid with "no rules expected the token X" errors.
2022-11-13fix some typos in commentscui fliter-1/+1
Signed-off-by: cui fliter <imcusg@gmail.com>
2022-11-04Small style improvementsnils-12/+13
2022-11-02Add some debug logs to macro matchingNilstrieb-0/+8
These were useful while debugging, so I'll leave them here.
2022-11-02Retry matching with tracking for diagnosticsNilstrieb-9/+109
For now, we only collect the small info for the `best_failure`, but using this tracker, we can easily extend it in the future to track things with more performance overhead. We cannot retry cases where the macro failed with a parser error that was emitted already, as that would cause us to emit the same error to the user twice.
2022-11-02Factor out matching into `try_match_macro`Nilstrieb-124/+129
This moves out the matching part of expansion into a new function. This function will try to match the macro and return an error if it failed to match. A tracker can be used to get more information about the matching.
2022-11-02Add `Tracker` to track matching operationsNilstrieb-16/+47
This should allow us to collect detailed information without slowing down the inital hot path.
2022-11-02Small parser cleanupsNilstrieb-5/+5
2022-11-02Store `ErrorGuaranteed` in `ErrorReported`Nilstrieb-5/+6
2022-10-25Add flag to forbid recovery in the parserNilstrieb-0/+1
2022-10-23Migrate all diagnosticsNilstrieb-2/+2
2022-10-18Fix the bug of next_point in spanyukang-1/+1
2022-10-11fix #102878Takayuki Maeda-8/+11
2022-09-21UPDATE - rename SessionSubdiagnostic macro to SubdiagnosticJhonny Bill Mena-1/+1
Also renames: - sym::AddSubdiagnostic to sym:: Subdiagnostic - rustc_diagnostic_item = "AddSubdiagnostic" to rustc_diagnostic_item = "Subdiagnostic"
2022-09-01Always import all tracing macros for the entire crate instead of piecemeal ↵Oli Scherer-1/+0
by module
2022-08-31Fix a bunch of typoDezhi Wu-2/+2
This PR will fix some typos detected by [typos]. I only picked the ones I was sure were spelling errors to fix, mostly in the comments. [typos]: https://github.com/crate-ci/typos
2022-08-18Rollup merge of #100651 - nidnogg:diagnostics_migration_expand_transcribe, ↵Matthias Krüger-24/+10
r=davidtwco Migrations for rustc_expand transcribe.rs This PR includes some migrations to the new diagnostics API for the `rustc_expand` module. r? ```@davidtwco```
2022-08-17Moved structs to rustc_expand::errors, added several more migrations, fixed ↵nidnogg-33/+7
slug name
2022-08-16Previous commit under x.py fmtnidnogg-1/+1
2022-08-16Migrated more diagnostics under transcribe.rsnidnogg-9/+17
2022-08-16Added first migration for repeated expressions without syntax varsnidnogg-5/+9
2022-08-16Rename some things related to literals.Nicholas Nethercote-1/+1
- Rename `ast::Lit::token` as `ast::Lit::token_lit`, because its type is `token::Lit`, which is not a token. (This has been confusing me for a long time.) reasonable because we have an `ast::token::Lit` inside an `ast::Lit`. - Rename `LitKind::{from,to}_lit_token` as `LitKind::{from,to}_token_lit`, to match the above change and `token::Lit`.
2022-08-10Use &mut Diagnostic instead of &mut DiagnosticBuilder unless neededMichael Goulet-6/+2
2022-07-29Remove `TreeAndSpacing`.Nicholas Nethercote-41/+38
A `TokenStream` contains a `Lrc<Vec<(TokenTree, Spacing)>>`. But this is not quite right. `Spacing` makes sense for `TokenTree::Token`, but does not make sense for `TokenTree::Delimited`, because a `TokenTree::Delimited` cannot be joined with another `TokenTree`. This commit fixes this problem, by adding `Spacing` to `TokenTree::Token`, changing `TokenStream` to contain a `Lrc<Vec<TokenTree>>`, and removing the `TreeAndSpacing` typedef. The commit removes these two impls: - `impl From<TokenTree> for TokenStream` - `impl From<TokenTree> for TreeAndSpacing` These were useful, but also resulted in code with many `.into()` calls that was hard to read, particularly for anyone not highly familiar with the relevant types. This commit makes some other changes to compensate: - `TokenTree::token()` becomes `TokenTree::token_{alone,joint}()`. - `TokenStream::token_{alone,joint}()` are added. - `TokenStream::delimited` is added. This results in things like this: ```rust TokenTree::token(token::Semi, stmt.span).into() ``` changing to this: ```rust TokenStream::token_alone(token::Semi, stmt.span) ``` This makes the type of the result, and its spacing, clearer. These changes also simplifies `Cursor` and `CursorRef`, because they no longer need to distinguish between `next` and `next_with_spacing`.
2022-07-23Auto merge of #99320 - NiklasJonsson:84447/rustc_expand, r=compiler-errorsbors-2/+2
rustc_expand: Switch FxHashMap to FxIndexMap where iteration is used Relates #84447