about summary refs log tree commit diff
path: root/compiler/rustc_expand/src/mbe
AgeCommit message (Collapse)AuthorLines
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.
2021-01-17Remove dead codeRyan Levick-29/+1
2021-01-14Use Option::map_or instead of `.map(..).unwrap_or(..)`LingMan-5/+5
2020-12-30Implement edition-based macro pat featuremark-46/+62
2020-12-22Revert "Promote missing_fragment_specifier to hard error"Wesley Wiser-14/+32
This reverts commit 02eae432e7476a0686633a8c2b7cb1d5aab1bd2c.
2020-12-19implement edition-specific :pat behavior for 2015/18mark-7/+26
2020-12-16Remove docs for non-existent parameters in `rustc_expand`Camelid-4/+1
2020-10-19Fix brace problem in panic message in rustc_expand.Mara Bos-1/+2
2020-11-03rustc_ast: `visit_mac` -> `visit_mac_call`Vadim Petrochenkov-1/+0
2020-11-03rustc_ast: Do not panic by default when visiting macro callsVadim Petrochenkov-4/+0
2020-11-03Expand `NtExpr` tokens only in key-value attributesVadim Petrochenkov-1/+5
2020-10-31expand: Tweak a comment in implementation of `macro_rules`Vadim Petrochenkov-9/+11
2020-10-30Fix some more clippy warningsJoshua Nelson-9/+5
2020-10-19Avoid cloning the contents of a `TokenStream` in a few placesAaron Hill-1/+2
2020-09-03Rename IsJoint -> SpacingAleksey Kladov-2/+2
To match better naming from proc-macro
2020-08-30mv compiler to compiler/mark-0/+3248