@@ -382,26 +382,43 @@ pub fn check_struct_like_enum_variant_pat(pcx: &pat_ctxt,
382
382
383
383
// Find the variant that was specified.
384
384
match tcx.def_map.borrow().find(&pat_id) {
385
- Some(&def::DefVariant(found_enum_id, variant_id, _ ))
385
+ Some(&def::DefVariant(found_enum_id, variant_id, true ))
386
386
if found_enum_id == enum_id => {
387
387
// Get the struct fields from this struct-like enum variant.
388
- let class_fields = ty::lookup_struct_fields(tcx, variant_id);
389
-
390
- check_struct_pat_fields(pcx, span, fields, class_fields,
388
+ let struct_fields = ty::lookup_struct_fields(tcx, variant_id);
389
+ check_struct_pat_fields(pcx, span, fields, struct_fields,
391
390
variant_id, substitutions, etc);
391
+ fcx.write_ty(pat_id, expected);
392
+ }
393
+ Some(&def::DefVariant(_, _, false)) => {
394
+ let name = pprust::path_to_string(path);
395
+ span_err!(tcx.sess, span, E0163,
396
+ "`{}` does not name a struct variant", name);
397
+ fcx.write_error(pat_id);
398
+ }
399
+ Some(&def::DefVariant(_, _, true)) => {
400
+ let name = pprust::path_to_string(path);
401
+ span_err!(tcx.sess, span, E0164,
402
+ "`{}` does not name a variant of the type being matched against", name);
403
+ fcx.write_error(pat_id);
392
404
}
393
405
Some(&def::DefStruct(..)) |
394
- Some(&def::DefVariant(..)) |
395
406
Some(&def::DefTy(..)) => {
396
407
let name = pprust::path_to_string(path);
397
408
span_err!(tcx.sess, span, E0028,
398
- "mismatched types: expected `{}`, found `{}`",
399
- fcx.infcx().ty_to_string(expected), name );
409
+ "`{}` does not name a variant", name);
410
+ fcx.write_error(pat_id );
400
411
}
401
412
_ => {
402
413
tcx.sess.span_bug(span, "resolve didn't write in variant");
403
414
}
404
415
}
416
+
417
+ if ty::type_is_error(fcx.node_ty(pat_id)) {
418
+ for field in fields.iter() {
419
+ check_pat(pcx, &*field.pat, ty::mk_err());
420
+ }
421
+ }
405
422
}
406
423
407
424
// Pattern checking is top-down rather than bottom-up so that bindings get
0 commit comments