use hir::def_id::LOCAL_CRATE;
use hir::intravisit as hir_visit;
use syntax::visit as ast_visit;
+use syntax::tokenstream::ThinTokenStream;
/// Information about the registered lints.
///
fn visit_attribute(&mut self, attr: &'a ast::Attribute) {
run_lints!(self, check_attribute, early_passes, attr);
}
+
+ fn visit_mac_def(&mut self, _mac: &'a ThinTokenStream, id: ast::NodeId) {
+ let lints = self.sess.lints.borrow_mut().take(id);
+ for early_lint in lints {
+ self.early_lint(&early_lint);
+ }
+ }
}
enum CheckLintNameResult {
}
self.syntax_exts.push((name, match extension {
NormalTT(ext, _, allow_internal_unstable) => {
- NormalTT(ext, Some(self.krate_span), allow_internal_unstable)
+ let nid = ast::CRATE_NODE_ID;
+ NormalTT(ext, Some((nid, self.krate_span)), allow_internal_unstable)
}
IdentTT(ext, _, allow_internal_unstable) => {
IdentTT(ext, Some(self.krate_span), allow_internal_unstable)
fn check_unused_macros(&self) {
for (did, _) in self.unused_macros.iter().filter(|&(_, b)| *b) {
- let span = match *self.macro_map[did] {
- SyntaxExtension::NormalTT(_, sp, _) => sp,
- SyntaxExtension::IdentTT(_, sp, _) => sp,
+ let id_span = match *self.macro_map[did] {
+ SyntaxExtension::NormalTT(_, isp, _) => isp,
_ => None
};
- if let Some(span) = span {
+ if let Some((id, span)) = id_span {
let lint = lint::builtin::UNUSED_MACROS;
- let msg = "unused macro".to_string();
- // We are using CRATE_NODE_ID here even though its inaccurate, as we
- // sadly don't have the NodeId of the macro definition.
- self.session.add_lint(lint, ast::CRATE_NODE_ID, span, msg);
+ let msg = "unused macro definition".to_string();
+ self.session.add_lint(lint, id, span, msg);
} else {
bug!("attempted to create unused macro error, but span not available");
}
///
/// The `bool` dictates whether the contents of the macro can
/// directly use `#[unstable]` things (true == yes).
- NormalTT(Box<TTMacroExpander>, Option<Span>, bool),
+ NormalTT(Box<TTMacroExpander>, Option<(ast::NodeId, Span)>, bool),
/// A function-like syntax extension that has an extra ident before
/// the block.
call_site: span,
callee: NameAndSpan {
format: MacroBang(Symbol::intern(&format!("{}", path))),
- span: exp_span,
+ span: exp_span.map(|(_, s)| s),
allow_internal_unstable: allow_internal_unstable,
},
});
valid: valid,
});
- NormalTT(exp, Some(def.span), attr::contains_name(&def.attrs, "allow_internal_unstable"))
+ NormalTT(
+ exp,
+ Some((def.id, def.span)),
+ attr::contains_name(&def.attrs, "allow_internal_unstable")
+ )
}
fn check_lhs_nt_follows(sess: &ParseSess,