]> git.lizzy.rs Git - rust.git/commitdiff
When matching a slice, the tail should have the same lifetime
authorJakub Wieczorek <jakubw@jakubw.net>
Sat, 15 Dec 2012 23:12:26 +0000 (23:12 +0000)
committerGraydon Hoare <graydon@mozilla.com>
Tue, 18 Dec 2012 00:50:40 +0000 (16:50 -0800)
src/librustc/middle/typeck/check/alt.rs

index 68e4c1a4b92cdea58fa1513bb8229fc4a0940e18..95f44af48e171161239f68451fa2392e4ce6bcd9 100644 (file)
@@ -526,8 +526,26 @@ fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
         }
       }
       ast::pat_vec(elts, tail) => {
-        let elt_type = match structure_of(fcx, pat.span, expected) {
-          ty::ty_evec(mt, _) | ty::ty_unboxed_vec(mt) => mt,
+        let default_region_var =
+            fcx.infcx().next_region_var_with_lb(
+                pat.span, pcx.block_region
+            );
+
+        let (elt_type, region_var) = match structure_of(
+          fcx, pat.span, expected
+        ) {
+          ty::ty_evec(mt, vstore) => {
+            let region_var = match vstore {
+                ty::vstore_slice(r) => r,
+                ty::vstore_box | ty::vstore_uniq | ty::vstore_fixed(_) => {
+                    default_region_var
+                }
+            };
+            (mt, region_var)
+          }
+          ty::ty_unboxed_vec(mt) => {
+            (mt, default_region_var)
+          },
           _ => {
             tcx.sess.span_fatal(
                 pat.span,
@@ -543,9 +561,6 @@ fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
 
         match tail {
             Some(tail_pat) => {
-                let region_var = fcx.infcx().next_region_var_with_lb(
-                    pat.span, pcx.block_region
-                );
                 let slice_ty = ty::mk_evec(tcx,
                     {ty: elt_type.ty, mutbl: elt_type.mutbl},
                     ty::vstore_slice(region_var)