about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-10-25 07:07:08 +0000
committerbors <bors@rust-lang.org>2014-10-25 07:07:08 +0000
commita34b8dec697014f15e725215e17ea8d956c0ab1a (patch)
treec0a34067e63f5fb5602926eedc82f453fa16335e /src/test
parent172b59abe510dde5826fec24377f208a19418c04 (diff)
parent1484f9cd46013a227d1d057508ff57ebc5930a8d (diff)
downloadrust-a34b8dec697014f15e725215e17ea8d956c0ab1a.tar.gz
rust-a34b8dec697014f15e725215e17ea8d956c0ab1a.zip
auto merge of #18171 : jakub-/rust/match-typeck, r=pcwalton
Rather than doing it top-down, with a known expected type, we will now simply establish the appropriate constraints between the pattern and the expression it destructures.

Closes #8783.
Closes #10200.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/destructure-trait-ref.rs12
-rw-r--r--src/test/compile-fail/issue-10200.rs19
-rw-r--r--src/test/compile-fail/issue-13482.rs3
-rw-r--r--src/test/compile-fail/issue-13624.rs3
-rw-r--r--src/test/compile-fail/issue-14541.rs4
-rw-r--r--src/test/compile-fail/issue-15260.rs22
-rw-r--r--src/test/compile-fail/issue-15896.rs4
-rw-r--r--src/test/compile-fail/issue-16338.rs3
-rw-r--r--src/test/compile-fail/issue-16401.rs3
-rw-r--r--src/test/compile-fail/issue-17405.rs2
-rw-r--r--src/test/compile-fail/issue-17800.rs2
-rw-r--r--src/test/compile-fail/issue-5100.rs13
-rw-r--r--src/test/compile-fail/issue-7092.rs5
-rw-r--r--src/test/compile-fail/match-vec-mismatch-2.rs3
-rw-r--r--src/test/compile-fail/pattern-error-continue.rs3
-rw-r--r--src/test/compile-fail/suppressed-error.rs3
-rw-r--r--src/test/run-pass/issue-8783.rs30
17 files changed, 105 insertions, 29 deletions
diff --git a/src/test/compile-fail/destructure-trait-ref.rs b/src/test/compile-fail/destructure-trait-ref.rs
index 27aa43638f4..a2a5a3e257f 100644
--- a/src/test/compile-fail/destructure-trait-ref.rs
+++ b/src/test/compile-fail/destructure-trait-ref.rs
@@ -30,12 +30,12 @@ fn main() {
     let &&x = &&(&1i as &T);
 
     // n == m
-    let &x = &1i as &T;      //~ ERROR cannot be dereferenced
-    let &&x = &(&1i as &T);  //~ ERROR cannot be dereferenced
-    let box x = box 1i as Box<T>; //~ ERROR cannot be dereferenced
+    let &x = &1i as &T;      //~ ERROR type `&T` cannot be dereferenced
+    let &&x = &(&1i as &T);  //~ ERROR type `&T` cannot be dereferenced
+    let box x = box 1i as Box<T>; //~ ERROR type `Box<T>` cannot be dereferenced
 
     // n > m
-    let &&x = &1i as &T;     //~ ERROR found an `&`-pointer pattern
-    let &&&x = &(&1i as &T); //~ ERROR found an `&`-pointer pattern
-    let box box x = box 1i as Box<T>;    //~ ERROR found a box pattern
+    let &&x = &1i as &T;     //~ ERROR found &-ptr
+    let &&&x = &(&1i as &T); //~ ERROR found &-ptr
+    let box box x = box 1i as Box<T>;    //~ ERROR found box
 }
