From 851d4c4e249f38c82846737af9cd80cccc5b2f02 Mon Sep 17 00:00:00 2001
From: bohan <bohan-zhang@foxmail.com>
Date: Sun, 21 Jan 2024 19:17:28 +0800
Subject: [PATCH] add several resolution test cases

---
 tests/ui/imports/ambiguous-2.rs               |  1 +
 tests/ui/imports/ambiguous-4.rs               |  2 +-
 .../glob-conflict-cross-crate-2-extern.rs     | 10 +++++++
 .../auxiliary/issue-114682-2-extern.rs        | 17 +++++++++++
 .../auxiliary/issue-114682-3-extern.rs        | 16 +++++++++++
 .../auxiliary/issue-114682-4-extern.rs        | 10 +++++++
 .../auxiliary/issue-114682-5-extern-1.rs      |  1 +
 .../auxiliary/issue-114682-5-extern-2.rs      | 13 +++++++++
 .../auxiliary/issue-114682-6-extern.rs        |  9 ++++++
 tests/ui/imports/extern-with-ambiguous-2.rs   |  2 ++
 tests/ui/imports/extern-with-ambiguous-3.rs   |  2 ++
 ...rate.rs => glob-conflict-cross-crate-1.rs} |  4 +++
 ...err => glob-conflict-cross-crate-1.stderr} |  4 +--
 .../ui/imports/glob-conflict-cross-crate-2.rs | 10 +++++++
 .../glob-conflict-cross-crate-2.stderr        |  9 ++++++
 .../ui/imports/glob-conflict-cross-crate-3.rs | 16 +++++++++++
 tests/ui/imports/issue-114682-1.rs            | 25 +++++++++++++++++
 tests/ui/imports/issue-114682-1.stderr        | 28 +++++++++++++++++++
 tests/ui/imports/issue-114682-2.rs            | 19 +++++++++++++
 tests/ui/imports/issue-114682-2.stderr        |  9 ++++++
 tests/ui/imports/issue-114682-3.rs            | 24 ++++++++++++++++
 tests/ui/imports/issue-114682-4.rs            | 13 +++++++++
 tests/ui/imports/issue-114682-5.rs            | 15 ++++++++++
 tests/ui/imports/issue-114682-6.rs            | 13 +++++++++
 24 files changed, 269 insertions(+), 3 deletions(-)
 create mode 100644 tests/ui/imports/auxiliary/glob-conflict-cross-crate-2-extern.rs
 create mode 100644 tests/ui/imports/auxiliary/issue-114682-2-extern.rs
 create mode 100644 tests/ui/imports/auxiliary/issue-114682-3-extern.rs
 create mode 100644 tests/ui/imports/auxiliary/issue-114682-4-extern.rs
 create mode 100644 tests/ui/imports/auxiliary/issue-114682-5-extern-1.rs
 create mode 100644 tests/ui/imports/auxiliary/issue-114682-5-extern-2.rs
 create mode 100644 tests/ui/imports/auxiliary/issue-114682-6-extern.rs
 rename tests/ui/imports/{glob-conflict-cross-crate.rs => glob-conflict-cross-crate-1.rs} (54%)
 rename tests/ui/imports/{glob-conflict-cross-crate.stderr => glob-conflict-cross-crate-1.stderr} (82%)
 create mode 100644 tests/ui/imports/glob-conflict-cross-crate-2.rs
 create mode 100644 tests/ui/imports/glob-conflict-cross-crate-2.stderr
 create mode 100644 tests/ui/imports/glob-conflict-cross-crate-3.rs
 create mode 100644 tests/ui/imports/issue-114682-1.rs
 create mode 100644 tests/ui/imports/issue-114682-1.stderr
 create mode 100644 tests/ui/imports/issue-114682-2.rs
 create mode 100644 tests/ui/imports/issue-114682-2.stderr
 create mode 100644 tests/ui/imports/issue-114682-3.rs
 create mode 100644 tests/ui/imports/issue-114682-4.rs
 create mode 100644 tests/ui/imports/issue-114682-5.rs
 create mode 100644 tests/ui/imports/issue-114682-6.rs

diff --git a/tests/ui/imports/ambiguous-2.rs b/tests/ui/imports/ambiguous-2.rs
index 7b38f3006b104..2918feb059107 100644
--- a/tests/ui/imports/ambiguous-2.rs
+++ b/tests/ui/imports/ambiguous-2.rs
@@ -6,4 +6,5 @@ extern crate ambiguous_1;
 
 fn main() {
     ambiguous_1::id();
+    //^ FIXME: `id` should be identified as an ambiguous item.
 }
