Skip to content

Commit

Permalink
Fix build after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
canndrew committed Jan 4, 2017
1 parent c0cd145 commit 70b7bd9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 23 deletions.
25 changes: 15 additions & 10 deletions src/librustc_const_eval/_match.rs
Expand Up @@ -29,8 +29,6 @@ use rustc::ty::{self, AdtKind, Ty, TyCtxt, TypeFoldable};
use rustc::mir::Field;
use rustc::util::common::ErrorReported;

use syntax::ast::DUMMY_NODE_ID;
use syntax::ptr::P;
use syntax_pos::{Span, DUMMY_SP};

use arena::TypedArena;
Expand Down Expand Up @@ -272,8 +270,14 @@ impl<'tcx> Witness<'tcx> {
ty: Ty<'tcx>)
-> Self
{
let arity = constructor_arity(cx, ctor, ty);
self.0.extend(repeat(cx.wild_pattern).take(arity).cloned());
let sub_pattern_tys = constructor_sub_pattern_tys(cx, ctor, ty);
self.0.extend(sub_pattern_tys.into_iter().map(|ty| {
Pattern {
ty: ty,
span: DUMMY_SP,
kind: box PatternKind::Wild,
}
}));
self.apply_constructor(cx, ctor, ty)
}

Expand Down Expand Up @@ -313,10 +317,11 @@ impl<'tcx> Witness<'tcx> {
}
}).collect();

if let ty::TyAdt(adt, _) = ty.sty {
if let ty::TyAdt(adt, substs) = ty.sty {
if adt.variants.len() > 1 {
PatternKind::Variant {
adt_def: adt,
substs: substs,
variant_index: ctor.variant_index_for_adt(adt),
subpatterns: pats
}
Expand Down Expand Up @@ -604,11 +609,11 @@ pub fn is_useful<'p, 'a: 'p, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
// All constructors are unused. Add wild patterns
// rather than each individual constructor
pats.into_iter().map(|mut witness| {
witness.0.push(P(hir::Pat {
id: DUMMY_NODE_ID,
node: PatKind::Wild,
witness.0.push(Pattern {
ty: pcx.ty,
span: DUMMY_SP,
}));
kind: box PatternKind::Wild,
});
witness
}).collect()
} else {
Expand Down Expand Up @@ -740,7 +745,7 @@ fn constructor_sub_pattern_tys<'a, 'tcx: 'a>(cx: &MatchCheckCtxt<'a, 'tcx>,
},
ty::TyRef(_, ref ty_and_mut) => vec![ty_and_mut.ty],
ty::TyAdt(adt, substs) => {
ctor.variant_for_adt(adt).fields.iter().map(|field| {
adt.variants[ctor.variant_index_for_adt(adt)].fields.iter().map(|field| {
field.ty(cx.tcx, substs)
}).collect()
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_const_eval/check_match.rs
Expand Up @@ -358,7 +358,7 @@ fn check_exhaustive<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
match is_useful(cx, matrix, &[&wild_pattern], ConstructWitness) {
UsefulWithWitness(pats) => {
let witnesses = if pats.is_empty() {
vec![cx.wild_pattern]
vec![&wild_pattern]
} else {
pats.iter().map(|w| w.single_pattern()).collect()
};
Expand Down
27 changes: 15 additions & 12 deletions src/librustc_const_eval/pattern.rs
Expand Up @@ -393,8 +393,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {

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

PatKind::Struct(ref qpath, ref fields, _) => {
let def = self.tcx.tables().qpath_def(qpath, pat.id);
let pat_ty = self.tcx.tables().node_id_to_type(pat.id);
let adt_def = match pat_ty.sty {
let adt_def = match ty.sty {
ty::TyAdt(adt_def, _) => adt_def,
_ => {
span_bug!(
Expand Down Expand Up @@ -537,11 +535,14 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
{
match def {
Def::Variant(variant_id) | Def::VariantCtor(variant_id, ..) => {
let (adt_def, substs) = match ty.sty {
TypeVariants::TyAdt(adt_def, substs) => (adt_def, substs),
_ => bug!("inappropriate type for def"),
};
let enum_id = self.tcx.parent_def_id(variant_id).unwrap();
let adt_def = self.tcx.lookup_adt_def(enum_id);
if adt_def.variants.len() > 1 {
let substs = match ty.sty {
TypeVariants::TyAdt(_, substs) => substs,
TypeVariants::TyFnDef(_, substs, _) => substs,
_ => bug!("inappropriate type for def: {:?}", ty.sty),
};
PatternKind::Variant {
adt_def: adt_def,
substs: substs,
Expand All @@ -568,6 +569,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
pat_id: ast::NodeId,
span: Span)
-> Pattern<'tcx> {
let ty = self.tcx.tables().node_id_to_type(id);
let def = self.tcx.tables().qpath_def(qpath, id);
let kind = match def {
Def::Const(def_id) | Def::AssociatedConst(def_id) => {
Expand All @@ -584,12 +586,12 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
}
}
}
_ => self.lower_variant_or_leaf(def, ty, vec![])
_ => self.lower_variant_or_leaf(def, ty, vec![]),
};

Pattern {
span: span,
ty: self.tcx.tables().node_id_to_type(id),
ty: ty,
kind: Box::new(kind),
}
}
Expand Down Expand Up @@ -657,6 +659,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
hir::ExprPath(ref qpath) => qpath,
_ => bug!()
};
let ty = self.tcx.tables().node_id_to_type(callee.id);
let def = self.tcx.tables().qpath_def(qpath, callee.id);
match def {
Def::Fn(..) | Def::Method(..) => self.lower_lit(expr),
Expand All @@ -667,7 +670,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
pattern: self.lower_const_expr(expr, pat_id, span)
}
}).collect();
self.lower_variant_or_leaf(def, subpatterns)
self.lower_variant_or_leaf(def, ty, subpatterns)
}
}
}
Expand Down Expand Up @@ -702,7 +705,7 @@ impl<'a, 'gcx, 'tcx> PatternContext<'a, 'gcx, 'tcx> {
})
.collect();

self.lower_variant_or_leaf(def, subpatterns)
self.lower_variant_or_leaf(def, pat_ty, subpatterns)
}

hir::ExprArray(ref exprs) => {
Expand Down

0 comments on commit 70b7bd9

Please sign in to comment.