diff options
| author | David Wood <david@davidtw.co> | 2019-01-29 13:34:40 +0100 |
|---|---|---|
| committer | David Wood <david@davidtw.co> | 2019-01-31 12:01:28 +0100 |
| commit | 1595163356546e8a4db55784bcc591e2c5cea26c (patch) | |
| tree | 29590b60d7f33441479541a23f1fc04fa7a56b20 /src/test/ui/issues | |
| parent | a21bd756889942cfed06dfd4ccd08838fc27ffdf (diff) | |
| download | rust-1595163356546e8a4db55784bcc591e2c5cea26c.tar.gz rust-1595163356546e8a4db55784bcc591e2c5cea26c.zip | |
Add suggestion for duplicated import.
This commit adds a suggestion when a import is duplicated (ie. the same name is used twice trying to import the same thing) to remove the second import.
Diffstat (limited to 'src/test/ui/issues')
| -rw-r--r-- | src/test/ui/issues/auxiliary/issue-52891.rs | 33 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-26886.stderr | 18 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-45829/import-twice.stderr | 10 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-52891.fixed | 37 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-52891.rs | 38 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-52891.stderr | 145 |
6 files changed, 265 insertions, 16 deletions
diff --git a/src/test/ui/issues/auxiliary/issue-52891.rs b/src/test/ui/issues/auxiliary/issue-52891.rs new file mode 100644 index 00000000000..07598118322 --- /dev/null +++ b/src/test/ui/issues/auxiliary/issue-52891.rs @@ -0,0 +1,33 @@ +pub mod a { + pub mod inner { + } +} + +pub mod b { + pub mod inner { + } +} + +pub mod c {} + +pub mod d {} + +pub mod e {} + +pub mod f {} + +pub mod g {} + +pub mod h {} + +pub mod i {} + +pub mod j {} + +pub mod k {} + +pub mod l {} + +pub mod m {} + +pub mod n {} diff --git a/src/test/ui/issues/issue-26886.stderr b/src/test/ui/issues/issue-26886.stderr index 08faa9c9ca2..70dacb353fe 100644 --- a/src/test/ui/issues/issue-26886.stderr +++ b/src/test/ui/issues/issue-26886.stderr @@ -4,13 +4,12 @@ error[E0252]: the name `Arc` is defined multiple times LL | use std::sync::{self, Arc}; | --- previous import of the type `Arc` here LL | use std::sync::Arc; //~ ERROR the name `Arc` is defined multiple times - | ^^^^^^^^^^^^^^ `Arc` reimported here + | ----^^^^^^^^^^^^^^- + | | | + | | `Arc` reimported here + | help: remove unnecessary import | = note: `Arc` must be defined only once in the type namespace of this module -help: you can use `as` to change the binding name of the import - | -LL | use std::sync::Arc as OtherArc; //~ ERROR the name `Arc` is defined multiple times - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0252]: the name `sync` is defined multiple times --> $DIR/issue-26886.rs:4:5 @@ -19,13 +18,12 @@ LL | use std::sync::{self, Arc}; | ---- previous import of the module `sync` here ... LL | use std::sync; //~ ERROR the name `sync` is defined multiple times - | ^^^^^^^^^ `sync` reimported here + | ----^^^^^^^^^- + | | | + | | `sync` reimported here + | help: remove unnecessary import | = note: `sync` must be defined only once in the type namespace of this module -help: you can use `as` to change the binding name of the import - | -LL | use std::sync as other_sync; //~ ERROR the name `sync` is defined multiple times - | ^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-45829/import-twice.stderr b/src/test/ui/issues/issue-45829/import-twice.stderr index 374b809647e..2a1ac576511 100644 --- a/src/test/ui/issues/issue-45829/import-twice.stderr +++ b/src/test/ui/issues/issue-45829/import-twice.stderr @@ -2,15 +2,13 @@ error[E0252]: the name `A` is defined multiple times --> $DIR/import-twice.rs:6:14 | LL | use foo::{A, A}; - | - ^ `A` reimported here - | | + | ---^ + | || | + | || `A` reimported here + | |help: remove unnecessary import | previous import of the type `A` here | = note: `A` must be defined only once in the type namespace of this module -help: you can use `as` to change the binding name of the import - | -LL | use foo::{A, A as OtherA}; - | ^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-52891.fixed b/src/test/ui/issues/issue-52891.fixed new file mode 100644 index 00000000000..e694b5c9b15 --- /dev/null +++ b/src/test/ui/issues/issue-52891.fixed @@ -0,0 +1,37 @@ +// aux-build:issue-52891.rs +// run-rustfix + +#![allow(warnings)] + +extern crate issue_52891; + +// Check that we don't suggest renaming duplicate imports but instead +// suggest removing one. + +use issue_52891::a; + //~ ERROR `a` is defined multiple times + +use issue_52891::{b, c}; //~ ERROR `a` is defined multiple times +use issue_52891::{d, e}; //~ ERROR `a` is defined multiple times +use issue_52891::{f, g}; //~ ERROR `a` is defined multiple times + +use issue_52891::{//~ ERROR `a` is defined multiple times + h, + i}; +use issue_52891::{j, + //~ ERROR `a` is defined multiple times + k}; +use issue_52891::{l, + m}; //~ ERROR `a` is defined multiple times + +use issue_52891::a::inner; +use issue_52891::b::inner as other_inner; //~ ERROR `inner` is defined multiple times + + +//~^ ERROR `issue_52891` is defined multiple times + + +#[macro_use] +use issue_52891::n; //~ ERROR `n` is defined multiple times + +fn main() {} diff --git a/src/test/ui/issues/issue-52891.rs b/src/test/ui/issues/issue-52891.rs new file mode 100644 index 00000000000..cd4b40629ab --- /dev/null +++ b/src/test/ui/issues/issue-52891.rs @@ -0,0 +1,38 @@ +// aux-build:issue-52891.rs +// run-rustfix + +#![allow(warnings)] + +extern crate issue_52891; + +// Check that we don't suggest renaming duplicate imports but instead +// suggest removing one. + +use issue_52891::a; +use issue_52891::a; //~ ERROR `a` is defined multiple times + +use issue_52891::{a, b, c}; //~ ERROR `a` is defined multiple times +use issue_52891::{d, a, e}; //~ ERROR `a` is defined multiple times +use issue_52891::{f, g, a}; //~ ERROR `a` is defined multiple times + +use issue_52891::{a, //~ ERROR `a` is defined multiple times + h, + i}; +use issue_52891::{j, + a, //~ ERROR `a` is defined multiple times + k}; +use issue_52891::{l, + m, + a}; //~ ERROR `a` is defined multiple times + +use issue_52891::a::inner; +use issue_52891::b::inner; //~ ERROR `inner` is defined multiple times + +use issue_52891::{self}; +//~^ ERROR `issue_52891` is defined multiple times + +use issue_52891::n; +#[macro_use] +use issue_52891::n; //~ ERROR `n` is defined multiple times + +fn main() {} diff --git a/src/test/ui/issues/issue-52891.stderr b/src/test/ui/issues/issue-52891.stderr new file mode 100644 index 00000000000..55d611070d9 --- /dev/null +++ b/src/test/ui/issues/issue-52891.stderr @@ -0,0 +1,145 @@ +error[E0252]: the name `a` is defined multiple times + --> $DIR/issue-52891.rs:12:5 + | +LL | use issue_52891::a; + | -------------- previous import of the module `a` here +LL | use issue_52891::a; //~ ERROR `a` is defined multiple times + | ----^^^^^^^^^^^^^^- + | | | + | | `a` reimported here + | help: remove unnecessary import + | + = note: `a` must be defined only once in the type namespace of this module + +error[E0252]: the name `a` is defined multiple times + --> $DIR/issue-52891.rs:14:19 + | +LL | use issue_52891::a; + | -------------- previous import of the module `a` here +... +LL | use issue_52891::{a, b, c}; //~ ERROR `a` is defined multiple times + | ^-- + | | + | `a` reimported here + | help: remove unnecessary import + | + = note: `a` must be defined only once in the type namespace of this module + +error[E0252]: the name `a` is defined multiple times + --> $DIR/issue-52891.rs:15:22 + | +LL | use issue_52891::a; + | -------------- previous import of the module `a` here +... +LL | use issue_52891::{d, a, e}; //~ ERROR `a` is defined multiple times + | ^-- + | | + | `a` reimported here + | help: remove unnecessary import + | + = note: `a` must be defined only once in the type namespace of this module + +error[E0252]: the name `a` is defined multiple times + --> $DIR/issue-52891.rs:16:25 + | +LL | use issue_52891::a; + | -------------- previous import of the module `a` here +... +LL | use issue_52891::{f, g, a}; //~ ERROR `a` is defined multiple times + | --^ + | | | + | | `a` reimported here + | help: remove unnecessary import + | + = note: `a` must be defined only once in the type namespace of this module + +error[E0252]: the name `a` is defined multiple times + --> $DIR/issue-52891.rs:18:19 + | +LL | use issue_52891::a; + | -------------- previous import of the module `a` here +... +LL | use issue_52891::{a, //~ ERROR `a` is defined multiple times + | ^-- + | | + | `a` reimported here + | help: remove unnecessary import + | + = note: `a` must be defined only once in the type namespace of this module + +error[E0252]: the name `a` is defined multiple times + --> $DIR/issue-52891.rs:22:5 + | +LL | use issue_52891::a; + | -------------- previous import of the module `a` here +... +LL | a, //~ ERROR `a` is defined multiple times + | ^-- + | | + | `a` reimported here + | help: remove unnecessary import + | + = note: `a` must be defined only once in the type namespace of this module + +error[E0252]: the name `a` is defined multiple times + --> $DIR/issue-52891.rs:26:5 + | +LL | use issue_52891::a; + | -------------- previous import of the module `a` here +... +LL | m, + | ______- +LL | | a}; //~ ERROR `a` is defined multiple times + | | - + | | | + | |_____`a` reimported here + | help: remove unnecessary import + | + = note: `a` must be defined only once in the type namespace of this module + +error[E0252]: the name `inner` is defined multiple times + --> $DIR/issue-52891.rs:29:5 + | +LL | use issue_52891::a::inner; + | --------------------- previous import of the module `inner` here +LL | use issue_52891::b::inner; //~ ERROR `inner` is defined multiple times + | ^^^^^^^^^^^^^^^^^^^^^ `inner` reimported here + | + = note: `inner` must be defined only once in the type namespace of this module +help: you can use `as` to change the binding name of the import + | +LL | use issue_52891::b::inner as other_inner; //~ ERROR `inner` is defined multiple times + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0254]: the name `issue_52891` is defined multiple times + --> $DIR/issue-52891.rs:31:19 + | +LL | extern crate issue_52891; + | ------------------------- previous import of the extern crate `issue_52891` here +... +LL | use issue_52891::{self}; + | ------------------^^^^-- + | | | + | | `issue_52891` reimported here + | help: remove unnecessary import + | + = note: `issue_52891` must be defined only once in the type namespace of this module + +error[E0252]: the name `n` is defined multiple times + --> $DIR/issue-52891.rs:36:5 + | +LL | use issue_52891::n; + | ------------------- + | | | + | | previous import of the module `n` here + | help: remove unnecessary import +LL | #[macro_use] +LL | use issue_52891::n; //~ ERROR `n` is defined multiple times + | ^^^^^^^^^^^^^^ `n` reimported here + | + = note: `n` must be defined only once in the type namespace of this module + +error: aborting due to 10 previous errors + +Some errors occurred: E0252, E0254. +For more information about an error, try `rustc --explain E0252`. |
