Skip to content

Commit 3f86775

Browse files
authoredOct 24, 2019
Rollup merge of rust-lang#65405 - GuillaumeGomez:long-err-explanation-E0740, r=Dylan-DPC
Create new error E0741 and add long error explanation Part of rust-lang#61137. Creates E0740 error code and add its long error explanation.
2 parents 8e0007f + b64d69d commit 3f86775

File tree

7 files changed

+54
-12
lines changed

7 files changed

+54
-12
lines changed
 

‎src/librustc_resolve/build_reduced_graph.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
258258
if self.r.is_accessible_from(vis, parent_scope.module) {
259259
vis
260260
} else {
261-
let msg =
262-
"visibilities can only be restricted to ancestor modules";
263-
self.r.session.span_err(path.span, msg);
261+
struct_span_err!(self.r.session, path.span, E0741,
262+
"visibilities can only be restricted to ancestor modules")
263+
.emit();
264264
ty::Visibility::Public
265265
}
266266
}

‎src/librustc_resolve/error_codes.rs

+38
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,44 @@ struct Foo<X = Box<Self>> {
19061906
```
19071907
"##,
19081908

1909+
E0741: r##"
1910+
Visibility is restricted to a module which isn't an ancestor of the current
1911+
item.
1912+
1913+
Erroneous code example:
1914+
1915+
```compile_fail,E0741,edition2018
1916+
pub mod Sea {}
1917+
1918+
pub (in crate::Sea) struct Shark; // error!
1919+
1920+
fn main() {}
1921+
```
1922+
1923+
To fix this error, we need to move the `Shark` struct inside the `Sea` module:
1924+
1925+
```edition2018
1926+
pub mod Sea {
1927+
pub (in crate::Sea) struct Shark; // ok!
1928+
}
1929+
1930+
fn main() {}
1931+
```
1932+
1933+
Of course, you can do it as long as the module you're referring to is an
1934+
ancestor:
1935+
1936+
```edition2018
1937+
pub mod Earth {
1938+
pub mod Sea {
1939+
pub (in crate::Earth) struct Shark; // ok!
1940+
}
1941+
}
1942+
1943+
fn main() {}
1944+
```
1945+
"##,
1946+
19091947
;
19101948
// E0153, unused error code
19111949
// 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[E0741]: 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 E0741`.

‎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[E0741]: 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, E0741.
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[E0741]: 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, E0741.
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[E0741]: 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, E0741.
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[E0741]: 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, E0741.
34+
For more information about an error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)