add regression test for align attribute on struct fields

This commit is contained in:
Aditya-PS-05 2025-11-28 00:55:07 +05:30
parent a4175159da
commit b27bb83592
2 changed files with 63 additions and 0 deletions

View file

@ -0,0 +1,30 @@
// Regression test for issue #143987
// Ensure that using `#[align]` on struct fields produces an error
// instead of causing an ICE (Internal Compiler Error)
// FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity
#![feature(rustc_attrs)]
#![feature(fn_align)]
struct Data {
#[rustc_align(8)] //~ ERROR `#[rustc_align]` attribute cannot be used on struct fields
x: usize,
}
// Test with invalid type to match the original issue more closely
struct DataInvalid {
#[rustc_align(8)] //~ ERROR `#[rustc_align]` attribute cannot be used on struct fields
x: usize8, //~ ERROR cannot find type `usize8` in this scope
}
// Test with tuple struct
struct TupleData(
#[rustc_align(32)] //~ ERROR `#[rustc_align]` attribute cannot be used on struct fields
u32
);
// Test that it works correctly on functions (no error)
#[rustc_align(16)]
fn aligned_function() {}
fn main() {}

View file

@ -0,0 +1,33 @@
error[E0412]: cannot find type `usize8` in this scope
--> $DIR/align-on-fields-143987.rs:17:8
|
LL | x: usize8,
| ^^^^^^ help: a builtin type with a similar name exists: `usize`
error: `#[rustc_align]` attribute cannot be used on struct fields
--> $DIR/align-on-fields-143987.rs:10:5
|
LL | #[rustc_align(8)]
| ^^^^^^^^^^^^^^^^^
|
= help: `#[rustc_align]` can only be applied to functions
error: `#[rustc_align]` attribute cannot be used on struct fields
--> $DIR/align-on-fields-143987.rs:16:5
|
LL | #[rustc_align(8)]
| ^^^^^^^^^^^^^^^^^
|
= help: `#[rustc_align]` can only be applied to functions
error: `#[rustc_align]` attribute cannot be used on struct fields
--> $DIR/align-on-fields-143987.rs:22:5
|
LL | #[rustc_align(32)]
| ^^^^^^^^^^^^^^^^^^
|
= help: `#[rustc_align]` can only be applied to functions
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0412`.