about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2024-02-09 19:52:41 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2024-02-09 20:17:48 +0300
commit8b6b9c5efc6635a75bcd15899bc4314483c8e836 (patch)
treecb0d0fa57abaead4ab339d169e7391e9d0447e06
parent8fb67fb37fed736cb04f307473af7c863be224fb (diff)
downloadrust-8b6b9c5efc6635a75bcd15899bc4314483c8e836.tar.gz
rust-8b6b9c5efc6635a75bcd15899bc4314483c8e836.zip
ast_lowering: Fix regression in `use ::{}` imports.
-rw-r--r--compiler/rustc_ast_lowering/src/item.rs7
-rw-r--r--tests/ui/imports/empty-import-prefix-pass-2015.rs10
-rw-r--r--tests/ui/imports/empty-import-prefix-pass.rs10
3 files changed, 26 insertions, 1 deletions
diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs
index 75410323f97..fb52f9cf58f 100644
--- a/compiler/rustc_ast_lowering/src/item.rs
+++ b/compiler/rustc_ast_lowering/src/item.rs
@@ -569,7 +569,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
                     });
                 }
 
-                let path = if trees.is_empty() && !prefix.segments.is_empty() {
+                // Condition should match `build_reduced_graph_for_use_tree`.
+                let path = if trees.is_empty()
+                    && !(prefix.segments.is_empty()
+                        || prefix.segments.len() == 1
+                            && prefix.segments[0].ident.name == kw::PathRoot)
+                {
                     // For empty lists we need to lower the prefix so it is checked for things
                     // like stability later.
                     let res = self.lower_import_res(id, span);
diff --git a/tests/ui/imports/empty-import-prefix-pass-2015.rs b/tests/ui/imports/empty-import-prefix-pass-2015.rs
new file mode 100644
index 00000000000..a3278007c11
--- /dev/null
+++ b/tests/ui/imports/empty-import-prefix-pass-2015.rs
@@ -0,0 +1,10 @@
+// check-pass
+// edition:2015
+
+use {};
+use {{}};
+
+use ::{};
+use {::{}};
+
+fn main() {}
diff --git a/tests/ui/imports/empty-import-prefix-pass.rs b/tests/ui/imports/empty-import-prefix-pass.rs
new file mode 100644
index 00000000000..d76c0da4bd8
--- /dev/null
+++ b/tests/ui/imports/empty-import-prefix-pass.rs
@@ -0,0 +1,10 @@
+// check-pass
+// edition:2018
+
+use {};
+use {{}};
+
+use ::{};
+use {::{}};
+
+fn main() {}