Skip to content

Commit 3f50a0d

Browse files
authored
Rollup merge of rust-lang#65405 - GuillaumeGomez:long-err-explanation-E0740, r=Dylan-DPC
Create new error E0742 and add long error explanation Part of rust-lang#61137. Creates E0742 error code and add its long error explanation.
2 parents d3d28a4 + 9869e5b commit 3f50a0d

File tree

7 files changed

+55
-12
lines changed

7 files changed

+55
-12
lines changed

src/librustc_resolve/build_reduced_graph.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
256256
if self.r.is_accessible_from(vis, parent_scope.module) {
257257
vis
258258
} else {
259-
let msg =
260-
"visibilities can only be restricted to ancestor modules";
261-
self.r.session.span_err(path.span, msg);
259+
struct_span_err!(self.r.session, path.span, E0742,
260+
"visibilities can only be restricted to ancestor modules")
261+
.emit();
262262
ty::Visibility::Public
263263
}
264264
}

src/librustc_resolve/error_codes.rs

+39
Original file line numberDiff line numberDiff line change
@@ -1910,6 +1910,7 @@ E0671: r##"
19101910
19111911
Const parameters cannot depend on type parameters.
19121912
The following is therefore invalid:
1913+
19131914
```compile_fail,E0741
19141915
#![feature(const_generics)]
19151916
@@ -1933,6 +1934,44 @@ struct Foo<X = Box<Self>> {
19331934
```
19341935
"##,
19351936

1937+
E0742: r##"
1938+
Visibility is restricted to a module which isn't an ancestor of the current
1939+
item.
1940+
1941+
Erroneous code example:
1942+
1943+
```compile_fail,E0742,edition2018
1944+
pub mod Sea {}
1945+
1946+
pub (in crate::Sea) struct Shark; // error!
1947+
1948+
fn main() {}
1949+
```
1950+
1951+
To fix this error, we need to move the `Shark` struct inside the `Sea` module:
1952+
1953+
```edition2018
1954+
pub mod Sea {
1955+
pub (in crate::Sea) struct Shark; // ok!
1956+
}
1957+
1958+
fn main() {}
1959+
```
1960+
1961+
Of course, you can do it as long as the module you're referring to is an
1962+
ancestor:
1963+
1964+
```edition2018
1965+
pub mod Earth {
1966+
pub mod Sea {
1967+
pub (in crate::Earth) struct Shark; // ok!
1968+
}
1969+
}
1970+
1971+
fn main() {}
1972+
```
1973+
"##,
1974+
19361975
;
19371976
// E0153, unused error code
19381977
// E0157, unused error code

src/test/ui/privacy/restricted/relative-2018.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: visibilities can only be restricted to ancestor modules
1+
error[E0742]: visibilities can only be restricted to ancestor modules
22
--> $DIR/relative-2018.rs:7:12
33
|
44
LL | pub(in ::core) struct S4;
@@ -14,3 +14,4 @@ LL | pub(in a::b) struct S5;
1414

1515
error: aborting due to 2 previous errors
1616

17+
For more information about this error, try `rustc --explain E0742`.

src/test/ui/privacy/restricted/test.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0433]: failed to resolve: maybe a missing crate `bad`?
44
LL | pub(in bad::path) mod m1 {}
55
| ^^^ maybe a missing crate `bad`?
66

7-
error: visibilities can only be restricted to ancestor modules
7+
error[E0742]: visibilities can only be restricted to ancestor modules
88
--> $DIR/test.rs:51:12
99
|
1010
LL | pub(in foo) mod m2 {}
@@ -78,5 +78,5 @@ LL | u.h();
7878

7979
error: aborting due to 12 previous errors
8080

81-
Some errors have detailed explanations: E0364, E0433, E0603, E0616, E0624.
81+
Some errors have detailed explanations: E0364, E0433, E0603, E0616, E0624, E0742.
8282
For more information about an error, try `rustc --explain E0364`.

src/test/ui/proc-macro/issue-50493.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: visibilities can only be restricted to ancestor modules
1+
error[E0742]: visibilities can only be restricted to ancestor modules
22
--> $DIR/issue-50493.rs:8:12
33
|
44
LL | pub(in restricted) field: usize,
@@ -12,4 +12,5 @@ LL | #[derive(Derive)]
1212

1313
error: aborting due to 2 previous errors
1414

15-
For more information about this error, try `rustc --explain E0616`.
15+
Some errors have detailed explanations: E0616, E0742.
16+
For more information about an error, try `rustc --explain E0616`.

src/test/ui/pub/pub-restricted.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ LL | pub (xyz) fn xyz() {}
5353
`pub(super)`: visible only in the current module's parent
5454
`pub(in path::to::module)`: visible only on the specified path
5555

56-
error: visibilities can only be restricted to ancestor modules
56+
error[E0742]: visibilities can only be restricted to ancestor modules
5757
--> $DIR/pub-restricted.rs:25:17
5858
|
5959
LL | pub (in x) non_parent_invalid: usize,
6060
| ^
6161

6262
error: aborting due to 6 previous errors
6363

64-
For more information about this error, try `rustc --explain E0704`.
64+
Some errors have detailed explanations: E0704, E0742.
65+
For more information about an error, try `rustc --explain E0704`.

src/test/ui/resolve/resolve-bad-visibility.stderr

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ error[E0577]: expected module, found trait `Tr`
1010
LL | pub(in Tr) struct Z;
1111
| ^^ not a module
1212

13-
error: visibilities can only be restricted to ancestor modules
13+
error[E0742]: visibilities can only be restricted to ancestor modules
1414
--> $DIR/resolve-bad-visibility.rs:6:8
1515
|
1616
LL | pub(in std::vec) struct F;
@@ -30,4 +30,5 @@ LL | pub(in too_soon) struct H;
3030

3131
error: aborting due to 5 previous errors
3232

33-
For more information about this error, try `rustc --explain E0433`.
33+
Some errors have detailed explanations: E0433, E0742.
34+
For more information about an error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)