Skip to content

Commit

Permalink
Address the asm! case of #22234.
Browse files Browse the repository at this point in the history
  • Loading branch information
pnkfelix committed Feb 15, 2015
1 parent 20d8222 commit 52bdda7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/libsyntax/ext/asm.rs
Expand Up @@ -18,6 +18,7 @@ use codemap;
use codemap::Span;
use ext::base;
use ext::base::*;
use feature_gate;
use parse::token::InternedString;
use parse::token;
use ptr::P;
Expand Down Expand Up @@ -48,6 +49,12 @@ static OPTIONS: &'static [&'static str] = &["volatile", "alignstack", "intel"];

pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
-> Box<base::MacResult+'cx> {
if !cx.ecfg.enable_asm() {
feature_gate::emit_feature_err(
&cx.parse_sess.span_diagnostic, "asm", sp, feature_gate::EXPLAIN_ASM);
return DummyResult::expr(sp);
}

let mut p = cx.new_parser_from_tts(tts);
let mut asm = InternedString::new("");
let mut asm_str_style = None;
Expand Down
9 changes: 8 additions & 1 deletion src/libsyntax/ext/expand.rs
Expand Up @@ -1425,7 +1425,14 @@ impl<'feat> ExpansionConfig<'feat> {

pub fn enable_quotes(&self) -> bool {
match self.features {
Some(&Features { quote: true, .. }) => true,
Some(&Features { allow_quote: true, .. }) => true,
_ => false,
}
}

pub fn enable_asm(&self) -> bool {
match self.features {
Some(&Features { allow_asm: true, .. }) => true,
_ => false,
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/libsyntax/feature_gate.rs
Expand Up @@ -156,7 +156,8 @@ pub struct Features {
pub unboxed_closures: bool,
pub rustc_diagnostic_macros: bool,
pub visible_private_types: bool,
pub quote: bool,
pub allow_quote: bool,
pub allow_asm: bool,
pub old_orphan_check: bool,
pub simd_ffi: bool,
pub unmarked_api: bool,
Expand All @@ -172,7 +173,8 @@ impl Features {
unboxed_closures: false,
rustc_diagnostic_macros: false,
visible_private_types: false,
quote: false,
allow_quote: false,
allow_asm: false,
old_orphan_check: false,
simd_ffi: false,
unmarked_api: false,
Expand Down Expand Up @@ -221,6 +223,9 @@ pub fn emit_feature_warn(diag: &SpanHandler, feature: &str, span: Span, explain:
}
}

pub const EXPLAIN_ASM: &'static str =
"inline assembly is not stable enough for use and is subject to change";

struct MacroVisitor<'a> {
context: &'a Context<'a>
}
Expand All @@ -231,8 +236,7 @@ impl<'a, 'v> Visitor<'v> for MacroVisitor<'a> {
let id = path.segments.last().unwrap().identifier;

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

else if id == token::str_to_ident("log_syntax") {
Expand Down Expand Up @@ -594,7 +598,8 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::C
unboxed_closures: cx.has_feature("unboxed_closures"),
rustc_diagnostic_macros: cx.has_feature("rustc_diagnostic_macros"),
visible_private_types: cx.has_feature("visible_private_types"),
quote: cx.has_feature("quote"),
allow_quote: cx.has_feature("quote"),
allow_asm: cx.has_feature("asm"),
old_orphan_check: cx.has_feature("old_orphan_check"),
simd_ffi: cx.has_feature("simd_ffi"),
unmarked_api: cx.has_feature("unmarked_api"),
Expand Down
15 changes: 15 additions & 0 deletions src/test/compile-fail/asm-gated2.rs
@@ -0,0 +1,15 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
unsafe {
println!("{}", asm!("")); //~ ERROR inline assembly is not stable
}
}

0 comments on commit 52bdda7

Please sign in to comment.