summaryrefslogtreecommitdiffstats
path: root/tests/ui/uniform-paths
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/uniform-paths
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/uniform-paths')
-rw-r--r--tests/ui/uniform-paths/auxiliary/issue-53691.rs7
-rw-r--r--tests/ui/uniform-paths/basic-nested.rs61
-rw-r--r--tests/ui/uniform-paths/basic.rs33
-rw-r--r--tests/ui/uniform-paths/issue-53691.rs9
-rw-r--r--tests/ui/uniform-paths/macros-nested.rs53
-rw-r--r--tests/ui/uniform-paths/macros.rs36
-rw-r--r--tests/ui/uniform-paths/same-crate.rs98
7 files changed, 297 insertions, 0 deletions
diff --git a/tests/ui/uniform-paths/auxiliary/issue-53691.rs b/tests/ui/uniform-paths/auxiliary/issue-53691.rs
new file mode 100644
index 000000000..a46533178
--- /dev/null
+++ b/tests/ui/uniform-paths/auxiliary/issue-53691.rs
@@ -0,0 +1,7 @@
+// edition:2018
+
+mod m { pub fn f() {} }
+mod n { pub fn g() {} }
+
+pub use m::f;
+pub use n::g;
diff --git a/tests/ui/uniform-paths/basic-nested.rs b/tests/ui/uniform-paths/basic-nested.rs
new file mode 100644
index 000000000..dcf0eb646
--- /dev/null
+++ b/tests/ui/uniform-paths/basic-nested.rs
@@ -0,0 +1,61 @@
+// This test is similar to `basic.rs`, but nested in modules.
+
+// run-pass
+// edition:2018
+
+#![feature(decl_macro)]
+
+#![allow(unused_imports)]
+#![allow(non_camel_case_types)]
+
+mod foo {
+ // Test that ambiguity errors are not emitted between `self::test` and
+ // `::test`, assuming the latter (crate) is not in `extern_prelude`.
+ mod test {
+ pub struct Foo(pub ());
+ }
+ pub use test::Foo;
+
+ // Test that qualified paths can refer to both the external crate and local item.
+ mod std {
+ pub struct io(pub ());
+ }
+ pub use ::std::io as std_io;
+ pub use self::std::io as local_io;
+}
+
+// Test that we can refer to the external crate unqualified
+// (when there isn't a local item with the same name).
+use std::io;
+
+mod bar {
+ // Also test the unqualified external crate import in a nested module,
+ // to show that the above import doesn't resolve through a local `std`
+ // item, e.g., the automatically injected `extern crate std;`, which in
+ // the Rust 2018 should no longer be visible through `crate::std`.
+ pub use std::io;
+
+ // Also test that items named `std` in other namespaces don't
+ // cause ambiguity errors for the import from `std` above.
+ pub fn std() {}
+ pub macro std() {}
+}
+
+
+fn main() {
+ foo::Foo(());
+ let _ = foo::std_io::stdout();
+ foo::local_io(());
+ let _ = io::stdout();
+ let _ = bar::io::stdout();
+ bar::std();
+ bar::std!();
+
+ {
+ // Test that having `io` in a module scope and a non-module
+ // scope is allowed, when both resolve to the same definition.
+ use std::io;
+ use io::stdout;
+ let _ = stdout();
+ }
+}
diff --git a/tests/ui/uniform-paths/basic.rs b/tests/ui/uniform-paths/basic.rs
new file mode 100644
index 000000000..ce611a7ca
--- /dev/null
+++ b/tests/ui/uniform-paths/basic.rs
@@ -0,0 +1,33 @@
+// run-pass
+// edition:2018
+
+#![allow(unused_imports)]
+#![allow(non_camel_case_types)]
+
+// Test that ambiguity errors are not emitted between `self::test` and
+// `::test`, assuming the latter (crate) is not in `extern_prelude`.
+mod test {
+ pub struct Foo(pub ());
+}
+use test::Foo;
+
+// Test that qualified paths can refer to both the external crate and local item.
+mod std {
+ pub struct io(pub ());
+}
+use ::std::io as std_io;
+use self::std::io as local_io;
+
+fn main() {
+ Foo(());
+ let _ = std_io::stdout();
+ local_io(());
+
+ {
+ // Test that having `std_io` in a module scope and a non-module
+ // scope is allowed, when both resolve to the same definition.
+ use ::std::io as std_io;
+ use std_io::stdout;
+ let _ = stdout();
+ }
+}
diff --git a/tests/ui/uniform-paths/issue-53691.rs b/tests/ui/uniform-paths/issue-53691.rs
new file mode 100644
index 000000000..5c5ca5b70
--- /dev/null
+++ b/tests/ui/uniform-paths/issue-53691.rs
@@ -0,0 +1,9 @@
+// run-pass
+// aux-build:issue-53691.rs
+
+extern crate issue_53691;
+
+fn main() {
+ issue_53691::f();
+ issue_53691::g();
+}
diff --git a/tests/ui/uniform-paths/macros-nested.rs b/tests/ui/uniform-paths/macros-nested.rs
new file mode 100644
index 000000000..175ccd34e
--- /dev/null
+++ b/tests/ui/uniform-paths/macros-nested.rs
@@ -0,0 +1,53 @@
+// This test is similar to `macros.rs`, but nested in modules.
+
+// run-pass
+// edition:2018
+
+#![allow(non_camel_case_types)]
+
+mod foo {
+ // Test that ambiguity errors are not emitted between `self::test` and
+ // `::test`, assuming the latter (crate) is not in `extern_prelude`.
+ macro_rules! m1 {
+ () => {
+ mod test {
+ pub struct Foo(pub ());
+ }
+ }
+ }
+ pub use test::Foo;
+ m1!();
+
+ // Test that qualified paths can refer to both the external crate and local item.
+ macro_rules! m2 {
+ () => {
+ mod std {
+ pub struct io(pub ());
+ }
+ }
+ }
+ pub use ::std::io as std_io;
+ pub use self::std::io as local_io;
+ m2!();
+}
+
+// Test that we can refer to the external crate unqualified
+// (when there isn't a local item with the same name).
+use std::io;
+
+mod bar {
+ // Also test the unqualified external crate import in a nested module,
+ // to show that the above import doesn't resolve through a local `std`
+ // item, e.g., the automatically injected `extern crate std;`, which in
+ // the Rust 2018 should no longer be visible through `crate::std`.
+ pub use std::io;
+}
+
+
+fn main() {
+ foo::Foo(());
+ let _ = foo::std_io::stdout();
+ foo::local_io(());
+ let _ = io::stdout();
+ let _ = bar::io::stdout();
+}
diff --git a/tests/ui/uniform-paths/macros.rs b/tests/ui/uniform-paths/macros.rs
new file mode 100644
index 000000000..bf512b305
--- /dev/null
+++ b/tests/ui/uniform-paths/macros.rs
@@ -0,0 +1,36 @@
+// This test is similar to `basic.rs`, but with macros defining local items.
+
+// run-pass
+// edition:2018
+
+#![allow(non_camel_case_types)]
+
+// Test that ambiguity errors are not emitted between `self::test` and
+// `::test`, assuming the latter (crate) is not in `extern_prelude`.
+macro_rules! m1 {
+ () => {
+ mod test {
+ pub struct Foo(pub ());
+ }
+ }
+}
+use test::Foo;
+m1!();
+
+// Test that qualified paths can refer to both the external crate and local item.
+macro_rules! m2 {
+ () => {
+ mod std {
+ pub struct io(pub ());
+ }
+ }
+}
+use ::std::io as std_io;
+use self::std::io as local_io;
+m2!();
+
+fn main() {
+ Foo(());
+ let _ = std_io::stdout();
+ local_io(());
+}
diff --git a/tests/ui/uniform-paths/same-crate.rs b/tests/ui/uniform-paths/same-crate.rs
new file mode 100644
index 000000000..ce4cc13d9
--- /dev/null
+++ b/tests/ui/uniform-paths/same-crate.rs
@@ -0,0 +1,98 @@
+// run-pass
+// edition:2018
+
+pub const A: usize = 0;
+
+pub mod foo {
+ pub const B: usize = 1;
+
+ pub mod bar {
+ pub const C: usize = 2;
+
+ pub enum E {
+ V1(usize),
+ V2(String),
+ }
+
+ pub fn test() -> String {
+ format!("{} {} {}", crate::A, crate::foo::B, C)
+ }
+
+ pub fn test_use() -> String {
+ use crate::A;
+ use crate::foo::B;
+
+ format!("{} {} {}", A, B, C)
+ }
+
+ pub fn test_enum() -> String {
+ use E::*;
+ match E::V1(10) {
+ V1(i) => { format!("V1: {}", i) }
+ V2(s) => { format!("V2: {}", s) }
+ }
+ }
+ }
+
+ pub fn test() -> String {
+ format!("{} {} {}", crate::A, B, bar::C)
+ }
+
+ pub fn test_use() -> String {
+ use crate::A;
+ use bar::C;
+
+ format!("{} {} {}", A, B, C)
+ }
+
+ pub fn test_enum() -> String {
+ use bar::E::*;
+ match bar::E::V1(10) {
+ V1(i) => { format!("V1: {}", i) }
+ V2(s) => { format!("V2: {}", s) }
+ }
+ }
+}
+
+pub fn test() -> String {
+ format!("{} {} {}", A, foo::B, foo::bar::C)
+}
+
+pub fn test_use() -> String {
+ use foo::B;
+ use foo::bar::C;
+
+ format!("{} {} {}", A, B, C)
+}
+
+pub fn test_enum() -> String {
+ use foo::bar::E::*;
+ match foo::bar::E::V1(10) {
+ V1(i) => { format!("V1: {}", i) }
+ V2(s) => { format!("V2: {}", s) }
+ }
+}
+
+fn main() {
+ let output = [
+ test(),
+ foo::test(),
+ foo::bar::test(),
+ test_use(),
+ foo::test_use(),
+ foo::bar::test_use(),
+ test_enum(),
+ foo::test_enum(),
+ foo::bar::test_enum(),
+ ].join("\n");
+ assert_eq!(output, "\
+0 1 2
+0 1 2
+0 1 2
+0 1 2
+0 1 2
+0 1 2
+V1: 10
+V1: 10
+V1: 10");
+}