Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b4ca2de

Browse files
authoredMar 17, 2025
Unrolled build for rust-lang#133870
Rollup merge of rust-lang#133870 - nbdd0121:asm, r=traviscross,nnethercote Stabilize `asm_goto` feature gate Stabilize `asm_goto` feature (tracked by rust-lang#119364). The issue will remain open and be updated to track `asm_goto_with_outputs`. Reference PR: rust-lang/reference#1693 # Stabilization Report This feature adds a `label <block>` operand type to `asm!`. `<block>` must be a block expression with type unit or never. The address of the block is substituted and the assembly may jump to the block. When block completes the `asm!` block returns and continues execution. The block starts a new safety context and unsafe operations within must have additional `unsafe`s; the effect of `unsafe` that surrounds `asm!` block is cancelled. See rust-lang#119364 (comment) and rust-lang#131544. It's currently forbidden to use `asm_goto` with output operands; that is still unstable under `asm_goto_with_outputs`. Example: ```rust unsafe { asm!( "jmp {}", label { println!("Jumped from asm!"); } ); } ``` Tests: - tests/ui/asm/x86_64/goto.rs - tests/ui/asm/x86_64/goto-block-safe.stderr - tests/ui/asm/x86_64/bad-options.rs - tests/codegen/asm/goto.rs
2 parents 8279176 + 292c622 commit b4ca2de

15 files changed

+36
-80
lines changed
 

‎compiler/rustc_ast_lowering/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,6 @@ ast_lowering_underscore_expr_lhs_assign =
185185
ast_lowering_unstable_inline_assembly = inline assembly is not stable yet on this architecture
186186
ast_lowering_unstable_inline_assembly_label_operand_with_outputs =
187187
using both label and output operands for inline assembly is unstable
188-
ast_lowering_unstable_inline_assembly_label_operands =
189-
label operands for inline assembly are unstable
190188
ast_lowering_unstable_may_unwind = the `may_unwind` option is unstable
191189
192190
ast_lowering_use_angle_brackets = use angle brackets instead

‎compiler/rustc_ast_lowering/src/asm.rs

+2-13
Original file line numberDiff line numberDiff line change
@@ -470,22 +470,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
470470
}
471471
}
472472

473-
// Feature gate checking for asm goto.
473+
// Feature gate checking for `asm_goto_with_outputs`.
474474
if let Some((_, op_sp)) =
475475
operands.iter().find(|(op, _)| matches!(op, hir::InlineAsmOperand::Label { .. }))
476476
{
477-
if !self.tcx.features().asm_goto() {
478-
feature_err(
479-
sess,
480-
sym::asm_goto,
481-
*op_sp,
482-
fluent::ast_lowering_unstable_inline_assembly_label_operands,
483-
)
484-
.emit();
485-
}
486-
487-
// In addition, check if an output operand is used.
488-
// This is gated behind an additional feature.
477+
// Check if an output operand is used.
489478
let output_operand_used = operands.iter().any(|(op, _)| {
490479
matches!(
491480
op,

‎compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ declare_features! (
6262
(accepted, arbitrary_enum_discriminant, "1.66.0", Some(60553)),
6363
/// Allows using `const` operands in inline assembly.
6464
(accepted, asm_const, "1.82.0", Some(93332)),
65+
/// Allows using `label` operands in inline assembly.
66+
(accepted, asm_goto, "CURRENT_RUSTC_VERSION", Some(119364)),
6567
/// Allows using `sym` operands in inline assembly.
6668
(accepted, asm_sym, "1.66.0", Some(93333)),
6769
/// Allows the definition of associated constants in `trait` or `impl` blocks.

‎compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,6 @@ declare_features! (
372372
(unstable, asm_experimental_arch, "1.58.0", Some(93335)),
373373
/// Enables experimental register support in inline assembly.
374374
(unstable, asm_experimental_reg, "1.85.0", Some(133416)),
375-
/// Allows using `label` operands in inline assembly.
376-
(unstable, asm_goto, "1.78.0", Some(119364)),
377375
/// Allows using `label` operands in inline assembly together with output operands.
378376
(unstable, asm_goto_with_outputs, "1.85.0", Some(119364)),
379377
/// Allows the `may_unwind` option in inline assembly.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# `asm_goto_with_outputs`
2+
3+
The tracking issue for this feature is: [#119364]
4+
5+
[#119364]: https://github.com/rust-lang/rust/issues/119364
6+
7+
------------------------
8+
9+
This feature allows label operands to be used together with output operands.
10+
11+
Example:
12+
```rust,ignore (partial-example, x86-only)
13+
14+
unsafe {
15+
let a: usize;
16+
asm!(
17+
"mov {}, 1"
18+
"jmp {}",
19+
out(reg) a,
20+
label {
21+
println!("Jumped from asm {}!", a);
22+
}
23+
);
24+
}
25+
```
26+
27+
The output operands are assigned before the label blocks are executed.

‎src/doc/unstable-book/src/language-features/asm-goto.md

-32
This file was deleted.

‎tests/codegen/asm/goto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//@ only-x86_64
33

44
#![crate_type = "rlib"]
5-
#![feature(asm_goto, asm_goto_with_outputs)]
5+
#![feature(asm_goto_with_outputs)]
66

77
use std::arch::asm;
88

‎tests/ui/asm/x86_64/bad-options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ only-x86_64
22

3-
#![feature(asm_unwind, asm_goto)]
3+
#![feature(asm_unwind)]
44

55
use std::arch::{asm, global_asm};
66

‎tests/ui/asm/x86_64/goto-block-safe.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//@ needs-asm-support
33

44
#![deny(unreachable_code)]
5-
#![feature(asm_goto)]
65

76
use std::arch::asm;
87

‎tests/ui/asm/x86_64/goto-block-safe.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0133]: call to unsafe function `unreachable_unchecked` is unsafe and requires unsafe function or block
2-
--> $DIR/goto-block-safe.rs:14:17
2+
--> $DIR/goto-block-safe.rs:13:17
33
|
44
LL | unsafe {
55
| ------ items do not inherit unsafety from separate enclosing items

‎tests/ui/asm/x86_64/goto.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//@ needs-asm-support
44

55
#![deny(unreachable_code)]
6-
#![feature(asm_goto, asm_goto_with_outputs)]
6+
#![feature(asm_goto_with_outputs)]
77

88
use std::arch::asm;
99

‎tests/ui/feature-gates/feature-gate-asm_goto.rs

-10
This file was deleted.

‎tests/ui/feature-gates/feature-gate-asm_goto.stderr

-13
This file was deleted.

‎tests/ui/feature-gates/feature-gate-asm_goto_with_outputs.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ only-x86_64
22

3-
#![feature(asm_goto)]
4-
53
use std::arch::asm;
64

75
fn main() {

‎tests/ui/feature-gates/feature-gate-asm_goto_with_outputs.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0658]: using both label and output operands for inline assembly is unstable
2-
--> $DIR/feature-gate-asm_goto_with_outputs.rs:10:52
2+
--> $DIR/feature-gate-asm_goto_with_outputs.rs:8:52
33
|
44
LL | asm!("mov {}, 1", "jmp {}", out(reg) _out, label {});
55
| ^^^^^^^^

0 commit comments

Comments
 (0)
Failed to load comments.