diff options
| author | Steven Fackler <sfackler@gmail.com> | 2014-05-21 00:05:45 -0700 |
|---|---|---|
| committer | Steven Fackler <sfackler@gmail.com> | 2014-05-24 16:49:46 -0700 |
| commit | e0648093d8f8cc4db3b309622b7efd95275a17d3 (patch) | |
| tree | 6531121b27807a9bf8eb474693fc7f950138ae90 /src/libsyntax | |
| parent | 50181add04279eaac2b078d36823035933844226 (diff) | |
| download | rust-e0648093d8f8cc4db3b309622b7efd95275a17d3.tar.gz rust-e0648093d8f8cc4db3b309622b7efd95275a17d3.zip | |
Port more stuff to mark used attributes
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/attr.rs | 64 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 3 |
2 files changed, 43 insertions, 24 deletions
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index ac5792febbb..bbd333163b5 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -238,14 +238,14 @@ pub fn contains_name<AM: AttrMetaMethods>(metas: &[AM], name: &str) -> bool { debug!("attr::contains_name (name={})", name); metas.iter().any(|item| { debug!(" testing: {}", item.name()); - item.name().equiv(&name) + item.check_name(name) }) } pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: &str) -> Option<InternedString> { attrs.iter() - .find(|at| at.name().equiv(&name)) + .find(|at| at.check_name(name)) .and_then(|at| at.value_str()) } @@ -253,7 +253,7 @@ pub fn last_meta_item_value_str_by_name(items: &[@MetaItem], name: &str) -> Option<InternedString> { items.iter() .rev() - .find(|mi| mi.name().equiv(&name)) + .find(|mi| mi.check_name(name)) .and_then(|i| i.value_str()) } @@ -289,7 +289,7 @@ pub fn sort_meta_items(items: &[@MetaItem]) -> Vec<@MetaItem> { */ pub fn find_linkage_metas(attrs: &[Attribute]) -> Vec<@MetaItem> { let mut result = Vec::new(); - for attr in attrs.iter().filter(|at| at.name().equiv(&("link"))) { + for attr in attrs.iter().filter(|at| at.check_name("link")) { match attr.meta().node { MetaList(_, ref items) => result.push_all(items.as_slice()), _ => () @@ -318,17 +318,21 @@ pub fn find_inline_attr(attrs: &[Attribute]) -> InlineAttr { // FIXME (#2809)---validate the usage of #[inline] and #[inline] attrs.iter().fold(InlineNone, |ia,attr| { match attr.node.value.node { - MetaWord(ref n) if n.equiv(&("inline")) => InlineHint, - MetaList(ref n, ref items) if n.equiv(&("inline")) => { - if contains_name(items.as_slice(), "always") { - InlineAlways - } else if contains_name(items.as_slice(), "never") { - InlineNever - } else { + MetaWord(ref n) if n.equiv(&("inline")) => { + mark_used(attr); InlineHint } - } - _ => ia + MetaList(ref n, ref items) if n.equiv(&("inline")) => { + mark_used(attr); + if contains_name(items.as_slice(), "always") { + InlineAlways + } else if contains_name(items.as_slice(), "never") { + InlineNever + } else { + InlineHint + } + } + _ => ia } }) } @@ -348,7 +352,7 @@ pub fn test_cfg<AM: AttrMetaMethods, It: Iterator<AM>> // this doesn't work. let some_cfg_matches = metas.any(|mi| { debug!("testing name: {}", mi.name()); - if mi.name().equiv(&("cfg")) { // it is a #[cfg()] attribute + if mi.check_name("cfg") { // it is a #[cfg()] attribute debug!("is cfg"); no_cfgs = false; // only #[cfg(...)] ones are understood. @@ -399,11 +403,13 @@ pub enum StabilityLevel { Locked } -/// Find the first stability attribute. `None` if none exists. -pub fn find_stability<AM: AttrMetaMethods, It: Iterator<AM>>(mut metas: It) - -> Option<Stability> { - for m in metas { - let level = match m.name().get() { +pub fn find_stability_generic<'a, + AM: AttrMetaMethods, + I: Iterator<&'a AM>> + (mut attrs: I) + -> Option<(Stability, &'a AM)> { + for attr in attrs { + let level = match attr.name().get() { "deprecated" => Deprecated, "experimental" => Experimental, "unstable" => Unstable, @@ -413,14 +419,22 @@ pub fn find_stability<AM: AttrMetaMethods, It: Iterator<AM>>(mut metas: It) _ => continue // not a stability level }; - return Some(Stability { + return Some((Stability { level: level, - text: m.value_str() - }); + text: attr.value_str() + }, attr)); } None } +/// Find the first stability attribute. `None` if none exists. +pub fn find_stability(attrs: &[Attribute]) -> Option<Stability> { + find_stability_generic(attrs.iter()).map(|(s, attr)| { + mark_used(attr); + s + }) +} + pub fn require_unique_names(diagnostic: &SpanHandler, metas: &[@MetaItem]) { let mut set = HashSet::new(); for meta in metas.iter() { @@ -447,11 +461,13 @@ pub fn require_unique_names(diagnostic: &SpanHandler, metas: &[@MetaItem]) { * present (before fields, if any) with that type; reprensentation * optimizations which would remove it will not be done. */ -pub fn find_repr_attr(diagnostic: &SpanHandler, attr: @ast::MetaItem, acc: ReprAttr) +pub fn find_repr_attr(diagnostic: &SpanHandler, attr: &Attribute, acc: ReprAttr) -> ReprAttr { let mut acc = acc; - match attr.node { + info!("{}", ::print::pprust::attribute_to_str(attr)); + match attr.node.value.node { ast::MetaList(ref s, ref items) if s.equiv(&("repr")) => { + mark_used(attr); for item in items.iter() { match item.node { ast::MetaWord(ref word) => { diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 64b7e1c28c1..658e4bafbe2 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -265,6 +265,8 @@ pub fn expand_item(it: @ast::Item, fld: &mut MacroExpander) match fld.extsbox.find(&intern(mname.get())) { Some(&ItemDecorator(dec_fn)) => { + attr::mark_used(attr); + fld.cx.bt_push(ExpnInfo { call_site: attr.span, callee: NameAndSpan { @@ -336,6 +338,7 @@ fn expand_item_modifiers(mut it: @ast::Item, fld: &mut MacroExpander) match fld.extsbox.find(&intern(mname.get())) { Some(&ItemModifier(dec_fn)) => { + attr::mark_used(attr); fld.cx.bt_push(ExpnInfo { call_site: attr.span, callee: NameAndSpan { |
