When matching a slice, the tail should have the same lifetime

This commit is contained in:
Jakub Wieczorek 2012-12-15 23:12:26 +00:00 committed by Graydon Hoare
parent 1fdfd3b1d6
commit 6530fd3401

View 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)