lint against repeated repr attributes#157036
Conversation
This comment has been minimized.
This comment has been minimized.
|
Wearing my lang hat but not speaking as team consensus (since we've not talked about it): I think you should start with the "obviously good" version, and we can do future PRs later to expand it or to update severity. Concretely, thus, I'd say it should be a warning (because if it's inert it doesn't need to be deny) when you have a clearly-unnecessary one that wasn't emitted from a macro, or something like that. (Our bar in the compiler for deny-by-default is pretty high. My personal heuristic is whether it's worth running your unit tests despite the warning, and an inert extra attribute doesn't need to block that.) We can then look at impacts and ratchet it up over time or over an edition, but those decisions can be made later and don't need to block you making a useful lint in the meantime. I'm a bad reviewer for lint stuff code-wise, though, so let's try |
|
+1 to what @scottmcm said on how best to approach this. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Some changes occurred in compiler/rustc_passes/src/check_attr.rs |
This comment has been minimized.
This comment has been minimized.
had to update several tests which used repeated aligns and packeds. they now produce both a warning and an error where appropriate (e.g. when using conflicting packeds) which i think is correct.
ae3cdee to
314903c
Compare
|
r? jdonszelmann |
| for (repr, _repr_span) in reprs { | ||
| match repr { | ||
| ReprAttr::ReprRust => { | ||
| if is_explicit_rust { |
There was a problem hiding this comment.
this seems very manual, and I'm not sure I like it. The logic gets quite complex. Is there any way you can figure out to do this in a more structured way that makes sure we can't make any logic errors? Something with iterators maybe?
|
@rustbot author |
| } | ||
|
|
||
| #[derive(Diagnostic)] | ||
| #[diag("representation attribute is specified more than once")] |
There was a problem hiding this comment.
I'd phrase the error as "#[repr(...)] attribute is specified more than once"
|
Reminder, once the PR becomes ready for a review, use |
|
Error: Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip. |
fixes #156029 by adding a lint against repeated repr attributes.
r? scottmcm