about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-02-05 05:14:15 +0000
committerbors <bors@rust-lang.org>2019-02-05 05:14:15 +0000
commitb2c6b8c29f13f8d1f242da89e587960b95337819 (patch)
tree92927fb4e6748fe396cd9eae073dd4d151f2830d /src/test
parent710ddc151baf9750e074229b8bdc794d63246eb8 (diff)
parent1595163356546e8a4db55784bcc591e2c5cea26c (diff)
Auto merge of #57973 - davidtwco:issue-52891, r=estebank
Add suggestion for duplicated import.

Fixes #52891.

This PR 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')
-rw-r--r--src/test/ui/double-type-import.stderr9
-rw-r--r--src/test/ui/error-codes/E0430.stderr10
-rw-r--r--src/test/ui/imports/duplicate.stderr9
-rw-r--r--src/test/ui/issues/auxiliary/issue-52891.rs33
-rw-r--r--src/test/ui/issues/issue-26886.stderr18
-rw-r--r--src/test/ui/issues/issue-45829/import-twice.stderr10
-rw-r--r--src/test/ui/issues/issue-52891.fixed37
-rw-r--r--src/test/ui/issues/issue-52891.rs38
-rw-r--r--src/test/ui/issues/issue-52891.stderr145
-rw-r--r--src/test/ui/proc-macro/shadow.stderr17
-rw-r--r--src/test/ui/resolve/resolve-conflict-import-vs-import.stderr9
-rw-r--r--src/test/ui/unresolved/unresolved-extern-mod-suggestion.stderr9
-rw-r--r--src/test/ui/use/use-mod.stderr9
-rw-r--r--src/test/ui/use/use-paths-as-items.stderr9
14 files changed, 301 insertions, 61 deletions
diff --git a/src/test/ui/double-type-import.stderr b/src/test/ui/double-type-import.stderr
index 4bdee0c4c9f..c7288af13c2 100644
--- a/src/test/ui/double-type-import.stderr
+++ b/src/test/ui/double-type-import.stderr
@@ -4,13 +4,12 @@ error[E0252]: the name `X` is defined multiple times
 LL |     pub use self::bar::X;
    |             ------------ previous import of the type `X` here
 LL |     use self::bar::X;
-   |         ^^^^^^^^^^^^ `X` reimported here
+   |     ----^^^^^^^^^^^^-
+   |     |   |
+   |     |   `X` reimported here
+   |     help: remove unnecessary import
    |
    = note: `X` 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 self::bar::X as OtherX;
-   |         ^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/error-codes/E0430.stderr b/src/test/ui/error-codes/E0430.stderr
index 0151cde887f..78e4e43ac2f 100644
--- a/src/test/ui/error-codes/E0430.stderr
+++ b/src/test/ui/error-codes/E0430.stderr
@@ -10,15 +10,13 @@ error[E0252]: the name `fmt` is defined multiple times
   --> $DIR/E0430.rs:1:22
    |
 LL | use std::fmt::{self, self}; //~ ERROR E0430
-   |                ----  ^^^^ `fmt` reimported here
-   |                |
+   |                ------^^^^
+   |                |   | |
+   |                |   | `fmt` reimported here
+   |                |   help: remove unnecessary import
    |                previous import of the module `fmt` here
    |
    = note: `fmt` 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::fmt::{self, self as other_fmt}; //~ ERROR E0430
-   |                      ^^^^^^^^^^^^^^^^^
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/imports/duplicate.stderr b/src/test/ui/imports/duplicate.stderr
index acd66826fdf..29660d908e4 100644
--- a/src/test/ui/imports/duplicate.stderr
+++ b/src/test/ui/imports/duplicate.stderr
@@ -4,13 +4,12 @@ error[E0252]: the name `foo` is defined multiple times
 LL |     use a::foo;
    |         ------ previous import of the value `foo` here
 LL |     use a::foo; //~ ERROR the name `foo` is defined multiple times
-   |         ^^^^^^ `foo` reimported here
+   |     ----^^^^^^-
+   |     |   |
+   |     |   `foo` reimported here
+   |     help: remove unnecessary import
    |
    = note: `foo` must be defined only once in the value namespace of this module
