diff options
| author | bors <bors@rust-lang.org> | 2014-08-17 21:16:10 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-08-17 21:16:10 +0000 |
| commit | 776c17f476c4be92f6cfe4dab528886973ea8c03 (patch) | |
| tree | 6d8c929d3eb1753cd3b920aacfbecc1e23dff3f6 | |
| parent | 3f57c8988dfd2eba8fb751fe72dde503a6ebf2c6 (diff) | |
| parent | 9b0f89d342de06b035c108186f0243a3bdc7528b (diff) | |
| download | rust-776c17f476c4be92f6cfe4dab528886973ea8c03.tar.gz rust-776c17f476c4be92f6cfe4dab528886973ea8c03.zip | |
auto merge of #16554 : jakub-/rust/struct-pat-fields-ty-err, r=pcwalton
Fixes #16338. Fixed #16401.
| -rw-r--r-- | src/librustc/middle/typeck/check/_match.rs | 20 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-16338.rs | 17 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-16401.rs | 19 |
3 files changed, 43 insertions, 13 deletions
diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index 76823155155..ff49aa8a40b 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -355,8 +355,7 @@ pub fn check_struct_pat_fields(pcx: &pat_ctxt, } } -pub fn check_struct_pat(pcx: &pat_ctxt, _pat_id: ast::NodeId, span: Span, - _expected: ty::t, _path: &ast::Path, +pub fn check_struct_pat(pcx: &pat_ctxt, span: Span, fields: &[ast::FieldPat], etc: bool, struct_id: ast::DefId, substitutions: &subst::Substs) { @@ -529,8 +528,7 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) { }, } - check_struct_pat(pcx, pat.id, pat.span, expected, path, - fields.as_slice(), etc, cid, substs); + check_struct_pat(pcx, pat.span, fields.as_slice(), etc, cid, substs); } ty::ty_enum(eid, ref substs) => { check_struct_like_enum_variant_pat(pcx, @@ -557,15 +555,11 @@ pub fn check_pat(pcx: &pat_ctxt, pat: &ast::Pat, expected: ty::t) { None); match tcx.def_map.borrow().find(&pat.id) { Some(def) => { - check_struct_pat(pcx, - pat.id, - pat.span, - ty::mk_err(), - path, - fields.as_slice(), - etc, - def.def_id(), - &subst::Substs::empty()); + let item_type = ty::lookup_item_type(tcx, def.def_id()); + let substitutions = fcx.infcx().fresh_substs_for_type( + pat.span, &item_type.generics); + check_struct_pat(pcx, pat.span, fields.as_slice(), + etc, def.def_id(), &substitutions); } None => { tcx.sess.span_bug(pat.span, diff --git a/src/test/compile-fail/issue-16338.rs b/src/test/compile-fail/issue-16338.rs new file mode 100644 index 00000000000..db0a0487687 --- /dev/null +++ b/src/test/compile-fail/issue-16338.rs @@ -0,0 +1,17 @@ +// 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::raw::Slice; + +fn main() { + let Slice { data: data, len: len } = "foo"; + //~^ ERROR mismatched types: expected `&'static str` but found a structure pattern +} + diff --git a/src/test/compile-fail/issue-16401.rs b/src/test/compile-fail/issue-16401.rs new file mode 100644 index 00000000000..79a824bbf69 --- /dev/null +++ b/src/test/compile-fail/issue-16401.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. + +use std::raw::Slice; + +fn main() { + match () { + Slice { data: data, len: len } => (), + //~^ ERROR mismatched types: expected `()` but found a structure pattern + _ => unreachable!() + } +} |
