diff options
author | Ms2ger <ms2ger@gmail.com> | 2015-02-13 00:02:18 +0100 |
---|---|---|
committer | Ms2ger <ms2ger@gmail.com> | 2015-02-13 00:02:18 +0100 |
commit | 542f62ae94d79e6a86eca0ef29dba0824d84358e (patch) | |
tree | 8dfd20315c73abc1c028d01367e5303ebf95a3e2 /components/plugins | |
parent | 69259e9975a0383d309b7ce678734c49e6616d32 (diff) | |
download | servo-542f62ae94d79e6a86eca0ef29dba0824d84358e.tar.gz servo-542f62ae94d79e6a86eca0ef29dba0824d84358e.zip |
Cleanup match_lang_ty a bit.
Diffstat (limited to 'components/plugins')
-rw-r--r-- | components/plugins/utils.rs | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/components/plugins/utils.rs b/components/plugins/utils.rs index 1be51283c1b..0bc146186be 100644 --- a/components/plugins/utils.rs +++ b/components/plugins/utils.rs @@ -38,26 +38,30 @@ pub fn match_ty_unwrap<'a>(ty: &'a Ty, segments: &[&str]) -> Option<&'a [P<Ty>]> /// Checks if a type has a #[servo_lang = "str"] attribute pub fn match_lang_ty(cx: &Context, ty: &Ty, value: &str) -> bool { - let mut found = false; - if let TyPath(_, ty_id) = ty.node { - if let Some(def::DefTy(def_id, _)) = cx.tcx.def_map.borrow().get(&ty_id).cloned() { - // Iterating through attributes is hard because of cross-crate defs - for attr in ty::get_attrs(cx.tcx, def_id).iter() { - if let ast::MetaNameValue(ref name, ref val) = attr.node.value.node { - if &**name == "servo_lang" { - if let ast::LitStr(ref v, _) = val.node { - if &**v == value { - mark_used(attr); - found = true; - break - } - } - } + let ty_id = match ty.node { + TyPath(_, ty_id) => ty_id, + _ => return false, + }; + + let def_id = match cx.tcx.def_map.borrow().get(&ty_id).cloned() { + Some(def::DefTy(def_id, _)) => def_id, + _ => return false, + }; + + ty::get_attrs(cx.tcx, def_id).iter().any(|attr| { + match attr.node.value.node { + ast::MetaNameValue(ref name, ref val) if &**name == "servo_lang" => { + match val.node { + ast::LitStr(ref v, _) if &**v == value => { + mark_used(attr); + true + }, + _ => false, } } - }; - } - found + _ => false, + } + }) } // Determines if a block is in an unsafe context so that an unhelpful |