do not reverse the expected type and found type for ObligationCauseCode of IfExpressionWithNoElse

this will fix #102397
This commit is contained in:
Yiming Lei 2022-10-05 14:00:51 -07:00
parent 8c71b67159
commit 0501d615bb
9 changed files with 9 additions and 9 deletions

View File

@ -259,7 +259,7 @@ pub(super) fn if_fallback_coercion<T>(
err.help("consider adding an `else` block that evaluates to the expected type");
error = true;
},
ret_reason.is_none(),
false,
);
error
}

View File

@ -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

View File

@ -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

View File

@ -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);
}

View File

@ -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

View File

@ -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
};
}

View File

@ -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

View File

@ -3,7 +3,7 @@
fn main() {
if let Some(homura) = Some("madoka") { //~ ERROR missing an `else` clause
//~| expected `()`, found integer
//~| expected integer, found `()`
765
};
}

View File

@ -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