From 0501d615bb1484fbbd6e2035cff4c3c44e94f10d Mon Sep 17 00:00:00 2001 From: Yiming Lei Date: Wed, 5 Oct 2022 14:00:51 -0700 Subject: [PATCH] do not reverse the expected type and found type for ObligationCauseCode of IfExpressionWithNoElse this will fix #102397 --- compiler/rustc_hir_analysis/src/check/_match.rs | 2 +- src/test/ui/async-await/issue-66387-if-without-else.stderr | 2 +- src/test/ui/consts/control-flow/issue-50577.stderr | 2 +- src/test/ui/expr/if/if-without-else-result.rs | 2 +- src/test/ui/expr/if/if-without-else-result.stderr | 2 +- src/test/ui/expr/if/issue-4201.rs | 2 +- src/test/ui/expr/if/issue-4201.stderr | 2 +- src/test/ui/issues/issue-19991.rs | 2 +- src/test/ui/issues/issue-19991.stderr | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/_match.rs b/compiler/rustc_hir_analysis/src/check/_match.rs index 201927091a60a..143508b785f1e 100644 --- a/compiler/rustc_hir_analysis/src/check/_match.rs +++ b/compiler/rustc_hir_analysis/src/check/_match.rs @@ -259,7 +259,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { err.help("consider adding an `else` block that evaluates to the expected type"); error = true; }, - ret_reason.is_none(), + false, ); error } diff --git a/src/test/ui/async-await/issue-66387-if-without-else.stderr b/src/test/ui/async-await/issue-66387-if-without-else.stderr index e8e2a48983c89..8155fcb56b697 100644 --- a/src/test/ui/async-await/issue-66387-if-without-else.stderr +++ b/src/test/ui/async-await/issue-66387-if-without-else.stderr @@ -4,7 +4,7 @@ error[E0317]: `if` may be missing an `else` clause LL | / if true { LL | | return 0; LL | | } - | |_____^ expected `()`, found `i32` + | |_____^ expected `i32`, found `()` | = note: `if` expressions without `else` evaluate to `()` = help: consider adding an `else` block that evaluates to the expected type diff --git a/src/test/ui/consts/control-flow/issue-50577.stderr b/src/test/ui/consts/control-flow/issue-50577.stderr index b6e73f889adab..a931c89f47e72 100644 --- a/src/test/ui/consts/control-flow/issue-50577.stderr +++ b/src/test/ui/consts/control-flow/issue-50577.stderr @@ -2,7 +2,7 @@ error[E0317]: `if` may be missing an `else` clause --> $DIR/issue-50577.rs:3:16 | LL | Drop = assert_eq!(1, 1), - | ^^^^^^^^^^^^^^^^ expected `()`, found `isize` + | ^^^^^^^^^^^^^^^^ expected `isize`, found `()` | = note: `if` expressions without `else` evaluate to `()` = help: consider adding an `else` block that evaluates to the expected type diff --git a/src/test/ui/expr/if/if-without-else-result.rs b/src/test/ui/expr/if/if-without-else-result.rs index cf84a99e53fa1..95604758a6b3e 100644 --- a/src/test/ui/expr/if/if-without-else-result.rs +++ b/src/test/ui/expr/if/if-without-else-result.rs @@ -1,6 +1,6 @@ fn main() { let a = if true { true }; //~^ ERROR `if` may be missing an `else` clause [E0317] - //~| expected `()`, found `bool` + //~| expected `bool`, found `()` println!("{}", a); } diff --git a/src/test/ui/expr/if/if-without-else-result.stderr b/src/test/ui/expr/if/if-without-else-result.stderr index 821635d3768f3..317faf7c619f6 100644 --- a/src/test/ui/expr/if/if-without-else-result.stderr +++ b/src/test/ui/expr/if/if-without-else-result.stderr @@ -5,7 +5,7 @@ LL | let a = if true { true }; | ^^^^^^^^^^----^^ | | | | | found here - | expected `()`, found `bool` + | expected `bool`, found `()` | = note: `if` expressions without `else` evaluate to `()` = help: consider adding an `else` block that evaluates to the expected type diff --git a/src/test/ui/expr/if/issue-4201.rs b/src/test/ui/expr/if/issue-4201.rs index 1f292229fd6cd..59c465b9e1492 100644 --- a/src/test/ui/expr/if/issue-4201.rs +++ b/src/test/ui/expr/if/issue-4201.rs @@ -3,7 +3,7 @@ fn main() { 0 } else if false { //~^ ERROR `if` may be missing an `else` clause -//~| expected `()`, found integer +//~| expected integer, found `()` 1 }; } diff --git a/src/test/ui/expr/if/issue-4201.stderr b/src/test/ui/expr/if/issue-4201.stderr index bc638ddf55be0..612fe77642ce5 100644 --- a/src/test/ui/expr/if/issue-4201.stderr +++ b/src/test/ui/expr/if/issue-4201.stderr @@ -8,7 +8,7 @@ LL | | LL | | 1 | | - found here LL | | }; - | |_____^ expected `()`, found integer + | |_____^ expected integer, found `()` | = note: `if` expressions without `else` evaluate to `()` = help: consider adding an `else` block that evaluates to the expected type diff --git a/src/test/ui/issues/issue-19991.rs b/src/test/ui/issues/issue-19991.rs index 1f3b73f96d8b9..dd0efa972ba3e 100644 --- a/src/test/ui/issues/issue-19991.rs +++ b/src/test/ui/issues/issue-19991.rs @@ -3,7 +3,7 @@ fn main() { if let Some(homura) = Some("madoka") { //~ ERROR missing an `else` clause - //~| expected `()`, found integer + //~| expected integer, found `()` 765 }; } diff --git a/src/test/ui/issues/issue-19991.stderr b/src/test/ui/issues/issue-19991.stderr index 6e92be87a02e9..57b0882b636e3 100644 --- a/src/test/ui/issues/issue-19991.stderr +++ b/src/test/ui/issues/issue-19991.stderr @@ -6,7 +6,7 @@ LL | | LL | | 765 | | --- found here LL | | }; - | |_____^ expected `()`, found integer + | |_____^ expected integer, found `()` | = note: `if` expressions without `else` evaluate to `()` = help: consider adding an `else` block that evaluates to the expected type