Skip to content

Commit 70b7bd9

Browse files
committed
Fix build after rebase
1 parent c0cd145 commit 70b7bd9

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

src/librustc_const_eval/_match.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ use rustc::ty::{self, AdtKind, Ty, TyCtxt, TypeFoldable};
2929
use rustc::mir::Field;
3030
use rustc::util::common::ErrorReported;
3131

32-
use syntax::ast::DUMMY_NODE_ID;
33-
use syntax::ptr::P;
3432
use syntax_pos::{Span, DUMMY_SP};
3533

3634
use arena::TypedArena;
@@ -272,8 +270,14 @@ impl<'tcx> Witness<'tcx> {
272270
ty: Ty<'tcx>)
273271
-> Self
274272
{
275-
let arity = constructor_arity(cx, ctor, ty);
276-
self.0.extend(repeat(cx.wild_pattern).take(arity).cloned());
273+
let sub_pattern_tys = constructor_sub_pattern_tys(cx, ctor, ty);
274+
self.0.extend(sub_pattern_tys.into_iter().map(|ty| {
275+
Pattern {
276+
ty: ty,
277+
span: DUMMY_SP,
278+
kind: box PatternKind::Wild,
279+
}
280+
}));
277281
self.apply_constructor(cx, ctor, ty)
278282
}
279283

@@ -313,10 +317,11 @@ impl<'tcx> Witness<'tcx> {
313317
}
314318
}).collect();
315319

316-
if let ty::TyAdt(adt, _) = ty.sty {
320+
if let ty::TyAdt(adt, substs) = ty.sty {
317321
if adt.variants.len() > 1 {
318322
PatternKind::Variant {
319323
adt_def: adt,
324+
substs: substs,
320325
variant_index: ctor.variant_index_for_adt(adt),
321326
subpatterns: pats
322327
}
@@ -604,11 +609,11 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
604609
// All constructors are unused. Add wild patterns
605610
// rather than each individual constructor
606611
pats.into_iter().map(|mut witness| {
607-
witness.0.push(P(hir::Pat {
608-
id: DUMMY_NODE_ID,
609-
node: PatKind::Wild,
612+
witness.0.push(Pattern {
613+
ty: pcx.ty,
610614
span: DUMMY_SP,
611-
}));
615+
kind: box PatternKind::Wild,
616+
});
612617
witness
613618
}).collect()
614619
} else {
@@ -740,7 +745,7 @@ fn constructor_sub_pattern_tys<'a, 'tcx: 'a>(cx: &MatchCheckCtxt<'a, 'tcx>,
740745
},
741746
ty::TyRef(_, ref ty_and_mut) => vec![ty_and_mut.ty],
742747
ty::TyAdt(adt, substs) => {
743-
ctor.variant_for_adt(adt).fields.iter().map(|field| {
748+
adt.variants[ctor.variant_index_for_adt(adt)].fields.iter().map(|field| {
744749
field.ty(cx.tcx, substs)
745750
}).collect()
746751
}

src/librustc_const_eval/check_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ fn check_exhaustive<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
358358
match is_useful(cx, matrix, &[&wild_pattern], ConstructWitness) {
359359
UsefulWithWitness(pats) => {
360360
let witnesses = if pats.is_empty() {
361-
vec![cx.wild_pattern]
361+
vec![&wild_pattern]
362362
} else {
363363
pats.iter().map(|w| w.single_pattern()).collect()
364364
};

src/librustc_const_eval/pattern.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -393,8 +393,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
393393

394394
PatKind::TupleStruct(ref qpath, ref subpatterns, ddpos) => {
395395
let def = self.tcx.tables().qpath_def(qpath, pat.id);
396-
let pat_ty = self.tcx.tables().node_id_to_type(pat.id);
397-
let adt_def = match pat_ty.sty {
396+
let adt_def = match ty.sty {
398397
ty::TyAdt(adt_def, _) => adt_def,
399398
_ => span_bug!(pat.span, "tuple struct pattern not applied to an ADT"),
400399
};
@@ -413,8 +412,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
413412

414413
PatKind::Struct(ref qpath, ref fields, _) => {
415414
let def = self.tcx.tables().qpath_def(qpath, pat.id);
416-
let pat_ty = self.tcx.tables().node_id_to_type(pat.id);
417-
let adt_def = match pat_ty.sty {
415+
let adt_def = match ty.sty {
418416
ty::TyAdt(adt_def, _) => adt_def,
419417
_ => {
420418
span_bug!(
@@ -537,11 +535,14 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
537535
{
538536
match def {
539537
Def::Variant(variant_id) | Def::VariantCtor(variant_id, ..) => {
540-
let (adt_def, substs) = match ty.sty {
541-
TypeVariants::TyAdt(adt_def, substs) => (adt_def, substs),
542-
_ => bug!("inappropriate type for def"),
543-
};
538+
let enum_id = self.tcx.parent_def_id(variant_id).unwrap();
539+
let adt_def = self.tcx.lookup_adt_def(enum_id);
544540
if adt_def.variants.len() > 1 {
541+
let substs = match ty.sty {
542+
TypeVariants::TyAdt(_, substs) => substs,
543+
TypeVariants::TyFnDef(_, substs, _) => substs,
544+
_ => bug!("inappropriate type for def: {:?}", ty.sty),
545+
};
545546
PatternKind::Variant {
546547
adt_def: adt_def,
547548
substs: substs,
@@ -568,6 +569,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
568569
pat_id: ast::NodeId,
569570
span: Span)
570571
-> Pattern<'tcx> {
572+
let ty = self.tcx.tables().node_id_to_type(id);
571573
let def = self.tcx.tables().qpath_def(qpath, id);
572574
let kind = match def {
573575
Def::Const(def_id) | Def::AssociatedConst(def_id) => {
@@ -584,12 +586,12 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
584586
}
585587
}
586588
}
587-
_ => self.lower_variant_or_leaf(def, ty, vec![])
589+
_ => self.lower_variant_or_leaf(def, ty, vec![]),
588590
};
589591

590592
Pattern {
591593
span: span,
592-
ty: self.tcx.tables().node_id_to_type(id),
594+
ty: ty,
593595
kind: Box::new(kind),
594596
}
595597
}
@@ -657,6 +659,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
657659
hir::ExprPath(ref qpath) => qpath,
658660
_ => bug!()
659661
};
662+
let ty = self.tcx.tables().node_id_to_type(callee.id);
660663
let def = self.tcx.tables().qpath_def(qpath, callee.id);
661664
match def {
662665
Def::Fn(..) | Def::Method(..) => self.lower_lit(expr),
@@ -667,7 +670,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
667670
pattern: self.lower_const_expr(expr, pat_id, span)
668671
}
669672
}).collect();
670-
self.lower_variant_or_leaf(def, subpatterns)
673+
self.lower_variant_or_leaf(def, ty, subpatterns)
671674
}
672675
}
673676
}
@@ -702,7 +705,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
702705
})
703706
.collect();
704707

705-
self.lower_variant_or_leaf(def, subpatterns)
708+
self.lower_variant_or_leaf(def, pat_ty, subpatterns)
706709
}
707710

708711
hir::ExprArray(ref exprs) => {

0 commit comments

Comments
 (0)