diff --git a/src/test/compile-fail/issue-10200.rs b/src/test/compile-fail/issue-10200.rs
new file mode 100644
index 00000000000..2b9ac705f32
--- /dev/null
+++ b/src/test/compile-fail/issue-10200.rs
@@ -0,0 +1,19 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+struct Foo(bool);
+fn foo(_: uint) -> Foo { Foo(false) }
+
+fn main() {
+    match Foo(true) {
+        foo(x) //~ ERROR `foo` is not an enum variant, struct or const
+        => ()
+    }
+}
diff --git a/src/test/compile-fail/issue-13482.rs b/src/test/compile-fail/issue-13482.rs
index 2c7b56f9dc7..43c7f45e15a 100644
--- a/src/test/compile-fail/issue-13482.rs
+++ b/src/test/compile-fail/issue-13482.rs
@@ -12,7 +12,8 @@ fn main() {
   let x = [1,2];
   let y = match x {
     [] => None,
-//~^ ERROR expected `[<generic integer #0>, ..2]`, found a fixed array pattern of size 0
+//~^ ERROR mismatched types: expected `[<generic integer #0>, ..2]`, found `[<generic #7>, ..0]`
+//         (expected array, found array)
     [a,_] => Some(a)
   };
 }
diff --git a/src/test/compile-fail/issue-13624.rs b/src/test/compile-fail/issue-13624.rs
index 0593b498192..0c103515981 100644
--- a/src/test/compile-fail/issue-13624.rs
+++ b/src/test/compile-fail/issue-13624.rs
@@ -29,7 +29,8 @@ mod b {
       let enum_struct_variant = ::a::get_enum_struct_variant();
       match enum_struct_variant {
         a::EnumStructVariant { x, y, z } => {
-        //~^ ERROR error: mismatched types: expected `()`, found a structure pattern
+        //~^ ERROR mismatched types: expected `()`, found `a::Enum`
+        //         (expected (), found enum a::Enum)
         }
       }
     }
diff --git a/src/test/compile-fail/issue-14541.rs b/src/test/compile-fail/issue-14541.rs
index 921e331e960..ac49f8b99cf 100644
--- a/src/test/compile-fail/issue-14541.rs
+++ b/src/test/compile-fail/issue-14541.rs
@@ -13,8 +13,8 @@ struct vec3 { y: f32, z: f32 }
 
 fn make(v: vec2) {
     let vec3 { y: _, z: _ } = v;
-    //~^ ERROR `vec3` does not name the structure `vec2`
-    //~^^ ERROR struct `vec2` does not have a field named `z`
+    //~^ ERROR mismatched types: expected `vec2`, found `vec3`
+    //         (expected struct vec2, found struct vec3)
 }
 
 fn main() { }
diff --git a/src/test/compile-fail/issue-15260.rs b/src/test/compile-fail/issue-15260.rs
index 06826139884..e3d19729710 100644
--- a/src/test/compile-fail/issue-15260.rs
+++ b/src/test/compile-fail/issue-15260.rs
@@ -9,11 +9,23 @@
 // except according to those terms.
 
 struct Foo {
-  a: uint,
+    a: uint,
 }
 
-fn main(){
-    let Foo {a: _, a: _} = Foo {a: 29};
-    //~^ ERROR field `a` bound twice in pattern
-}
+fn main() {
+    let Foo {
+        a: _, //~ NOTE field `a` previously bound here
+        a: _ //~ ERROR field `a` bound multiple times in the pattern
+    } = Foo { a: 29 };
+
+    let Foo {
+        a, //~ NOTE field `a` previously bound here
+        a: _ //~ ERROR field `a` bound multiple times in the pattern
+    } = Foo { a: 29 };
 
+    let Foo {
+        a, //~ NOTE field `a` previously bound here
+        a: _, //~ ERROR field `a` bound multiple times in the pattern
+        a: x //~ ERROR field `a` bound multiple times in the pattern
+    } = Foo { a: 29 };
+}
diff --git a/src/test/compile-fail/issue-15896.rs b/src/test/compile-fail/issue-15896.rs
index b7fa54e5c18..5d92208d3e3 100644
--- a/src/test/compile-fail/issue-15896.rs
+++ b/src/test/compile-fail/issue-15896.rs
@@ -18,7 +18,9 @@ fn main() {
     let e = B(REB(()), Tau { t: 3 });
     let u = match e {
         B(
-          Tau{t: x}, //~ ERROR `Tau` does not name a variant
+          Tau{t: x},
+          //~^ ERROR mismatched types: expected `main::R`, found `main::Tau`
+          //        (expected enum main::R, found struct main::Tau)
           _) => x,
     };
 }
