Shorten Span of unused macro lints
The span has been recuded to the actual ident, instead of linting the *whole* macro.
This commit is contained in:
parent
9dbbbb12c0
commit
9f6ca7482c
7 changed files with 41 additions and 62 deletions
|
@ -1194,15 +1194,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||||
// Mark the given macro as unused unless its name starts with `_`.
|
// Mark the given macro as unused unless its name starts with `_`.
|
||||||
// Macro uses will remove items from this set, and the remaining
|
// Macro uses will remove items from this set, and the remaining
|
||||||
// items will be reported as `unused_macros`.
|
// items will be reported as `unused_macros`.
|
||||||
fn insert_unused_macro(
|
fn insert_unused_macro(&mut self, ident: Ident, def_id: LocalDefId, node_id: NodeId) {
|
||||||
&mut self,
|
|
||||||
ident: Ident,
|
|
||||||
def_id: LocalDefId,
|
|
||||||
node_id: NodeId,
|
|
||||||
span: Span,
|
|
||||||
) {
|
|
||||||
if !ident.as_str().starts_with('_') {
|
if !ident.as_str().starts_with('_') {
|
||||||
self.r.unused_macros.insert(def_id, (node_id, span));
|
self.r.unused_macros.insert(def_id, (node_id, ident));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1246,7 +1240,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||||
self.r.define(module, ident, MacroNS, (res, vis, span, expansion, IsMacroExport));
|
self.r.define(module, ident, MacroNS, (res, vis, span, expansion, IsMacroExport));
|
||||||
} else {
|
} else {
|
||||||
self.r.check_reserved_macro_name(ident, res);
|
self.r.check_reserved_macro_name(ident, res);
|
||||||
self.insert_unused_macro(ident, def_id, item.id, span);
|
self.insert_unused_macro(ident, def_id, item.id);
|
||||||
}
|
}
|
||||||
self.r.visibilities.insert(def_id, vis);
|
self.r.visibilities.insert(def_id, vis);
|
||||||
self.r.arenas.alloc_macro_rules_scope(MacroRulesScope::Binding(
|
self.r.arenas.alloc_macro_rules_scope(MacroRulesScope::Binding(
|
||||||
|
@ -1267,7 +1261,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||||
_ => self.resolve_visibility(&item.vis),
|
_ => self.resolve_visibility(&item.vis),
|
||||||
};
|
};
|
||||||
if vis != ty::Visibility::Public {
|
if vis != ty::Visibility::Public {
|
||||||
self.insert_unused_macro(ident, def_id, item.id, span);
|
self.insert_unused_macro(ident, def_id, item.id);
|
||||||
}
|
}
|
||||||
self.r.define(module, ident, MacroNS, (res, vis, span, expansion));
|
self.r.define(module, ident, MacroNS, (res, vis, span, expansion));
|
||||||
self.r.visibilities.insert(def_id, vis);
|
self.r.visibilities.insert(def_id, vis);
|
||||||
|
|
|
@ -988,7 +988,7 @@ pub struct Resolver<'a> {
|
||||||
non_macro_attr: Lrc<SyntaxExtension>,
|
non_macro_attr: Lrc<SyntaxExtension>,
|
||||||
local_macro_def_scopes: FxHashMap<LocalDefId, Module<'a>>,
|
local_macro_def_scopes: FxHashMap<LocalDefId, Module<'a>>,
|
||||||
ast_transform_scopes: FxHashMap<LocalExpnId, Module<'a>>,
|
ast_transform_scopes: FxHashMap<LocalExpnId, Module<'a>>,
|
||||||
unused_macros: FxHashMap<LocalDefId, (NodeId, Span)>,
|
unused_macros: FxHashMap<LocalDefId, (NodeId, Ident)>,
|
||||||
proc_macro_stubs: FxHashSet<LocalDefId>,
|
proc_macro_stubs: FxHashSet<LocalDefId>,
|
||||||
/// Traces collected during macro resolution and validated when it's complete.
|
/// Traces collected during macro resolution and validated when it's complete.
|
||||||
single_segment_macro_resolutions:
|
single_segment_macro_resolutions:
|
||||||
|
|
|
@ -315,8 +315,13 @@ impl<'a> ResolverExpand for Resolver<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_unused_macros(&mut self) {
|
fn check_unused_macros(&mut self) {
|
||||||
for (_, &(node_id, span)) in self.unused_macros.iter() {
|
for (_, &(node_id, ident)) in self.unused_macros.iter() {
|
||||||
self.lint_buffer.buffer_lint(UNUSED_MACROS, node_id, span, "unused macro definition");
|
self.lint_buffer.buffer_lint(
|
||||||
|
UNUSED_MACROS,
|
||||||
|
node_id,
|
||||||
|
ident.span,
|
||||||
|
&format!("unused macro definition: `{}`", ident.as_str()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
warning: unused macro definition
|
warning: unused macro definition: `regex`
|
||||||
--> $DIR/issue-70041.rs:4:1
|
--> $DIR/issue-70041.rs:4:14
|
||||||
|
|
|
|
||||||
LL | / macro_rules! regex {
|
LL | macro_rules! regex {
|
||||||
LL | |
|
| ^^^^^
|
||||||
LL | | () => {};
|
|
||||||
LL | | }
|
|
||||||
| |_^
|
|
||||||
|
|
|
|
||||||
= note: `#[warn(unused_macros)]` on by default
|
= note: `#[warn(unused_macros)]` on by default
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
error: unused macro definition
|
error: unused macro definition: `unused`
|
||||||
--> $DIR/unused-macro-rules.rs:4:1
|
--> $DIR/unused-macro-rules.rs:4:14
|
||||||
|
|
|
|
||||||
LL | / macro_rules! unused {
|
LL | macro_rules! unused {
|
||||||
LL | | () => {};
|
| ^^^^^^
|
||||||
LL | | }
|
|
||||||
| |_^
|
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/unused-macro-rules.rs:1:9
|
--> $DIR/unused-macro-rules.rs:1:9
|
||||||
|
@ -12,26 +10,17 @@ note: the lint level is defined here
|
||||||
LL | #![deny(unused_macros)]
|
LL | #![deny(unused_macros)]
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: unused macro definition
|
error: unused macro definition: `m`
|
||||||
--> $DIR/unused-macro-rules.rs:11:9
|
--> $DIR/unused-macro-rules.rs:11:22
|
||||||
|
|
|
|
||||||
LL | / macro_rules! m {
|
LL | macro_rules! m {
|
||||||
LL | | () => {};
|
| ^
|
||||||
LL | | }
|
|
||||||
| |_________^
|
|
||||||
...
|
|
||||||
LL | create_macro!();
|
|
||||||
| --------------- in this macro invocation
|
|
||||||
|
|
|
||||||
= note: this error originates in the macro `create_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
|
|
||||||
|
|
||||||
error: unused macro definition
|
error: unused macro definition: `unused`
|
||||||
--> $DIR/unused-macro-rules.rs:24:5
|
--> $DIR/unused-macro-rules.rs:24:18
|
||||||
|
|
|
|
||||||
LL | / macro_rules! unused {
|
LL | macro_rules! unused {
|
||||||
LL | | () => {};
|
| ^^^^^^
|
||||||
LL | | }
|
|
||||||
| |_____^
|
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/unused-macro-rules.rs:23:12
|
--> $DIR/unused-macro-rules.rs:23:12
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
error: unused macro definition
|
error: unused macro definition: `unused`
|
||||||
--> $DIR/unused-macro.rs:5:1
|
--> $DIR/unused-macro.rs:5:7
|
||||||
|
|
|
|
||||||
LL | / macro unused {
|
LL | macro unused {
|
||||||
LL | | () => {}
|
| ^^^^^^
|
||||||
LL | | }
|
|
||||||
| |_^
|
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/unused-macro.rs:2:9
|
--> $DIR/unused-macro.rs:2:9
|
||||||
|
@ -12,13 +10,11 @@ note: the lint level is defined here
|
||||||
LL | #![deny(unused_macros)]
|
LL | #![deny(unused_macros)]
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: unused macro definition
|
error: unused macro definition: `unused`
|
||||||
--> $DIR/unused-macro.rs:15:5
|
--> $DIR/unused-macro.rs:15:11
|
||||||
|
|
|
|
||||||
LL | / macro unused {
|
LL | macro unused {
|
||||||
LL | | () => {}
|
| ^^^^^^
|
||||||
LL | | }
|
|
||||||
| |_____^
|
|
||||||
|
|
|
|
||||||
note: the lint level is defined here
|
note: the lint level is defined here
|
||||||
--> $DIR/unused-macro.rs:14:12
|
--> $DIR/unused-macro.rs:14:12
|
||||||
|
@ -26,13 +22,11 @@ note: the lint level is defined here
|
||||||
LL | #[deny(unused_macros)]
|
LL | #[deny(unused_macros)]
|
||||||
| ^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: unused macro definition
|
error: unused macro definition: `unused`
|
||||||
--> $DIR/unused-macro.rs:21:5
|
--> $DIR/unused-macro.rs:21:22
|
||||||
|
|
|
|
||||||
LL | / pub(crate) macro unused {
|
LL | pub(crate) macro unused {
|
||||||
LL | | () => {}
|
| ^^^^^^
|
||||||
LL | | }
|
|
||||||
| |_____^
|
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// run-pass
|
// run-pass
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code, unused_macros)]
|
||||||
// aux-build:issue-39889.rs
|
// aux-build:issue-39889.rs
|
||||||
|
|
||||||
extern crate issue_39889;
|
extern crate issue_39889;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue