Skip to content

Commit

Permalink
add list of recognized repr attributes to the unrecognized repr error
Browse files Browse the repository at this point in the history
  • Loading branch information
asquared31415 committed Sep 6, 2022
1 parent 9ba169a commit ad275f5
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 12 deletions.
22 changes: 10 additions & 12 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1040,18 +1040,16 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
&name,
),
});
} else {
if matches!(
meta_item.name_or_empty(),
sym::C | sym::simd | sym::transparent
) || int_type_of_word(meta_item.name_or_empty()).is_some()
{
recognised = true;
sess.emit_err(session_diagnostics::InvalidReprHintNoValue {
span: meta_item.span,
name: meta_item.name_or_empty().to_ident_string(),
});
}
} else if matches!(
meta_item.name_or_empty(),
sym::C | sym::simd | sym::transparent
) || int_type_of_word(meta_item.name_or_empty()).is_some()
{
recognised = true;
sess.emit_err(session_diagnostics::InvalidReprHintNoValue {
span: meta_item.span,
name: meta_item.name_or_empty().to_ident_string(),
});
}
} else if let MetaItemKind::List(_) = meta_item.kind {
if meta_item.has_name(sym::align) {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,7 @@ impl CheckAttrVisitor<'_> {
E0552,
"unrecognized representation hint"
)
.help("valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`")
.emit();

continue;
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/issues/issue-43988.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ error[E0552]: unrecognized representation hint
|
LL | #[repr(nothing)]
| ^^^^^^^
|
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`

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

error[E0518]: attribute should be applied to function or closure
--> $DIR/issue-43988.rs:30:5
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/repr/invalid_repr_list_help.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![crate_type = "lib"]

#[repr(uwu)] //~ERROR: unrecognized representation hint
pub struct OwO;

#[repr(uwu = "a")] //~ERROR: unrecognized representation hint
pub struct OwO2(i32);

#[repr(uwu(4))] //~ERROR: unrecognized representation hint
pub struct OwO3 {
x: i32,
}

#[repr(uwu, u8)] //~ERROR: unrecognized representation hint
pub enum OwO4 {
UwU = 1,
}
35 changes: 35 additions & 0 deletions src/test/ui/repr/invalid_repr_list_help.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
error[E0552]: unrecognized representation hint
--> $DIR/invalid_repr_list_help.rs:3:8
|
LL | #[repr(uwu)]
| ^^^
|
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`

error[E0552]: unrecognized representation hint
--> $DIR/invalid_repr_list_help.rs:6:8
|
LL | #[repr(uwu = "a")]
| ^^^^^^^^^
|
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`

error[E0552]: unrecognized representation hint
--> $DIR/invalid_repr_list_help.rs:9:8
|
LL | #[repr(uwu(4))]
| ^^^^^^
|
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`

error[E0552]: unrecognized representation hint
--> $DIR/invalid_repr_list_help.rs:14:8
|
LL | #[repr(uwu, u8)]
| ^^^
|
= help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0552`.

0 comments on commit ad275f5

Please sign in to comment.