Skip to content

Commit

Permalink
Rollup merge of #97941 - CorinJG:error_naming_conventions, r=compiler…
Browse files Browse the repository at this point in the history
…-errors

nit: Fixed several error_codes/Exxxx.md messages which used UpperCamelCase…

… instead of snake_case for module names
  • Loading branch information
Dylan-DPC authored Jun 10, 2022
2 parents 345e067 + 6227d89 commit 9eee69e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
12 changes: 6 additions & 6 deletions compiler/rustc_error_codes/src/error_codes/E0451.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@ A struct constructor with private fields was invoked.
Erroneous code example:

```compile_fail,E0451
mod Bar {
mod bar {
pub struct Foo {
pub a: isize,
b: isize,
}
}
let f = Bar::Foo{ a: 0, b: 0 }; // error: field `b` of struct `Bar::Foo`
let f = bar::Foo{ a: 0, b: 0 }; // error: field `b` of struct `bar::Foo`
// is private
```

To fix this error, please ensure that all the fields of the struct are public,
or implement a function for easy instantiation. Examples:

```
mod Bar {
mod bar {
pub struct Foo {
pub a: isize,
pub b: isize, // we set `b` field public
}
}
let f = Bar::Foo{ a: 0, b: 0 }; // ok!
let f = bar::Foo{ a: 0, b: 0 }; // ok!
```

Or:

```
mod Bar {
mod bar {
pub struct Foo {
pub a: isize,
b: isize, // still private
Expand All @@ -44,5 +44,5 @@ mod Bar {
}
}
let f = Bar::Foo::new(); // ok!
let f = bar::Foo::new(); // ok!
```
10 changes: 5 additions & 5 deletions compiler/rustc_error_codes/src/error_codes/E0574.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ expected.
Erroneous code example:

```compile_fail,E0574
mod Mordor {}
mod mordor {}
let sauron = Mordor { x: () }; // error!
let sauron = mordor { x: () }; // error!
enum Jak {
Daxter { i: isize },
Expand All @@ -19,17 +19,17 @@ match eco {
```

In all these errors, a type was expected. For example, in the first error,
we tried to instantiate the `Mordor` module, which is impossible. If you want
we tried to instantiate the `mordor` module, which is impossible. If you want
to instantiate a type inside a module, you can do it as follow:

```
mod Mordor {
mod mordor {
pub struct TheRing {
pub x: usize,
}
}
let sauron = Mordor::TheRing { x: 1 }; // ok!
let sauron = mordor::TheRing { x: 1 }; // ok!
```

In the second error, we tried to bind the `Jak` enum directly, which is not
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_error_codes/src/error_codes/E0577.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ fn main() {}
```

`Sea` is not a module, therefore it is invalid to use it in a visibility path.
To fix this error we need to ensure `Sea` is a module.
To fix this error we need to ensure `sea` is a module.

Please note that the visibility scope can only be applied on ancestors!

```edition2018
pub mod Sea {
pub (in crate::Sea) struct Shark; // ok!
pub mod sea {
pub (in crate::sea) struct Shark; // ok!
}
fn main() {}
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_error_codes/src/error_codes/E0603.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ A private item was used outside its scope.
Erroneous code example:

```compile_fail,E0603
mod SomeModule {
mod foo {
const PRIVATE: u32 = 0x_a_bad_1dea_u32; // This const is private, so we
// can't use it outside of the
// `SomeModule` module.
// `foo` module.
}
println!("const value: {}", SomeModule::PRIVATE); // error: constant `PRIVATE`
println!("const value: {}", foo::PRIVATE); // error: constant `PRIVATE`
// is private
```

In order to fix this error, you need to make the item public by using the `pub`
keyword. Example:

```
mod SomeModule {
mod foo {
pub const PRIVATE: u32 = 0x_a_bad_1dea_u32; // We set it public by using the
// `pub` keyword.
}
println!("const value: {}", SomeModule::PRIVATE); // ok!
println!("const value: {}", foo::PRIVATE); // ok!
```
16 changes: 8 additions & 8 deletions compiler/rustc_error_codes/src/error_codes/E0742.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ item.
Erroneous code example:

```compile_fail,E0742,edition2018
pub mod Sea {}
pub mod sea {}
pub (in crate::Sea) struct Shark; // error!
pub (in crate::sea) struct Shark; // error!
fn main() {}
```

To fix this error, we need to move the `Shark` struct inside the `Sea` module:
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!
pub mod sea {
pub (in crate::sea) struct Shark; // ok!
}
fn main() {}
Expand All @@ -25,9 +25,9 @@ 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!
pub mod earth {
pub mod sea {
pub (in crate::earth) struct Shark; // ok!
}
}
Expand Down

0 comments on commit 9eee69e

Please sign in to comment.