Skip to content

Commit 1cc2786

Browse files
committed
---
yaml --- r: 232493 b: refs/heads/try c: e35fd74 h: refs/heads/master i: 232491: be061b0 v: v3
1 parent 65beccf commit 1cc2786

File tree

14 files changed

+309
-299
lines changed

14 files changed

+309
-299
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: edeb4f1c86cbf6af8ef9874d4b3af50f721ea1b8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: 02e97342c136d2d13411ebd0a687100d8be248e0
4+
refs/heads/try: e35fd748114c22df6d08991980c4f7e199414497
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try/src/librustc_typeck/check/_match.rs

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -528,60 +528,31 @@ pub fn check_pat_struct<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>, pat: &'tcx ast::Pat,
528528
let tcx = pcx.fcx.ccx.tcx;
529529

530530
let def = tcx.def_map.borrow().get(&pat.id).unwrap().full_def();
531-
let (adt_def, variant) = match def {
532-
def::DefTrait(_) => {
531+
let variant = match fcx.def_struct_variant(def) {
532+
Some((_, variant)) => variant,
533+
None => {
533534
let name = pprust::path_to_string(path);
534-
span_err!(tcx.sess, pat.span, E0168,
535-
"use of trait `{}` in a struct pattern", name);
535+
span_err!(tcx.sess, pat.span, E0163,
536+
"`{}` does not name a struct or a struct variant", name);
536537
fcx.write_error(pat.id);
537538

538539
for field in fields {
539-
check_pat(pcx, &*field.node.pat, tcx.types.err);
540+
check_pat(pcx, &field.node.pat, tcx.types.err);
540541
}
541542
return;
542-
},
543-
_ => {
544-
let def_type = tcx.lookup_item_type(def.def_id());
545-
match def_type.ty.sty {
546-
ty::TyStruct(struct_def, _) =>
547-
(struct_def, struct_def.struct_variant()),
548-
ty::TyEnum(enum_def, _)
549-
if def == def::DefVariant(enum_def.did, def.def_id(), true) =>
550-
(enum_def, enum_def.variant_of_def(def)),
551-
_ => {
552-
let name = pprust::path_to_string(path);
553-
span_err!(tcx.sess, pat.span, E0163,
554-
"`{}` does not name a struct or a struct variant", name);
555-
fcx.write_error(pat.id);
556-
557-
for field in fields {
558-
check_pat(pcx, &*field.node.pat, tcx.types.err);
559-
}
560-
return;
561-
}
562-
}
563543
}
564544
};
565545

566-
instantiate_path(pcx.fcx,
567-
&path.segments,
568-
adt_def.type_scheme(tcx),
569-
&adt_def.predicates(tcx),
570-
None,
571-
def,
572-
pat.span,
573-
pat.id);
574-
575-
let pat_ty = fcx.node_ty(pat.id);
546+
let pat_ty = pcx.fcx.instantiate_type(def.def_id(), path);
547+
let item_substs = match pat_ty.sty {
548+
ty::TyStruct(_, substs) | ty::TyEnum(_, substs) => substs,
549+
_ => tcx.sess.span_bug(pat.span, "struct variant is not an ADT")
550+
};
576551
demand::eqtype(fcx, pat.span, expected, pat_ty);
577-
578-
let item_substs = fcx
579-
.item_substs()
580-
.get(&pat.id)
581-
.map(|substs| substs.substs.clone())
582-
.unwrap_or_else(|| Substs::empty());
583-
584552
check_struct_pat_fields(pcx, pat.span, fields, variant, &item_substs, etc);
553+
554+
fcx.write_ty(pat.id, pat_ty);
555+
fcx.write_substs(pat.id, ty::ItemSubsts { substs: item_substs.clone() });
585556
}
586557

587558
pub fn check_pat_enum<'a, 'tcx>(pcx: &pat_ctxt<'a, 'tcx>,

0 commit comments

Comments
 (0)