Skip to content

Commit

Permalink
Restructure a bit check_aggregate_rvalue code
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino authored and nikomatsakis committed Dec 13, 2017
1 parent 4449240 commit 8635548
Showing 1 changed file with 35 additions and 35 deletions.
70 changes: 35 additions & 35 deletions src/librustc_mir/transform/type_check.rs
Expand Up @@ -1210,41 +1210,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {

self.prove_aggregate_predicates(aggregate_kind, location);

match aggregate_kind {
if *aggregate_kind == AggregateKind::Tuple {
// tuple rvalue field type is always the type of the op. Nothing to check here.
AggregateKind::Tuple => return,

// For closures, we have some **extra requirements** we
// have to check. In particular, in their upvars and
// signatures, closures often reference various regions
// from the surrounding function -- we call those the
// closure's free regions. When we borrow-check (and hence
// region-check) closures, we may find that the closure
// requires certain relationships between those free
// regions. However, because those free regions refer to
// portions of the CFG of their caller, the closure is not
// in a position to verify those relationships. In that
// case, the requirements get "propagated" to us, and so
// we have to solve them here where we instantiate the
// closure.
//
// Despite the opacity of the previous parapgrah, this is
// actually relatively easy to understand in terms of the
// desugaring. A closure gets desugared to a struct, and
// these extra requirements are basically like where
// clauses on the struct.
AggregateKind::Closure(def_id, substs) => {
if let Some(closure_region_requirements) = tcx.mir_borrowck(*def_id) {
closure_region_requirements.apply_requirements(
self.infcx,
location,
*def_id,
*substs,
);
}
}

_ => {}
return;
}

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

AggregateKind::Closure(def_id, substs) |
// For closures, we have some **extra requirements** we
//
// have to check. In particular, in their upvars and
// signatures, closures often reference various regions
// from the surrounding function -- we call those the
// closure's free regions. When we borrow-check (and hence
// region-check) closures, we may find that the closure
// requires certain relationships between those free
// regions. However, because those free regions refer to
// portions of the CFG of their caller, the closure is not
// in a position to verify those relationships. In that
// case, the requirements get "propagated" to us, and so
// we have to solve them here where we instantiate the
// closure.
//
// Despite the opacity of the previous parapgrah, this is
// actually relatively easy to understand in terms of the
// desugaring. A closure gets desugared to a struct, and
// these extra requirements are basically like where
// clauses on the struct.
AggregateKind::Closure(def_id, substs) => {
if let Some(closure_region_requirements) = tcx.mir_borrowck(*def_id) {
closure_region_requirements.apply_requirements(
self.infcx,
location,
*def_id,
*substs,
);
}

tcx.predicates_of(*def_id).instantiate(tcx, substs.substs)
}

AggregateKind::Generator(def_id, substs, _) => {
tcx.predicates_of(*def_id).instantiate(tcx, substs.substs)
}
Expand Down

0 comments on commit 8635548

Please sign in to comment.