]> git.lizzy.rs Git - rust.git/commitdiff
Add feature gate
authorJared Roesch <roeschinc@gmail.com>
Tue, 28 Jul 2015 16:00:32 +0000 (09:00 -0700)
committerJared Roesch <roeschinc@gmail.com>
Tue, 4 Aug 2015 23:05:07 +0000 (16:05 -0700)
src/librustdoc/clean/mod.rs
src/libsyntax/ext/expand.rs
src/libsyntax/feature_gate.rs

index a79a571f0c7a4685a92abd19467f00bc8bdd3bb6..64575e6856993fed492ab18c0029e513b1f69012 100644 (file)
@@ -1611,7 +1611,7 @@ fn clean(&self, cx: &DocContext) -> Type {
             TyTypeof(..) => {
                 panic!("Unimplemented type {:?}", self.node)
             },
-            TyMac(..) => {
+            TyMac(ref m) => {
                 cx.tcx().sess.span_bug(m.span, "unexpanded type macro found during cleaning")
             }
         }
index cd340fc91891f6aa206a51378cc4f2b68730ffa0..aadc3cfbafe00fcf0ddb128fdb396b9e982fe318 100644 (file)
@@ -1555,29 +1555,39 @@ fn expand_and_rename_method(sig: ast::MethodSig, body: P<ast::Block>,
 pub fn expand_type(t: P<ast::Ty>, fld: &mut MacroExpander) -> P<ast::Ty> {
     let t = match t.node.clone() {
         ast::Ty_::TyMac(mac) => {
-            let expanded_ty = match expand_mac_invoc(mac, t.span,
-                                                     |r| r.make_ty(),
-                                                     mark_ty,
-                                                     fld) {
-                Some(ty) => ty,
-                None => {
-                    return DummyResult::raw_ty(t.span);
-                }
-            };
-
-            // Keep going, outside-in.
-            //
-            let fully_expanded = fld.fold_ty(expanded_ty);
-            fld.cx.bt_pop();
+            if fld.cx.ecfg.features.unwrap().type_macros {
+                let expanded_ty = match expand_mac_invoc(mac, t.span,
+                                                         |r| r.make_ty(),
+                                                         mark_ty,
+                                                         fld) {
+                    Some(ty) => ty,
+                    None => {
+                        return DummyResult::raw_ty(t.span);
+                    }
+                };
 
-            fully_expanded.map(|t| ast::Ty {
-                id: ast::DUMMY_NODE_ID,
-                node: t.node,
-                span: t.span,
-            })
+                // Keep going, outside-in.
+                //
+                let fully_expanded = fld.fold_ty(expanded_ty);
+                fld.cx.bt_pop();
+
+                fully_expanded.map(|t| ast::Ty {
+                    id: ast::DUMMY_NODE_ID,
+                    node: t.node,
+                    span: t.span,
+                    })
+            } else {
+                feature_gate::emit_feature_err(
+                    &fld.cx.parse_sess.span_diagnostic,
+                    "type_macros",
+                    t.span,
+                    "type macros are experimental (see tracking issue: 27336)");
+                t
+            }
         }
         _ => t
     };
+
     fold::noop_fold_ty(t, fld)
 }
 
index 945e457a77b7313dc55259e81387397ac850def0..02764215612e6d1f1b72aca854d8207735aa17b5 100644 (file)
 
     // Allows associated type defaults
     ("associated_type_defaults", "1.2.0", Active),
+// Allows macros to appear in the type position.
+    ("type_macros", "1.3.0", Active),
 ];
 // (changing above list without updating src/doc/reference.md makes @cmr sad)
 
@@ -228,8 +230,7 @@ enum Status {
                      "no_std is experimental")),
     ("lang", Gated("lang_items",
                      "language items are subject to change")),
-    ("linkage", Gated("linkage",
-                      "the `linkage` attribute is experimental \
+    ("linkage", Gated("linkage", "the `linkage` attribute is experimental \
                        and not portable across platforms")),
     ("thread_local", Gated("thread_local",
                             "`#[thread_local]` is an experimental feature, and does not \
@@ -349,6 +350,7 @@ pub struct Features {
     pub const_fn: bool,
     pub static_recursion: bool,
     pub default_type_parameter_fallback: bool,
+    pub type_macros: bool,
 }
 
 impl Features {
@@ -375,6 +377,7 @@ pub fn new() -> Features {
             const_fn: false,
             static_recursion: false,
             default_type_parameter_fallback: false,
+            type_macros: false,
         }
     }
 }
@@ -878,6 +881,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler,
         const_fn: cx.has_feature("const_fn"),
         static_recursion: cx.has_feature("static_recursion"),
         default_type_parameter_fallback: cx.has_feature("default_type_parameter_fallback"),
+        type_macros: cx.has_feature("type_macros"),
     }
 }