You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
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.
The text was updated successfully, but these errors were encountered:
Gankra
added
the
A-lint
Area: Lints (warnings about flaws in source code) such as unused_mut.
label
May 23, 2015
This is an artifact of the current implementation which is entirely housed in librustc_resolve. The resolution pass collects all traits which could be candidates for a function call, and then it relies on type checking later on to figure out which trait was actually used. All candidates, however, are considered "used imports" and the typechecking phase doesn't later come along and say "oh I didn't actually use this trait".
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:
In my executable crate I have the following code:
Now the compiler warns me about the unused import
testtrait::OutsideTrait
However, if I change the name of
method
tofunction
in order to makeOutsideTrait
matchInsideTrait
, the compiler will not warn me about the unused import oftesttrait::OutsideTrait
.This happens regardless of whether I add an additional parameter to the function in
OutsideTrait
orInsideTrait
.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.The text was updated successfully, but these errors were encountered: