File tree Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change 1+ // Regression test for issue https://github.com/rust-lang/rust/issues/143987
2+ // Ensure that using `#[align]` on struct fields produces an error
3+ // instead of causing an ICE (Internal Compiler Error)
4+
5+ // FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
6+ #![ feature( rustc_attrs) ]
7+ #![ feature( fn_align) ]
8+
9+ struct Data {
10+ #[ rustc_align( 8 ) ] //~ ERROR `#[rustc_align]` attribute cannot be used on struct fields
11+ x : usize ,
12+ }
13+
14+ // Test with invalid type to match the original issue more closely
15+ struct DataInvalid {
16+ #[ rustc_align( 8 ) ] //~ ERROR `#[rustc_align]` attribute cannot be used on struct fields
17+ x : usize8 , //~ ERROR cannot find type `usize8` in this scope
18+ }
19+
20+ // Test with tuple struct
21+ struct TupleData (
22+ #[ rustc_align( 32 ) ] //~ ERROR `#[rustc_align]` attribute cannot be used on struct fields
23+ u32
24+ ) ;
25+
26+ // Test that it works correctly on functions (no error)
27+ #[ rustc_align( 16 ) ]
28+ fn aligned_function ( ) { }
29+
30+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error[E0412]: cannot find type `usize8` in this scope
2+ --> $DIR/align-on-fields-143987.rs:17:8
3+ |
4+ LL | x: usize8,
5+ | ^^^^^^ help: a builtin type with a similar name exists: `usize`
6+
7+ error: `#[rustc_align]` attribute cannot be used on struct fields
8+ --> $DIR/align-on-fields-143987.rs:10:5
9+ |
10+ LL | #[rustc_align(8)]
11+ | ^^^^^^^^^^^^^^^^^
12+ |
13+ = help: `#[rustc_align]` can only be applied to functions
14+
15+ error: `#[rustc_align]` attribute cannot be used on struct fields
16+ --> $DIR/align-on-fields-143987.rs:16:5
17+ |
18+ LL | #[rustc_align(8)]
19+ | ^^^^^^^^^^^^^^^^^
20+ |
21+ = help: `#[rustc_align]` can only be applied to functions
22+
23+ error: `#[rustc_align]` attribute cannot be used on struct fields
24+ --> $DIR/align-on-fields-143987.rs:22:5
25+ |
26+ LL | #[rustc_align(32)]
27+ | ^^^^^^^^^^^^^^^^^^
28+ |
29+ = help: `#[rustc_align]` can only be applied to functions
30+
31+ error: aborting due to 4 previous errors
32+
33+ For more information about this error, try `rustc --explain E0412`.
You can’t perform that action at this time.
0 commit comments