-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
repr
without hints
- 1.86.0
- 1.85.1
- 1.85.0
- 1.84.1
- 1.84.0
- 1.83.0
- 1.82.0
- 1.81.0
- 1.80.1
- 1.80.0
- 1.79.0
- 1.78.0
- 1.77.2
- 1.77.1
- 1.77.0
- 1.76.0
- 1.75.0
- 1.74.1
- 1.74.0
- 1.73.0
- 1.72.1
- 1.72.0
- 1.71.1
- 1.71.0
- 1.70.0
- 1.69.0
- 1.68.2
- 1.68.1
- 1.68.0
- 1.67.1
- 1.67.0
- 1.66.1
- 1.66.0
- 1.65.0
- 1.64.0
- 1.63.0
- 1.62.1
- 1.62.0
- 1.61.0
- 1.60.0
- 1.59.0
- 1.58.1
- 1.58.0
- 1.57.0
- 1.56.1
- 1.56.0
- 1.55.0
- 1.54.0
- 1.53.0
- 1.52.1
- 1.52.0
- 1.51.0
- 1.50.0
- 1.49.0
- 1.48.0
- 1.47.0
- 1.46.0
- 1.45.2
- 1.45.1
- 1.45.0
- 1.44.1
- 1.44.0
- 1.43.1
- 1.43.0
- 1.42.0
- 1.41.1
- 1.41.0
- 1.40.0
- 1.39.0
- 1.38.0
- 1.37.0
- 1.36.0
- 1.35.0
- 1.34.2
- 1.34.1
- 1.34.0
- 1.33.0
- 1.32.0
- 1.31.1
- 1.31.0
- 1.30.1
- 1.30.0
- 1.29.2
- 1.29.1
- 1.29.0
- 1.28.0
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!( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be an unsilencable warning instead of a lint, is that intended? So far we reserved that for future incompatibility warnings. A test for this would be good, too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll be adding a test. I feel that an empty There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think all the overhead of carefully managing the transition to a hard error, and the eventual breakage of (hypothetical) old crates, is worth it for this. This is just supposed to catch a silly programmer mistake, it's not a soundness issue or anything. IMO this should be a lint, warn-by-default for now and maybe later upgraded to deny-by-default. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel strongly that having an incorrect There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does indicate a severe bug, and it should report an error, but making it a hard error rather than a deny-by-default-lint error just unnecessarily breaks stability promises and unmaintained crates without helping users any more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will turn into a lint once I free myself to work on this a bit more. Please verify that the current output is reasonable. |
||
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.