Skip to content

Suggest dereferencing boolean reference when used in 'if' #64557

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
Aaron1011 opened this issue Sep 17, 2019 · 10 comments
Closed

Suggest dereferencing boolean reference when used in 'if' #64557

Aaron1011 opened this issue Sep 17, 2019 · 10 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-feature-request Category: A feature request, i.e: not implemented / a PR. D-papercut Diagnostics: An error or lint that needs small tweaks. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

Aaron1011 commented Sep 17, 2019

The following code:

fn take_bool(val: bool) {}

fn main() {
    let a = &true;
    if a {
        println!("Hello!");
    }
    take_bool(a)
}

gives the following errors:

error[E0308]: mismatched types
 --> src/main.rs:5:8
  |
5 |     if a {
  |        ^ expected bool, found &bool
  |
  = note: expected type `bool`
             found type `&bool`

error[E0308]: mismatched types
 --> src/main.rs:8:15
  |
8 |     take_bool(a)
  |               ^
  |               |
  |               expected bool, found &bool
  |               help: consider dereferencing the borrow: `*a`
  |
  = note: expected type `bool`
             found type `&bool`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
error: Could not compile `playground`.

Note that the first error is missing the "help: consider dereferencing the borrow: *a" suggestion.

For consistency, Rust should suggest dereferencing a boolean reference when used in an 'if' expression.

This issue has been assigned to @XiangQingW via this comment.

@Aaron1011
Copy link
Member Author

@rustbot modify labels to +A-lint

@rustbot rustbot added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Sep 17, 2019
@Aaron1011
Copy link
Member Author

@rustbot modify labels to -A-lint +A-suggestion-diagnostics

@rustbot rustbot added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` and removed A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. labels Sep 17, 2019
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Sep 17, 2019
@XiangQingW
Copy link
Contributor

@Aaron1011 I'd love to be assigned to the issue.

@Aaron1011
Copy link
Member Author

@XiangQingW: You can use @rustbot claim to assign the issue to yourself.

@rustbot
Copy link
Collaborator

rustbot commented Sep 19, 2019

Error: Parsing assign command in comment failed: ... assign me|error: user should start with @ at >|...

Please let @rust-lang/release know if you're having trouble with this bot.

1 similar comment
@rustbot
Copy link
Collaborator

rustbot commented Sep 19, 2019

Error: Parsing assign command in comment failed: ... assign me|error: user should start with @ at >|...

Please let @rust-lang/release know if you're having trouble with this bot.

@XiangQingW
Copy link
Contributor

@rustbot claim

@rustbot rustbot self-assigned this Sep 19, 2019
@estebank estebank added the D-papercut Diagnostics: An error or lint that needs small tweaks. label Oct 5, 2019
@mayabyte
Copy link

mayabyte commented Oct 5, 2019

Has a PR been submitted for this yet? I'm happy to take it if not

@XiangQingW
Copy link
Contributor

XiangQingW commented Oct 6, 2019

Has a PR been submitted for this yet? I'm happy to take it if not
Hum... I'm working on this, and sorry for the delay because I was busy last several days.

Centril added a commit to Centril/rust that referenced this issue Oct 7, 2019
Suggest dereferencing boolean reference when used in 'if' or 'while'

Implements rust-lang#64557
Centril added a commit to Centril/rust that referenced this issue Oct 8, 2019
Suggest dereferencing boolean reference when used in 'if' or 'while'

Implements rust-lang#64557
@Aaron1011
Copy link
Member Author

Fixed in #65150

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-feature-request Category: A feature request, i.e: not implemented / a PR. D-papercut Diagnostics: An error or lint that needs small tweaks. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants