-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Extend dead code analysis of impls and impl items to non-ADTs #142968
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
base: master
Are you sure you want to change the base?
Conversation
compiler/rustc_passes/src/dead.rs
Outdated
|| assoc_item.trait_item_def_id.is_none() | ||
} | ||
_ => true, | ||
}) |
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.
How is this change related to supporting non-ADTs?
Isn't this reverting a part of changes from #141407?
The logic is again spread randomly between the various analysis stages, what is the principle behind all this, what is filtered away or analyzed at what stage?
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.
Removed this and edited the reachable analysis in the new change
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.
The logic here is removing impl ReachableTrait for ReachableTy<PrivateTy>
from the seed worklist. Because the reachable analysis considers impl ReachableTrait for ReachableTy<UnreachableTy>
reachable due to the trait and the "shallow" type are both reachable, but this will also mark impl ReachableTrait for ReachableTy<PrivateTy>
and impl ReachableTrait for [PrivateTy]
reachable. The latter is not expected.
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.
impl ReachableTrait for ReachableTy<PrivateTy>
and impl ReachableTrait for [PrivateTy]
may indeed be reachable due to type inference, even it's not intuitive.
(But they will produce an error on use.)
I need to check though, whether we mark private items as reachable in other, non-impl cases.
If we do, then private impls can probably be treated as non-reachable as well.
This is a change that may have language implications.
28d6722
to
9242dd0
Compare
9242dd0
to
7e29893
Compare
@rustbot ready |
The cases reported by dead code lint in this PR are most similar to this case. struct Priv;
pub fn leak_priv() -> Priv { Priv }
On the other hand marking it reachable is exactly what allows the
So what we really need is two different "effective visibility" tables, one with the rules making |
(I'll think about this more tomorrow.) |
I'm thinking about whether it's correct to extend to non-ADT. Considering the following: #![deny(dead_code)]
struct T;
fn foo(_: &[T]) {}
struct U;
pub trait Bar {
fn bar(&self);
}
impl Bar for [U] {
fn bar(&self) {}
}
fn main() {
foo(&[]);
[].bar();
} This PR will mark |
Then we can lint more unused structs and traits like the following:
Extracted from #128637.
r? @petrochenkov