a3cf3822d2
When the return type of a function call depends on the type of an argument, e.g. ``` fn foo<T>(x: T) -> T { x } ``` and the expected type is set due to either an explicitly typed binding, or because the call to the function is in a tail position without semicolon, the current error implies that the argument in the call has the wrong type. This new hint highlights that the expected type doesn't match the returned type, which matches the argument type, and that that's why we're flagging the argument type. Fixes #43608.
28 lines
1.2 KiB
Plaintext
28 lines
1.2 KiB
Plaintext
error[E0308]: mismatched types
|
|
--> $DIR/sugg-else-for-closure.rs:6:26
|
|
|
|
|
LL | let _s = y.unwrap_or(|| x.split('.').nth(1).unwrap());
|
|
| --------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found closure
|
|
| |
|
|
| arguments to this method are incorrect
|
|
|
|
|
= note: expected reference `&str`
|
|
found closure `[closure@$DIR/sugg-else-for-closure.rs:6:26: 6:28]`
|
|
help: the return type of this call is `[closure@$DIR/sugg-else-for-closure.rs:6:26: 6:28]` due to the type of the argument passed
|
|
--> $DIR/sugg-else-for-closure.rs:6:14
|
|
|
|
|
LL | let _s = y.unwrap_or(|| x.split('.').nth(1).unwrap());
|
|
| ^^^^^^^^^^^^-------------------------------^
|
|
| |
|
|
| this argument influences the return type of `unwrap_or`
|
|
note: associated function defined here
|
|
--> $SRC_DIR/core/src/option.rs:LL:COL
|
|
help: try calling `unwrap_or_else` instead
|
|
|
|
|
LL | let _s = y.unwrap_or_else(|| x.split('.').nth(1).unwrap());
|
|
| +++++
|
|
|
|
error: aborting due to previous error
|
|
|
|
For more information about this error, try `rustc --explain E0308`.
|