diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2019-03-07 14:37:18 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2019-03-07 14:37:18 -0800 |
| commit | dcaec88a57cd0f388af1678f8db155b2add8b175 (patch) | |
| tree | b10cb61b772cd7fd5450b8c5bd860154315a04bd /src/test | |
| parent | ffa40cb45c195e317602437d8a40178e72807d46 (diff) | |
| download | rust-dcaec88a57cd0f388af1678f8db155b2add8b175.tar.gz rust-dcaec88a57cd0f388af1678f8db155b2add8b175.zip | |
Add more details to elseless if error
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/if/if-without-else-as-fn-expr.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/if/if-without-else-as-fn-expr.stderr | 33 | ||||
| -rw-r--r-- | src/test/ui/if/if-without-else-result.stderr | 5 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-4201.stderr | 1 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-50577.stderr | 5 |
5 files changed, 56 insertions, 3 deletions
diff --git a/src/test/ui/if/if-without-else-as-fn-expr.rs b/src/test/ui/if/if-without-else-as-fn-expr.rs index 76ffb49697f..67e4445629f 100644 --- a/src/test/ui/if/if-without-else-as-fn-expr.rs +++ b/src/test/ui/if/if-without-else-as-fn-expr.rs @@ -5,6 +5,21 @@ fn foo(bar: usize) -> usize { //~^^^ ERROR if may be missing an else clause } +fn foo2(bar: usize) -> usize { + let x: usize = if bar % 5 == 0 { + return 3; + }; + //~^^^ ERROR if may be missing an else clause + x +} + +fn foo3(bar: usize) -> usize { + if bar % 5 == 0 { + 3 + } + //~^^^ ERROR if may be missing an else clause +} + fn main() { let _ = foo(1); } diff --git a/src/test/ui/if/if-without-else-as-fn-expr.stderr b/src/test/ui/if/if-without-else-as-fn-expr.stderr index 062e0b9c44d..0ba72726ca7 100644 --- a/src/test/ui/if/if-without-else-as-fn-expr.stderr +++ b/src/test/ui/if/if-without-else-as-fn-expr.stderr @@ -13,6 +13,37 @@ LL | | } = note: `if` expressions without `else` evaluate to `()` = help: consider adding an `else` block that evaluates to the expected type -error: aborting due to previous error +error[E0317]: if may be missing an else clause + --> $DIR/if-without-else-as-fn-expr.rs:9:20 + | +LL | let x: usize = if bar % 5 == 0 { + | _________-__________^ + | | | + | | expected because of this assignment +LL | | return 3; +LL | | }; + | |_____^ expected usize, found () + | + = note: expected type `usize` + found type `()` + = note: `if` expressions without `else` evaluate to `()` + = help: consider adding an `else` block that evaluates to the expected type + +error[E0317]: if may be missing an else clause + --> $DIR/if-without-else-as-fn-expr.rs:17:5 + | +LL | fn foo3(bar: usize) -> usize { + | ----- expected `usize` because of this return type +LL | / if bar % 5 == 0 { +LL | | 3 +LL | | } + | |_____^ expected usize, found () + | + = note: expected type `usize` + found type `()` + = note: `if` expressions without `else` evaluate to `()` + = help: consider adding an `else` block that evaluates to the expected type + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0317`. diff --git a/src/test/ui/if/if-without-else-result.stderr b/src/test/ui/if/if-without-else-result.stderr index cb1df141bcb..ddb013ab711 100644 --- a/src/test/ui/if/if-without-else-result.stderr +++ b/src/test/ui/if/if-without-else-result.stderr @@ -2,7 +2,10 @@ error[E0317]: if may be missing an else clause --> $DIR/if-without-else-result.rs:2:13 | LL | let a = if true { true }; - | ^^^^^^^^^^^^^^^^ expected (), found bool + | ^^^^^^^^^^----^^ + | | | + | | found here + | expected (), found bool | = note: expected type `()` found type `bool` diff --git a/src/test/ui/issues/issue-4201.stderr b/src/test/ui/issues/issue-4201.stderr index 53397c8ec90..4d7116a0ee9 100644 --- a/src/test/ui/issues/issue-4201.stderr +++ b/src/test/ui/issues/issue-4201.stderr @@ -8,6 +8,7 @@ LL | | //~| expected type `()` LL | | //~| found type `{integer}` LL | | //~| expected (), found integer LL | | 1 + | | - found here LL | | }; | |_____^ expected (), found integer | diff --git a/src/test/ui/issues/issue-50577.stderr b/src/test/ui/issues/issue-50577.stderr index 323f5ac6547..0c3ba2ea4f9 100644 --- a/src/test/ui/issues/issue-50577.stderr +++ b/src/test/ui/issues/issue-50577.stderr @@ -2,7 +2,10 @@ 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 (), found isize + | found here | = note: expected type `()` found type `isize` |
