From 2faa2626ccb9fa163c0c890657d26e98ba04ed7c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sun, 19 Mar 2023 10:46:19 +0000 Subject: [PATCH 1/2] Resolve visibility paths as modules not as types. --- compiler/rustc_resolve/src/build_reduced_graph.rs | 2 +- tests/ui/resolve/unresolved-segments-visibility.rs | 11 +++++++++++ .../ui/resolve/unresolved-segments-visibility.stderr | 9 +++++++++ tests/ui/span/visibility-ty-params.rs | 2 +- tests/ui/span/visibility-ty-params.stderr | 6 +++--- tests/ui/use/use-self-type.stderr | 4 ++-- 6 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 tests/ui/resolve/unresolved-segments-visibility.rs create mode 100644 tests/ui/resolve/unresolved-segments-visibility.stderr diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 2f4327990224d..80d6a47ff5383 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 0000000000000..c26171f75d2ca --- /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 0000000000000..0a11549cdbf39 --- /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 d77febe0aa22b..11c2cf44cb459 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); m!{ S } //~ 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 067893fd22d34..97d05c4644e82 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 } | ^^^^ -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 } - | ^^^^^ 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 3da04a851f651..498df34fe325e 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 From 69ea85da02441c310b4aee39f4483ede937400fa Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 2 Aug 2023 15:30:29 +0000 Subject: [PATCH 2/2] Adapt error code doc. --- compiler/rustc_error_codes/src/error_codes/E0577.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0577.md b/compiler/rustc_error_codes/src/error_codes/E0577.md index eba2d3b14175b..383ca61f6c48a 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0577.md +++ b/compiler/rustc_error_codes/src/error_codes/E0577.md @@ -3,7 +3,7 @@ Something other than a module was found in visibility scope. Erroneous code example: ```compile_fail,E0577,edition2018 -pub struct Sea; +pub enum Sea {} pub (in crate::Sea) struct Shark; // error!