-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Warn on repr without hints
#51401
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
Warn on repr without hints
#51401
Changes from 1 commit
36381fa
2c7099b
3580de8
48e45ee
451eb66
9a80c2b
b3810f6
3cc09c8
0e3f19d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -154,7 +154,22 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> { | |
| let hints: Vec<_> = item.attrs | ||
| .iter() | ||
| .filter(|attr| attr.name() == "repr") | ||
| .filter_map(|attr| attr.meta_item_list()) | ||
| .filter_map(|attr| { | ||
| let list = attr.meta_item_list(); | ||
| let mut has_hints = false; | ||
| if let Some(ref list) = list { | ||
| has_hints = !list.is_empty(); | ||
| } | ||
| if !has_hints { | ||
| span_warn!( | ||
|
||
| self.tcx.sess, | ||
| item.span, | ||
| E0689, | ||
| "`repr` attribute cannot be empty", | ||
| ); | ||
| } | ||
| list | ||
| }) | ||
| .flat_map(|hints| hints) | ||
| .collect(); | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think this is better written as
let is_empty = list.map(|list| list.is_empty()).unwrap_or(true);and thenif empty { ... }.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I caught that while reworking this. Changed it.