// Find the variant that was specified.
match tcx.def_map.borrow().find(&pat_id) {
- Some(&def::DefVariant(found_enum_id, variant_id, _))
+ Some(&def::DefVariant(found_enum_id, variant_id, true))
if found_enum_id == enum_id => {
// 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, fields, class_fields,
+ let struct_fields = ty::lookup_struct_fields(tcx, variant_id);
+ check_struct_pat_fields(pcx, span, fields, struct_fields,
variant_id, substitutions, etc);
+ fcx.write_ty(pat_id, expected);
+ }
+ Some(&def::DefVariant(_, _, false)) => {
+ let name = pprust::path_to_string(path);
+ span_err!(tcx.sess, span, E0163,
+ "`{}` does not name a struct variant", name);
+ fcx.write_error(pat_id);
+ }
+ Some(&def::DefVariant(_, _, true)) => {
+ let name = pprust::path_to_string(path);
+ span_err!(tcx.sess, span, E0164,
+ "`{}` does not name a variant of the type being matched against", name);
+ fcx.write_error(pat_id);
}
Some(&def::DefStruct(..)) |
- Some(&def::DefVariant(..)) |
Some(&def::DefTy(..)) => {
let name = pprust::path_to_string(path);
span_err!(tcx.sess, span, E0028,
- "mismatched types: expected `{}`, found `{}`",
- fcx.infcx().ty_to_string(expected), name);
+ "`{}` does not name a variant", name);
+ fcx.write_error(pat_id);
}
_ => {
tcx.sess.span_bug(span, "resolve didn't write in variant");
}
}
+
+ if ty::type_is_error(fcx.node_ty(pat_id)) {
+ for field in fields.iter() {
+ check_pat(pcx, &*field.pat, ty::mk_err());
+ }
+ }
}
// Pattern checking is top-down rather than bottom-up so that bindings get
--- /dev/null
+// 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.
+
+enum Foo {
+ Bar(int)
+}
+
+fn main() {
+ match Bar(1i) {
+ Foo { i } => () //~ ERROR `Foo` does not name a variant
+ }
+}
--- /dev/null
+// 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.
+
+enum SomeEnum {
+ E
+}
+
+fn main() {
+ E { name: "foobar" }; //~ ERROR `E` does not name a structure
+}
--- /dev/null
+// 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.
+
+enum MyOption<T> {
+ MySome(T),
+ MyNone,
+}
+
+fn main() {
+ match MySome(42i) {
+ MySome { x: 42i } => (), //~ ERROR `MySome` does not name a struct variant
+ _ => (),
+ }
+}