]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/front/feature_gate.rs
Replace all ~"" with "".to_owned()
[rust.git] / src / librustc / front / feature_gate.rs
index 4450fbb04a9319a98eb9e697da57ef5a614accc3..3ab39dd121f082aca119f359f69293b8863e4b42 100644 (file)
     ("macro_registrar", Active),
     ("log_syntax", Active),
     ("trace_macros", Active),
+    ("concat_idents", Active),
+
     ("simd", Active),
     ("default_type_params", Active),
     ("quote", Active),
+    ("linkage", Active),
 
     // These are used to test this portion of the compiler, they don't actually
     // mean anything
@@ -73,7 +76,7 @@ enum Status {
 
 /// A set of features to be used by later passes.
 pub struct Features {
-    default_type_params: Cell<bool>
+    pub default_type_params: Cell<bool>
 }
 
 impl Features {
@@ -84,16 +87,16 @@ pub fn new() -> Features {
     }
 }
 
-struct Context {
-    features: ~[&'static str],
-    sess: Session,
+struct Context<'a> {
+    features: Vec<&'static str>,
+    sess: &'a Session,
 }
 
-impl Context {
+impl<'a> Context<'a> {
     fn gate_feature(&self, feature: &str, span: Span, explain: &str) {
         if !self.has_feature(feature) {
             self.sess.span_err(span, explain);
-            self.sess.span_note(span, format!("add \\#[feature({})] to the \
+            self.sess.span_note(span, format!("add \\#![feature({})] to the \
                                                   crate attributes to enable",
                                                  feature));
         }
@@ -112,7 +115,7 @@ fn has_feature(&self, feature: &str) -> bool {
     }
 }
 
-impl Visitor<()> for Context {
+impl<'a> Visitor<()> for Context<'a> {
     fn visit_ident(&mut self, sp: Span, id: ast::Ident, _: ()) {
         if !token::get_ident(id).get().is_ascii() {
             self.gate_feature("non_ascii_idents", sp,
@@ -134,7 +137,7 @@ fn visit_view_item(&mut self, i: &ast::ViewItem, _: ()) {
                     }
                 }
             }
-            ast::ViewItemExternMod(..) => {
+            ast::ViewItemExternCrate(..) => {
                 for attr in i.attrs.iter() {
                     if attr.name().get() == "phase"{
                         self.gate_feature("phase", attr.span,
@@ -171,7 +174,7 @@ fn visit_item(&mut self, i: &ast::Item, _:()) {
             }
 
             ast::ItemForeignMod(..) => {
-                if attr::contains_name(i.attrs, "link_args") {
+                if attr::contains_name(i.attrs.as_slice(), "link_args") {
                     self.gate_feature("link_args", i.span,
                                       "the `link_args` attribute is not portable \
                                        across platforms, it is recommended to \
@@ -180,7 +183,7 @@ fn visit_item(&mut self, i: &ast::Item, _:()) {
             }
 
             ast::ItemFn(..) => {
-                if attr::contains_name(i.attrs, "macro_registrar") {
+                if attr::contains_name(i.attrs.as_slice(), "macro_registrar") {
                     self.gate_feature("macro_registrar", i.span,
                                       "cross-crate macro exports are \
                                        experimental and possibly buggy");
@@ -188,7 +191,7 @@ fn visit_item(&mut self, i: &ast::Item, _:()) {
             }
 
             ast::ItemStruct(..) => {
-                if attr::contains_name(i.attrs, "simd") {
+                if attr::contains_name(i.attrs.as_slice(), "simd") {
                     self.gate_feature("simd", i.span,
                                       "SIMD types are experimental and possibly buggy");
                 }
@@ -228,6 +231,11 @@ fn visit_mac(&mut self, macro: &ast::Mac, _: ()) {
                 stable enough for use and is subject to change");
         }
 
+        else if id == token::str_to_ident("concat_idents") {
+            self.gate_feature("concat_idents", path.span, "`concat_idents` is not \
+                stable enough for use and is subject to change");
+        }
+
         else {
             for &quote in quotes.iter() {
                 if id == token::str_to_ident(quote) {
@@ -237,10 +245,22 @@ fn visit_mac(&mut self, macro: &ast::Mac, _: ()) {
         }
     }
 
+    fn visit_foreign_item(&mut self, i: &ast::ForeignItem, _: ()) {
+        match i.node {
+            ast::ForeignItemFn(..) | ast::ForeignItemStatic(..) => {
+                if attr::contains_name(i.attrs.as_slice(), "linkage") {
+                    self.gate_feature("linkage", i.span,
+                                      "the `linkage` attribute is experimental \
+                                       and not portable across platforms")
+                }
+            }
+        }
+        visit::walk_foreign_item(self, i, ())
+    }
+
     fn visit_ty(&mut self, t: &ast::Ty, _: ()) {
         match t.node {
-            ast::TyClosure(closure) if closure.onceness == ast::Once &&
-                    closure.sigil != ast::OwnedSigil => {
+            ast::TyClosure(closure, _) if closure.onceness == ast::Once => {
                 self.gate_feature("once_fns", t.span,
                                   "once functions are \
                                    experimental and likely to be removed");
@@ -278,9 +298,9 @@ fn visit_generics(&mut self, generics: &ast::Generics, _: ()) {
     }
 }
 
-pub fn check_crate(sess: Session, krate: &ast::Crate) {
+pub fn check_crate(sess: &Session, krate: &ast::Crate) {
     let mut cx = Context {
-        features: ~[],
+        features: Vec::new(),
         sess: sess,
     };
 
@@ -319,7 +339,7 @@ pub fn check_crate(sess: Session, krate: &ast::Crate) {
                             sess.add_lint(lint::UnknownFeatures,
                                           ast::CRATE_NODE_ID,
                                           mi.span,
-                                          ~"unknown feature");
+                                          "unknown feature".to_owned());
                         }
                     }
                 }