mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-13 08:13:21 +00:00
Address the asm!
case of #22234.
This commit is contained in:
parent
20d8222e6a
commit
52bdda778a
@ -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;
|
||||
@ -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;
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
@ -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,
|
||||
@ -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>
|
||||
}
|
||||
@ -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") {
|
||||
@ -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"),
|
||||
|
15
src/test/compile-fail/asm-gated2.rs
Normal file
15
src/test/compile-fail/asm-gated2.rs
Normal file
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user