-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 detection of unused struct fields #14696
Conversation
It would be nice to teach this to ignore the marker types. They're lang items so it's possible to detect these without too much effort. It would also make sense to ignore a |
@thestinger I think #[repr(C)] can only be used for enums. As for markers, that does sound like a good idea! I made that change. The warning is still a false positive for resources (locks) but I do not see a way to whitelist those other than whitelisting types implementing Drop but that would introduce some false negatives as well. |
It's also going to be used for every |
Ah, it didn't land - it's #14479. |
@thestinger I see, thanks! I went ahead and I added repr(C) handling to this PR. |
This needs a rebase. |
I'm a little worried about how noisy our lints are becoming, it seems there are some legitimate use cases here that are being warned about and it's annoying to have to put I think that whitelisting fields of
Was this left out by accident? I may have missed it as well. |
👍 mirrors the use of local-variables guards too: |
Yes, no idea how that'd happened. I couldn't even find it in my reflog! I agree that noisy lints are bad. But I was concerned that limiting the warnings to a smaller subset of scenarios reduces their utility. In this case, though, the leading underscore rule does seem like a good solution! Updated to include both repr(C) and leading _ changes. |
@@ -254,7 +254,7 @@ pub struct TcpStream { | |||
|
|||
struct Inner { | |||
fd: sock_t, | |||
lock: mutex::NativeMutex, | |||
_lock: mutex::NativeMutex, |
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.
It seems... weird that this field would be unused. Why is it creating a mutex without using it?
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.
It is using it but not on Linux. I'll make the field compile-time conditional to non-Linux.
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.
Okay, that's not really possible. I'll stick with an underscore, then.
Awesome work! I'm quite happy with how the leading underscore turned out. |
Agreed. (Travis failed.) |
@alexcrichton So this failed on the 32-bit Linux bot, which I've fixed, and it looks like it's bootstrapped on the other bots before the builds were interrupted so hopefully it should go through next time. |
@alexcrichton Oh dear, it's Android now. Third time's a charm? I also went ahead and cherry-picked @cmr's fc44834 from #14479. |
The compiler, today, should reject |
Ah I see, nevermind. First time seeing this patch. |
This uncovered some dead code, most notably in middle/liveness.rs, which I think suggests there must be something fishy with that part of the code. The #[allow(dead_code)] annotations on some of the fields I am not super happy about but as I understand, marker type may disappear at some point.
This uncovered some dead code, most notably in middle/liveness.rs, which I think suggests there must be something fishy with that part of the code.
The #[allow(dead_code)] annotations on some of the fields I am not super happy about but as I understand, marker type may disappear at some point.