Skip to content

Commit 5b55f00

Browse files
authored
Unrolled build for rust-lang#118366
Rollup merge of rust-lang#118366 - fmease:detect-reject-malformed-rust-repr, r=compiler-errors Detect and reject malformed `repr(Rust)` hints Fixes rust-lang#118334.
2 parents e06c94d + 16c164f commit 5b55f00

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

compiler/rustc_attr/src/builtin.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
985985
Ok(literal) => acc.push(ReprPacked(literal)),
986986
Err(message) => literal_error = Some(message),
987987
};
988-
} else if matches!(name, sym::C | sym::simd | sym::transparent)
988+
} else if matches!(name, sym::Rust | sym::C | sym::simd | sym::transparent)
989989
|| int_type_of_word(name).is_some()
990990
{
991991
recognised = true;
@@ -1018,7 +1018,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
10181018
});
10191019
} else if matches!(
10201020
meta_item.name_or_empty(),
1021-
sym::C | sym::simd | sym::transparent
1021+
sym::Rust | sym::C | sym::simd | sym::transparent
10221022
) || int_type_of_word(meta_item.name_or_empty()).is_some()
10231023
{
10241024
recognised = true;
@@ -1043,7 +1043,7 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
10431043
);
10441044
} else if matches!(
10451045
meta_item.name_or_empty(),
1046-
sym::C | sym::simd | sym::transparent
1046+
sym::Rust | sym::C | sym::simd | sym::transparent
10471047
) || int_type_of_word(meta_item.name_or_empty()).is_some()
10481048
{
10491049
recognised = true;

tests/ui/repr/issue-83921-ice.rs tests/ui/repr/malformed-repr-hints.rs

+9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ struct S3;
1919
//~^ ERROR: incorrect `repr(align)` attribute format
2020
struct S4;
2121

22+
// Regression test for issue #118334:
23+
#[repr(Rust(u8))]
24+
//~^ ERROR: invalid representation hint
25+
#[repr(Rust(0))]
26+
//~^ ERROR: invalid representation hint
27+
#[repr(Rust = 0)]
28+
//~^ ERROR: invalid representation hint
29+
struct S5;
30+
2231
#[repr(i8())]
2332
//~^ ERROR: invalid representation hint
2433
enum E1 { A, B }
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,64 @@
11
error[E0552]: incorrect `repr(packed)` attribute format: `packed` takes exactly one parenthesized argument, or no parentheses at all
2-
--> $DIR/issue-83921-ice.rs:6:8
2+
--> $DIR/malformed-repr-hints.rs:6:8
33
|
44
LL | #[repr(packed())]
55
| ^^^^^^^^
66

77
error[E0589]: invalid `repr(align)` attribute: `align` needs an argument
8-
--> $DIR/issue-83921-ice.rs:10:8
8+
--> $DIR/malformed-repr-hints.rs:10:8
99
|
1010
LL | #[repr(align)]
1111
| ^^^^^ help: supply an argument here: `align(...)`
1212

1313
error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
14-
--> $DIR/issue-83921-ice.rs:14:8
14+
--> $DIR/malformed-repr-hints.rs:14:8
1515
|
1616
LL | #[repr(align(2, 4))]
1717
| ^^^^^^^^^^^
1818

1919
error[E0693]: incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
20-
--> $DIR/issue-83921-ice.rs:18:8
20+
--> $DIR/malformed-repr-hints.rs:18:8
2121
|
2222
LL | #[repr(align())]
2323
| ^^^^^^^
2424

25+
error[E0552]: invalid representation hint: `Rust` does not take a parenthesized argument list
26+
--> $DIR/malformed-repr-hints.rs:23:8
27+
|
28+
LL | #[repr(Rust(u8))]
29+
| ^^^^^^^^
30+
31+
error[E0552]: invalid representation hint: `Rust` does not take a parenthesized argument list
32+
--> $DIR/malformed-repr-hints.rs:25:8
33+
|
34+
LL | #[repr(Rust(0))]
35+
| ^^^^^^^
36+
37+
error[E0552]: invalid representation hint: `Rust` does not take a value
38+
--> $DIR/malformed-repr-hints.rs:27:8
39+
|
40+
LL | #[repr(Rust = 0)]
41+
| ^^^^^^^^
42+
2543
error[E0552]: invalid representation hint: `i8` does not take a parenthesized argument list
26-
--> $DIR/issue-83921-ice.rs:22:8
44+
--> $DIR/malformed-repr-hints.rs:31:8
2745
|
2846
LL | #[repr(i8())]
2947
| ^^^^
3048

3149
error[E0552]: invalid representation hint: `u32` does not take a parenthesized argument list
32-
--> $DIR/issue-83921-ice.rs:26:8
50+
--> $DIR/malformed-repr-hints.rs:35:8
3351
|
3452
LL | #[repr(u32(42))]
3553
| ^^^^^^^
3654

3755
error[E0552]: invalid representation hint: `i64` does not take a value
38-
--> $DIR/issue-83921-ice.rs:30:8
56+
--> $DIR/malformed-repr-hints.rs:39:8
3957
|
4058
LL | #[repr(i64 = 2)]
4159
| ^^^^^^^
4260

43-
error: aborting due to 7 previous errors
61+
error: aborting due to 10 previous errors
4462

4563
Some errors have detailed explanations: E0552, E0589, E0693.
4664
For more information about an error, try `rustc --explain E0552`.

0 commit comments

Comments
 (0)