break up lints.rs into separate files

This commit is contained in:
Rohan Prinja 2014-12-31 19:36:13 +05:30
parent 0da57abec6
commit 7ac58f202f
9 changed files with 430 additions and 378 deletions

View file

@ -4,12 +4,14 @@
use rustc::lint::Context;
use rustc::middle::{ty, def};
use rustc::middle::typeck::astconv::AstConv;
use syntax::ptr::P;
use syntax::ast;
use syntax::{ast, ast_map};
use syntax::ast::{TyPath, Path, AngleBracketedParameters, PathSegment, Ty};
use syntax::attr::mark_used;
/// Matches a type with a provided string, and returns its type parameters if successful
///
/// Try not to use this for types defined in crates you own, use match_lang_ty instead (for lint passes)
@ -60,3 +62,32 @@ pub fn match_lang_ty(cx: &Context, ty: &Ty, value: &str) -> bool {
}
found
}
// Determines if a block is in an unsafe context so that an unhelpful
// lint can be aborted.
pub fn unsafe_context(map: &ast_map::Map, id: ast::NodeId) -> bool {
match map.find(map.get_parent(id)) {
Some(ast_map::NodeImplItem(itm)) => {
match *itm {
ast::MethodImplItem(ref meth) => match meth.node {
ast::MethDecl(_, _, _, _, style, _, _, _) => match style {
ast::UnsafeFn => true,
_ => false,
},
_ => false,
},
_ => false,
}
},
Some(ast_map::NodeItem(itm)) => {
match itm.node {
ast::ItemFn(_, style, _, _, _) => match style {
ast::UnsafeFn => true,
_ => false,
},
_ => false,
}
}
_ => false // There are probably a couple of other unsafe cases we don't care to lint, those will need to be added.
}
}