-help: you can use `as` to change the binding name of the import
-   |
-LL |     use a::foo as other_foo; //~ ERROR the name `foo` is defined multiple times
-   |         ^^^^^^^^^^^^^^^^^^^
 
 error[E0659]: `foo` is ambiguous (glob import vs glob import in the same module)
   --> $DIR/duplicate.rs:46:15
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`.
diff --git a/src/test/ui/proc-macro/shadow.stderr b/src/test/ui/proc-macro/shadow.stderr
index 103c78126a8..2dfe2a94c88 100644
--- a/src/test/ui/proc-macro/shadow.stderr
+++ b/src/test/ui/proc-macro/shadow.stderr
@@ -1,17 +1,16 @@
 error[E0259]: the name `derive_a` is defined multiple times
   --> $DIR/shadow.rs:6:1
    |
-LL | extern crate derive_a;
-   | ---------------------- previous import of the extern crate `derive_a` here
-LL | #[macro_use]
-LL | extern crate derive_a; //~ ERROR the name `derive_a` is defined multiple times
-   | ^^^^^^^^^^^^^^^^^^^^^^ `derive_a` reimported here
+LL |   extern crate derive_a;
+   |   ---------------------- previous import of the extern crate `derive_a` here
+LL | / #[macro_use]
+LL | | extern crate derive_a; //~ ERROR the name `derive_a` is defined multiple times
+   | | ^^^^^^^^^^^^^^^^^^^^^-
+   | |_|____________________|
+   |   |                    help: remove unnecessary import
+   |   `derive_a` reimported here
    |
    = note: `derive_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 | extern crate derive_a as other_derive_a; //~ ERROR the name `derive_a` is defined multiple times
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/resolve/resolve-conflict-import-vs-import.stderr b/src/test/ui/resolve/resolve-conflict-import-vs-import.stderr
index 2852d122e5e..1b4b058b783 100644
--- a/src/test/ui/resolve/resolve-conflict-import-vs-import.stderr
+++ b/src/test/ui/resolve/resolve-conflict-import-vs-import.stderr
@@ -4,13 +4,12 @@ error[E0252]: the name `transmute` is defined multiple times
 LL | use std::mem::transmute;
    |     ------------------- previous import of the value `transmute` here
 LL | use std::mem::transmute;
-   |     ^^^^^^^^^^^^^^^^^^^ `transmute` reimported here
+   | ----^^^^^^^^^^^^^^^^^^^-
+   | |   |
+   | |   `transmute` reimported here
+   | help: remove unnecessary import
    |
    = note: `transmute` must be defined only once in the value namespace of this module
-help: you can use `as` to change the binding name of the import
-   |
-LL | use std::mem::transmute as other_transmute;
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/unresolved/unresolved-extern-mod-suggestion.stderr b/src/test/ui/unresolved/unresolved-extern-mod-suggestion.stderr
index 012d3c3a751..e8679a3726d 100644
--- a/src/test/ui/unresolved/unresolved-extern-mod-suggestion.stderr
+++ b/src/test/ui/unresolved/unresolved-extern-mod-suggestion.stderr
@@ -4,13 +4,12 @@ error[E0254]: the name `core` is defined multiple times
 LL | extern crate core;
    | ------------------ previous import of the extern crate `core` here
 LL | use core;
-   |     ^^^^ `core` reimported here
+   | ----^^^^-
+   | |   |
+   | |   `core` reimported here
+   | help: remove unnecessary import
    |
    = note: `core` 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 core as other_core;
-   |     ^^^^^^^^^^^^^^^^^^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/use/use-mod.stderr b/src/test/ui/use/use-mod.stderr
index 9ab873b3598..c23ab34eae6 100644
--- a/src/test/ui/use/use-mod.stderr
+++ b/src/test/ui/use/use-mod.stderr
@@ -20,13 +20,12 @@ LL |     self,
    |     ---- previous import of the module `bar` here
 ...
 LL |     self
-   |     ^^^^ `bar` reimported here
+   |     ^^^^
+   |     |
+   |     `bar` reimported here
+   |     help: remove unnecessary import
    |
    = note: `bar` 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 |     self as other_bar
-   |
 
 error: aborting due to 3 previous errors
 
diff --git a/src/test/ui/use/use-paths-as-items.stderr b/src/test/ui/use/use-paths-as-items.stderr
index 5bcdf937d56..00f468cdf31 100644
--- a/src/test/ui/use/use-paths-as-items.stderr
+++ b/src/test/ui/use/use-paths-as-items.stderr
@@ -4,13 +4,12 @@ error[E0252]: the name `mem` is defined multiple times
 LL | use std::{mem, ptr};
    |           --- previous import of the module `mem` here
 LL | use std::mem; //~ ERROR the name `mem` is defined multiple times
-   |     ^^^^^^^^ `mem` reimported here
+   | ----^^^^^^^^-
+   | |   |
+   | |   `mem` reimported here
+   | help: remove unnecessary import
    |
    = note: `mem` 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::mem as other_mem; //~ ERROR the name `mem` is defined multiple times
-   |     ^^^^^^^^^^^^^^^^^^^^^
 
 error: aborting due to previous error