Skip to content

Commit c5346fe

Browse files
committed
Add a feature flag for ASM
1 parent 424c171 commit c5346fe

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

src/librustc/front/feature_gate.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
3434
("macro_rules", Active),
3535
("struct_variant", Active),
3636
("once_fns", Active),
37+
("asm", Active),
3738

3839
// These are used to test this portion of the compiler, they don't actually
3940
// mean anything
@@ -108,26 +109,29 @@ impl Visitor<()> for Context {
108109
}
109110
}
110111

111-
ast::item_mac(ref mac) => {
112-
match mac.node {
113-
ast::mac_invoc_tt(ref path, _, _) => {
114-
let rules = self.sess.ident_of("macro_rules");
115-
if path.segments.last().identifier == rules {
116-
self.gate_feature("macro_rules", i.span,
117-
"macro definitions are not \
118-
stable enough for use and are \
119-
subject to change");
120-
}
121-
}
122-
}
123-
}
124-
125112
_ => {}
126113
}
127114

128115
visit::walk_item(self, i, ());
129116
}
130117

118+
fn visit_mac(&mut self, macro: &ast::mac, _: ()) {
119+
let ast::mac_invoc_tt(ref path, _, _) = macro.node;
120+
121+
if path.segments.last().identifier == self.sess.ident_of("macro_rules") {
122+
self.gate_feature("macro_rules", path.span, "macro definitions are \
123+
not stable enough for use and are subject to change");
124+
}
125+
126+
else if path.segments.last().identifier == self.sess.ident_of("asm") {
127+
// NOTE: remove the false once the ASM feature is in the next snapshot
128+
if false {
129+
self.gate_feature("asm", path.span, "inline assembly is not \
130+
stable enough for use and is subject to change");
131+
}
132+
}
133+
}
134+
131135
fn visit_ty(&mut self, t: &ast::Ty, _: ()) {
132136
match t.node {
133137
ast::ty_closure(closure) if closure.onceness == ast::Once => {

src/libsyntax/visit.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ pub trait Visitor<E:Clone> {
9090
walk_struct_def(self, s, i, g, n, e)
9191
}
9292
fn visit_struct_field(&mut self, s:@struct_field, e:E) { walk_struct_field(self, s, e) }
93+
fn visit_mac(&mut self, m:&mac, e:E) { walk_mac(self, m, e); }
9394
}
9495

9596
impl<E:Clone> Visitor<E> for @mut Visitor<E> {
@@ -150,6 +151,9 @@ impl<E:Clone> Visitor<E> for @mut Visitor<E> {
150151
fn visit_struct_field(&mut self, a:@struct_field, e:E) {
151152
(*self).visit_struct_field(a, e)
152153
}
154+
fn visit_mac(&mut self, macro:&mac, e:E) {
155+
(*self).visit_mac(macro, e);
156+
}
153157
}
154158

155159
pub fn walk_crate<E:Clone, V:Visitor<E>>(visitor: &mut V, crate: &Crate, env: E) {
@@ -247,7 +251,7 @@ pub fn walk_item<E:Clone, V:Visitor<E>>(visitor: &mut V, item: &item, env: E) {
247251
visitor.visit_trait_method(method, env.clone())
248252
}
249253
}
250-
item_mac(ref macro) => walk_mac(visitor, macro, env),
254+
item_mac(ref macro) => visitor.visit_mac(macro, env),
251255
}
252256
}
253257

@@ -507,7 +511,7 @@ pub fn walk_stmt<E:Clone, V:Visitor<E>>(visitor: &mut V, statement: &Stmt, env:
507511
StmtExpr(expression, _) | StmtSemi(expression, _) => {
508512
visitor.visit_expr(expression, env)
509513
}
510-
StmtMac(ref macro, _) => walk_mac(visitor, macro, env),
514+
StmtMac(ref macro, _) => visitor.visit_mac(macro, env),
511515
}
512516
}
513517

@@ -644,7 +648,7 @@ pub fn walk_expr<E:Clone, V:Visitor<E>>(visitor: &mut V, expression: @Expr, env:
644648
walk_expr_opt(visitor, optional_expression, env.clone())
645649
}
646650
ExprLogLevel => {}
647-
ExprMac(ref macro) => walk_mac(visitor, macro, env.clone()),
651+
ExprMac(ref macro) => visitor.visit_mac(macro, env.clone()),
648652
ExprParen(subexpression) => {
649653
visitor.visit_expr(subexpression, env.clone())
650654
}

src/test/compile-fail/asm-gated.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// xfail-test
12+
13+
fn main() {
14+
unsafe {
15+
asm!(""); //~ ERROR inline assembly is not stable enough
16+
}
17+
}

0 commit comments

Comments
 (0)