-
Notifications
You must be signed in to change notification settings - Fork 13.3k
dead code lint is incorrectly reporting code as being unused with static methods #19613
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
This should be as simple as visiting param substitutions for method calls in dead.rs. |
Adjusting the code for current rust, this no longer produces any warnings (although I did have to use trait Visitor<R> {
fn foo();
}
fn visit<V: Visitor<R>, R>() {
V::foo()
}
struct V;
impl Visitor<()> for V {
fn foo() { println!("hi") }
}
fn main() {
visit::<V, ()>()
} |
I'm not sure that @TimNN's updated code exhibits the original issue, because it explicitly uses |
I was thinking about that when I adapted the code. Do you know a way to avoid explicitly mentioning V? |
From the duplicate issue: struct A;
trait As {
fn banana();
}
impl As for A {
fn banana() { panic!("banana"); }
}
trait Bs<T: As> {
fn do_it(&self) { T::banana() }
}
struct B;
impl Bs<A> for B {}
fn main() {
Bs::do_it(&B)
} When compiled, the dead_code lint fires, claiming that This code, when run, panics with Removing E-needstest, because the issue is not resolved. |
Closing in favor of #18290. |
fix: Fix a panic when a trait method in an impl declares a lifetime parameter not in the trait declaration
I was playing with passing around a trait that only has static methods. It works okay, but it appears that this confuses the dead code lint. Here's an example:
Which warns with:
As best as I can tell, Rust is able to infer that there's only one implementation possible and uses it, but this information isn't conveyed to the lint, so it marks the struct as being unused.
The text was updated successfully, but these errors were encountered: