Skip to content

Commit 52bdda7

Browse files
committed
Address the asm! case of #22234.
1 parent 20d8222 commit 52bdda7

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

src/libsyntax/ext/asm.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use codemap;
1818
use codemap::Span;
1919
use ext::base;
2020
use ext::base::*;
21+
use feature_gate;
2122
use parse::token::InternedString;
2223
use parse::token;
2324
use ptr::P;
@@ -48,6 +49,12 @@ static OPTIONS: &'static [&'static str] = &["volatile", "alignstack", "intel"];
4849

4950
pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
5051
-> Box<base::MacResult+'cx> {
52+
if !cx.ecfg.enable_asm() {
53+
feature_gate::emit_feature_err(
54+
&cx.parse_sess.span_diagnostic, "asm", sp, feature_gate::EXPLAIN_ASM);
55+
return DummyResult::expr(sp);
56+
}
57+
5158
let mut p = cx.new_parser_from_tts(tts);
5259
let mut asm = InternedString::new("");
5360
let mut asm_str_style = None;

src/libsyntax/ext/expand.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1425,7 +1425,14 @@ impl<'feat> ExpansionConfig<'feat> {
14251425

14261426
pub fn enable_quotes(&self) -> bool {
14271427
match self.features {
1428-
Some(&Features { quote: true, .. }) => true,
1428+
Some(&Features { allow_quote: true, .. }) => true,
1429+
_ => false,
1430+
}
1431+
}
1432+
1433+
pub fn enable_asm(&self) -> bool {
1434+
match self.features {
1435+
Some(&Features { allow_asm: true, .. }) => true,
14291436
_ => false,
14301437
}
14311438
}

src/libsyntax/feature_gate.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ pub struct Features {
156156
pub unboxed_closures: bool,
157157
pub rustc_diagnostic_macros: bool,
158158
pub visible_private_types: bool,
159-
pub quote: bool,
159+
pub allow_quote: bool,
160+
pub allow_asm: bool,
160161
pub old_orphan_check: bool,
161162
pub simd_ffi: bool,
162163
pub unmarked_api: bool,
@@ -172,7 +173,8 @@ impl Features {
172173
unboxed_closures: false,
173174
rustc_diagnostic_macros: false,
174175
visible_private_types: false,
175-
quote: false,
176+
allow_quote: false,
177+
allow_asm: false,
176178
old_orphan_check: false,
177179
simd_ffi: false,
178180
unmarked_api: false,
@@ -221,6 +223,9 @@ pub fn emit_feature_warn(diag: &SpanHandler, feature: &str, span: Span, explain:
221223
}
222224
}
223225

226+
pub const EXPLAIN_ASM: &'static str =
227+
"inline assembly is not stable enough for use and is subject to change";
228+
224229
struct MacroVisitor<'a> {
225230
context: &'a Context<'a>
226231
}
@@ -231,8 +236,7 @@ impl<'a, 'v> Visitor<'v> for MacroVisitor<'a> {
231236
let id = path.segments.last().unwrap().identifier;
232237

233238
if id == token::str_to_ident("asm") {
234-
self.context.gate_feature("asm", path.span, "inline assembly is not \
235-
stable enough for use and is subject to change");
239+
self.context.gate_feature("asm", path.span, EXPLAIN_ASM);
236240
}
237241

238242
else if id == token::str_to_ident("log_syntax") {
@@ -594,7 +598,8 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::C
594598
unboxed_closures: cx.has_feature("unboxed_closures"),
595599
rustc_diagnostic_macros: cx.has_feature("rustc_diagnostic_macros"),
596600
visible_private_types: cx.has_feature("visible_private_types"),
597-
quote: cx.has_feature("quote"),
601+
allow_quote: cx.has_feature("quote"),
602+
allow_asm: cx.has_feature("asm"),
598603
old_orphan_check: cx.has_feature("old_orphan_check"),
599604
simd_ffi: cx.has_feature("simd_ffi"),
600605
unmarked_api: cx.has_feature("unmarked_api"),

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 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+
fn main() {
12+
unsafe {
13+
println!("{}", asm!("")); //~ ERROR inline assembly is not stable
14+
}
15+
}

0 commit comments

Comments
 (0)