]> git.lizzy.rs Git - rust.git/commit
in which we plug the crack where `?`-desugaring leaked into errors
authorZack M. Davis <code@zackmdavis.net>
Sat, 30 Jun 2018 05:02:52 +0000 (22:02 -0700)
committerZack M. Davis <code@zackmdavis.net>
Sat, 30 Jun 2018 05:11:39 +0000 (22:11 -0700)
commit6cc78bf8d76383395e307cef5e601cfe561337e6
tree130d5ab2ec33ff4903dfcbe1f401429b2c722bce
parent1029775ad5f15d2200e087ebb4a867cf30dbbb25
in which we plug the crack where `?`-desugaring leaked into errors

Most of the time, it's not a problem that the types of the arm bodies in
a desugared-from-`?` match are different (that is, specifically: in `x?`
where x is a `Result<A, B>`, the `Ok` arm body is an `A`, whereas the
`Err` arm diverges to return a `Result<A, B>`), because they're being
assigned to different places. But in tail position, the types do need to
match, and our error message was explicitly referring to "match arms",
which is confusing when there's no `match` in the sweetly sugared
source.

It is not without some misgivings that we pollute the clarity-of-purpose
of `note_error_origin` with the suggestion to wrap with `Ok` (the other
branches are pointing out the odd-arm-out in the HIR that is the origin
of the error; the new branch that issues the `Ok` suggestion is serving
a different purpose), but it's the natural place to do it given that
we're already matching on `ObligationCauseCode::MatchExpressionArm {
arm_span, source }` there.

Resolves #51632.
src/librustc/infer/error_reporting/mod.rs
src/test/ui/issue-51632-try-desugar-incompatible-types.fixed [new file with mode: 0644]
src/test/ui/issue-51632-try-desugar-incompatible-types.rs [new file with mode: 0644]
src/test/ui/issue-51632-try-desugar-incompatible-types.stderr [new file with mode: 0644]