Make asm_goto_with_outputs a separate feature gate · rust-lang/rust@0178ba2 (original) (raw)

8 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -181,6 +181,8 @@ ast_lowering_underscore_expr_lhs_assign =
181 181 .label = `_` not allowed here
182 182
183 183 ast_lowering_unstable_inline_assembly = inline assembly is not stable yet on this architecture
184 +ast_lowering_unstable_inline_assembly_label_operand_with_outputs =
185 + using both label and output operands for inline assembly is unstable
184 186 ast_lowering_unstable_inline_assembly_label_operands =
185 187 label operands for inline assembly are unstable
186 188 ast_lowering_unstable_may_unwind = the `may_unwind` option is unstable
Original file line number Diff line number Diff line change
@@ -239,15 +239,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
239 239 }
240 240 }
241 241 InlineAsmOperand::Label { block } => {
242 -if !self.tcx.features().asm_goto() {
243 -feature_err(
244 - sess,
245 - sym::asm_goto,
246 -*op_sp,
247 - fluent::ast_lowering_unstable_inline_assembly_label_operands,
248 -)
249 -.emit();
250 -}
251 242 hir::InlineAsmOperand::Label { block: self.lower_block(block, false) }
252 243 }
253 244 };
@@ -466,6 +457,41 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
466 457 }
467 458 }
468 459
460 +// Feature gate checking for asm goto.
461 +if let Some((_, op_sp)) =
462 + operands.iter().find(|(op, _)
463 +{
464 +if !self.tcx.features().asm_goto() {
465 +feature_err(
466 + sess,
467 + sym::asm_goto,
468 +*op_sp,
469 + fluent::ast_lowering_unstable_inline_assembly_label_operands,
470 +)
471 +.emit();
472 +}
473 +
474 +// In addition, check if an output operand is used.
475 +// This is gated behind an additional feature.
476 +let output_operand_used = operands.iter().any(|(op, _)
477 +matches!(
478 + op,
479 + hir::InlineAsmOperand::Out { expr: Some(_), .. }
480 + | hir::InlineAsmOperand::InOut { .. }
481 + | hir::InlineAsmOperand::SplitInOut { out_expr: Some(_), .. }
482 +)
483 +});
484 +if output_operand_used && !self.tcx.features().asm_goto_with_outputs() {
485 +feature_err(
486 + sess,
487 + sym::asm_goto_with_outputs,
488 +*op_sp,
489 + fluent::ast_lowering_unstable_inline_assembly_label_operand_with_outputs,
490 +)
491 +.emit();
492 +}
493 +}
494 +
469 495 let operands = self.arena.alloc_from_iter(operands);
470 496 let template = self.arena.alloc_from_iter(asm.template.iter().cloned());
471 497 let template_strs = self.arena.alloc_from_iter(
Original file line number Diff line number Diff line change
@@ -378,6 +378,8 @@ declare_features! (
378 378 (unstable, asm_experimental_arch, "1.58.0", Some(93335)),
379 379 /// Allows using `label` operands in inline assembly.
380 380 (unstable, asm_goto, "1.78.0", Some(119364)),
381 +/// Allows using `label` operands in inline assembly together with output operands.
382 + (unstable, asm_goto_with_outputs, "CURRENT_RUSTC_VERSION", Some(119364)),
381 383 /// Allows the `may_unwind` option in inline assembly.
382 384 (unstable, asm_unwind, "1.58.0", Some(93334)),
383 385 /// Allows users to enforce equality of associated constants `TraitImpl<AssocConst=3>`.
Original file line number Diff line number Diff line change
@@ -417,6 +417,7 @@ symbols! {
417 417 asm_const,
418 418 asm_experimental_arch,
419 419 asm_goto,
420 + asm_goto_with_outputs,
420 421 asm_sym,
421 422 asm_unwind,
422 423 assert,
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
2 2 //@ only-x86_64
3 3
4 4 #![crate_type = "rlib"]
5 -#![feature(asm_goto)]
5 +#![feature(asm_goto, asm_goto_with_outputs)]
6 6
7 7 use std::arch::asm;
8 8
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
3 3 //@ needs-asm-support
4 4
5 5 #![deny(unreachable_code)]
6 -#![feature(asm_goto)]
6 +#![feature(asm_goto, asm_goto_with_outputs)]
7 7
8 8 use std::arch::asm;
9 9
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
1 +//@ only-x86_64
2 +
3 +#![feature(asm_goto)]
4 +
5 +use std::arch::asm;
6 +
7 +fn main() {
8 +let mut _out: u64;
9 +unsafe {
10 +asm!("mov {}, 1", "jmp {}", out(reg) _out, label {});
11 +//~^ ERROR using both label and output operands for inline assembly is unstable
12 +}
13 +}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
1 +error[E0658]: using both label and output operands for inline assembly is unstable
2 + --> $DIR/feature-gate-asm_goto_with_outputs.rs:10:52
3 + |
4 +LL | asm!("mov {}, 1", "jmp {}", out(reg) _out, label {});
5 + | ^^^^^^^^
6 + |
7 + = note: see issue #119364 https://github.com/rust-lang/rust/issues/119364 for more information
8 + = help: add `#![feature(asm_goto_with_outputs)]` to the crate attributes to enable
9 + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10 +
11 +error: aborting due to 1 previous error
12 +
13 +For more information about this error, try `rustc --explain E0658`.