Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one should stay as-is, because the error is trying to describe how someone tried to use a module as a struct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the usage of a module in struct position that's problematic, so I'd argue the module is correctly snake_case... but I guess it's just a matter of perspective: did they mean to write struct Mordor {} or did they mean to write let sauron = Sauron { x: () }; (or similar)?

Copy link
Contributor Author

@CorinJG CorinJG Jun 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If someone tried to use a module as a struct, it's possible they made a naming convention error too. (Maybe they used snake_case for the module and the struct!). It's not clear to me that violating naming conventions in the error description is helpful though.


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