Given the following code:
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.
Given the following code:
rustc suggests
The suggestion should be enclosing the entire expression in parenthesis.
This was introduced in #47247. The solution is to change
needs_parento be inclusive of the precedence ofas, in other words, change the<with<=and add a test for the behavior.