about summary refs log tree commit diff
path: root/compiler/rustc_expand/src/mbe
AgeCommit message (Collapse)AuthorLines
2022-03-11Add a useful assertion.Nicholas Nethercote-0/+2
2022-03-11Disallow `TokenTree::{MetaVar,MetaVarExpr}` in matchers.Nicholas Nethercote-4/+5
They should only appear in transcribers.
2022-03-11Refactor the second half of `parse_tt`.Nicholas Nethercote-61/+68
The current structure makes it hard to tell that there are just four distinct code paths, depending on how many items there are in `bb_items` and `next_items`. This commit introduces a `match` that clarifies things.
2022-03-09Implement macro meta-variable expressionsCaio-37/+307
2022-03-03Rollup merge of #94555 - cuishuang:master, r=oli-obkMatthias Krüger-1/+1
all: fix some typos Signed-off-by: cuishuang <imcusg@gmail.com>
2022-03-03Rollup merge of #94547 - nnethercote:parse_tt-cleanups, r=petrochenkovMatthias Krüger-101/+115
`parse_tt` cleanups I've been looking closely at this code, and saw some opportunities to improve its readability. r? ```````@petrochenkov```````
2022-03-03all: fix some typoscuishuang-1/+1
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-03-03Change `initial_matcher_pos()` into `MatcherPos::new()`.Nicholas Nethercote-29/+29
2022-03-03Use a better return type for `inner_parse_loop`.Nicholas Nethercote-25/+35
Because `inner_parse_loop` has only one way to not succeed, not three.
2022-03-03Introduce `MatcherPosRepetition`.Nicholas Nethercote-23/+27
There are three `Option` fields in `MatcherPos` that are only used in tandem. This commit combines them, making the code slightly easier to read. (It also makes clear that the `sep` field arguably should have been `Option<Option<Token>>`!)
2022-03-03Add a static size assertion for `MatcherPos`.Nicholas Nethercote-0/+4
2022-03-03Improve if/else formatting in macro_parser.rs.Nicholas Nethercote-32/+28
To avoid the strange style where comments force `else` onto its own line. The commit also removes several else-after-return constructs, which can be hard to read.
2022-03-03Rollup merge of #94544 - mark-i-m:macro-comments, r=petrochenkovMatthias Krüger-0/+38
Add some examples to comments in mbe code I found these things non-obvious when re-familiarizing myself with the code. r? `@petrochenkov`
2022-03-02add some examples to comments in mbe codemark-0/+38
2022-03-02rename ErrorReported -> ErrorGuaranteedmark-1/+1
2022-02-23rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission".Eduard-Mihai Burtescu-1/+1
2022-02-23rustc_errors: take `self` by value in `DiagnosticBuilder::cancel`.Eduard-Mihai Burtescu-1/+1
2022-02-23Replace `&mut DiagnosticBuilder`, in signatures, with `&mut Diagnostic`.Eduard-Mihai Burtescu-6/+2
2022-02-03compiler: clippy::complexity fixesMatthias Krüger-1/+1
useless_format map_flatten useless_conversion needless_bool filter_next clone_on_copy needless_option_as_deref
2021-12-09Remove redundant [..]sest31-7/+7
2021-12-04Rollup merge of #91385 - ecstatic-morse:pat-param-spec-suggest, r=estebankMatthias Krüger-0/+18
Suggest the `pat_param` specifier before `|` on 2021 edition Ran into this today after writing some Rust for the first time in a while. r? `@estebank`
2021-11-30re-format with new rustfmtMark Rousskov-3/+1
2021-11-29Suggest the `pat_param` specifier before `|` on 2021 editionDylan MacKenzie-0/+18
We have a migration warning but no lint for users who have enabled the new edition.
2021-10-22Rollup merge of #89991 - petrochenkov:visitok2, r=jackh726Yuki Okushi-3/+1
rustc_ast: Turn `MutVisitor::token_visiting_enabled` into a constant It's a visitor property rather than something that needs to be determined at runtime
2021-10-19Auto merge of #89933 - est31:let_else, r=michaelwoeristerbors-7/+3
Adopt let_else across the compiler This performs a substitution of code following the pattern: ``` let <id> = if let <pat> = ... { identity } else { ... : ! }; ``` To simplify it to: ``` let <pat> = ... { identity } else { ... : ! }; ``` By adopting the `let_else` feature (cc #87335). The PR also updates the syn crate because the currently used version of the crate doesn't support `let_else` syntax yet. Note: Generally I'm the person who *removes* usages of unstable features from the compiler, not adds more usages of them, but in this instance I think it hopefully helps the feature get stabilized sooner and in a better state. I have written a [comment](https://github.com/rust-lang/rust/issues/87335#issuecomment-944846205) on the tracking issue about my experience and what I feel could be improved before stabilization of `let_else`.
2021-10-18rustc_ast: Turn `MutVisitor::token_visiting_enabled` into a constantVadim Petrochenkov-3/+1
It's a visitor property rather than something that needs to be determined at runtime
2021-10-17rustc_span: `Ident::invalid` -> `Ident::empty`Vadim Petrochenkov-1/+1
The equivalent for `Symbol`s was renamed some time ago (`kw::Invalid` -> `kw::Empty`), and it makes sense to do the same thing for `Ident`s.
2021-10-16Adopt let_else across the compilerest31-7/+3
This performs a substitution of code following the pattern: let <id> = if let <pat> = ... { identity } else { ... : ! }; To simplify it to: let <pat> = ... { identity } else { ... : ! }; By adopting the let_else feature.
2021-09-15chore(rustc_expand): fix typo in commentMichael Howell-1/+1
2021-08-29Auto merge of #88262 - klensy:pprust-cow, r=nagisabors-1/+1
Cow'ify some pprust methods Reduce number of potential needless de/allocations by using `Cow<'static, str>` instead of explicit `String` type.
2021-08-25Convert some functions to return Cow<'static,str> instead of String to ↵klensy-1/+1
reduce potential reallocations
2021-08-21Remove `Session.used_attrs` and move logic to `CheckAttrVisitor`Aaron Hill-1/+1
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-07-27Only emit lint for local macrosAaron Hill-7/+19
2021-07-24Display an extra note for trailing semicolon lint with trailing macroAaron Hill-3/+12
Currently, we parse macros at the end of a block (e.g. `fn foo() { my_macro!() }`) as expressions, rather than statements. This means that a macro invoked in this position cannot expand to items or semicolon-terminated expressions. In the future, we might want to start parsing these kinds of macros as statements. This would make expansion more 'token-based' (i.e. macro expansion behaves (almost) as if you just textually replaced the macro invocation with its output). However, this is a breaking change (see PR #78991), so it will require further discussion. Since the current behavior will not be changing any time soon, we need to address the interaction with the `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lint. Since we are parsing the result of macro expansion as an expression, we will emit a lint if there's a trailing semicolon in the macro output. However, this results in a somewhat confusing message for users, since it visually looks like there should be no problem with having a semicolon at the end of a block (e.g. `fn foo() { my_macro!() }` => `fn foo() { produced_expr; }`) To help reduce confusion, this commit adds a note explaining that the macro is being interpreted as an expression. Additionally, we suggest adding a semicolon after the macro *invocation* - this will cause us to parse the macro call as a statement. We do *not* use a structured suggestion for this, since the user may actually want to remove the semicolon from the macro definition (allowing the block to evaluate to the expression produced by the macro).
2021-07-17Compute a better `lint_node_id` during expansionAaron Hill-2/+1
When we need to emit a lint at a macro invocation, we currently use the `NodeId` of its parent definition (e.g. the enclosing function). This means that any `#[allow]` / `#[deny]` attributes placed 'closer' to the macro (e.g. on an enclosing block or statement) will have no effect. This commit computes a better `lint_node_id` in `InvocationCollector`. When we visit/flat_map an AST node, we assign it a `NodeId` (earlier than we normally would), and store than `NodeId` in current `ExpansionData`. When we collect a macro invocation, the current `lint_node_id` gets cloned along with our `ExpansionData`, allowing it to be used if we need to emit a lint later on. This improves the handling of `#[allow]` / `#[deny]` for `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` and some `asm!`-related lints. The 'legacy derive helpers' lint retains its current behavior (I've inlined the now-removed `lint_node_id` function), since there isn't an `ExpansionData` readily available.
2021-07-17Use LocalExpnId where possible.Camille GILLOT-3/+3
2021-07-06Change or_patterns_back_compat lint to rust_2021_incompatible_or_patternsRyan Levick-2/+4
2021-06-24Don't lint :pat when re-parsing a macro from another crate.Mara Bos-32/+34
2021-06-07Include macro name in 'local ambiguity' errorAaron Hill-5/+10
Currently, we only point at the span of the macro argument. When the macro call is itself generated by another macro, this can make it difficult or impossible to determine which macro is responsible for producing the error.
2021-05-29Use correct edition when parsing `:pat` matchersAaron Hill-5/+24
As described in issue #85708, we currently do not properly decode `SyntaxContext::root()` and `ExpnId::root()` from foreign crates. As a result, when we decode a span from a foreign crate with `SyntaxContext::root()`, we end up up considering it to have the edition of the *current* crate, instead of the foreign crate where it was originally created. A full fix for this issue will be a fairly significant undertaking. Fortunately, it's possible to implement a partial fix, which gives us the correct edition-dependent behavior for `:pat` matchers when the macro is loaded from another crate. Since we have the edition of the macro's defining crate available, we can 'recover' from seeing a `SyntaxContext::root()` and use the edition of the macro's defining crate. Any solution to issue #85708 must reproduce the behavior of this targeted fix - properly preserving a foreign `SyntaxContext::root()` means (among other things) preserving its edition, which by definition is the edition of the foreign crate itself. Therefore, this fix moves us closer to the correct overall solution, and does not expose any new incorrect behavior to macros.
2021-04-28Auto merge of #83386 - mark-i-m:stabilize-pat2015, r=nikomatsakisbors-22/+7
Stabilize `:pat_param` and remove `:pat2021` Blocked on #83384 cc `@rust-lang/lang` #79278 If I understand `@nikomatsakis` in https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/or.20patterns/near/231133873, another FCP is not needed. r? `@nikomatsakis`
2021-04-27remove pat2021mark-15/+3
2021-04-19fix few typosklensy-2/+2
2021-04-15rename pat2015 to pat_parammark-4/+4
2021-04-15stabilize :pat2015, leave :pat2021 gatedmark-13/+10
2021-04-02address commentshi-rustin-1/+1
2021-04-01add OR_PATTERNS_BACK_COMPAT linthi-rustin-3/+39
test: add more cases test: add comments refine msg
2021-03-26Use iter::zip in compiler/Josh Stone-1/+3
2021-03-22rename :pat2018 -> :pat215mark-3/+3
2021-01-28Add `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` lintAaron Hill-1/+13
cc #79813 This PR adds an allow-by-default future-compatibility lint `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS`. It fires when a trailing semicolon in a macro body is ignored due to the macro being used in expression position: ```rust macro_rules! foo { () => { true; // WARN } } fn main() { let val = match true { true => false, _ => foo!() }; } ``` The lint takes its level from the macro call site, and can be allowed for a particular macro by adding `#[allow(semicolon_in_expressions_from_macros)]`. The lint is set to warn for all internal rustc crates (when being built by a stage1 compiler). After the next beta bump, we can enable the lint for the bootstrap compiler as well.