summaryrefslogtreecommitdiffstats
path: root/tests/ui/imports/imports.rs
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/imports/imports.rs
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/imports/imports.rs')
-rw-r--r--tests/ui/imports/imports.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/ui/imports/imports.rs b/tests/ui/imports/imports.rs
new file mode 100644
index 000000000..acb2b32b5
--- /dev/null
+++ b/tests/ui/imports/imports.rs
@@ -0,0 +1,66 @@
+// run-pass
+#![allow(unused)]
+
+// Like other items, private imports can be imported and used non-lexically in paths.
+mod a {
+ use a as foo;
+ use self::foo::foo as bar;
+
+ mod b {
+ use super::bar;
+ }
+}
+
+mod foo { pub fn f() {} }
+mod bar { pub fn f() {} }
+
+pub fn f() -> bool { true }
+
+// Items and explicit imports shadow globs.
+fn g() {
+ use foo::*;
+ use bar::*;
+ fn f() -> bool { true }
+ let _: bool = f();
+}
+
+fn h() {
+ use foo::*;
+ use bar::*;
+ use f;
+ let _: bool = f();
+}
+
+// Here, there appears to be shadowing but isn't because of namespaces.
+mod b {
+ use foo::*; // This imports `f` in the value namespace.
+ use super::b as f; // This imports `f` only in the type namespace,
+ fn test() { self::f(); } // so the glob isn't shadowed.
+}
+
+// Here, there is shadowing in one namespace, but not the other.
+mod c {
+ mod test {
+ pub fn f() {}
+ pub mod f {}
+ }
+ use self::test::*; // This glob-imports `f` in both namespaces.
+ mod f { pub fn f() {} } // This shadows the glob only in the value namespace.
+
+ fn test() {
+ self::f(); // Check that the glob-imported value isn't shadowed.
+ self::f::f(); // Check that the glob-imported module is shadowed.
+ }
+}
+
+// Unused names can be ambiguous.
+mod d {
+ pub use foo::*; // This imports `f` in the value namespace.
+ pub use bar::*; // This also imports `f` in the value namespace.
+}
+
+mod e {
+ pub use d::*; // n.b. Since `e::f` is not used, this is not considered to be a use of `d::f`.
+}
+
+fn main() {}