You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In 6cc78bf / #51632, we reworded the error methods for type-mismatches-in-matches when the match comes from a ?-expression, and added a suggestion to Ok-wrap the expression. While that's often the right fix (notably, when a ?-expression is in tail position of a function that returns Result), sometimes it isn't. Here's a counterexample:
error[E0308]: try expression alternatives have incompatible types
--> success_variant.rs:6:18
|
6 | let n: i32 = maybe_numbers()?;
| ^^^^^^^^^^^^^^^^
| |
| expected i32, found struct `std::vec::Vec`
| help: try wrapping with a success variant: `Ok(maybe_numbers()?)`
|
= note: expected type `i32`
found type `std::vec::Vec<i32>`
We should, somehow, not issue the "try wrapping with a success variant" suggestion (which lives in librustc/infer/error_reporting/mod.rs) in cases like these.
The text was updated successfully, but these errors were encountered:
zackmdavis
changed the title
suggestion for E0308 "try expression alternatives have incompatible types" are sometimes wrong
suggestion for E0308 "try expression alternatives have incompatible types" is sometimes wrong
Jul 21, 2018
This suggestion was introduced in rust-lang#51938 / 6cc78bf (while
introducing different language for type errors coming from `?` rather
than a `match`), but it has a lot of false-positives (as repeatedly
reported in Issues rust-lang#52537, rust-lang#52598, rust-lang#54578, rust-lang#55336), and incorrect
suggestions carry more badness than marginal good suggestions do
goodness. Just get rid of it (unless and until someone figures out how
to do it correctly).
Resolvesrust-lang#52537, resolvesrust-lang#54578.
This suggestion was introduced in rust-lang#51938 / 6cc78bf (while
introducing different language for type errors coming from `?` rather
than a `match`), but it has a lot of false-positives (as repeatedly
reported in Issues rust-lang#52537, rust-lang#52598, rust-lang#54578, rust-lang#55336), and incorrect
suggestions carry more badness than marginal good suggestions do
goodness. Just get rid of it (unless and until someone figures out how
to do it correctly).
Resolvesrust-lang#52537, resolvesrust-lang#54578.
In 6cc78bf / #51632, we reworded the error methods for type-mismatches-in-matches when the match comes from a
?
-expression, and added a suggestion toOk
-wrap the expression. While that's often the right fix (notably, when a?
-expression is in tail position of a function that returnsResult
), sometimes it isn't. Here's a counterexample:Currently, we emit:
We should, somehow, not issue the "try wrapping with a success variant" suggestion (which lives in librustc/infer/error_reporting/mod.rs) in cases like these.
The text was updated successfully, but these errors were encountered: