Description
The "here are some functions that may meet your needs" tips are rather broad. I think we should impose some limits. As a spin-off from #42764, consider this (same) example:
fn main() {
let _: Option<i32> = 42i32;
}
Right now this gives:
error[E0308]: mismatched types
--> <anon>:2:26
|
2 | let _: Option<i32> = 42i32;
| ^^^^^ expected enum `std::option::Option`, found i32
|
= note: expected type `std::option::Option<i32>`
found type `i32`
= help: here are some functions which might fulfill your needs:
- .checked_abs()
- .checked_neg()
checked_abs()
and checked_neg()
seem like very silly suggestions to me. Similarly, #42746 points out that suggesting unwrap()
is sort of inappropriate. I think it would be better if used a whitelist whitelist of approved conversion functions, or else if we limited them to the prefixes as_
, to_
, or into_
. The latter is sort of codifying an existing convention -- I personally see no problem with that, since this is just a compiler hint. It has the plus and minus that it would apply rather broadly (i.e., to functions outside the stdlib), where a whitelist obviously wouldn't unless we standardized it.