提交 777e136f 编写于 作者: E est31

Suppress the unused_macro_rules lint if malformed rules are encountered

Prior to this commit, if a macro had any malformed rules, all rules would
be reported as unused, regardless of whether they were used or not.
So we just turn off unused rule checking completely for macros with
malformed rules.
上级 eb3c611e
......@@ -539,11 +539,11 @@ pub fn compile_declarative_macro(
None => {}
}
// Compute the spans of the macro rules
// We only take the span of the lhs here,
// so that the spans of created warnings are smaller.
// Compute the spans of the macro rules for unused rule linting.
// To avoid warning noise, only consider the rules of this
// macro for the lint, if all rules are valid.
// Also, we are only interested in non-foreign macros.
let rule_spans = if def.id != DUMMY_NODE_ID {
let rule_spans = if valid && def.id != DUMMY_NODE_ID {
lhses
.iter()
.zip(rhses.iter())
......@@ -551,6 +551,8 @@ pub fn compile_declarative_macro(
// If the rhs contains an invocation like compile_error!,
// don't consider the rule for the unused rule lint.
.filter(|(_idx, (_lhs, rhs))| !has_compile_error_macro(rhs))
// We only take the span of the lhs here,
// so that the spans of created warnings are smaller.
.map(|(idx, (lhs, _rhs))| (idx, lhs.span()))
.collect::<Vec<_>>()
} else {
......
#![deny(unused_macro_rules)]
macro_rules! foo {
(v) => {};
(w) => {};
() => 0; //~ ERROR: macro rhs must be delimited
}
fn main() {
foo!(v);
}
error: macro rhs must be delimited
--> $DIR/unused-macro-rules-malformed-rule.rs:6:11
|
LL | () => 0;
| ^
error: aborting due to previous error
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册