diff --git a/src/test/compile-fail/issue-16338.rs b/src/test/compile-fail/issue-16338.rs
index 305b1fe2ad7..537fc5aaa55 100644
--- a/src/test/compile-fail/issue-16338.rs
+++ b/src/test/compile-fail/issue-16338.rs
@@ -12,6 +12,7 @@ use std::raw::Slice;
 
 fn main() {
     let Slice { data: data, len: len } = "foo";
-    //~^ ERROR mismatched types: expected `&str`, found a structure pattern
+    //~^ ERROR mismatched types: expected `&str`, found `core::raw::Slice<<generic #3>>`
+    //         (expected &-ptr, found struct core::raw::Slice)
 }
 
diff --git a/src/test/compile-fail/issue-16401.rs b/src/test/compile-fail/issue-16401.rs
index bece4381e41..deb2f5912b6 100644
--- a/src/test/compile-fail/issue-16401.rs
+++ b/src/test/compile-fail/issue-16401.rs
@@ -13,7 +13,8 @@ use std::raw::Slice;
 fn main() {
     match () {
         Slice { data: data, len: len } => (),
-        //~^ ERROR mismatched types: expected `()`, found a structure pattern
+        //~^ ERROR mismatched types: expected `()`, found `core::raw::Slice<<generic #3>>`
+        //         (expected (), found struct core::raw::Slice)
         _ => unreachable!()
     }
 }
