Skip to content

Commit

Permalink
Rollup merge of rust-lang#65405 - GuillaumeGomez:long-err-explanation…
Browse files Browse the repository at this point in the history
…-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.
  • Loading branch information
Centril committed Oct 24, 2019
2 parents 8e0007f + b64d69d commit 3f86775
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
if self.r.is_accessible_from(vis, parent_scope.module) {
vis
} else {
let msg =
"visibilities can only be restricted to ancestor modules";
self.r.session.span_err(path.span, msg);
struct_span_err!(self.r.session, path.span, E0741,
"visibilities can only be restricted to ancestor modules")
.emit();
ty::Visibility::Public
}
}
Expand Down
38 changes: 38 additions & 0 deletions src/librustc_resolve/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,44 @@ struct Foo<X = Box<Self>> {
```
"##,

E0741: r##"
Visibility is restricted to a module which isn't an ancestor of the current
item.
Erroneous code example:
```compile_fail,E0741,edition2018
pub mod Sea {}
pub (in crate::Sea) struct Shark; // error!
fn main() {}
```
To fix this error, we need to move the `Shark` struct inside the `Sea` module:
```edition2018
pub mod Sea {
pub (in crate::Sea) struct Shark; // ok!
}
fn main() {}
```
Of course, you can do it as long as the module you're referring to is an
ancestor:
```edition2018
pub mod Earth {
pub mod Sea {
pub (in crate::Earth) struct Shark; // ok!
}
}
fn main() {}
```
"##,

;
// E0153, unused error code
// E0157, unused error code
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/privacy/restricted/relative-2018.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: visibilities can only be restricted to ancestor modules
error[E0741]: visibilities can only be restricted to ancestor modules
--> $DIR/relative-2018.rs:7:12
|
LL | pub(in ::core) struct S4;
Expand All @@ -14,3 +14,4 @@ LL | pub(in a::b) struct S5;

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0741`.
4 changes: 2 additions & 2 deletions src/test/ui/privacy/restricted/test.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0433]: failed to resolve: maybe a missing crate `bad`?
LL | pub(in bad::path) mod m1 {}
| ^^^ maybe a missing crate `bad`?

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

error: aborting due to 12 previous errors

Some errors have detailed explanations: E0364, E0433, E0603, E0616, E0624.
Some errors have detailed explanations: E0364, E0433, E0603, E0616, E0624, E0741.
For more information about an error, try `rustc --explain E0364`.
5 changes: 3 additions & 2 deletions src/test/ui/proc-macro/issue-50493.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: visibilities can only be restricted to ancestor modules
error[E0741]: visibilities can only be restricted to ancestor modules
--> $DIR/issue-50493.rs:8:12
|
LL | pub(in restricted) field: usize,
Expand All @@ -12,4 +12,5 @@ LL | #[derive(Derive)]

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0616`.
Some errors have detailed explanations: E0616, E0741.
For more information about an error, try `rustc --explain E0616`.
5 changes: 3 additions & 2 deletions src/test/ui/pub/pub-restricted.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ LL | pub (xyz) fn xyz() {}
`pub(super)`: visible only in the current module's parent
`pub(in path::to::module)`: visible only on the specified path

error: visibilities can only be restricted to ancestor modules
error[E0741]: visibilities can only be restricted to ancestor modules
--> $DIR/pub-restricted.rs:25:17
|
LL | pub (in x) non_parent_invalid: usize,
| ^

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0704`.
Some errors have detailed explanations: E0704, E0741.
For more information about an error, try `rustc --explain E0704`.
5 changes: 3 additions & 2 deletions src/test/ui/resolve/resolve-bad-visibility.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ error[E0577]: expected module, found trait `Tr`
LL | pub(in Tr) struct Z;
| ^^ not a module

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

error: aborting due to 5 previous errors

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

0 comments on commit 3f86775

Please sign in to comment.