Skip to content

Commit f68d05c

Browse files
authored
Rollup merge of #101486 - asquared31415:invalid_repr_list, r=estebank
Add list of recognized repr attributes to the unrecognized repr error
2 parents 1d49dce + ad275f5 commit f68d05c

File tree

5 files changed

+67
-12
lines changed

5 files changed

+67
-12
lines changed

compiler/rustc_attr/src/builtin.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -1045,18 +1045,16 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
10451045
&name,
10461046
),
10471047
});
1048-
} else {
1049-
if matches!(
1050-
meta_item.name_or_empty(),
1051-
sym::C | sym::simd | sym::transparent
1052-
) || int_type_of_word(meta_item.name_or_empty()).is_some()
1053-
{
1054-
recognised = true;
1055-
sess.emit_err(session_diagnostics::InvalidReprHintNoValue {
1056-
span: meta_item.span,
1057-
name: meta_item.name_or_empty().to_ident_string(),
1058-
});
1059-
}
1048+
} else if matches!(
1049+
meta_item.name_or_empty(),
1050+
sym::C | sym::simd | sym::transparent
1051+
) || int_type_of_word(meta_item.name_or_empty()).is_some()
1052+
{
1053+
recognised = true;
1054+
sess.emit_err(session_diagnostics::InvalidReprHintNoValue {
1055+
span: meta_item.span,
1056+
name: meta_item.name_or_empty().to_ident_string(),
1057+
});
10601058
}
10611059
} else if let MetaItemKind::List(_) = meta_item.kind {
10621060
if meta_item.has_name(sym::align) {

compiler/rustc_passes/src/check_attr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,7 @@ impl CheckAttrVisitor<'_> {
16511651
E0552,
16521652
"unrecognized representation hint"
16531653
)
1654+
.help("valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`")
16541655
.emit();
16551656

16561657
continue;

src/test/ui/issues/issue-43988.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ error[E0552]: unrecognized representation hint
3131
|
3232
LL | #[repr(nothing)]
3333
| ^^^^^^^
34+
|
35+
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
3436

3537
error[E0552]: unrecognized representation hint
3638
--> $DIR/issue-43988.rs:18:12
3739
|
3840
LL | #[repr(something_not_real)]
3941
| ^^^^^^^^^^^^^^^^^^
42+
|
43+
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
4044

4145
error[E0518]: attribute should be applied to function or closure
4246
--> $DIR/issue-43988.rs:30:5
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![crate_type = "lib"]
2+
3+
#[repr(uwu)] //~ERROR: unrecognized representation hint
4+
pub struct OwO;
5+
6+
#[repr(uwu = "a")] //~ERROR: unrecognized representation hint
7+
pub struct OwO2(i32);
8+
9+
#[repr(uwu(4))] //~ERROR: unrecognized representation hint
10+
pub struct OwO3 {
11+
x: i32,
12+
}
13+
14+
#[repr(uwu, u8)] //~ERROR: unrecognized representation hint
15+
pub enum OwO4 {
16+
UwU = 1,
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
error[E0552]: unrecognized representation hint
2+
--> $DIR/invalid_repr_list_help.rs:3:8
3+
|
4+
LL | #[repr(uwu)]
5+
| ^^^
6+
|
7+
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
8+
9+
error[E0552]: unrecognized representation hint
10+
--> $DIR/invalid_repr_list_help.rs:6:8
11+
|
12+
LL | #[repr(uwu = "a")]
13+
| ^^^^^^^^^
14+
|
15+
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
16+
17+
error[E0552]: unrecognized representation hint
18+
--> $DIR/invalid_repr_list_help.rs:9:8
19+
|
20+
LL | #[repr(uwu(4))]
21+
| ^^^^^^
22+
|
23+
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
24+
25+
error[E0552]: unrecognized representation hint
26+
--> $DIR/invalid_repr_list_help.rs:14:8
27+
|
28+
LL | #[repr(uwu, u8)]
29+
| ^^^
30+
|
31+
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
32+
33+
error: aborting due to 4 previous errors
34+
35+
For more information about this error, try `rustc --explain E0552`.

0 commit comments

Comments
 (0)