Skip to content

Commit 25b7f10

Browse files
committed
Address review comments
1 parent 0d0cb27 commit 25b7f10

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

src/librustc_resolve/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,11 +1195,9 @@ pub struct Resolver<'a> {
11951195
pub whitelisted_legacy_custom_derives: Vec<Name>,
11961196
pub found_unresolved_macro: bool,
11971197

1198-
// List of macros that we need to warn about as being unused.
1199-
// The bool is true if the macro is unused, and false if its used.
1200-
// Setting a bool to false should be much faster than removing a single
1201-
// element from a FxHashSet.
1202-
unused_macros: FxHashMap<DefId, bool>,
1198+
// List of crate local macros that we need to warn about as being unused.
1199+
// Right now this only includes macro_rules! macros.
1200+
unused_macros: FxHashSet<DefId>,
12031201

12041202
// Maps the `Mark` of an expansion to its containing module or block.
12051203
invocations: FxHashMap<Mark, &'a InvocationData<'a>>,
@@ -1406,7 +1404,7 @@ impl<'a> Resolver<'a> {
14061404
potentially_unused_imports: Vec::new(),
14071405
struct_constructors: DefIdMap(),
14081406
found_unresolved_macro: false,
1409-
unused_macros: FxHashMap(),
1407+
unused_macros: FxHashSet(),
14101408
}
14111409
}
14121410

src/librustc_resolve/macros.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,24 +291,24 @@ impl<'a> base::Resolver for Resolver<'a> {
291291
},
292292
};
293293
self.macro_defs.insert(invoc.expansion_data.mark, def.def_id());
294-
self.unused_macros.get_mut(&def.def_id()).map(|m| *m = false);
294+
self.unused_macros.remove(&def.def_id());
295295
Ok(Some(self.get_macro(def)))
296296
}
297297

298298
fn resolve_macro(&mut self, scope: Mark, path: &ast::Path, kind: MacroKind, force: bool)
299299
-> Result<Rc<SyntaxExtension>, Determinacy> {
300300
self.resolve_macro_to_def(scope, path, kind, force).map(|def| {
301-
self.unused_macros.get_mut(&def.def_id()).map(|m| *m = false);
301+
self.unused_macros.remove(&def.def_id());
302302
self.get_macro(def)
303303
})
304304
}
305305

306306
fn check_unused_macros(&self) {
307-
for (did, _) in self.unused_macros.iter().filter(|&(_, b)| *b) {
307+
for did in self.unused_macros.iter() {
308308
let id_span = match *self.macro_map[did] {
309-
SyntaxExtension::NormalTT(_, isp, _) => isp,
310-
_ => None
311-
};
309+
SyntaxExtension::NormalTT(_, isp, _) => isp,
310+
_ => None,
311+
};
312312
if let Some((id, span)) = id_span {
313313
let lint = lint::builtin::UNUSED_MACROS;
314314
let msg = "unused macro definition".to_string();
@@ -708,7 +708,7 @@ impl<'a> Resolver<'a> {
708708
let def = Def::Macro(def_id, MacroKind::Bang);
709709
self.macro_exports.push(Export { name: ident.name, def: def, span: item.span });
710710
} else {
711-
self.unused_macros.insert(def_id, true);
711+
self.unused_macros.insert(def_id);
712712
}
713713
}
714714

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,9 @@ pub fn compile(sess: &ParseSess, features: &RefCell<Features>, def: &ast::Item)
252252
valid: valid,
253253
});
254254

255-
NormalTT(
256-
exp,
255+
NormalTT(exp,
257256
Some((def.id, def.span)),
258-
attr::contains_name(&def.attrs, "allow_internal_unstable")
259-
)
257+
attr::contains_name(&def.attrs, "allow_internal_unstable"))
260258
}
261259

262260
fn check_lhs_nt_follows(sess: &ParseSess,

0 commit comments

Comments
 (0)