Closed
Description
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.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Suggestions generated by the compiler applied by `cargo fix`Category: A feature request, i.e: not implemented / a PR.Diagnostics: An error or lint that needs small tweaks.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Relevant to the compiler team, which will review and decide on the PR/issue.