diff options
author | Rohan Prinja <rohan.prinja@gmail.com> | 2014-12-31 19:36:13 +0530 |
---|---|---|
committer | Rohan Prinja <rohan.prinja@gmail.com> | 2015-01-01 13:50:55 +0530 |
commit | 7ac58f202f44bebf1021ff523a3ac913dcfe0b4c (patch) | |
tree | 5a2c525e6cb7bacaf7a5037f29f42c9d0cec3e0d /components/plugins/utils.rs | |
parent | 0da57abec6014f8a6edde9781598053deab996c7 (diff) | |
download | servo-7ac58f202f44bebf1021ff523a3ac913dcfe0b4c.tar.gz servo-7ac58f202f44bebf1021ff523a3ac913dcfe0b4c.zip |
break up lints.rs into separate files
Diffstat (limited to 'components/plugins/utils.rs')
-rw-r--r-- | components/plugins/utils.rs | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/components/plugins/utils.rs b/components/plugins/utils.rs index 34d74a4001f..132d7afaaa8 100644 --- a/components/plugins/utils.rs +++ b/components/plugins/utils.rs @@ -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. + } +} |