diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-02-13 23:21:49 -0700 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-02-13 23:21:49 -0700 |
commit | 736c58067064a421f732dae118fde811b50b8aa6 (patch) | |
tree | ffaa0728bb2d2210a3b0ada01535d992e05930ed | |
parent | b5749e9855b68636d5366450602cd73397a6f219 (diff) | |
parent | 542f62ae94d79e6a86eca0ef29dba0824d84358e (diff) | |
download | servo-736c58067064a421f732dae118fde811b50b8aa6.tar.gz servo-736c58067064a421f732dae118fde811b50b8aa6.zip |
auto merge of #4914 : Ms2ger/servo/match_lang_ty, r=saneyuki
-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 |