Skip to content

Commit ad275f5

Browse files
committed
add list of recognized repr attributes to the unrecognized repr error
1 parent 9ba169a commit ad275f5

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
@@ -1040,18 +1040,16 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
10401040
&name,
10411041
),
10421042
});
1043-
} else {
1044-
if matches!(
1045-
meta_item.name_or_empty(),
1046-
sym::C | sym::simd | sym::transparent
1047-
) || int_type_of_word(meta_item.name_or_empty()).is_some()
1048-
{
1049-
recognised = true;
1050-
sess.emit_err(session_diagnostics::InvalidReprHintNoValue {
1051-
span: meta_item.span,
1052-
name: meta_item.name_or_empty().to_ident_string(),
1053-
});
1054-
}
1043+
} else if matches!(
1044+
meta_item.name_or_empty(),
1045+
sym::C | sym::simd | sym::transparent
1046+
) || int_type_of_word(meta_item.name_or_empty()).is_some()
1047+
{
1048+
recognised = true;
1049+
sess.emit_err(session_diagnostics::InvalidReprHintNoValue {
1050+
span: meta_item.span,
1051+
name: meta_item.name_or_empty().to_ident_string(),
1052+
});
10551053
}
10561054
} else if let MetaItemKind::List(_) = meta_item.kind {
10571055
if meta_item.has_name(sym::align) {

compiler/rustc_passes/src/check_attr.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1658,6 +1658,7 @@ impl CheckAttrVisitor<'_> {
16581658
E0552,
16591659
"unrecognized representation hint"
16601660
)
1661+
.help("valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`")
16611662
.emit();
16621663

16631664
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)