-
Notifications
You must be signed in to change notification settings - Fork 13.3k
dead_code
: Inherent associated types are unconditionally considered dead
#110332
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
Comments
dead_code
lint pass never considers inherent associated types alivedead_code
pass unconditionally considers inherent associated types dead
dead_code
pass unconditionally considers inherent associated types deaddead_code
: Inherent associated types are unconditionally considered dead
@rustbot claim EDIT: just realized that the linked PR is mine lol 😅. I'd say it is a regression, albeit on an unstable feature. |
Implementation is blocked on the following issue (not sure I'll be able to fix this):
(note the I believe my impl of this issue is blocked on this. |
Right, I stopped investigating after noticing |
Ok, I have a pretty trivial fix ready for when that PR is merged. |
As a – not so happy – update, with some changes I was able to update the resolution from As far as I understand, that's not just a limitation of my implementation but a general architectural limitation: There generally isn't a meaningful rust/compiler/rustc_passes/src/dead.rs Lines 63 to 70 in de96f3d
The way I understand it, this isn't a problem for trait associated types as they are unconditionally considered alive (which is also not ideal, see #66543). There is a similar case where a path segment has fn f<T: Trait>() {
let _: T::Item /* Res::Err */ = loop {};
}
fn main() {
f::<Struct>();
}
struct Struct;
trait Trait { type Item; }
impl Trait for Struct { type Item = (); } Since (trait) associated types are always alive, this works out "fine". |
I might be slightly wrong with my analysis but I think this roughly sums it. I'm gonna drop a message on Zulip later though to double-check. As a temporary mitigation, we can consider IATs always alive, too. |
@fmease IIUC (and I don't know a lot about the compiler), it should be enough for now to only have the paths in the function body. We can then resolve it to a For the case where the type isn't referenced from within a function, eg the following: fn main() {
f::<Struct>();
}
struct Struct;
impl Struct { type Item = usize; }
struct Foo { s: Struct::Item } we can leave it as is for now, until a better solution is found. As an aside (and this might be naive), we should never have |
Sorry for the delay. I'm gonna look into the matter one more time to see what we can do about paths outside of If I don't find anything useful, I will open a PR to update the The presence of |
All good, time as much time as you need. I agree we should consider |
On nightly, the following code triggers
dead_code
even though it should not.Actually until recently,
dead_code
was never triggered at all for inherent associated types.PR #110277 was just merged which started visiting more associated items exposing this bug.
The
dead_code
pass never considers IATs as live symbols (live_symbols
) even in cases where they should be.This feels like a regression but technically speaking it is not:
We switched from one extreme to the other. Thus not marking as such.
@rustbot label A-lint F-inherent_associated_types requires-nightly
The text was updated successfully, but these errors were encountered: