]> git.lizzy.rs Git - rust.git/commitdiff
Various test changes
authorMazdak Farrokhzad <twingoow@gmail.com>
Tue, 19 Mar 2019 03:47:07 +0000 (04:47 +0100)
committerMazdak Farrokhzad <twingoow@gmail.com>
Fri, 10 May 2019 17:41:10 +0000 (19:41 +0200)
src/test/incremental/hashes/if_expressions.rs
src/test/run-pass/if-ret.stderr [new file with mode: 0644]
src/test/ui/if/if-let-arm-types.rs
src/test/ui/if/if-let-arm-types.stderr
src/test/ui/if/if-without-else-as-fn-expr.rs
src/test/ui/if/if-without-else-as-fn-expr.stderr
src/test/ui/issues/issue-19991.stderr
src/test/ui/issues/issue-50577.rs
src/test/ui/issues/issue-50577.stderr
src/test/ui/reachable/expr_if.rs
src/test/ui/reachable/expr_if.stderr

index fba7869af42f25f1b3aa669da1d099a29bfd1cf3..6bc7d286e3adba5b6826647ddb77a5a6342e16a2 100644 (file)
@@ -94,7 +94,7 @@ pub fn add_else_branch(x: bool) -> u32 {
 }
 
 #[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;
@@ -191,7 +191,7 @@ pub fn add_else_branch_if_let(x: Option<u32>) -> u32 {
 }
 
 #[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;
diff --git a/src/test/run-pass/if-ret.stderr b/src/test/run-pass/if-ret.stderr
new file mode 100644 (file)
index 0000000..a642818
--- /dev/null
@@ -0,0 +1,8 @@
+warning: unreachable block in `if` expression
+  --> $DIR/if-ret.rs:4:24
+   |
+LL | fn foo() { if (return) { } }
+   |                        ^^^
+   |
+   = note: #[warn(unreachable_code)] on by default
+
index 819f5dd1cfc352ca57e52014f66cd79cc33d0b8e..0f8815f0479f5fa256c449d316c9193d1dadd430 100644 (file)
@@ -1,11 +1,12 @@
 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 `()`
 }
index b986973fe91f4f019ef4b718977a41d0ccbadf21..ff88de20f76ccf709b9991361d3fe2edf1b67e20 100644 (file)
@@ -1,14 +1,16 @@
-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}`
index 67e4445629f8caa044d2c2bd25b6051168d34e14..15892de83854c215f7e81cf8ba2ca20762a78c56 100644 (file)
@@ -3,6 +3,7 @@ fn foo(bar: usize) -> usize {
         return 3;
     }
     //~^^^ ERROR if may be missing an else clause
+    //~| ERROR mismatched types [E0308]
 }
 
 fn foo2(bar: usize) -> usize {
@@ -10,6 +11,7 @@ fn foo2(bar: usize) -> usize {
         return 3;
     };
     //~^^^ ERROR if may be missing an else clause
+    //~| ERROR mismatched types [E0308]
     x
 }
 
@@ -18,8 +20,36 @@ fn foo3(bar: usize) -> usize {
         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);
 }
index 0ba72726ca78795807758c74146bb5ffa44189b3..06600b1cb9aea34da952af9915b9d05085e482cd 100644 (file)
@@ -1,3 +1,14 @@
+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
    |
@@ -13,8 +24,20 @@ 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:9:20
+  --> $DIR/if-without-else-as-fn-expr.rs:10:20
    |
 LL |       let x: usize = if bar % 5 == 0 {
    |  _________-__________^
@@ -29,8 +52,19 @@ 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: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
@@ -44,6 +78,87 @@ LL | |     }
    = 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`.
index 4c6d150229a3e6910b793067fdb59d5a0dc3f2a3..d9ea910adef5027c7302e7b5671bd319f33256c6 100644 (file)
@@ -6,11 +6,14 @@ LL | |
 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
 
index f0f1dc6c28667758f4655f1fb856dc32aac97348..bf892a8daa27ff5877d335903919e694a5bab8b0 100644 (file)
@@ -2,5 +2,6 @@ fn main() {
     enum Foo {
         Drop = assert_eq!(1, 1)
         //~^ ERROR if may be missing an else clause
+        //~| ERROR mismatched types [E0308]
     }
 }
index 0c3ba2ea4f94dabe1d95ab15c10e7ad590f6cefb..413c8c5c80b52c6c4ff97520c260f0e2d30679cd 100644 (file)
@@ -1,3 +1,13 @@
+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
    |
@@ -13,6 +23,7 @@ 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 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`.
index ed43bd8c6895e803a7fa6b46e1c152cecb74739e..a3d54892de5bbc61f2649a85ec512fbb9cc8dcdc 100644 (file)
@@ -4,7 +4,7 @@
 #![deny(unreachable_code)]
 
 fn foo() {
-    if {return} {
+    if {return} { //~ ERROR unreachable block in `if` expression
         println!("Hello, world!");
     }
 }
index d11471da1a6a38c719e6dd51b1b1df24c61793ad..f1690e595e5d1367941ccc95e3a742a9b96dc6c1 100644 (file)
@@ -1,15 +1,25 @@
-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