Skip to content

Resolve visibility paths as modules not as types. #109348

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes/E0577.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/resolve/unresolved-segments-visibility.rs
Original file line number Diff line number Diff line change
@@ -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]
}
}
9 changes: 9 additions & 0 deletions tests/ui/resolve/unresolved-segments-visibility.stderr
Original file line number Diff line number Diff line change
@@ -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`.
2 changes: 1 addition & 1 deletion tests/ui/span/visibility-ty-params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/span/visibility-ty-params.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`.
4 changes: 2 additions & 2 deletions tests/ui/use/use-self-type.stderr
Original file line number Diff line number Diff line change
@@ -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
Expand Down