Skip to content

Commit 147a597

Browse files
authored
Unrolled build for #149398
Rollup merge of #149398 - Aditya-PS-05:test-issue-143987-align-struct-fields, r=Kivooeo add regression test for issue #143987 closes #143987
2 parents 9050733 + 3ceea47 commit 147a597

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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() {}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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`.

0 commit comments

Comments
 (0)