diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2015-07-21 21:09:18 +0530 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2015-07-22 00:00:14 +0530 |
commit | f6f0a7e4aaaa3c1ec7aca3876b0b0fe9e5fca9aa (patch) | |
tree | 1affaf3d3bff8cc1ef9dc3c2090fc88bb3dfa698 /components/plugins/utils.rs | |
parent | 126f5ae8f0a1041aa881b5b8d9396d0957b16036 (diff) | |
download | servo-f6f0a7e4aaaa3c1ec7aca3876b0b0fe9e5fca9aa.tar.gz servo-f6f0a7e4aaaa3c1ec7aca3876b0b0fe9e5fca9aa.zip |
Make stmt part of unrooted_must_root handle type parameters (fixes #6651)
Diffstat (limited to 'components/plugins/utils.rs')
-rw-r--r-- | components/plugins/utils.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/components/plugins/utils.rs b/components/plugins/utils.rs index 8e4c8bcf495..9cd843ae5a7 100644 --- a/components/plugins/utils.rs +++ b/components/plugins/utils.rs @@ -49,7 +49,11 @@ pub fn match_lang_ty(cx: &Context, ty: &Ty, value: &str) -> bool { _ => return false, }; - cx.tcx.get_attrs(def_id).iter().any(|attr| { + match_lang_did(cx, def_id, value) +} + +pub fn match_lang_did(cx: &Context, did: ast::DefId, value: &str) -> bool { + cx.tcx.get_attrs(did).iter().any(|attr| { match attr.node.value.node { ast::MetaNameValue(ref name, ref val) if &**name == "servo_lang" => { match val.node { @@ -88,3 +92,11 @@ pub fn unsafe_context(map: &ast_map::Map, id: ast::NodeId) -> bool { // to be added. } } + +/// check if a DefId's path matches the given absolute type path +/// usage e.g. with +/// `match_def_path(cx, id, &["core", "option", "Option"])` +pub fn match_def_path(cx: &Context, def_id: ast::DefId, path: &[&str]) -> bool { + cx.tcx.with_path(def_id, |iter| iter.map(|elem| elem.name()) + .zip(path.iter()).all(|(nm, p)| &nm.as_str() == p)) +} |