Skip to content

Commit 776c17f

Browse files
committed
auto merge of #16554 : jakub-/rust/struct-pat-fields-ty-err, r=pcwalton
Fixes #16338. Fixed #16401.
2 parents 3f57c89 + 9b0f89d commit 776c17f

File tree

3 files changed

+43
-13
lines changed

3 files changed

+43
-13
lines changed

src/librustc/middle/typeck/check/_match.rs

+7-13
Original file line numberDiff line numberDiff line change
@@ -355,8 +355,7 @@ pub fn check_struct_pat_fields(pcx: &pat_ctxt,
355355
}
356356
}
357357

358-
pub fn check_struct_pat(pcx: &pat_ctxt, _pat_id: ast::NodeId, span: Span,
359-
_expected: ty::t, _path: &ast::Path,
358+
pub fn check_struct_pat(pcx: &pat_ctxt, span: Span,
360359
fields: &[ast::FieldPat], etc: bool,
361360
struct_id: ast::DefId,
362361
substitutions: &subst::Substs) {
@@ -529,8 +528,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
529528
},
530529
}
531530

532-
check_struct_pat(pcx, pat.id, pat.span, expected, path,
533-
fields.as_slice(), etc, cid, substs);
531+
check_struct_pat(pcx, pat.span, fields.as_slice(), etc, cid, substs);
534532
}
535533
ty::ty_enum(eid, ref substs) => {
536534
check_struct_like_enum_variant_pat(pcx,
@@ -557,15 +555,11 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) {
557555
None);
558556
match tcx.def_map.borrow().find(&pat.id) {
559557
Some(def) => {
560-
check_struct_pat(pcx,
561-
pat.id,
562-
pat.span,
563-
ty::mk_err(),
564-
path,
565-
fields.as_slice(),
566-
etc,
567-
def.def_id(),
568-
&subst::Substs::empty());
558+
let item_type = ty::lookup_item_type(tcx, def.def_id());
559+
let substitutions = fcx.infcx().fresh_substs_for_type(
560+
pat.span, &item_type.generics);
561+
check_struct_pat(pcx, pat.span, fields.as_slice(),
562+
etc, def.def_id(), &substitutions);
569563
}
570564
None => {
571565
tcx.sess.span_bug(pat.span,

src/test/compile-fail/issue-16338.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::raw::Slice;
12+
13+
fn main() {
14+
let Slice { data: data, len: len } = "foo";
15+
//~^ ERROR mismatched types: expected `&'static str` but found a structure pattern
16+
}
17+

src/test/compile-fail/issue-16401.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::raw::Slice;
12+
13+
fn main() {
14+
match () {
15+
Slice { data: data, len: len } => (),
16+
//~^ ERROR mismatched types: expected `()` but found a structure pattern
17+
_ => unreachable!()
18+
}
19+
}

0 commit comments

Comments
 (0)