}
#[cfg(not(cfail1))]
-#[rustc_clean(cfg="cfail2", except="HirBody,typeck_tables_of")]
+#[rustc_clean(cfg="cfail2", except="HirBody")]
#[rustc_clean(cfg="cfail3")]
pub fn add_else_branch(x: bool) -> u32 {
let mut ret = 1;
}
#[cfg(not(cfail1))]
-#[rustc_clean(cfg="cfail2", except="HirBody,typeck_tables_of")]
+#[rustc_clean(cfg="cfail2", except="HirBody")]
#[rustc_clean(cfg="cfail3")]
pub fn add_else_branch_if_let(x: Option<u32>) -> u32 {
let mut ret = 1;
--- /dev/null
+warning: unreachable block in `if` expression
+ --> $DIR/if-ret.rs:4:24
+ |
+LL | fn foo() { if (return) { } }
+ | ^^^
+ |
+ = note: #[warn(unreachable_code)] on by default
+
fn main() {
if let Some(b) = None {
- //~^ NOTE if let` arms have incompatible types
+ //~^ NOTE if and else have incompatible types
()
+ //~^ NOTE expected because of this
} else {
1
};
- //~^^ ERROR: `if let` arms have incompatible types
+ //~^^ ERROR: if and else have incompatible types
//~| NOTE expected (), found integer
//~| NOTE expected type `()`
}
-error[E0308]: `if let` arms have incompatible types
- --> $DIR/if-let-arm-types.rs:6:9
+error[E0308]: if and else have incompatible types
+ --> $DIR/if-let-arm-types.rs:7:9
|
LL | / if let Some(b) = None {
LL | |
LL | | ()
+ | | -- expected because of this
+LL | |
LL | | } else {
LL | | 1
| | ^ expected (), found integer
LL | | };
- | |_____- `if let` arms have incompatible types
+ | |_____- if and else have incompatible types
|
= note: expected type `()`
found type `{integer}`
return 3;
}
//~^^^ ERROR if may be missing an else clause
+ //~| ERROR mismatched types [E0308]
}
fn foo2(bar: usize) -> usize {
return 3;
};
//~^^^ ERROR if may be missing an else clause
+ //~| ERROR mismatched types [E0308]
x
}
3
}
//~^^^ ERROR if may be missing an else clause
+ //~| ERROR mismatched types [E0308]
}
+fn foo_let(bar: usize) -> usize {
+ if let 0 = 1 {
+ return 3;
+ }
+ //~^^^ ERROR if may be missing an else clause
+ //~| ERROR mismatched types [E0308]
+}
+
+fn foo2_let(bar: usize) -> usize {
+ let x: usize = if let 0 = 1 {
+ return 3;
+ };
+ //~^^^ ERROR if may be missing an else clause
+ //~| ERROR mismatched types [E0308]
+ x
+}
+
+fn foo3_let(bar: usize) -> usize {
+ if let 0 = 1 {
+ 3
+ }
+ //~^^^ ERROR if may be missing an else clause
+ //~| ERROR mismatched types [E0308]
+}
+
+// FIXME(60254): deduplicate first error in favor of second.
+
fn main() {
let _ = foo(1);
}
+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
|
= 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:9:20
+ --> $DIR/if-without-else-as-fn-expr.rs:10:20
|
LL | let x: usize = if bar % 5 == 0 {
| _________-__________^
= 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:17:5
+ --> $DIR/if-without-else-as-fn-expr.rs:19:5
|
LL | fn foo3(bar: usize) -> usize {
| ----- expected `usize` because of this return 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
+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
+ |
+LL | fn foo_let(bar: usize) -> usize {
+ | ----- expected `usize` because of this return type
+LL | / if let 0 = 1 {
+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[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
+ |
+LL | let x: usize = if let 0 = 1 {
+ | _________-__________^
+ | | |
+ | | 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[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
+ |
+LL | fn foo3_let(bar: usize) -> usize {
+ | ----- expected `usize` because of this return type
+LL | / if let 0 = 1 {
+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 12 previous errors
-For more information about this error, try `rustc --explain E0317`.
+Some errors have detailed explanations: E0308, E0317.
+For more information about an error, try `rustc --explain E0308`.
LL | |
LL | |
LL | | 765
+ | | --- found here
LL | | };
| |_____^ expected (), found integer
|
= note: expected type `()`
found type `{integer}`
+ = 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
enum Foo {
Drop = assert_eq!(1, 1)
//~^ ERROR if may be missing an else clause
+ //~| ERROR mismatched types [E0308]
}
}
+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
|
= 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 previous error
+error: aborting due to 2 previous errors
-For more information about this error, try `rustc --explain E0317`.
+Some errors have detailed explanations: E0308, E0317.
+For more information about an error, try `rustc --explain E0308`.
#![deny(unreachable_code)]
fn foo() {
- if {return} {
+ if {return} { //~ ERROR unreachable block in `if` expression
println!("Hello, world!");
}
}
-error: unreachable statement
- --> $DIR/expr_if.rs:27:5
+error: unreachable block in `if` expression
+ --> $DIR/expr_if.rs:7:17
|
-LL | println!("But I am.");
- | ^^^^^^^^^^^^^^^^^^^^^^
+LL | if {return} {
+ | _________________^
+LL | | println!("Hello, world!");
+LL | | }
+ | |_____^
|
note: lint level defined here
--> $DIR/expr_if.rs:4:9
|
LL | #![deny(unreachable_code)]
| ^^^^^^^^^^^^^^^^
+
+error: unreachable statement
+ --> $DIR/expr_if.rs:27:5
+ |
+LL | println!("But I am.");
+ | ^^^^^^^^^^^^^^^^^^^^^^
+ |
= 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 previous error
+error: aborting due to 2 previous errors