-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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.
estebank
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.