Skip to content

Commit 28b6607

Browse files
committed
Auto merge of #109348 - cjgillot:issue-109146, r=petrochenkov
Resolve visibility paths as modules not as types. Asking for a resolution with `opt_ns = Some(TypeNS)` allows path resolution to look for type-relative paths, leaving unresolved segments behind. However, for visibility paths we really need to look for a module, so we need to pass `opt_ns = None`. Fixes #109146 r? `@petrochenkov`
2 parents 1cabb8e + 69ea85d commit 28b6607

File tree

7 files changed

+28
-8
lines changed

7 files changed

+28
-8
lines changed

Diff for: compiler/rustc_error_codes/src/error_codes/E0577.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Something other than a module was found in visibility scope.
33
Erroneous code example:
44

55
```compile_fail,E0577,edition2018
6-
pub struct Sea;
6+
pub enum Sea {}
77
88
pub (in crate::Sea) struct Shark; // error!
99

Diff for: compiler/rustc_resolve/src/build_reduced_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
278278
};
279279
match self.r.resolve_path(
280280
&segments,
281-
Some(TypeNS),
281+
None,
282282
parent_scope,
283283
finalize.then(|| Finalize::new(id, path.span)),
284284
None,

Diff for: tests/ui/resolve/unresolved-segments-visibility.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Check that we do not ICE due to unresolved segments in visibility path.
2+
#![crate_type = "lib"]
3+
4+
extern crate alloc as b;
5+
6+
mod foo {
7+
mod bar {
8+
pub(in b::string::String::newy) extern crate alloc as e;
9+
//~^ ERROR failed to resolve: `String` is a struct, not a module [E0433]
10+
}
11+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0433]: failed to resolve: `String` is a struct, not a module
2+
--> $DIR/unresolved-segments-visibility.rs:8:27
3+
|
4+
LL | pub(in b::string::String::newy) extern crate alloc as e;
5+
| ^^^^^^ `String` is a struct, not a module
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0433`.

Diff for: tests/ui/span/visibility-ty-params.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ macro_rules! m {
44

55
struct S<T>(T);
66
m!{ S<u8> } //~ ERROR unexpected generic arguments in path
7-
//~| ERROR expected module, found struct `S`
7+
//~| ERROR failed to resolve: `S` is a struct, not a module [E0433]
88

99
mod m {
1010
m!{ m<> } //~ ERROR unexpected generic arguments in path

Diff for: tests/ui/span/visibility-ty-params.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ error: unexpected generic arguments in path
44
LL | m!{ S<u8> }
55
| ^^^^
66

7-
error[E0577]: expected module, found struct `S`
7+
error[E0433]: failed to resolve: `S` is a struct, not a module
88
--> $DIR/visibility-ty-params.rs:6:5
99
|
1010
LL | m!{ S<u8> }
11-
| ^^^^^ not a module
11+
| ^ `S` is a struct, not a module
1212

1313
error: unexpected generic arguments in path
1414
--> $DIR/visibility-ty-params.rs:10:10
@@ -18,4 +18,4 @@ LL | m!{ m<> }
1818

1919
error: aborting due to 3 previous errors
2020

21-
For more information about this error, try `rustc --explain E0577`.
21+
For more information about this error, try `rustc --explain E0433`.

Diff for: tests/ui/use/use-self-type.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error[E0433]: failed to resolve: `Self` is only available in impls, traits, and type definitions
1+
error[E0433]: failed to resolve: `Self` cannot be used in imports
22
--> $DIR/use-self-type.rs:7:16
33
|
44
LL | pub(in Self::f) struct Z;
5-
| ^^^^ `Self` is only available in impls, traits, and type definitions
5+
| ^^^^ `Self` cannot be used in imports
66

77
error[E0432]: unresolved import `Self`
88
--> $DIR/use-self-type.rs:6:13

0 commit comments

Comments
 (0)