Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list of recognized repr attributes to the unrecognized repr error #101486

Merged
merged 1 commit into from
Sep 7, 2022
Merged
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
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`")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally this list would be generated from some canonical source.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we don't seem to have such a source, and there's code in another place that also replicates a lot of these checks and they all just seem to check symbols.

.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`.