From ccd8498afbb371939b7decdbee712f726ccbded3 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Sat, 13 Sep 2014 19:06:01 +0300 Subject: syntax: fix fallout from using ptr::P. --- src/libsyntax/attr.rs | 95 ++++++++++++++++++++++++--------------------------- 1 file changed, 45 insertions(+), 50 deletions(-) (limited to 'src/libsyntax/attr.rs') diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index dd422d02149..80e4d148bde 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -18,10 +18,10 @@ use diagnostic::SpanHandler; use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration}; use parse::token::InternedString; use parse::token; +use ptr::P; use std::collections::HashSet; use std::collections::BitvSet; -use std::gc::{Gc, GC}; local_data_key!(used_attrs: BitvSet) @@ -50,7 +50,7 @@ pub trait AttrMetaMethods { /// containing a string, otherwise None. fn value_str(&self) -> Option; /// Gets a list of inner meta items from a list MetaItem type. - fn meta_item_list<'a>(&'a self) -> Option<&'a [Gc]>; + fn meta_item_list<'a>(&'a self) -> Option<&'a [P]>; } impl AttrMetaMethods for Attribute { @@ -65,7 +65,7 @@ impl AttrMetaMethods for Attribute { fn value_str(&self) -> Option { self.meta().value_str() } - fn meta_item_list<'a>(&'a self) -> Option<&'a [Gc]> { + fn meta_item_list<'a>(&'a self) -> Option<&'a [P]> { self.node.value.meta_item_list() } } @@ -91,7 +91,7 @@ impl AttrMetaMethods for MetaItem { } } - fn meta_item_list<'a>(&'a self) -> Option<&'a [Gc]> { + fn meta_item_list<'a>(&'a self) -> Option<&'a [P]> { match self.node { MetaList(_, ref l) => Some(l.as_slice()), _ => None @@ -100,30 +100,30 @@ impl AttrMetaMethods for MetaItem { } // Annoying, but required to get test_cfg to work -impl AttrMetaMethods for Gc { +impl AttrMetaMethods for P { fn name(&self) -> InternedString { (**self).name() } fn value_str(&self) -> Option { (**self).value_str() } - fn meta_item_list<'a>(&'a self) -> Option<&'a [Gc]> { + fn meta_item_list<'a>(&'a self) -> Option<&'a [P]> { (**self).meta_item_list() } } pub trait AttributeMethods { - fn meta(&self) -> Gc; - fn desugar_doc(&self) -> Attribute; + fn meta<'a>(&'a self) -> &'a MetaItem; + fn with_desugared_doc(&self, f: |&Attribute| -> T) -> T; } impl AttributeMethods for Attribute { /// Extract the MetaItem from inside this Attribute. - fn meta(&self) -> Gc { - self.node.value + fn meta<'a>(&'a self) -> &'a MetaItem { + &*self.node.value } /// Convert self to a normal #[doc="foo"] comment, if it is a /// comment like `///` or `/** */`. (Returns self unchanged for /// non-sugared doc attributes.) - fn desugar_doc(&self) -> Attribute { + fn with_desugared_doc(&self, f: |&Attribute| -> T) -> T { if self.node.is_sugared_doc { let comment = self.value_str().unwrap(); let meta = mk_name_value_item_str( @@ -131,12 +131,12 @@ impl AttributeMethods for Attribute { token::intern_and_get_ident(strip_doc_comment_decoration( comment.get()).as_slice())); if self.node.style == ast::AttrOuter { - mk_attr_outer(self.node.id, meta) + f(&mk_attr_outer(self.node.id, meta)) } else { - mk_attr_inner(self.node.id, meta) + f(&mk_attr_inner(self.node.id, meta)) } } else { - *self + f(self) } } } @@ -144,23 +144,22 @@ impl AttributeMethods for Attribute { /* Constructors */ pub fn mk_name_value_item_str(name: InternedString, value: InternedString) - -> Gc { + -> P { let value_lit = dummy_spanned(ast::LitStr(value, ast::CookedStr)); mk_name_value_item(name, value_lit) } pub fn mk_name_value_item(name: InternedString, value: ast::Lit) - -> Gc { - box(GC) dummy_spanned(MetaNameValue(name, value)) + -> P { + P(dummy_spanned(MetaNameValue(name, value))) } -pub fn mk_list_item(name: InternedString, - items: Vec>) -> Gc { - box(GC) dummy_spanned(MetaList(name, items)) +pub fn mk_list_item(name: InternedString, items: Vec>) -> P { + P(dummy_spanned(MetaList(name, items))) } -pub fn mk_word_item(name: InternedString) -> Gc { - box(GC) dummy_spanned(MetaWord(name)) +pub fn mk_word_item(name: InternedString) -> P { + P(dummy_spanned(MetaWord(name))) } local_data_key!(next_attr_id: uint) @@ -172,7 +171,7 @@ pub fn mk_attr_id() -> AttrId { } /// Returns an inner attribute with the given value. -pub fn mk_attr_inner(id: AttrId, item: Gc) -> Attribute { +pub fn mk_attr_inner(id: AttrId, item: P) -> Attribute { dummy_spanned(Attribute_ { id: id, style: ast::AttrInner, @@ -182,7 +181,7 @@ pub fn mk_attr_inner(id: AttrId, item: Gc) -> Attribute { } /// Returns an outer attribute with the given value. -pub fn mk_attr_outer(id: AttrId, item: Gc) -> Attribute { +pub fn mk_attr_outer(id: AttrId, item: P) -> Attribute { dummy_spanned(Attribute_ { id: id, style: ast::AttrOuter, @@ -199,8 +198,8 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, let attr = Attribute_ { id: id, style: style, - value: box(GC) spanned(lo, hi, MetaNameValue(InternedString::new("doc"), - lit)), + value: P(spanned(lo, hi, MetaNameValue(InternedString::new("doc"), + lit))), is_sugared_doc: true }; spanned(lo, hi, attr) @@ -210,8 +209,7 @@ pub fn mk_sugared_doc_attr(id: AttrId, text: InternedString, lo: BytePos, /// Check if `needle` occurs in `haystack` by a structural /// comparison. This is slightly subtle, and relies on ignoring the /// span included in the `==` comparison a plain MetaItem. -pub fn contains(haystack: &[Gc], - needle: Gc) -> bool { +pub fn contains(haystack: &[P], needle: &MetaItem) -> bool { debug!("attr::contains (name={})", needle.name()); haystack.iter().any(|item| { debug!(" testing: {}", item.name()); @@ -234,7 +232,7 @@ pub fn first_attr_value_str_by_name(attrs: &[Attribute], name: &str) .and_then(|at| at.value_str()) } -pub fn last_meta_item_value_str_by_name(items: &[Gc], name: &str) +pub fn last_meta_item_value_str_by_name(items: &[P], name: &str) -> Option { items.iter() .rev() @@ -244,28 +242,25 @@ pub fn last_meta_item_value_str_by_name(items: &[Gc], name: &str) /* Higher-level applications */ -pub fn sort_meta_items(items: &[Gc]) -> Vec> { +pub fn sort_meta_items(items: Vec>) -> Vec> { // This is sort of stupid here, but we need to sort by // human-readable strings. - let mut v = items.iter() - .map(|&mi| (mi.name(), mi)) - .collect::)> >(); + let mut v = items.move_iter() + .map(|mi| (mi.name(), mi)) + .collect::)>>(); v.sort_by(|&(ref a, _), &(ref b, _)| a.cmp(b)); // There doesn't seem to be a more optimal way to do this - v.move_iter().map(|(_, m)| { - match m.node { - MetaList(ref n, ref mis) => { - box(GC) Spanned { - node: MetaList((*n).clone(), - sort_meta_items(mis.as_slice())), - .. /*bad*/ (*m).clone() - } - } - _ => m + v.move_iter().map(|(_, m)| m.map(|Spanned {node, span}| { + Spanned { + node: match node { + MetaList(n, mis) => MetaList(n, sort_meta_items(mis)), + _ => node + }, + span: span } - }).collect() + })).collect() } pub fn find_crate_name(attrs: &[Attribute]) -> Option { @@ -318,8 +313,8 @@ pub fn requests_inline(attrs: &[Attribute]) -> bool { /// test_cfg(`[foo="a", bar]`, `[cfg(not(bar))]`) == false /// test_cfg(`[foo="a", bar]`, `[cfg(bar, foo="a")]`) == true /// test_cfg(`[foo="a", bar]`, `[cfg(bar, foo="b")]`) == false -pub fn test_cfg> - (cfg: &[Gc], mut metas: It) -> bool { +pub fn test_cfg<'a, AM: AttrMetaMethods, It: Iterator<&'a AM>> + (cfg: &[P], mut metas: It) -> bool { // having no #[cfg(...)] attributes counts as matching. let mut no_cfgs = true; @@ -344,10 +339,10 @@ pub fn test_cfg> // not match. !not_cfgs.iter().all(|mi| { debug!("cfg(not({}[...]))", mi.name()); - contains(cfg, *mi) + contains(cfg, &**mi) }) } - _ => contains(cfg, *cfg_mi) + _ => contains(cfg, &**cfg_mi) } }) } @@ -397,7 +392,7 @@ pub fn find_stability_generic<'a, }; return Some((Stability { - level: level, + level: level, text: attr.value_str() }, attr)); } @@ -412,7 +407,7 @@ pub fn find_stability(attrs: &[Attribute]) -> Option { }) } -pub fn require_unique_names(diagnostic: &SpanHandler, metas: &[Gc]) { +pub fn require_unique_names(diagnostic: &SpanHandler, metas: &[P]) { let mut set = HashSet::new(); for meta in metas.iter() { let name = meta.name(); -- cgit 1.4.1-3-g733a5