Skip to content

Provide a pointer to the correct names for Boolean types #98492

New issue

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

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

Already on GitHub? # to your account

Closed
alexwlchan opened this issue Jun 25, 2022 · 2 comments · Fixed by #98677
Closed

Provide a pointer to the correct names for Boolean types #98492

alexwlchan opened this issue Jun 25, 2022 · 2 comments · Fixed by #98677
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alexwlchan
Copy link

alexwlchan commented Jun 25, 2022

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4e7d539241dfe92a24817728751e5523

fn main() {
    let value: Boolean = true;
}

The current output is:

error[E0412]: cannot find type `Boolean` in this scope
 --> src/main.rs:2:16
  |
2 |     let value: Boolean = true;
  |                ^^^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0412`.
error: could not compile `example` due to previous error

Ideally the output should look like:

error[E0412]: cannot find type `Boolean ` in this scope
    --> src/main.rs:4:16
     |
4    |       let value: Boolean = true;
     |                  ^^^^^^^ help: a type with a similar meaning exists: `bool`

I stumbled here when returning to Rust after a while writing code in non-Rust languages; I'm sure I'm not the only person who's gotten the name of Rust's boolean type wrong. It's not hard to work out the correct behaviour, but I thought it would be nice if Rust could help programmers coming from other languages.

(I don't feel strongly about this suggestion and won't mind if it's closed as WONTFIX, but I know Esteban would be sad if he knew I'd had an idea for a diagnostic improvement that I didn't tell anyone.)

@alexwlchan alexwlchan added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 25, 2022
@lyming2007
Copy link

if we change the code to

fn main() {
    let value: boolean = true;
}

the error will be like:

error[E0412]: cannot find type `boolean` in this scope
 --> boolean.rs:2:14
  |
2 |   let value: boolean = true;
  |              ^^^^^^^
  |              |
  |              not found in this scope
  |              help: perhaps you intended to use this type: `bool`

error: aborting due to previous error

How about we make the error message for your case like:
Ideally the output should look like:

error[E0412]: cannot find type `Boolean` in this scope
 --> Boolean.rs:2:14
  |
2 |   let value: Boolean = true;
  |              ^^^^^^^
  |              |
  |              not found in this scope
  |              help: perhaps you intended to use this type: `bool`

error: aborting due to previous error

@lyming2007
Copy link

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 30, 2022
For diagnostic information of Boolean, remind it as use the type: 'bool'

Fixes rust-lang#98492.

It helps programmers coming from other languages
	modified:   compiler/rustc_resolve/src/late/diagnostics.rs
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 30, 2022
For diagnostic information of Boolean, remind it as use the type: 'bool'

Fixes rust-lang#98492.

It helps programmers coming from other languages
	modified:   compiler/rustc_resolve/src/late/diagnostics.rs
@bors bors closed this as completed in 6ee6673 Jul 1, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants