Skip to content

Commit 527a5dd

Browse files
Nashenas88nikomatsakis
authored andcommitted
Normalize LvalueTy for ops and format code to satisfy tidy check
1 parent 47c6db0 commit 527a5dd

File tree

1 file changed

+39
-24
lines changed

1 file changed

+39
-24
lines changed

src/librustc_mir/transform/type_check.rs

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,23 +1012,27 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
10121012
}
10131013
}
10141014

1015-
fn aggregate_field_ty(&mut self, ak: &Box<AggregateKind<'tcx>>, field: usize, location: Location)
1016-
-> Result<Ty<'tcx>, FieldAccessError>
1017-
{
1015+
fn aggregate_field_ty(
1016+
&mut self,
1017+
ak: &Box<AggregateKind<'tcx>>,
1018+
field: usize,
1019+
location: Location,
1020+
) -> Result<Ty<'tcx>, FieldAccessError> {
10181021
let tcx = self.tcx();
10191022

10201023
let (variant, substs) = match **ak {
1021-
AggregateKind::Adt(def, variant, substs, _) => { // handle unions?
1024+
AggregateKind::Adt(def, variant, substs, _) => {
1025+
// handle unions?
10221026
(&def.variants[variant], substs)
1023-
},
1027+
}
10241028
AggregateKind::Closure(def_id, substs) => {
10251029
return match substs.upvar_tys(def_id, tcx).nth(field) {
10261030
Some(ty) => Ok(ty),
10271031
None => Err(FieldAccessError::OutOfRange {
1028-
field_count: substs.upvar_tys(def_id, tcx).count()
1032+
field_count: substs.upvar_tys(def_id, tcx).count(),
10291033
}),
10301034
}
1031-
},
1035+
}
10321036
AggregateKind::Generator(def_id, substs, _) => {
10331037
if let Some(ty) = substs.upvar_tys(def_id, tcx).nth(field) {
10341038
return Ok(ty);
@@ -1037,22 +1041,24 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
10371041
return match substs.field_tys(def_id, tcx).nth(field) {
10381042
Some(ty) => Ok(ty),
10391043
None => Err(FieldAccessError::OutOfRange {
1040-
field_count: substs.field_tys(def_id, tcx).count() + 1
1044+
field_count: substs.field_tys(def_id, tcx).count() + 1,
10411045
}),
1042-
}
1043-
},
1046+
};
1047+
}
10441048
AggregateKind::Array(ty) => {
10451049
return Ok(ty);
1046-
},
1050+
}
10471051
AggregateKind::Tuple => {
10481052
unreachable!("This should have been covered in check_rvalues");
1049-
},
1053+
}
10501054
};
10511055

10521056
if let Some(field) = variant.fields.get(field) {
10531057
Ok(self.normalize(&field.ty(tcx, substs), location))
10541058
} else {
1055-
Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() })
1059+
Err(FieldAccessError::OutOfRange {
1060+
field_count: variant.fields.len(),
1061+
})
10561062
}
10571063
}
10581064

@@ -1062,7 +1068,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
10621068
Rvalue::Aggregate(ak, ops) => {
10631069
match **ak {
10641070
// tuple rvalue field type is always the type of the op. Nothing to check here.
1065-
AggregateKind::Tuple => { },
1071+
AggregateKind::Tuple => {}
10661072
_ => {
10671073
for (i, op) in ops.iter().enumerate() {
10681074
let field_ty = match self.aggregate_field_ty(ak, i, location) {
@@ -1073,27 +1079,36 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
10731079
rv,
10741080
"accessed field #{} but variant only has {}",
10751081
i,
1076-
field_count);
1082+
field_count
1083+
);
10771084
continue;
1078-
},
1085+
}
10791086
};
10801087
let op_ty = match op {
1081-
Operand::Consume(lv) => lv.ty(mir, tcx).to_ty(tcx),
1088+
Operand::Consume(lv) => {
1089+
self.normalize(&lv.ty(mir, tcx), location).to_ty(tcx)
1090+
}
10821091
Operand::Constant(c) => c.ty,
10831092
};
1084-
if let Err(terr) = self.sub_types(op_ty, field_ty, location.at_successor_within_block()) {
1085-
span_mirbug!(
1093+
if let Err(terr) = self.sub_types(
1094+
op_ty,
1095+
field_ty,
1096+
location.at_successor_within_block(),
1097+
)
1098+
{
1099+
span_mirbug!(
10861100
self,
10871101
rv,
10881102
"{:?} is not a subtype of {:?}: {:?}",
10891103
op_ty,
10901104
field_ty,
1091-
terr);
1092-
}
1105+
terr
1106+
);
1107+
}
10931108
}
1094-
},
1109+
}
10951110
}
1096-
},
1111+
}
10971112
// FIXME: These other cases have to be implemented in future PRs
10981113
Rvalue::Use(..) |
10991114
Rvalue::Repeat(..) |
@@ -1104,7 +1119,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
11041119
Rvalue::CheckedBinaryOp(..) |
11051120
Rvalue::UnaryOp(..) |
11061121
Rvalue::Discriminant(..) |
1107-
Rvalue::NullaryOp(..) => { }
1122+
Rvalue::NullaryOp(..) => {}
11081123
}
11091124
}
11101125

0 commit comments

Comments
 (0)