From b27bb8359275939608ce155f042c67dcd1bb7f39 Mon Sep 17 00:00:00 2001 From: Aditya-PS-05 Date: Fri, 28 Nov 2025 00:55:07 +0530 Subject: [PATCH 1/2] add regression test for align attribute on struct fields --- tests/ui/attributes/align-on-fields-143987.rs | 30 +++++++++++++++++ .../attributes/align-on-fields-143987.stderr | 33 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 tests/ui/attributes/align-on-fields-143987.rs create mode 100644 tests/ui/attributes/align-on-fields-143987.stderr 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..387e8f80e54d2 --- /dev/null +++ b/tests/ui/attributes/align-on-fields-143987.rs @@ -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() {} 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`. From 3ceea4768bed17c188ebc73866d5c2c13bf953e5 Mon Sep 17 00:00:00 2001 From: Aditya-PS-05 Date: Fri, 28 Nov 2025 01:15:22 +0530 Subject: [PATCH 2/2] add issue link in test --- tests/ui/attributes/align-on-fields-143987.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/attributes/align-on-fields-143987.rs b/tests/ui/attributes/align-on-fields-143987.rs index 387e8f80e54d2..7abd61a264995 100644 --- a/tests/ui/attributes/align-on-fields-143987.rs +++ b/tests/ui/attributes/align-on-fields-143987.rs @@ -1,4 +1,4 @@ -// Regression test for issue #143987 +// 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)