diff --git a/tests/ui/imports/ambiguous-4.rs b/tests/ui/imports/ambiguous-4.rs
index 24ae33784c526..1e8f5be5a882e 100644
--- a/tests/ui/imports/ambiguous-4.rs
+++ b/tests/ui/imports/ambiguous-4.rs
@@ -5,5 +5,5 @@ extern crate ambiguous_4_extern;
 
 fn main() {
     ambiguous_4_extern::id();
-    // `warning_ambiguous` had been lost at metadata.
+    //^ FIXME: `id` should be identified as an ambiguous item.
 }
diff --git a/tests/ui/imports/auxiliary/glob-conflict-cross-crate-2-extern.rs b/tests/ui/imports/auxiliary/glob-conflict-cross-crate-2-extern.rs
new file mode 100644
index 0000000000000..5dec6d4699496
--- /dev/null
+++ b/tests/ui/imports/auxiliary/glob-conflict-cross-crate-2-extern.rs
@@ -0,0 +1,10 @@
+mod a {
+    pub type C = i8;
+}
+
+mod b {
+    pub type C = i16;
+}
+
+pub use a::*;
+pub use b::*;
diff --git a/tests/ui/imports/auxiliary/issue-114682-2-extern.rs b/tests/ui/imports/auxiliary/issue-114682-2-extern.rs
new file mode 100644
index 0000000000000..df2af78916682
--- /dev/null
+++ b/tests/ui/imports/auxiliary/issue-114682-2-extern.rs
@@ -0,0 +1,17 @@
+macro_rules! m {
+    () => {
+        pub fn max() {}
+        pub(crate) mod max {}
+    };
+}
+
+mod d {
+    m! {}
+}
+
+mod e {
+    pub type max = i32;
+}
+
+pub use self::d::*;
+pub use self::e::*;
diff --git a/tests/ui/imports/auxiliary/issue-114682-3-extern.rs b/tests/ui/imports/auxiliary/issue-114682-3-extern.rs
new file mode 100644
index 0000000000000..999b66342fe00
--- /dev/null
+++ b/tests/ui/imports/auxiliary/issue-114682-3-extern.rs
@@ -0,0 +1,16 @@
+mod gio {
+    pub trait SettingsExt {
+        fn abc(&self) {}
+    }
+    impl<T> SettingsExt for T {}
+}
+
+mod gtk {
+    pub trait SettingsExt {
+        fn efg(&self) {}
+    }
+    impl<T> SettingsExt for T {}
+}
+
+pub use gtk::*;
+pub use gio::*;
diff --git a/tests/ui/imports/auxiliary/issue-114682-4-extern.rs b/tests/ui/imports/auxiliary/issue-114682-4-extern.rs
new file mode 100644
index 0000000000000..86663f11b31eb
--- /dev/null
+++ b/tests/ui/imports/auxiliary/issue-114682-4-extern.rs
@@ -0,0 +1,10 @@
+mod a {
+    pub type Result<T> = std::result::Result<T, ()>;
+}
+
+mod b {
+    pub type Result<T> = std::result::Result<T, ()>;
+}
+
+pub use a::*;
+pub use b::*;
diff --git a/tests/ui/imports/auxiliary/issue-114682-5-extern-1.rs b/tests/ui/imports/auxiliary/issue-114682-5-extern-1.rs
new file mode 100644
index 0000000000000..ebf6493f9f718
--- /dev/null
+++ b/tests/ui/imports/auxiliary/issue-114682-5-extern-1.rs
@@ -0,0 +1 @@
+pub struct Url;
diff --git a/tests/ui/imports/auxiliary/issue-114682-5-extern-2.rs b/tests/ui/imports/auxiliary/issue-114682-5-extern-2.rs
new file mode 100644
index 0000000000000..9dbefdd531be3
--- /dev/null
+++ b/tests/ui/imports/auxiliary/issue-114682-5-extern-2.rs
@@ -0,0 +1,13 @@
+// edition: 2018
+// aux-build: issue-114682-5-extern-1.rs
+// compile-flags: --extern issue_114682_5_extern_1
+
+pub mod p {
+    pub use crate::types::*;
+    pub use crate::*;
+}
+mod types {
+    pub mod issue_114682_5_extern_1 {}
+}
+
+pub use issue_114682_5_extern_1;
diff --git a/tests/ui/imports/auxiliary/issue-114682-6-extern.rs b/tests/ui/imports/auxiliary/issue-114682-6-extern.rs
new file mode 100644
index 0000000000000..caf3c4e35a0e9
--- /dev/null
+++ b/tests/ui/imports/auxiliary/issue-114682-6-extern.rs
@@ -0,0 +1,9 @@
+mod a {
+    pub fn log() {}
+}
+mod b {
+    pub fn log() {}
+}
+
+pub use self::a::*;
+pub use self::b::*;
diff --git a/tests/ui/imports/extern-with-ambiguous-2.rs b/tests/ui/imports/extern-with-ambiguous-2.rs
index 68c623c1c4a65..b7c9cccdb6402 100644
--- a/tests/ui/imports/extern-with-ambiguous-2.rs
+++ b/tests/ui/imports/extern-with-ambiguous-2.rs
@@ -12,5 +12,7 @@ mod s {
 use s::*;
 use extern_with_ambiguous_2_extern::*;
 use error::*;
+//^ FIXME: An ambiguity error should be thrown for `error`,
+// as there is ambiguity present within `extern-with-ambiguous-2-extern.rs`.
 
 fn main() {}
diff --git a/tests/ui/imports/extern-with-ambiguous-3.rs b/tests/ui/imports/extern-with-ambiguous-3.rs
index 282c1d569b0cc..44a9a2a00a453 100644
--- a/tests/ui/imports/extern-with-ambiguous-3.rs
+++ b/tests/ui/imports/extern-with-ambiguous-3.rs
@@ -13,5 +13,7 @@ mod s {
 use s::*;
 use extern_with_ambiguous_3_extern::*;
 use error::*;
+//^ FIXME: An ambiguity error should be thrown for `error`,
+// as there is ambiguity present within `extern-with-ambiguous-3-extern.rs`.
 
 fn main() {}
diff --git a/tests/ui/imports/glob-conflict-cross-crate.rs b/tests/ui/imports/glob-conflict-cross-crate-1.rs
similarity index 54%
rename from tests/ui/imports/glob-conflict-cross-crate.rs
rename to tests/ui/imports/glob-conflict-cross-crate-1.rs
index d84c243f2139c..832e6c888a646 100644
--- a/tests/ui/imports/glob-conflict-cross-crate.rs
+++ b/tests/ui/imports/glob-conflict-cross-crate-1.rs
@@ -4,5 +4,9 @@ extern crate glob_conflict;
 
 fn main() {
     glob_conflict::f(); //~ ERROR cannot find function `f` in crate `glob_conflict`
+    //^ FIXME: `glob_conflict::f` should raise an
+    // ambiguity error instead of a not found error.
     glob_conflict::glob::f(); //~ ERROR cannot find function `f` in module `glob_conflict::glob`
+    //^ FIXME: `glob_conflict::glob::f` should raise an
+    // ambiguity error instead of a not found error.
 }
diff --git a/tests/ui/imports/glob-conflict-cross-crate.stderr b/tests/ui/imports/glob-conflict-cross-crate-1.stderr
similarity index 82%
rename from tests/ui/imports/glob-conflict-cross-crate.stderr
rename to tests/ui/imports/glob-conflict-cross-crate-1.stderr
index 0e3b4222fe44f..758087107f397 100644
--- a/tests/ui/imports/glob-conflict-cross-crate.stderr
+++ b/tests/ui/imports/glob-conflict-cross-crate-1.stderr
@@ -1,11 +1,11 @@
 error[E0425]: cannot find function `f` in crate `glob_conflict`
-  --> $DIR/glob-conflict-cross-crate.rs:6:20
+  --> $DIR/glob-conflict-cross-crate-1.rs:6:20
    |
 LL |     glob_conflict::f();
    |                    ^ not found in `glob_conflict`
 
 error[E0425]: cannot find function `f` in module `glob_conflict::glob`
-  --> $DIR/glob-conflict-cross-crate.rs:7:26
+  --> $DIR/glob-conflict-cross-crate-1.rs:9:26
    |
 LL |     glob_conflict::glob::f();
    |                          ^ not found in `glob_conflict::glob`
diff --git a/tests/ui/imports/glob-conflict-cross-crate-2.rs b/tests/ui/imports/glob-conflict-cross-crate-2.rs
new file mode 100644
index 0000000000000..6ba71ad30ac54
--- /dev/null
+++ b/tests/ui/imports/glob-conflict-cross-crate-2.rs
@@ -0,0 +1,10 @@
+// aux-build:glob-conflict-cross-crate-2-extern.rs
+
+extern crate glob_conflict_cross_crate_2_extern;
+
+use glob_conflict_cross_crate_2_extern::*;
+
+fn main() {
+    let _a: C = 1; //~ ERROR cannot find type `C` in this scope
+    //^ FIXME: `C` should be identified as an ambiguous item.
+}
diff --git a/tests/ui/imports/glob-conflict-cross-crate-2.stderr b/tests/ui/imports/glob-conflict-cross-crate-2.stderr
new file mode 100644
index 0000000000000..aebb2d59d063a
--- /dev/null
+++ b/tests/ui/imports/glob-conflict-cross-crate-2.stderr
@@ -0,0 +1,9 @@
+error[E0412]: cannot find type `C` in this scope
+  --> $DIR/glob-conflict-cross-crate-2.rs:8:13
+   |
+LL |     let _a: C = 1;
+   |             ^ not found in this scope
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0412`.
diff --git a/tests/ui/imports/glob-conflict-cross-crate-3.rs b/tests/ui/imports/glob-conflict-cross-crate-3.rs
new file mode 100644
index 0000000000000..535d87d8ea284
--- /dev/null
+++ b/tests/ui/imports/glob-conflict-cross-crate-3.rs
@@ -0,0 +1,16 @@
+// check-pass
+// aux-build:glob-conflict-cross-crate-2-extern.rs
+
+extern crate glob_conflict_cross_crate_2_extern;
+
+mod a {
+    pub type C = i32;
+}
+
+use glob_conflict_cross_crate_2_extern::*;
+use a::*;
+
+fn main() {
+    let _a: C = 1;
+    //^ FIXME: `C` should be identified as an ambiguous item.
+}
diff --git a/tests/ui/imports/issue-114682-1.rs b/tests/ui/imports/issue-114682-1.rs
new file mode 100644
index 0000000000000..88fe05e51444d
--- /dev/null
+++ b/tests/ui/imports/issue-114682-1.rs
@@ -0,0 +1,25 @@
+// https://github.com/rust-lang/rust/pull/114682#discussion_r1420534109
+
+#![feature(decl_macro)]
+
+macro_rules! mac {
+    () => {
+        pub macro A() {
+            println!("non import")
+        }
+    }
+}
+
+mod m {
+    pub macro A() {
+        println!("import")
+    }
+}
+
+pub use m::*;
+mac!();
+
+fn main() {
+    A!();
+    //~^ ERROR `A` is ambiguous
+}
diff --git a/tests/ui/imports/issue-114682-1.stderr b/tests/ui/imports/issue-114682-1.stderr
new file mode 100644
index 0000000000000..85fb7f7919e4e
--- /dev/null
+++ b/tests/ui/imports/issue-114682-1.stderr
@@ -0,0 +1,28 @@
+error[E0659]: `A` is ambiguous
+  --> $DIR/issue-114682-1.rs:23:5
+   |
+LL |     A!();
+   |     ^ ambiguous name
+   |
+   = note: ambiguous because of a conflict between a name from a glob import and a macro-expanded name in the same module during import or macro resolution
+note: `A` could refer to the macro defined here
+  --> $DIR/issue-114682-1.rs:7:9
+   |
+LL | /         pub macro A() {
+LL | |             println!("non import")
+LL | |         }
+   | |_________^
+...
+LL |   mac!();
+   |   ------ in this macro invocation
+note: `A` could also refer to the macro imported here
+  --> $DIR/issue-114682-1.rs:19:9
+   |
+LL | pub use m::*;
+   |         ^^^^
+   = help: consider adding an explicit import of `A` to disambiguate
+   = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0659`.
diff --git a/tests/ui/imports/issue-114682-2.rs b/tests/ui/imports/issue-114682-2.rs
new file mode 100644
index 0000000000000..491105e62efea
--- /dev/null
+++ b/tests/ui/imports/issue-114682-2.rs
@@ -0,0 +1,19 @@
+// aux-build: issue-114682-2-extern.rs
+// https://github.com/rust-lang/rust/pull/114682#issuecomment-1879998900
+
+extern crate issue_114682_2_extern;
+
+use issue_114682_2_extern::max;
+
+type A = issue_114682_2_extern::max;
+//~^ ERROR: expected type, found function `issue_114682_2_extern::max`
+// FIXME:
+// The above error was emitted due to `(Mod(issue_114682_2_extern), Namespace(Type), Ident(max))`
+// being identified as an ambiguous item.
+// However, there are two points worth discussing:
+// First, should this ambiguous item be omitted considering the maximum visibility
+// of `issue_114682_2_extern::m::max` in the type namespace is only within the extern crate.
+// Second, if we retain the ambiguous item of the extern crate, should it be treated
+// as an ambiguous item within the local crate for the same reasoning?
+
+fn main() {}
diff --git a/tests/ui/imports/issue-114682-2.stderr b/tests/ui/imports/issue-114682-2.stderr
new file mode 100644
index 0000000000000..972bcecb56bc2
--- /dev/null
+++ b/tests/ui/imports/issue-114682-2.stderr
@@ -0,0 +1,9 @@
+error[E0573]: expected type, found function `issue_114682_2_extern::max`
+  --> $DIR/issue-114682-2.rs:8:10
+   |
+LL | type A = issue_114682_2_extern::max;
+   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^ not a type
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0573`.
diff --git a/tests/ui/imports/issue-114682-3.rs b/tests/ui/imports/issue-114682-3.rs
new file mode 100644
index 0000000000000..0f658bfe1597a
--- /dev/null
+++ b/tests/ui/imports/issue-114682-3.rs
@@ -0,0 +1,24 @@
+// check-pass
+// aux-build: issue-114682-3-extern.rs
+// https://github.com/rust-lang/rust/pull/114682#issuecomment-1880625909
+
+extern crate issue_114682_3_extern;
+
+use issue_114682_3_extern::*;
+
+mod auto {
+    pub trait SettingsExt {
+        fn ext(&self) {}
+    }
+
+    impl<T> SettingsExt for T {}
+}
+
+pub use self::auto::*;
+
+fn main() {
+    let a: u8 = 1;
+    a.ext();
+    //^ FIXME: it should report `ext` not found because `SettingsExt`
+    // is an ambiguous item in `issue-114682-3-extern.rs`.
+}
diff --git a/tests/ui/imports/issue-114682-4.rs b/tests/ui/imports/issue-114682-4.rs
new file mode 100644
index 0000000000000..97615c1041049
--- /dev/null
+++ b/tests/ui/imports/issue-114682-4.rs
@@ -0,0 +1,13 @@
+// check-pass
+// aux-build: issue-114682-4-extern.rs
+// https://github.com/rust-lang/rust/pull/114682#issuecomment-1880755441
+
+extern crate issue_114682_4_extern;
+
+use issue_114682_4_extern::*;
+
+fn a() -> Result<i32, ()> { // FIXME: `Result` should be identified as an ambiguous item.
+    Ok(1)
+}
+
+fn main() {}
diff --git a/tests/ui/imports/issue-114682-5.rs b/tests/ui/imports/issue-114682-5.rs
new file mode 100644
index 0000000000000..eb5ac10495bee
--- /dev/null
+++ b/tests/ui/imports/issue-114682-5.rs
@@ -0,0 +1,15 @@
+// check-pass
+// edition: 2018
+// aux-build: issue-114682-5-extern-1.rs
+// aux-build: issue-114682-5-extern-2.rs
+// compile-flags: --extern issue_114682_5_extern_1
+// https://github.com/rust-lang/rust/pull/114682#issuecomment-1880755441
+
+extern crate issue_114682_5_extern_2;
+
+use issue_114682_5_extern_2::p::*;
+use issue_114682_5_extern_1::Url;
+// FIXME: The `issue_114682_5_extern_1` should be considered an ambiguous item,
+// as it has already been recognized as ambiguous in `issue_114682_5_extern_2`.
+
+fn main() {}
diff --git a/tests/ui/imports/issue-114682-6.rs b/tests/ui/imports/issue-114682-6.rs
new file mode 100644
index 0000000000000..29a7d9e942643
--- /dev/null
+++ b/tests/ui/imports/issue-114682-6.rs
@@ -0,0 +1,13 @@
+// check-pass
+// aux-build: issue-114682-6-extern.rs
+// https://github.com/rust-lang/rust/pull/114682#issuecomment-1880755441
+
+extern crate issue_114682_6_extern;
+
+use issue_114682_6_extern::*;
+
+fn main() {
+    let log = 2;
+    //^ `log` should be identified as an ambiguous item.
+    let _ = log;
+}