Description
If I import a trait from an external crate into my crate and not use it, the compiler warns me about the unused import. But if I have a trait inside my crate with the same method and implement it, the compiler does not emit a warning about the unused trait from outside.
Let's say I have this trait in its own library crate:
// library crate 'testtrait'
pub trait OutsideTrait {
fn method(&self) -> String;
}
In my executable crate I have the following code:
// executable crate
extern crate testtrait;
use testtrait::OutsideTrait;
trait InsideTrait {
fn function(&self) -> String;
}
#[derive(Debug)]
struct Foo;
impl InsideTrait for Foo {
fn function(&self) -> String {
format!("{:?}", *self)
}
}
fn main() {
let b = Foo;
println!("{}", b.function());
}
Now the compiler warns me about the unused import testtrait::OutsideTrait
However, if I change the name of method
to function
in order to make OutsideTrait
match InsideTrait
, the compiler will not warn me about the unused import of testtrait::OutsideTrait
.
pub trait OutsideTrait {
fn function(&self) -> String;
}
This happens regardless of whether I add an additional parameter to the function in OutsideTrait
or InsideTrait
.
Note, that if I implement neither trait, the compiler will again warn me about the unused import of OutsideTrait
, which is totally fine.
The warning is not emitted by the compiler but the issue is still valid. OutsideTrait
is an unused import and should be reported as such.