diff options
| author | Brian Anderson <banderson@mozilla.com> | 2015-01-12 18:40:19 -0800 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2015-01-21 16:16:18 -0800 |
| commit | 94ca8a361026d1a622a961e8dc8cacc331ed1ac3 (patch) | |
| tree | 58179e85714f0a1ee618a8a9982aadbeb65822cf /src/libsyntax | |
| parent | 90aa581cff54ed1bb5f53ee2ead3764fca94fdf3 (diff) | |
| download | rust-94ca8a361026d1a622a961e8dc8cacc331ed1ac3.tar.gz rust-94ca8a361026d1a622a961e8dc8cacc331ed1ac3.zip | |
Add 'feature' and 'since' to stability attributes
Diffstat (limited to 'src/libsyntax')
| -rw-r--r-- | src/libsyntax/attr.rs | 72 | ||||
| -rw-r--r-- | src/libsyntax/ext/base.rs | 3 | ||||
| -rw-r--r-- | src/libsyntax/lib.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/util/small_vector.rs | 2 |
4 files changed, 68 insertions, 11 deletions
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 74d7ddc21c3..9aa226103f3 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -21,7 +21,7 @@ use codemap::{Span, Spanned, spanned, dummy_spanned}; use codemap::BytePos; use diagnostic::SpanHandler; use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration}; -use parse::token::InternedString; +use parse::token::{InternedString, intern_and_get_ident}; use parse::token; use ptr::P; @@ -56,6 +56,8 @@ pub trait AttrMetaMethods { fn value_str(&self) -> Option<InternedString>; /// Gets a list of inner meta items from a list MetaItem type. fn meta_item_list<'a>(&'a self) -> Option<&'a [P<MetaItem>]>; + + fn span(&self) -> Span; } impl AttrMetaMethods for Attribute { @@ -73,6 +75,7 @@ impl AttrMetaMethods for Attribute { fn meta_item_list<'a>(&'a self) -> Option<&'a [P<MetaItem>]> { self.node.value.meta_item_list() } + fn span(&self) -> Span { self.meta().span } } impl AttrMetaMethods for MetaItem { @@ -102,6 +105,7 @@ impl AttrMetaMethods for MetaItem { _ => None } } + fn span(&self) -> Span { self.span } } // Annoying, but required to get test_cfg to work @@ -111,6 +115,7 @@ impl AttrMetaMethods for P<MetaItem> { fn meta_item_list<'a>(&'a self) -> Option<&'a [P<MetaItem>]> { (**self).meta_item_list() } + fn span(&self) -> Span { (**self).span() } } @@ -340,11 +345,13 @@ pub fn cfg_matches(diagnostic: &SpanHandler, cfgs: &[P<MetaItem>], cfg: &ast::Me } } -/// Represents the #[deprecated="foo"] and friends attributes. +/// Represents the #[deprecated] and friends attributes. #[derive(RustcEncodable,RustcDecodable,Clone,Show)] pub struct Stability { pub level: StabilityLevel, - pub text: Option<InternedString> + pub feature: InternedString, + pub since: InternedString, + pub reason: Option<InternedString>, } /// The available stability levels. @@ -364,7 +371,7 @@ impl fmt::String for StabilityLevel { pub fn find_stability_generic<'a, AM: AttrMetaMethods, I: Iterator<Item=&'a AM>> - (mut attrs: I) + (diagnostic: &SpanHandler, mut attrs: I) -> Option<(Stability, &'a AM)> { for attr in attrs { let level = match attr.name().get() { @@ -374,17 +381,66 @@ pub fn find_stability_generic<'a, _ => continue // not a stability level }; + let (feature, since, reason) = match attr.meta_item_list() { + Some(metas) => { + let mut feature = None; + let mut since = None; + let mut reason = None; + for meta in metas.iter() { + if meta.name().get() == "feature" { + match meta.value_str() { + Some(v) => feature = Some(v), + None => { + diagnostic.span_err(meta.span, "incorrect meta item"); + } + } + } + if meta.name().get() == "since" { + match meta.value_str() { + Some(v) => since = Some(v), + None => { + diagnostic.span_err(meta.span, "incorrect meta item"); + } + } + } + if meta.name().get() == "reason" { + match meta.value_str() { + Some(v) => reason = Some(v), + None => { + diagnostic.span_err(meta.span, "incorrect meta item"); + } + } + } + } + (feature, since, reason) + } + None => { + diagnostic.span_err(attr.span(), "incorrect stability attribute type"); + (None, None, None) + } + }; + + if feature == None { + diagnostic.span_err(attr.span(), "missing 'feature'"); + } + + if since == None { + diagnostic.span_err(attr.span(), "missing 'since'"); + } + return Some((Stability { level: level, - text: attr.value_str() - }, attr)); + feature: feature.unwrap_or(intern_and_get_ident("bogus")), + since: since.unwrap_or(intern_and_get_ident("bogus")), + reason: reason, + }, 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)| { +pub fn find_stability(diagnostic: &SpanHandler, attrs: &[Attribute]) -> Option<Stability> { + find_stability_generic(diagnostic, attrs.iter()).map(|(s, attr)| { mark_used(attr); s }) diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index f2498abfa6a..cd04332b47f 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -568,7 +568,8 @@ impl<'a> ExtCtxt<'a> { } } - #[deprecated = "Replaced with `expander().fold_expr()`"] + #[deprecated(feature = "oldstuff", since = "1.0.0", + reason = "Replaced with `expander().fold_expr()`")] pub fn expand_expr(&mut self, e: P<ast::Expr>) -> P<ast::Expr> { self.expander().fold_expr(e) } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index fa675a9fcaa..d8a0c51b5ab 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -15,7 +15,7 @@ //! This API is completely unstable and subject to change. #![crate_name = "syntax"] -#![unstable] +#![unstable(feature = "unnamed_feature", since = "1.0.0")] #![staged_api] #![crate_type = "dylib"] #![crate_type = "rlib"] diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index b68c9926391..342fed1653d 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -112,7 +112,7 @@ impl<T> SmallVector<T> { } /// Deprecated: use `into_iter`. - #[deprecated = "use into_iter"] + #[deprecated(feature = "oldstuff", since = "1.0.0", reason = "use into_iter")] pub fn move_iter(self) -> IntoIter<T> { self.into_iter() } |
