Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
est31 committed May 15, 2017
1 parent 0d0cb27 commit 25b7f10
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 17 deletions.
10 changes: 4 additions & 6 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1195,11 +1195,9 @@ pub struct Resolver<'a> {
pub whitelisted_legacy_custom_derives: Vec<Name>,
pub found_unresolved_macro: bool,

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

// Maps the `Mark` of an expansion to its containing module or block.
invocations: FxHashMap<Mark, &'a InvocationData<'a>>,
Expand Down Expand Up @@ -1406,7 +1404,7 @@ impl<'a> Resolver<'a> {
potentially_unused_imports: Vec::new(),
struct_constructors: DefIdMap(),
found_unresolved_macro: false,
unused_macros: FxHashMap(),
unused_macros: FxHashSet(),
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,24 +291,24 @@ impl<'a> base::Resolver for Resolver<'a> {
},
};
self.macro_defs.insert(invoc.expansion_data.mark, def.def_id());
self.unused_macros.get_mut(&def.def_id()).map(|m| *m = false);
self.unused_macros.remove(&def.def_id());
Ok(Some(self.get_macro(def)))
}

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

fn check_unused_macros(&self) {
for (did, _) in self.unused_macros.iter().filter(|&(_, b)| *b) {
for did in self.unused_macros.iter() {
let id_span = match *self.macro_map[did] {
SyntaxExtension::NormalTT(_, isp, _) => isp,
_ => None
};
SyntaxExtension::NormalTT(_, isp, _) => isp,
_ => None,
};
if let Some((id, span)) = id_span {
let lint = lint::builtin::UNUSED_MACROS;
let msg = "unused macro definition".to_string();
Expand Down Expand Up @@ -708,7 +708,7 @@ impl<'a> Resolver<'a> {
let def = Def::Macro(def_id, MacroKind::Bang);
self.macro_exports.push(Export { name: ident.name, def: def, span: item.span });
} else {
self.unused_macros.insert(def_id, true);
self.unused_macros.insert(def_id);
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/libsyntax/ext/tt/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,9 @@ pub fn compile(sess: &ParseSess, features: &RefCell<Features>, def: &ast::Item)
valid: valid,
});

NormalTT(
exp,
NormalTT(exp,
Some((def.id, def.span)),
attr::contains_name(&def.attrs, "allow_internal_unstable")
)
attr::contains_name(&def.attrs, "allow_internal_unstable"))
}

fn check_lhs_nt_follows(sess: &ParseSess,
Expand Down

0 comments on commit 25b7f10

Please sign in to comment.