diff --git a/src/test/compile-fail/issue-17405.rs b/src/test/compile-fail/issue-17405.rs
index b80cfb521ef..b0f2e0b666e 100644
--- a/src/test/compile-fail/issue-17405.rs
+++ b/src/test/compile-fail/issue-17405.rs
@@ -14,6 +14,6 @@ enum Foo {
 
 fn main() {
     match Bar(1i) {
-        Foo { i } => () //~ ERROR `Foo` does not name a variant
+        Foo { i } => () //~ ERROR `Foo` does not name a struct or a struct variant
     }
 }
diff --git a/src/test/compile-fail/issue-17800.rs b/src/test/compile-fail/issue-17800.rs
index 8ef016e3fd5..30a8a51ed8c 100644
--- a/src/test/compile-fail/issue-17800.rs
+++ b/src/test/compile-fail/issue-17800.rs
@@ -15,7 +15,7 @@ enum MyOption<T> {
 
 fn main() {
     match MySome(42i) {
-        MySome { x: 42i } => (), //~ ERROR `MySome` does not name a struct variant
+        MySome { x: 42i } => (), //~ ERROR `MySome` does not name a struct or a struct variant
         _ => (),
     }
 }
diff --git a/src/test/compile-fail/issue-5100.rs b/src/test/compile-fail/issue-5100.rs
index 5c4127c5bae..6524056df88 100644
--- a/src/test/compile-fail/issue-5100.rs
+++ b/src/test/compile-fail/issue-5100.rs
@@ -12,24 +12,29 @@ enum A { B, C }
 
 fn main() {
     match (true, false) {
-        B => (), //~ ERROR expected `(bool,bool)`, found an enum or structure pattern
+        B => (),
+        //~^ ERROR mismatched types: expected `(bool,bool)`, found `A`
+        //         (expected tuple, found enum A)
         _ => ()
     }
 
     match (true, false) {
         (true, false, false) => ()
-        //~^ ERROR mismatched types: expected `(bool,bool)`, found tuple
+        //~^ ERROR mismatched types: expected `(bool,bool)`,
+        //         found `(<generic #7>,<generic #8>,<generic #9>)`
         //         (expected a tuple with 2 elements, found one with 3 elements)
     }
 
     match (true, false) {
         box (true, false) => ()
-        //~^ ERROR mismatched types: expected `(bool,bool)`, found a box pattern
+        //~^ ERROR mismatched types: expected `(bool,bool)`, found `Box<<generic #11>>`
+        //         (expected tuple, found box)
     }
 
     match (true, false) {
         &(true, false) => ()
-        //~^ ERROR mismatched types: expected `(bool,bool)`, found an `&`-pointer pattern
+        //~^ ERROR mismatched types: expected `(bool,bool)`, found `&<generic #15>`
+        //         (expected tuple, found &-ptr)
     }
 
 
diff --git a/src/test/compile-fail/issue-7092.rs b/src/test/compile-fail/issue-7092.rs
index 8b3df6f9f95..cc7e8052920 100644
--- a/src/test/compile-fail/issue-7092.rs
+++ b/src/test/compile-fail/issue-7092.rs
@@ -13,8 +13,9 @@ enum Whatever {
 
 fn foo(x: Whatever) {
     match x {
-        Some(field) => field.access(),
-        //~^ ERROR: mismatched types: expected `Whatever`, found
+        Some(field) =>
+//~^ ERROR: mismatched types: expected `Whatever`, found `core::option::Option<<generic #3>>`
+            field.access(), //~ ERROR the type of this value must be known in this context
     }
 }
 
diff --git a/src/test/compile-fail/match-vec-mismatch-2.rs b/src/test/compile-fail/match-vec-mismatch-2.rs
index e095c7c2408..6d37eb8a636 100644
--- a/src/test/compile-fail/match-vec-mismatch-2.rs
+++ b/src/test/compile-fail/match-vec-mismatch-2.rs
@@ -10,6 +10,7 @@
 
 fn main() {
     match () {
-        [()] => { } //~ ERROR mismatched types: expected `()`, found an array pattern
+        [()] => { }
+//~^ ERROR mismatched types: expected `()`, found `&[<generic #1>]` (expected (), found &-ptr)
     }
 }
diff --git a/src/test/compile-fail/pattern-error-continue.rs b/src/test/compile-fail/pattern-error-continue.rs
index 01feda34e08..f438f9973cf 100644
--- a/src/test/compile-fail/pattern-error-continue.rs
+++ b/src/test/compile-fail/pattern-error-continue.rs
@@ -29,7 +29,8 @@ fn main() {
         _ => ()
     }
     match 'c' {
-        S { .. } => (),   //~ ERROR mismatched types: expected `char`, found a structure pattern
+        S { .. } => (),
+        //~^ ERROR mismatched types: expected `char`, found `S` (expected char, found struct S)
 
         _ => ()
     }
diff --git a/src/test/compile-fail/suppressed-error.rs b/src/test/compile-fail/suppressed-error.rs
index f13aabe5259..54d6fa5bdd3 100644
--- a/src/test/compile-fail/suppressed-error.rs
+++ b/src/test/compile-fail/suppressed-error.rs
@@ -9,6 +9,7 @@
 // except according to those terms.
 
 fn main() {
-    let (x, y) = (); //~ ERROR expected `()`, found tuple (types differ)
+    let (x, y) = ();
+//~^ ERROR types: expected `()`, found `(<generic #3>,<generic #4>)` (expected (), found tuple)
     return x;
 }
diff --git a/src/test/run-pass/issue-8783.rs b/src/test/run-pass/issue-8783.rs
new file mode 100644
index 00000000000..d59c0ad52e9
--- /dev/null
+++ b/src/test/run-pass/issue-8783.rs
@@ -0,0 +1,30 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+use std::default::Default;
+
+struct X { pub x: uint }
+impl Default for X {
+    fn default() -> X {
+        X { x: 42u }
+    }
+}
+
+struct Y<T> { pub y: T }
+impl<T: Default> Default for Y<T> {
+    fn default() -> Y<T> {
+        Y { y: Default::default() }
+    }
+}
+
+fn main() {
+    let X { x: _ } = Default::default();
+    let Y { y: X { x } } = Default::default();
+}