type_check.rs: rustfmt

This commit is contained in:
Niko Matsakis 2017-12-01 21:24:08 -05:00
parent 506e80c899
commit c1708abb07

View file

@ -104,12 +104,7 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> {
} }
} }
fn visit_place( fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) {
&mut self,
place: &Place<'tcx>,
context: PlaceContext,
location: Location,
) {
self.sanitize_place(place, location, context); self.sanitize_place(place, location, context);
} }
@ -164,11 +159,12 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
} }
} }
fn sanitize_place(&mut self, fn sanitize_place(
place: &Place<'tcx>, &mut self,
location: Location, place: &Place<'tcx>,
context: PlaceContext) location: Location,
-> PlaceTy<'tcx> { context: PlaceContext,
) -> PlaceTy<'tcx> {
debug!("sanitize_place: {:?}", place); debug!("sanitize_place: {:?}", place);
let place_ty = match *place { let place_ty = match *place {
Place::Local(index) => PlaceTy::Ty { Place::Local(index) => PlaceTy::Ty {
@ -210,9 +206,11 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
}; };
if let PlaceContext::Copy = context { if let PlaceContext::Copy = context {
let ty = place_ty.to_ty(self.tcx()); let ty = place_ty.to_ty(self.tcx());
if self.cx.infcx.type_moves_by_default(self.cx.param_env, ty, DUMMY_SP) { if self.cx
span_mirbug!(self, place, .infcx
"attempted copy of non-Copy type ({:?})", ty); .type_moves_by_default(self.cx.param_env, ty, DUMMY_SP)
{
span_mirbug!(self, place, "attempted copy of non-Copy type ({:?})", ty);
} }
} }
place_ty place_ty
@ -312,18 +310,16 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
ProjectionElem::Field(field, fty) => { ProjectionElem::Field(field, fty) => {
let fty = self.sanitize_type(place, fty); let fty = self.sanitize_type(place, fty);
match self.field_ty(place, base, field, location) { match self.field_ty(place, base, field, location) {
Ok(ty) => { Ok(ty) => if let Err(terr) = self.cx.eq_types(ty, fty, location.at_self()) {
if let Err(terr) = self.cx.eq_types(ty, fty, location.at_self()) { span_mirbug!(
span_mirbug!( self,
self, place,
place, "bad field access ({:?}: {:?}): {:?}",
"bad field access ({:?}: {:?}): {:?}", ty,
ty, fty,
fty, terr
terr );
); },
}
}
Err(FieldAccessError::OutOfRange { field_count }) => span_mirbug!( Err(FieldAccessError::OutOfRange { field_count }) => span_mirbug!(
self, self,
place, place,
@ -358,9 +354,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
variant_index, variant_index,
} => (&adt_def.variants[variant_index], substs), } => (&adt_def.variants[variant_index], substs),
PlaceTy::Ty { ty } => match ty.sty { PlaceTy::Ty { ty } => match ty.sty {
ty::TyAdt(adt_def, substs) if !adt_def.is_enum() => { ty::TyAdt(adt_def, substs) if !adt_def.is_enum() => (&adt_def.variants[0], substs),
(&adt_def.variants[0], substs)
}
ty::TyClosure(def_id, substs) => { ty::TyClosure(def_id, substs) => {
return match substs.upvar_tys(def_id, tcx).nth(field.index()) { return match substs.upvar_tys(def_id, tcx).nth(field.index()) {
Some(ty) => Ok(ty), Some(ty) => Ok(ty),