about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-05-31 11:21:38 -0700
committerbors <bors@rust-lang.org>2014-05-31 11:21:38 -0700
commit60b4a97de70b9b40550a576b11c5670899be00c4 (patch)
tree85d1e008f58748f6f12eb44595824674920f64b5
parentb38712071efd09fd602cef6a11621db09672f990 (diff)
parent80e84e00010ee8a1c924619e6834d4a51eaf0f34 (diff)
downloadrust-60b4a97de70b9b40550a576b11c5670899be00c4.tar.gz
rust-60b4a97de70b9b40550a576b11c5670899be00c4.zip
auto merge of #14562 : jakub-/rust/issue-14541, r=alexcrichton
Fixes #14541
-rw-r--r--src/librustc/middle/typeck/check/_match.rs10
-rw-r--r--src/test/compile-fail/issue-14541.rs20
2 files changed, 24 insertions, 6 deletions
diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs
index 072b4ea7fe1..36606ae816e 100644
--- a/src/librustc/middle/typeck/check/_match.rs
+++ b/src/librustc/middle/typeck/check/_match.rs
@@ -298,9 +298,8 @@ pub fn check_pat_variant(pcx: &pat_ctxt, pat: &ast::Pat, path: &ast::Path,
 /// `etc` is true if the pattern said '...' and false otherwise.
 pub fn check_struct_pat_fields(pcx: &pat_ctxt,
                                span: Span,
-                               path: &ast::Path,
                                fields: &[ast::FieldPat],
-                               class_fields: Vec<ty::field_ty> ,
+                               class_fields: Vec<ty::field_ty>,
                                class_id: ast::DefId,
                                substitutions: &ty::substs,
                                etc: bool) {
@@ -333,13 +332,12 @@ pub fn check_struct_pat_fields(pcx: &pat_ctxt,
                 found_fields.insert(index);
             }
             None => {
-                let name = pprust::path_to_str(path);
                 // Check the pattern anyway, so that attempts to look
                 // up its type won't fail
                 check_pat(pcx, field.pat, ty::mk_err());
                 tcx.sess.span_err(span,
                     format!("struct `{}` does not have a field named `{}`",
-                            name,
+                            ty::item_path_str(tcx, class_id),
                             token::get_ident(field.ident)).as_slice());
             }
         }
@@ -390,7 +388,7 @@ pub fn check_struct_pat(pcx: &pat_ctxt, pat_id: ast::NodeId, span: Span,
         }
     }
 
-    check_struct_pat_fields(pcx, span, path, fields, class_fields, struct_id,
+    check_struct_pat_fields(pcx, span, fields, class_fields, struct_id,
                             substitutions, etc);
 }
 
@@ -413,7 +411,7 @@ pub fn check_struct_like_enum_variant_pat(pcx: &pat_ctxt,
             // Get the struct fields from this struct-like enum variant.
             let class_fields = ty::lookup_struct_fields(tcx, variant_id);
 
-            check_struct_pat_fields(pcx, span, path, fields, class_fields,
+            check_struct_pat_fields(pcx, span, fields, class_fields,
                                     variant_id, substitutions, etc);
         }
         Some(&ast::DefStruct(..)) | Some(&ast::DefVariant(..)) => {
diff --git a/src/test/compile-fail/issue-14541.rs b/src/test/compile-fail/issue-14541.rs
new file mode 100644
index 00000000000..2dcfeac513c
--- /dev/null
+++ b/src/test/compile-fail/issue-14541.rs
@@ -0,0 +1,20 @@
+// 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 vec2 { y: f32 }
+struct vec3 { y: f32, z: f32 }
+
+fn make(v: vec2) {
+    let vec3 { y: _, z: _ } = v;
+    //~^ ERROR mismatched types: expected `vec2` but found `vec3`
+    //~^^ ERROR struct `vec2` does not have a field named `z`
+}
+
+fn main() { }
\ No newline at end of file