cx.span_lint(lint, span, msg.as_slice());
}
-}
-
-impl LintPass for Stability {
- fn get_lints(&self) -> LintArray {
- lint_array!(DEPRECATED, EXPERIMENTAL, UNSTABLE)
- }
-
- fn check_view_item(&mut self, cx: &Context, item: &ast::ViewItem) {
- // compiler-generated `extern crate` statements have a dummy span.
- if item.span == DUMMY_SP { return }
-
- let id = match item.node {
- ast::ViewItemExternCrate(_, _, id) => id,
- ast::ViewItemUse(..) => return,
- };
- let cnum = match cx.tcx.sess.cstore.find_extern_mod_stmt_cnum(id) {
- Some(cnum) => cnum,
- None => return,
- };
- let id = ast::DefId { krate: cnum, node: ast::CRATE_NODE_ID };
- self.lint(cx, id, item.span);
- }
- fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
+ fn is_internal(&self, cx: &Context, span: Span) -> bool {
// first, check if the given expression was generated by a macro or not
// we need to go back the expn_info tree to check only the arguments
// of the initial macro call, not the nested ones.
- let mut expnid = e.span.expn_id;
+ let mut expnid = span.expn_id;
let mut is_internal = false;
while cx.tcx.sess.codemap().with_expn_info(expnid, |expninfo| {
match expninfo {
true // continue looping
} else {
// was this expression from the current macro arguments ?
- is_internal = !( e.span.lo > info.call_site.lo &&
- e.span.hi < info.call_site.hi );
+ is_internal = !( span.lo > info.call_site.lo &&
+ span.hi < info.call_site.hi );
true // continue looping
}
},
_ => false // stop looping
}
}) { /* empty while loop body */ }
- if is_internal { return; }
+ return is_internal;
+ }
+}
+
+impl LintPass for Stability {
+ fn get_lints(&self) -> LintArray {
+ lint_array!(DEPRECATED, EXPERIMENTAL, UNSTABLE)
+ }
+
+ fn check_view_item(&mut self, cx: &Context, item: &ast::ViewItem) {
+ // compiler-generated `extern crate` statements have a dummy span.
+ if item.span == DUMMY_SP { return }
+
+ let id = match item.node {
+ ast::ViewItemExternCrate(_, _, id) => id,
+ ast::ViewItemUse(..) => return,
+ };
+ let cnum = match cx.tcx.sess.cstore.find_extern_mod_stmt_cnum(id) {
+ Some(cnum) => cnum,
+ None => return,
+ };
+ let id = ast::DefId { krate: cnum, node: ast::CRATE_NODE_ID };
+ self.lint(cx, id, item.span);
+ }
+
+ fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
+ if self.is_internal(cx, e.span) { return; }
let mut span = e.span;
};
self.lint(cx, id, span);
}
+
+ fn check_item(&mut self, cx: &Context, item: &ast::Item) {
+ if self.is_internal(cx, item.span) { return }
+
+ match item.node {
+ ast::ItemTrait(_, _, ref supertraits, _) => {
+ for t in supertraits.iter() {
+ match *t {
+ ast::TraitTyParamBound(ref t) => {
+ let id = ty::trait_ref_to_def_id(cx.tcx, t);
+ self.lint(cx, id, t.path.span);
+ }
+ _ => (/* pass */)
+ }
+ }
+ }
+ ast::ItemImpl(_, Some(ref t), _, _) => {
+ let id = ty::trait_ref_to_def_id(cx.tcx, t);
+ self.lint(cx, id, t.path.span);
+ }
+ _ => (/* pass */)
+ }
+ }
}
declare_lint!(pub UNUSED_IMPORTS, Warn,