about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2023-03-19 10:46:19 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2023-08-02 15:30:24 +0000
commit2faa2626ccb9fa163c0c890657d26e98ba04ed7c (patch)
tree86a75c0ea53f844b05e8083b8c4c57b3e57b0787
parent7a5d2d0138d4a3d7d97cad0ca72ab62e938e0b0b (diff)
downloadrust-2faa2626ccb9fa163c0c890657d26e98ba04ed7c.tar.gz
rust-2faa2626ccb9fa163c0c890657d26e98ba04ed7c.zip
Resolve visibility paths as modules not as types.
-rw-r--r--compiler/rustc_resolve/src/build_reduced_graph.rs2
-rw-r--r--tests/ui/resolve/unresolved-segments-visibility.rs11
-rw-r--r--tests/ui/resolve/unresolved-segments-visibility.stderr9
-rw-r--r--tests/ui/span/visibility-ty-params.rs2
-rw-r--r--tests/ui/span/visibility-ty-params.stderr6
-rw-r--r--tests/ui/use/use-self-type.stderr4
6 files changed, 27 insertions, 7 deletions
diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs
index 2f432799022..80d6a47ff53 100644
--- a/compiler/rustc_resolve/src/build_reduced_graph.rs
+++ b/compiler/rustc_resolve/src/build_reduced_graph.rs
@@ -278,7 +278,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
                 };
                 match self.r.resolve_path(
                     &segments,
-                    Some(TypeNS),
+                    None,
                     parent_scope,
                     finalize.then(|| Finalize::new(id, path.span)),
                     None,
diff --git a/tests/ui/resolve/unresolved-segments-visibility.rs b/tests/ui/resolve/unresolved-segments-visibility.rs
new file mode 100644
index 00000000000..c26171f75d2
--- /dev/null
+++ b/tests/ui/resolve/unresolved-segments-visibility.rs
@@ -0,0 +1,11 @@
+// Check that we do not ICE due to unresolved segments in visibility path.
+#![crate_type = "lib"]
+
+extern crate alloc as b;
+
+mod foo {
+    mod bar {
+        pub(in b::string::String::newy) extern crate alloc as e;
+        //~^ ERROR failed to resolve: `String` is a struct, not a module [E0433]
+    }
+}
diff --git a/tests/ui/resolve/unresolved-segments-visibility.stderr b/tests/ui/resolve/unresolved-segments-visibility.stderr
new file mode 100644
index 00000000000..0a11549cdbf
--- /dev/null
+++ b/tests/ui/resolve/unresolved-segments-visibility.stderr
@@ -0,0 +1,9 @@
+error[E0433]: failed to resolve: `String` is a struct, not a module
+  --> $DIR/unresolved-segments-visibility.rs:8:27
+   |
+LL |         pub(in b::string::String::newy) extern crate alloc as e;
+   |                           ^^^^^^ `String` is a struct, not a module
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0433`.
diff --git a/tests/ui/span/visibility-ty-params.rs b/tests/ui/span/visibility-ty-params.rs
index d77febe0aa2..11c2cf44cb4 100644
--- a/tests/ui/span/visibility-ty-params.rs
+++ b/tests/ui/span/visibility-ty-params.rs
@@ -4,7 +4,7 @@ macro_rules! m {
 
 struct S<T>(T);
 m!{ S<u8> } //~ ERROR unexpected generic arguments in path
-            //~| ERROR expected module, found struct `S`
+            //~| ERROR failed to resolve: `S` is a struct, not a module [E0433]
 
 mod m {
     m!{ m<> } //~ ERROR unexpected generic arguments in path
diff --git a/tests/ui/span/visibility-ty-params.stderr b/tests/ui/span/visibility-ty-params.stderr
index 067893fd22d..97d05c4644e 100644
--- a/tests/ui/span/visibility-ty-params.stderr
+++ b/tests/ui/span/visibility-ty-params.stderr
@@ -4,11 +4,11 @@ error: unexpected generic arguments in path
 LL | m!{ S<u8> }
    |      ^^^^
 
-error[E0577]: expected module, found struct `S`
+error[E0433]: failed to resolve: `S` is a struct, not a module
   --> $DIR/visibility-ty-params.rs:6:5
    |
 LL | m!{ S<u8> }
-   |     ^^^^^ not a module
+   |     ^ `S` is a struct, not a module
 
 error: unexpected generic arguments in path
   --> $DIR/visibility-ty-params.rs:10:10
@@ -18,4 +18,4 @@ LL |     m!{ m<> }
 
 error: aborting due to 3 previous errors
 
-For more information about this error, try `rustc --explain E0577`.
+For more information about this error, try `rustc --explain E0433`.
diff --git a/tests/ui/use/use-self-type.stderr b/tests/ui/use/use-self-type.stderr
index 3da04a851f6..498df34fe32 100644
--- a/tests/ui/use/use-self-type.stderr
+++ b/tests/ui/use/use-self-type.stderr
@@ -1,8 +1,8 @@
-error[E0433]: failed to resolve: `Self` is only available in impls, traits, and type definitions
+error[E0433]: failed to resolve: `Self` cannot be used in imports
   --> $DIR/use-self-type.rs:7:16
    |
 LL |         pub(in Self::f) struct Z;
-   |                ^^^^ `Self` is only available in impls, traits, and type definitions
+   |                ^^^^ `Self` cannot be used in imports
 
 error[E0432]: unresolved import `Self`
   --> $DIR/use-self-type.rs:6:13