Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions tests/ui/attributes/align-on-fields-143987.rs
Original file line number Diff line number Diff line change
@@ -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() {}
33 changes: 33 additions & 0 deletions tests/ui/attributes/align-on-fields-143987.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Loading