diff options
| author | bors <bors@rust-lang.org> | 2021-11-07 04:59:42 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-11-07 04:59:42 +0000 |
| commit | 90a273b785b3bc482b82c4896ba1bdea68745e46 (patch) | |
| tree | 9cd6cd6c8bd91cc49309a564e9079e3e010d8f47 /compiler | |
| parent | 88b4ea8fb67ff5f754366157cbd98d9813253d93 (diff) | |
| parent | 87d0d64b7869c9cb0be7cad957b2b3939ed15fdc (diff) | |
| download | rust-90a273b785b3bc482b82c4896ba1bdea68745e46.tar.gz rust-90a273b785b3bc482b82c4896ba1bdea68745e46.zip | |
Auto merge of #90348 - Amanieu:asm_feature_gates, r=joshtriplett
Add features gates for experimental asm features This PR splits off parts of `asm!` into separate features because they are not ready for stabilization. Specifically this adds: - `asm_const` for `const` operands. - `asm_sym` for `sym` operands. - `asm_experimental_arch` for architectures other than x86, x86_64, arm, aarch64 and riscv. r? `@nagisa`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_ast_lowering/src/asm.rs | 50 | ||||
| -rw-r--r-- | compiler/rustc_feature/src/active.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_span/src/symbol.rs | 3 |
3 files changed, 58 insertions, 4 deletions
diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index d0da88f1cc0..95997a37d84 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -4,7 +4,8 @@ use rustc_ast::*; use rustc_data_structures::fx::FxHashMap; use rustc_errors::struct_span_err; use rustc_hir as hir; -use rustc_span::{Span, Symbol}; +use rustc_session::parse::feature_err; +use rustc_span::{sym, Span, Symbol}; use rustc_target::asm; use std::collections::hash_map::Entry; use std::fmt::Write; @@ -18,6 +19,27 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { struct_span_err!(self.sess, sp, E0472, "inline assembly is unsupported on this target") .emit(); } + if let Some(asm_arch) = asm_arch { + // Inline assembly is currently only stable for these architectures. + let is_stable = matches!( + asm_arch, + asm::InlineAsmArch::X86 + | asm::InlineAsmArch::X86_64 + | asm::InlineAsmArch::Arm + | asm::InlineAsmArch::AArch64 + | asm::InlineAsmArch::RiscV32 + | asm::InlineAsmArch::RiscV64 + ); + if !is_stable && !self.sess.features_untracked().asm_experimental_arch { + feature_err( + &self.sess.parse_sess, + sym::asm_experimental_arch, + sp, + "inline assembly is not stable yet on this architecture", + ) + .emit(); + } + } if asm.options.contains(InlineAsmOptions::ATT_SYNTAX) && !matches!(asm_arch, Some(asm::InlineAsmArch::X86 | asm::InlineAsmArch::X86_64)) && !self.sess.opts.actually_rustdoc @@ -121,10 +143,30 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { out_expr: out_expr.as_ref().map(|expr| self.lower_expr_mut(expr)), } } - InlineAsmOperand::Const { ref anon_const } => hir::InlineAsmOperand::Const { - anon_const: self.lower_anon_const(anon_const), - }, + InlineAsmOperand::Const { ref anon_const } => { + if !self.sess.features_untracked().asm_const { + feature_err( + &self.sess.parse_sess, + sym::asm_const, + *op_sp, + "const operands for inline assembly are unstable", + ) + .emit(); + } + hir::InlineAsmOperand::Const { + anon_const: self.lower_anon_const(anon_const), + } + } InlineAsmOperand::Sym { ref expr } => { + if !self.sess.features_untracked().asm_sym { + feature_err( + &self.sess.parse_sess, + sym::asm_sym, + *op_sp, + "sym operands for inline assembly are unstable", + ) + .emit(); + } hir::InlineAsmOperand::Sym { expr: self.lower_expr_mut(expr) } } }; diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 1c6f1344e8a..0266b7844ba 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -692,6 +692,15 @@ declare_features! ( /// Tells rustdoc to automatically generate `#[doc(cfg(...))]`. (active, doc_auto_cfg, "1.58.0", Some(43781), None), + /// Allows using `const` operands in inline assembly. + (active, asm_const, "1.58.0", Some(72016), None), + + /// Allows using `sym` operands in inline assembly. + (active, asm_sym, "1.58.0", Some(72016), None), + + /// Enables experimental inline assembly support for additional architectures. + (active, asm_experimental_arch, "1.58.0", Some(72016), None), + // ------------------------------------------------------------------------- // feature-group-end: actual feature gates // ------------------------------------------------------------------------- diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 52e2a8f48e2..b9730a1e420 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -327,6 +327,9 @@ symbols! { as_ptr, as_str, asm, + asm_const, + asm_experimental_arch, + asm_sym, assert, assert_inhabited, assert_macro, |
