diff --git a/tests/ui/attributes/align-on-fields-143987.rs b/tests/ui/attributes/align-on-fields-143987.rs new file mode 100644 index 0000000000000..7abd61a264995 --- /dev/null +++ b/tests/ui/attributes/align-on-fields-143987.rs @@ -0,0 +1,30 @@ +// Regression test for issue https://github.com/rust-lang/rust/issues/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() {} diff --git a/tests/ui/attributes/align-on-fields-143987.stderr b/tests/ui/attributes/align-on-fields-143987.stderr new file mode 100644 index 0000000000000..2356cdb1e5fb9 --- /dev/null +++ b/tests/ui/attributes/align-on-fields-143987.stderr @@ -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`.