Skip to content

Commit 15e7aa7

Browse files
committed
Add feature gate
1 parent 0bb5a1a commit 15e7aa7

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ impl Clean<Type> for ast::Ty {
16111611
TyTypeof(..) => {
16121612
panic!("Unimplemented type {:?}", self.node)
16131613
},
1614-
TyMac(..) => {
1614+
TyMac(ref m) => {
16151615
cx.tcx().sess.span_bug(m.span, "unexpanded type macro found during cleaning")
16161616
}
16171617
}

src/libsyntax/ext/expand.rs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,29 +1555,39 @@ fn expand_and_rename_method(sig: ast::MethodSig, body: P<ast::Block>,
15551555
pub fn expand_type(t: P<ast::Ty>, fld: &mut MacroExpander) -> P<ast::Ty> {
15561556
let t = match t.node.clone() {
15571557
ast::Ty_::TyMac(mac) => {
1558-
let expanded_ty = match expand_mac_invoc(mac, t.span,
1559-
|r| r.make_ty(),
1560-
mark_ty,
1561-
fld) {
1562-
Some(ty) => ty,
1563-
None => {
1564-
return DummyResult::raw_ty(t.span);
1565-
}
1566-
};
1567-
1568-
// Keep going, outside-in.
1569-
//
1570-
let fully_expanded = fld.fold_ty(expanded_ty);
1571-
fld.cx.bt_pop();
1558+
if fld.cx.ecfg.features.unwrap().type_macros {
1559+
let expanded_ty = match expand_mac_invoc(mac, t.span,
1560+
|r| r.make_ty(),
1561+
mark_ty,
1562+
fld) {
1563+
Some(ty) => ty,
1564+
None => {
1565+
return DummyResult::raw_ty(t.span);
1566+
}
1567+
};
15721568

1573-
fully_expanded.map(|t| ast::Ty {
1574-
id: ast::DUMMY_NODE_ID,
1575-
node: t.node,
1576-
span: t.span,
1577-
})
1569+
// Keep going, outside-in.
1570+
//
1571+
let fully_expanded = fld.fold_ty(expanded_ty);
1572+
fld.cx.bt_pop();
1573+
1574+
fully_expanded.map(|t| ast::Ty {
1575+
id: ast::DUMMY_NODE_ID,
1576+
node: t.node,
1577+
span: t.span,
1578+
})
1579+
} else {
1580+
feature_gate::emit_feature_err(
1581+
&fld.cx.parse_sess.span_diagnostic,
1582+
"type_macros",
1583+
t.span,
1584+
"type macros are experimental (see tracking issue: 27336)");
1585+
t
1586+
}
15781587
}
15791588
_ => t
15801589
};
1590+
15811591
fold::noop_fold_ty(t, fld)
15821592
}
15831593

src/libsyntax/feature_gate.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
169169

170170
// Allows associated type defaults
171171
("associated_type_defaults", "1.2.0", Active),
172+
// Allows macros to appear in the type position.
173+
("type_macros", "1.3.0", Active),
172174
];
173175
// (changing above list without updating src/doc/reference.md makes @cmr sad)
174176

@@ -228,8 +230,7 @@ pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
228230
"no_std is experimental")),
229231
("lang", Gated("lang_items",
230232
"language items are subject to change")),
231-
("linkage", Gated("linkage",
232-
"the `linkage` attribute is experimental \
233+
("linkage", Gated("linkage", "the `linkage` attribute is experimental \
233234
and not portable across platforms")),
234235
("thread_local", Gated("thread_local",
235236
"`#[thread_local]` is an experimental feature, and does not \
@@ -349,6 +350,7 @@ pub struct Features {
349350
pub const_fn: bool,
350351
pub static_recursion: bool,
351352
pub default_type_parameter_fallback: bool,
353+
pub type_macros: bool,
352354
}
353355

354356
impl Features {
@@ -375,6 +377,7 @@ impl Features {
375377
const_fn: false,
376378
static_recursion: false,
377379
default_type_parameter_fallback: false,
380+
type_macros: false,
378381
}
379382
}
380383
}
@@ -878,6 +881,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler,
878881
const_fn: cx.has_feature("const_fn"),
879882
static_recursion: cx.has_feature("static_recursion"),
880883
default_type_parameter_fallback: cx.has_feature("default_type_parameter_fallback"),
884+
type_macros: cx.has_feature("type_macros"),
881885
}
882886
}
883887

0 commit comments

Comments
 (0)