Compute a better `lint_node_id` during expansion by Aaron1011 · Pull Request #87...
source link: https://github.com/rust-lang/rust/pull/87146
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
When we need to emit a lint at a macro invocation, we currently use theNodeId
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 currentExpansionData
. When we collect a macro invocation, the currentlint_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]
forSEMICOLON_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.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK