Fix build after rebase
This commit is contained in:
parent
c0cd145c1f
commit
70b7bd94cc
3 changed files with 31 additions and 23 deletions
|
|
@ -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;
|
||||
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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 {
|
||||
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
};
|
||||
|
|
@ -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!(
|
||||
|
|
@ -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,
|
||||
|
|
@ -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) => {
|
||||
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
@ -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),
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue