Skip to content

Commit 8635548

Browse files
spastorinonikomatsakis
authored andcommitted
Restructure a bit check_aggregate_rvalue code
1 parent 4449240 commit 8635548

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

src/librustc_mir/transform/type_check.rs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,41 +1210,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
12101210

12111211
self.prove_aggregate_predicates(aggregate_kind, location);
12121212

1213-
match aggregate_kind {
1213+
if *aggregate_kind == AggregateKind::Tuple {
12141214
// tuple rvalue field type is always the type of the op. Nothing to check here.
1215-
AggregateKind::Tuple => return,
1216-
1217-
// For closures, we have some **extra requirements** we
1218-
// have to check. In particular, in their upvars and
1219-
// signatures, closures often reference various regions
1220-
// from the surrounding function -- we call those the
1221-
// closure's free regions. When we borrow-check (and hence
1222-
// region-check) closures, we may find that the closure
1223-
// requires certain relationships between those free
1224-
// regions. However, because those free regions refer to
1225-
// portions of the CFG of their caller, the closure is not
1226-
// in a position to verify those relationships. In that
1227-
// case, the requirements get "propagated" to us, and so
1228-
// we have to solve them here where we instantiate the
1229-
// closure.
1230-
//
1231-
// Despite the opacity of the previous parapgrah, this is
1232-
// actually relatively easy to understand in terms of the
1233-
// desugaring. A closure gets desugared to a struct, and
1234-
// these extra requirements are basically like where
1235-
// clauses on the struct.
1236-
AggregateKind::Closure(def_id, substs) => {
1237-
if let Some(closure_region_requirements) = tcx.mir_borrowck(*def_id) {
1238-
closure_region_requirements.apply_requirements(
1239-
self.infcx,
1240-
location,
1241-
*def_id,
1242-
*substs,
1243-
);
1244-
}
1245-
}
1246-
1247-
_ => {}
1215+
return;
12481216
}
12491217

12501218
for (i, operand) in operands.iter().enumerate() {
@@ -1295,7 +1263,39 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
12951263
tcx.predicates_of(def.did).instantiate(tcx, substs)
12961264
}
12971265

1298-
AggregateKind::Closure(def_id, substs) |
1266+
// For closures, we have some **extra requirements** we
1267+
//
1268+
// have to check. In particular, in their upvars and
1269+
// signatures, closures often reference various regions
1270+
// from the surrounding function -- we call those the
1271+
// closure's free regions. When we borrow-check (and hence
1272+
// region-check) closures, we may find that the closure
1273+
// requires certain relationships between those free
1274+
// regions. However, because those free regions refer to
1275+
// portions of the CFG of their caller, the closure is not
1276+
// in a position to verify those relationships. In that
1277+
// case, the requirements get "propagated" to us, and so
1278+
// we have to solve them here where we instantiate the
1279+
// closure.
1280+
//
1281+
// Despite the opacity of the previous parapgrah, this is
1282+
// actually relatively easy to understand in terms of the
1283+
// desugaring. A closure gets desugared to a struct, and
1284+
// these extra requirements are basically like where
1285+
// clauses on the struct.
1286+
AggregateKind::Closure(def_id, substs) => {
1287+
if let Some(closure_region_requirements) = tcx.mir_borrowck(*def_id) {
1288+
closure_region_requirements.apply_requirements(
1289+
self.infcx,
1290+
location,
1291+
*def_id,
1292+
*substs,
1293+
);
1294+
}
1295+
1296+
tcx.predicates_of(*def_id).instantiate(tcx, substs.substs)
1297+
}
1298+
12991299
AggregateKind::Generator(def_id, substs, _) => {
13001300
tcx.predicates_of(*def_id).instantiate(tcx, substs.substs)
13011301
}

0 commit comments

Comments
 (0)