Closed
Description
This (very contrived) example emits a warning:
mod foo {
pub struct String;
#[derive(Debug)]
pub struct Number;
}
fn main() {
use std::string::String;
use foo::*;
let n = Number;
let s = String::new();
println!("{:?} {}", n, s);
}
Playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=4333aa0dec7b94c3d2942e7380894003
warning: the item `String` is imported redundantly
--> src/main.rs:9:9
|
9 | use std::string::String;
| ^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
This is a false positive because removing use std::string::String
results in a compilation error:
error[E0599]: no function or associated item named `new` found for struct `foo::String` in the current scope
--> src/main.rs:13:21
|
2 | pub struct String;
| ------------------ function or associated item `new` not found for this
...
13 | let s = String::new();
| ^^^ function or associated item not found in `foo::String`
Meta
$ rustc --version --verbose
rustc 1.42.0 (b8cedc004 2020-03-09)
binary: rustc
commit-hash: b8cedc00407a4c56a3bda1ed605c6fc166655447
commit-date: 2020-03-09
host: x86_64-pc-windows-msvc
release: 1.42.0
LLVM version: 9.0
Same for 1.43.0-beta.6
and 1.44.0-nightly (2020-04-21 45d050cde277b22a7558)
.
Activity
dillona commentedon Apr 27, 2020
It seems this regressed somewhere between 1.34.0 and 1.35.0
dillona commentedon Apr 28, 2020
More accurately, it looks like the false positive has been present since the introduction of the warning in #58805
Kinrany commentedon Apr 28, 2020
I was actually a little surprised that
did not cause a compilation error due to two imports of the same name at the same level.
Kreijstal commentedon Mar 28, 2023
I got something similar while implementing ops::Div
when removed, it errors
petrochenkov commentedon Mar 2, 2024
This issue no longer reproduces and can be closed when a corresponding test is added.
add test for rust-lang#71450
add test for rust-lang#71450
add test for rust-lang#71450
add test for rust-lang#71450
11 remaining items