-
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 lintsC-bugCategory: This is a bug.Category: This is a bug.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.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Description
fn main() {
let array = [1, 2, 3];
test(array.len() as u8);
}
fn test(length: u32) {
println!("{}", length);
}
rustc suggests
error[E0308]: mismatched types
--> src/main.rs:3:10
|
3 | test(array.len() as u8);
| ^^^^^^^^^^^^^^^^^ expected u32, found u8
help: you can cast an `u8` to `u32`, which will zero-extend the source value
|
3 | test(array.len() as u8.into());
| ^^^^^^^^^^^^^^^^^^^^^^^^
The suggestion should be enclosing the entire expression in parenthesis.
This was introduced in #47247. The solution is to change needs_paren
to be inclusive of the precedence of as
, in other words, change the <
with <=
and add a test for the behavior.
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.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.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.