Skip to content

Commit ae9e03c

Browse files
committed
stabilize repr(align(N)) on function items
1 parent dc8fe1f commit ae9e03c

17 files changed

+26
-73
lines changed

compiler/rustc_feature/src/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ declare_features! (
214214
(accepted, f16c_target_feature, "1.68.0", Some(44839)),
215215
/// Allows field shorthands (`x` meaning `x: x`) in struct literal expressions.
216216
(accepted, field_init_shorthand, "1.17.0", Some(37340)),
217+
/// Allows using `#[repr(align(...))]` on function items
218+
(accepted, fn_align, "CURRENT_RUSTC_VERSION", Some(82232)),
217219
/// Allows `#[must_use]` on functions, and introduces must-use operators (RFC 1940).
218220
(accepted, fn_must_use, "1.27.0", Some(43302)),
219221
/// Allows capturing variables in scope using format_args!

compiler/rustc_feature/src/unstable.rs

-2
Original file line numberDiff line numberDiff line change
@@ -496,8 +496,6 @@ declare_features! (
496496
(unstable, ffi_pure, "1.45.0", Some(58329)),
497497
/// Controlling the behavior of fmt::Debug
498498
(unstable, fmt_debug, "1.82.0", Some(129709)),
499-
/// Allows using `#[repr(align(...))]` on function items
500-
(unstable, fn_align, "1.53.0", Some(82232)),
501499
/// Support delegating implementation of functions to other already implemented functions.
502500
(incomplete, fn_delegation, "1.76.0", Some(118212)),
503501
/// Allows impls for the Freeze trait.

compiler/rustc_passes/messages.ftl

-3
Original file line numberDiff line numberDiff line change
@@ -629,9 +629,6 @@ passes_remove_fields =
629629
*[other] fields
630630
}
631631
632-
passes_repr_align_function =
633-
`repr(align)` attributes on functions are unstable
634-
635632
passes_repr_align_greater_than_target_max =
636633
alignment must not be greater than `isize::MAX` bytes
637634
.note = `isize::MAX` is {$size} for the current target

compiler/rustc_passes/src/check_attr.rs

+2-20
Original file line numberDiff line numberDiff line change
@@ -1975,17 +1975,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
19751975
ReprAttr::ReprAlign(align) => {
19761976
match target {
19771977
Target::Struct | Target::Union | Target::Enum => {}
1978-
Target::Fn | Target::Method(_) => {
1979-
if !self.tcx.features().fn_align() {
1980-
feature_err(
1981-
&self.tcx.sess,
1982-
sym::fn_align,
1983-
*repr_span,
1984-
fluent::passes_repr_align_function,
1985-
)
1986-
.emit();
1987-
}
1988-
}
1978+
Target::Fn | Target::Method(_) => {}
19891979
_ => {
19901980
self.dcx().emit_err(
19911981
errors::AttrApplication::StructEnumFunctionMethodUnion {
@@ -2049,15 +2039,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
20492039
if item.is_some() {
20502040
match target {
20512041
Target::Struct | Target::Union | Target::Enum => continue,
2052-
Target::Fn | Target::Method(_) => {
2053-
feature_err(
2054-
&self.tcx.sess,
2055-
sym::fn_align,
2056-
*repr_span,
2057-
fluent::passes_repr_align_function,
2058-
)
2059-
.emit();
2060-
}
2042+
Target::Fn | Target::Method(_) => continue,
20612043
_ => {
20622044
self.dcx().emit_err(
20632045
errors::AttrApplication::StructEnumFunctionMethodUnion {

src/tools/miri/tests/pass/fn_align.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@compile-flags: -Zmin-function-alignment=8
2-
#![feature(fn_align)]
32

43
// When a function uses `repr(align(N))`, the function address should be a multiple of `N`.
54

tests/assembly/naked-functions/aix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//@[aix] needs-llvm-components: powerpc
1010

1111
#![crate_type = "lib"]
12-
#![feature(no_core, asm_experimental_arch, f128, linkage, fn_align)]
12+
#![feature(no_core, asm_experimental_arch, f128, linkage)]
1313
#![no_core]
1414

1515
// tests that naked functions work for the `powerpc64-ibm-aix` target.

tests/assembly/naked-functions/wasm32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//@ [wasm32-wasip1] needs-llvm-components: webassembly
1010

1111
#![crate_type = "lib"]
12-
#![feature(no_core, asm_experimental_arch, f128, linkage, fn_align)]
12+
#![feature(no_core, asm_experimental_arch, f128, linkage)]
1313
#![no_core]
1414

1515
extern crate minicore;

tests/codegen/align-fn.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0
22

33
#![crate_type = "lib"]
4-
#![feature(fn_align)]
54

65
// CHECK: align 16
76
#[no_mangle]

tests/codegen/min-function-alignment.rs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//@ [align1024] compile-flags: -Zmin-function-alignment=1024
55

66
#![crate_type = "lib"]
7-
#![feature(fn_align)]
87

98
// functions without explicit alignment use the global minimum
109
//

tests/codegen/naked-fn/aligned.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//@ ignore-arm no "ret" mnemonic
44

55
#![crate_type = "lib"]
6-
#![feature(fn_align)]
76
use std::arch::naked_asm;
87

98
// CHECK: .balign 16

tests/codegen/naked-fn/min-function-alignment.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//@ needs-asm-support
33
//@ ignore-arm no "ret" mnemonic
44

5-
#![feature(fn_align)]
65
#![crate_type = "lib"]
76

87
// functions without explicit alignment use the global minimum

tests/ui/asm/naked-with-invalid-repr-attr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ needs-asm-support
2-
#![feature(fn_align)]
32
#![crate_type = "lib"]
43
use std::arch::naked_asm;
54

tests/ui/asm/naked-with-invalid-repr-attr.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0517]: attribute should be applied to a struct, enum, or union
2-
--> $DIR/naked-with-invalid-repr-attr.rs:6:8
2+
--> $DIR/naked-with-invalid-repr-attr.rs:5:8
33
|
44
LL | #[repr(C)]
55
| ^
@@ -11,7 +11,7 @@ LL | | }
1111
| |_- not a struct, enum, or union
1212

1313
error[E0517]: attribute should be applied to a struct, enum, or union
14-
--> $DIR/naked-with-invalid-repr-attr.rs:14:8
14+
--> $DIR/naked-with-invalid-repr-attr.rs:13:8
1515
|
1616
LL | #[repr(transparent)]
1717
| ^^^^^^^^^^^
@@ -23,7 +23,7 @@ LL | | }
2323
| |_- not a struct, enum, or union
2424

2525
error[E0517]: attribute should be applied to a struct, enum, or union
26-
--> $DIR/naked-with-invalid-repr-attr.rs:22:19
26+
--> $DIR/naked-with-invalid-repr-attr.rs:21:19
2727
|
2828
LL | #[repr(align(16), C)]
2929
| ^
@@ -35,7 +35,7 @@ LL | | }
3535
| |_- not a struct, enum, or union
3636

3737
error[E0517]: attribute should be applied to a struct, enum, or union
38-
--> $DIR/naked-with-invalid-repr-attr.rs:31:8
38+
--> $DIR/naked-with-invalid-repr-attr.rs:30:8
3939
|
4040
LL | #[repr(C, packed)]
4141
| ^
@@ -48,7 +48,7 @@ LL | | }
4848
| |_- not a struct, enum, or union
4949

5050
error[E0517]: attribute should be applied to a struct or union
51-
--> $DIR/naked-with-invalid-repr-attr.rs:31:11
51+
--> $DIR/naked-with-invalid-repr-attr.rs:30:11
5252
|
5353
LL | #[repr(C, packed)]
5454
| ^^^^^^
@@ -61,7 +61,7 @@ LL | | }
6161
| |_- not a struct or union
6262

6363
error[E0517]: attribute should be applied to an enum
64-
--> $DIR/naked-with-invalid-repr-attr.rs:41:8
64+
--> $DIR/naked-with-invalid-repr-attr.rs:40:8
6565
|
6666
LL | #[repr(u8)]
6767
| ^^
+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
#![feature(fn_align)]
21
#![crate_type = "lib"]
32

43
trait MyTrait {
54
#[repr(align)] //~ ERROR invalid `repr(align)` attribute: `align` needs an argument
6-
fn myfun();
5+
fn myfun1();
6+
7+
#[repr(align(1, 2))] //~ ERROR incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
8+
fn myfun2();
79
}
+10-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
error[E0589]: invalid `repr(align)` attribute: `align` needs an argument
2-
--> $DIR/malformed-fn-align.rs:5:12
2+
--> $DIR/malformed-fn-align.rs:4:12
33
|
44
LL | #[repr(align)]
55
| ^^^^^ help: supply an argument here: `align(...)`
66

7-
error: aborting due to 1 previous error
7+
error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
8+
--> $DIR/malformed-fn-align.rs:7:12
9+
|
10+
LL | #[repr(align(1, 2))]
11+
| ^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
814

9-
For more information about this error, try `rustc --explain E0589`.
15+
Some errors have detailed explanations: E0589, E0693.
16+
For more information about an error, try `rustc --explain E0589`.

tests/ui/feature-gates/feature-gate-fn_align.rs

-9
This file was deleted.

tests/ui/feature-gates/feature-gate-fn_align.stderr

-20
This file was deleted.

0 commit comments

Comments
 (0)