Skip to content

Commit

Permalink
do not reverse the expected type and found type for ObligationCauseCo…
Browse files Browse the repository at this point in the history
…de of IfExpressionWithNoElse

this will fix #102397
  • Loading branch information
Yiming Lei committed Oct 5, 2022
1 parent 8c71b67 commit 0501d61
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/async-await/issue-66387-if-without-else.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/consts/control-flow/issue-50577.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/expr/if/if-without-else-result.rs
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion src/test/ui/expr/if/if-without-else-result.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/expr/if/issue-4201.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
}
2 changes: 1 addition & 1 deletion src/test/ui/expr/if/issue-4201.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-19991.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

fn main() {
if let Some(homura) = Some("madoka") { //~ ERROR missing an `else` clause
//~| expected `()`, found integer
//~| expected integer, found `()`
765
};
}
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-19991.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0501d61

Please sign in to comment.