Closed
Description
Given the following code: https://godbolt.org/z/vdc4YYafK
pub struct Foo(bar::Bar);
pub mod bar {
pub struct Foo(pub Bar);
pub struct Bar(pub char);
}
pub fn warning() -> Foo {
use bar::*;
use self::Foo;
Foo(Bar('a'))
}
pub fn error() -> Foo {
use bar::*;
// use self::Foo;
Foo(Bar('a'))
}
The current output is:
warning: the item `Foo` is imported redundantly
--> <source>:10:7
|
1 | pub struct Foo(bar::Bar);
| ------------------------- the item `Foo` is already defined here
...
10 | use self::Foo;
| ^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
error[E0308]: mismatched types
--> <source>:17:3
|
14 | pub fn error() -> Foo {
| --- expected `Foo` because of return type
...
17 | Foo(Bar('a'))
| ^^^^^^^^^^^^^ expected struct `Foo`, found struct `bar::Foo`
error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0308`.
The warning for redundant import is incorrect, and is required for code to compile: bar::*
shadows the implicit self::Foo
in this scope, so making it explicit shadows the implicit bar::*
. This should either be an error or not a warning; the latter is probably correct.
The non-glob version is handled correctly: https://godbolt.org/z/653K6svve
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Name/path resolution done by `rustc_resolve` specificallyDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: An error or lint that needs small tweaks.Relevant to the compiler team, which will review and decide on the PR/issue.