about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src/source_util.rs
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2021-07-14 18:24:12 -0500
committerAaron Hill <aa1ronham@gmail.com>2021-07-17 23:03:56 -0500
commitddd544856ecd181ee02490d12f723be549d3ecb3 (patch)
tree36bec16c3a8132f356fdb4713a63aac33e0471a9 /compiler/rustc_builtin_macros/src/source_util.rs
parenteb0b95b55a0b38d91e834dd30902b67627ed2eb0 (diff)
downloadrust-ddd544856ecd181ee02490d12f723be549d3ecb3.tar.gz
rust-ddd544856ecd181ee02490d12f723be549d3ecb3.zip
Compute a better `lint_node_id` during expansion
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.
Diffstat (limited to 'compiler/rustc_builtin_macros/src/source_util.rs')
-rw-r--r--compiler/rustc_builtin_macros/src/source_util.rs2
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler/rustc_builtin_macros/src/source_util.rs b/compiler/rustc_builtin_macros/src/source_util.rs
index ccb9f15b0f5..1ea2c8843d6 100644
--- a/compiler/rustc_builtin_macros/src/source_util.rs
+++ b/compiler/rustc_builtin_macros/src/source_util.rs
@@ -159,7 +159,7 @@ pub fn expand_include<'cx>(
         }
     }
 
-    Box::new(ExpandResult { p, node_id: cx.resolver.lint_node_id(cx.current_expansion.id) })
+    Box::new(ExpandResult { p, node_id: cx.current_expansion.lint_node_id })
 }
 
 // include_str! : read the given file, insert it as a literal string expr