Rollup merge of #64049 - estebank:if-else-type-err, r=Centril
Emit a single error on if expr with expectation and no else clause Fix https://github.com/rust-lang/rust/issues/60254. r? @Centril
This commit is contained in:
commit
4245be7fb3
5 changed files with 30 additions and 105 deletions
|
|
@ -3,7 +3,6 @@ fn foo(bar: usize) -> usize {
|
|||
return 3;
|
||||
}
|
||||
//~^^^ ERROR if may be missing an else clause
|
||||
//~| ERROR mismatched types [E0308]
|
||||
}
|
||||
|
||||
fn foo2(bar: usize) -> usize {
|
||||
|
|
@ -11,7 +10,6 @@ fn foo2(bar: usize) -> usize {
|
|||
return 3;
|
||||
};
|
||||
//~^^^ ERROR if may be missing an else clause
|
||||
//~| ERROR mismatched types [E0308]
|
||||
x
|
||||
}
|
||||
|
||||
|
|
@ -20,7 +18,6 @@ fn foo3(bar: usize) -> usize {
|
|||
3
|
||||
}
|
||||
//~^^^ ERROR if may be missing an else clause
|
||||
//~| ERROR mismatched types [E0308]
|
||||
}
|
||||
|
||||
fn foo_let(bar: usize) -> usize {
|
||||
|
|
@ -28,7 +25,6 @@ fn foo_let(bar: usize) -> usize {
|
|||
return 3;
|
||||
}
|
||||
//~^^^ ERROR if may be missing an else clause
|
||||
//~| ERROR mismatched types [E0308]
|
||||
}
|
||||
|
||||
fn foo2_let(bar: usize) -> usize {
|
||||
|
|
@ -36,7 +32,6 @@ fn foo2_let(bar: usize) -> usize {
|
|||
return 3;
|
||||
};
|
||||
//~^^^ ERROR if may be missing an else clause
|
||||
//~| ERROR mismatched types [E0308]
|
||||
x
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +40,6 @@ fn foo3_let(bar: usize) -> usize {
|
|||
3
|
||||
}
|
||||
//~^^^ ERROR if may be missing an else clause
|
||||
//~| ERROR mismatched types [E0308]
|
||||
}
|
||||
|
||||
// FIXME(60254): deduplicate first error in favor of second.
|
||||
|
|
|
|||
|
|
@ -1,14 +1,3 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:2:5
|
||||
|
|
||||
LL | / if bar % 5 == 0 {
|
||||
LL | | return 3;
|
||||
LL | | }
|
||||
| |_____^ expected usize, found ()
|
||||
|
|
||||
= note: expected type `usize`
|
||||
found type `()`
|
||||
|
||||
error[E0317]: if may be missing an else clause
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:2:5
|
||||
|
|
||||
|
|
@ -24,20 +13,8 @@ LL | | }
|
|||
= note: `if` expressions without `else` evaluate to `()`
|
||||
= help: consider adding an `else` block that evaluates to the expected type
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:10:20
|
||||
|
|
||||
LL | let x: usize = if bar % 5 == 0 {
|
||||
| ____________________^
|
||||
LL | | return 3;
|
||||
LL | | };
|
||||
| |_____^ expected usize, found ()
|
||||
|
|
||||
= note: expected type `usize`
|
||||
found type `()`
|
||||
|
||||
error[E0317]: if may be missing an else clause
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:10:20
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:9:20
|
||||
|
|
||||
LL | let x: usize = if bar % 5 == 0 {
|
||||
| _________-__________^
|
||||
|
|
@ -52,19 +29,8 @@ LL | | };
|
|||
= note: `if` expressions without `else` evaluate to `()`
|
||||
= help: consider adding an `else` block that evaluates to the expected type
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:19:5
|
||||
|
|
||||
LL | / if bar % 5 == 0 {
|
||||
LL | | 3
|
||||
LL | | }
|
||||
| |_____^ expected usize, found ()
|
||||
|
|
||||
= note: expected type `usize`
|
||||
found type `()`
|
||||
|
||||
error[E0317]: if may be missing an else clause
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:19:5
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:17:5
|
||||
|
|
||||
LL | fn foo3(bar: usize) -> usize {
|
||||
| ----- expected `usize` because of this return type
|
||||
|
|
@ -78,19 +44,8 @@ LL | | }
|
|||
= note: `if` expressions without `else` evaluate to `()`
|
||||
= help: consider adding an `else` block that evaluates to the expected type
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:27:5
|
||||
|
|
||||
LL | / if let 0 = 1 {
|
||||
LL | | return 3;
|
||||
LL | | }
|
||||
| |_____^ expected usize, found ()
|
||||
|
|
||||
= note: expected type `usize`
|
||||
found type `()`
|
||||
|
||||
error[E0317]: if may be missing an else clause
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:27:5
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:24:5
|
||||
|
|
||||
LL | fn foo_let(bar: usize) -> usize {
|
||||
| ----- expected `usize` because of this return type
|
||||
|
|
@ -104,20 +59,8 @@ LL | | }
|
|||
= note: `if` expressions without `else` evaluate to `()`
|
||||
= help: consider adding an `else` block that evaluates to the expected type
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:35:20
|
||||
|
|
||||
LL | let x: usize = if let 0 = 1 {
|
||||
| ____________________^
|
||||
LL | | return 3;
|
||||
LL | | };
|
||||
| |_____^ expected usize, found ()
|
||||
|
|
||||
= note: expected type `usize`
|
||||
found type `()`
|
||||
|
||||
error[E0317]: if may be missing an else clause
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:35:20
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:31:20
|
||||
|
|
||||
LL | let x: usize = if let 0 = 1 {
|
||||
| _________-__________^
|
||||
|
|
@ -132,19 +75,8 @@ LL | | };
|
|||
= note: `if` expressions without `else` evaluate to `()`
|
||||
= help: consider adding an `else` block that evaluates to the expected type
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:44:5
|
||||
|
|
||||
LL | / if let 0 = 1 {
|
||||
LL | | 3
|
||||
LL | | }
|
||||
| |_____^ expected usize, found ()
|
||||
|
|
||||
= note: expected type `usize`
|
||||
found type `()`
|
||||
|
||||
error[E0317]: if may be missing an else clause
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:44:5
|
||||
--> $DIR/if-without-else-as-fn-expr.rs:39:5
|
||||
|
|
||||
LL | fn foo3_let(bar: usize) -> usize {
|
||||
| ----- expected `usize` because of this return type
|
||||
|
|
@ -158,7 +90,6 @@ LL | | }
|
|||
= note: `if` expressions without `else` evaluate to `()`
|
||||
= help: consider adding an `else` block that evaluates to the expected type
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0308, E0317.
|
||||
For more information about an error, try `rustc --explain E0308`.
|
||||
For more information about this error, try `rustc --explain E0317`.
|
||||
|
|
|
|||
|
|
@ -2,6 +2,5 @@ fn main() {
|
|||
enum Foo {
|
||||
Drop = assert_eq!(1, 1)
|
||||
//~^ ERROR if may be missing an else clause
|
||||
//~| ERROR mismatched types [E0308]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,3 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-50577.rs:3:16
|
||||
|
|
||||
LL | Drop = assert_eq!(1, 1)
|
||||
| ^^^^^^^^^^^^^^^^ expected isize, found ()
|
||||
|
|
||||
= note: expected type `isize`
|
||||
found type `()`
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error[E0317]: if may be missing an else clause
|
||||
--> $DIR/issue-50577.rs:3:16
|
||||
|
|
||||
|
|
@ -23,7 +13,6 @@ LL | Drop = assert_eq!(1, 1)
|
|||
= help: consider adding an `else` block that evaluates to the expected type
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
error: aborting due to previous error
|
||||
|
||||
Some errors have detailed explanations: E0308, E0317.
|
||||
For more information about an error, try `rustc --explain E0308`.
|
||||
For more information about this error, try `rustc --explain E0317`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue