Skip to content

Commit 672e071

Browse files
committed
change RegionObligation to store a SubregionOrigin
1 parent 1830c9e commit 672e071

File tree

4 files changed

+57
-50
lines changed

4 files changed

+57
-50
lines changed

src/librustc/infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ pub enum FixupError {
418418
pub struct RegionObligation<'tcx> {
419419
pub sub_region: ty::Region<'tcx>,
420420
pub sup_type: Ty<'tcx>,
421-
pub cause: ObligationCause<'tcx>,
421+
pub origin: SubregionOrigin<'tcx>,
422422
}
423423

424424
impl fmt::Display for FixupError {

src/librustc/infer/outlives/obligations.rs

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@
7272
use hir::def_id::DefId;
7373
use infer::{self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, VerifyBound};
7474
use syntax::ast;
75-
use traits;
75+
use traits::{self, ObligationCause};
7676
use ty::outlives::Component;
7777
use ty::subst::{Subst, Substs};
78-
use ty::{self, Ty, TyCtxt, TypeFoldable};
78+
use ty::{self, Region, Ty, TyCtxt, TypeFoldable};
7979

8080
impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
8181
/// Registers that the given region obligation must be resolved
@@ -98,6 +98,26 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
9898
.push((body_id, obligation));
9999
}
100100

101+
pub fn register_region_obligation_with_cause(
102+
&self,
103+
sup_type: Ty<'tcx>,
104+
sub_region: Region<'tcx>,
105+
cause: &ObligationCause<'tcx>,
106+
) {
107+
let origin = SubregionOrigin::from_obligation_cause(cause, || {
108+
infer::RelateParamBound(cause.span, sup_type)
109+
});
110+
111+
self.register_region_obligation(
112+
cause.body_id,
113+
RegionObligation {
114+
sup_type,
115+
sub_region,
116+
origin,
117+
},
118+
);
119+
}
120+
101121
/// Trait queries just want to pass back type obligations "as is"
102122
pub fn take_registered_region_obligations(&self) -> Vec<(ast::NodeId, RegionObligation<'tcx>)> {
103123
::std::mem::replace(&mut *self.region_obligations.borrow_mut(), vec![])
@@ -154,10 +174,9 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
154174
let mut my_region_obligations = Vec::with_capacity(self.region_obligations.borrow().len());
155175
{
156176
let mut r_o = self.region_obligations.borrow_mut();
157-
my_region_obligations.extend(
158-
r_o.drain_filter(|(ro_body_id, _)| *ro_body_id == body_id)
159-
.map(|(_, obligation)| obligation)
160-
);
177+
my_region_obligations.extend(r_o.drain_filter(|(ro_body_id, _)| {
178+
*ro_body_id == body_id
179+
}).map(|(_, obligation)| obligation));
161180
}
162181

163182
let outlives = &mut TypeOutlives::new(
@@ -171,18 +190,14 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
171190
for RegionObligation {
172191
sup_type,
173192
sub_region,
174-
cause,
193+
origin,
175194
} in my_region_obligations
176195
{
177196
debug!(
178-
"process_registered_region_obligations: sup_type={:?} sub_region={:?} cause={:?}",
179-
sup_type, sub_region, cause
197+
"process_registered_region_obligations: sup_type={:?} sub_region={:?} origin={:?}",
198+
sup_type, sub_region, origin
180199
);
181200

182-
let origin = SubregionOrigin::from_obligation_cause(&cause, || {
183-
infer::RelateParamBound(cause.span, sup_type)
184-
});
185-
186201
let sup_type = self.resolve_type_vars_if_possible(&sup_type);
187202
outlives.type_must_outlive(origin, sup_type, sub_region);
188203
}
@@ -302,7 +317,8 @@ where
302317
let origin = origin.clone();
303318
match component {
304319
Component::Region(region1) => {
305-
self.delegate.push_sub_region_constraint(origin, region, region1);
320+
self.delegate
321+
.push_sub_region_constraint(origin, region, region1);
306322
}
307323
Component::Param(param_ty) => {
308324
self.param_ty_must_outlive(origin, region, param_ty);
@@ -405,7 +421,8 @@ where
405421
}
406422

407423
for r in projection_ty.substs.regions() {
408-
self.delegate.push_sub_region_constraint(origin.clone(), region, r);
424+
self.delegate
425+
.push_sub_region_constraint(origin.clone(), region, r);
409426
}
410427

411428
return;
@@ -497,16 +514,17 @@ where
497514
);
498515

499516
// see the extensive comment in projection_must_outlive
500-
let ty = self
501-
.tcx
517+
let ty = self.tcx
502518
.mk_projection(projection_ty.item_def_id, projection_ty.substs);
503519
let recursive_bound = self.recursive_type_bound(ty);
504520

505521
VerifyBound::AnyRegion(declared_bounds).or(recursive_bound)
506522
}
507523

508524
fn recursive_type_bound(&self, ty: Ty<'tcx>) -> VerifyBound<'tcx> {
509-
let mut bounds = ty.walk_shallow().map(|subty| self.type_bound(subty)).collect::<Vec<_>>();
525+
let mut bounds = ty.walk_shallow()
526+
.map(|subty| self.type_bound(subty))
527+
.collect::<Vec<_>>();
510528

511529
let mut regions = ty.regions();
512530
regions.retain(|r| !r.is_late_bound()); // ignore late-bound regions
@@ -674,4 +692,3 @@ impl<'cx, 'gcx, 'tcx> TypeOutlivesDelegate<'tcx> for &'cx InferCtxt<'cx, 'gcx, '
674692
self.verify_generic_bound(origin, kind, a, bound)
675693
}
676694
}
677-

src/librustc/traits/auto_trait.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::collections::VecDeque;
1919
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2020

2121
use infer::region_constraints::{Constraint, RegionConstraintData};
22-
use infer::{InferCtxt, RegionObligation};
22+
use infer::InferCtxt;
2323

2424
use ty::fold::TypeFolder;
2525
use ty::{Region, RegionVid};
@@ -693,23 +693,17 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
693693
binder.map_bound_ref(|pred| pred.0).no_late_bound_regions(),
694694
) {
695695
(None, Some(t_a)) => {
696-
select.infcx().register_region_obligation(
697-
ast::DUMMY_NODE_ID,
698-
RegionObligation {
699-
sup_type: t_a,
700-
sub_region: select.infcx().tcx.types.re_static,
701-
cause: dummy_cause.clone(),
702-
},
696+
select.infcx().register_region_obligation_with_cause(
697+
t_a,
698+
select.infcx().tcx.types.re_static,
699+
&dummy_cause,
703700
);
704701
}
705702
(Some(ty::OutlivesPredicate(t_a, r_b)), _) => {
706-
select.infcx().register_region_obligation(
707-
ast::DUMMY_NODE_ID,
708-
RegionObligation {
709-
sup_type: t_a,
710-
sub_region: r_b,
711-
cause: dummy_cause.clone(),
712-
},
703+
select.infcx().register_region_obligation_with_cause(
704+
t_a,
705+
r_b,
706+
&dummy_cause,
713707
);
714708
}
715709
_ => {}

src/librustc/traits/fulfill.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use infer::{RegionObligation, InferCtxt};
11+
use infer::InferCtxt;
1212
use mir::interpret::GlobalId;
1313
use ty::{self, Ty, TypeFoldable, ToPolyTraitRef, ToPredicate};
1414
use ty::error::ExpectedFound;
@@ -372,13 +372,11 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
372372
Some(t_a) => {
373373
let r_static = self.selcx.tcx().types.re_static;
374374
if self.register_region_obligations {
375-
self.selcx.infcx().register_region_obligation(
376-
obligation.cause.body_id,
377-
RegionObligation {
378-
sup_type: t_a,
379-
sub_region: r_static,
380-
cause: obligation.cause.clone(),
381-
});
375+
self.selcx.infcx().register_region_obligation_with_cause(
376+
t_a,
377+
r_static,
378+
&obligation.cause,
379+
);
382380
}
383381
ProcessResult::Changed(vec![])
384382
}
@@ -387,13 +385,11 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
387385
// If there aren't, register the obligation.
388386
Some(ty::OutlivesPredicate(t_a, r_b)) => {
389387
if self.register_region_obligations {
390-
self.selcx.infcx().register_region_obligation(
391-
obligation.cause.body_id,
392-
RegionObligation {
393-
sup_type: t_a,
394-
sub_region: r_b,
395-
cause: obligation.cause.clone()
396-
});
388+
self.selcx.infcx().register_region_obligation_with_cause(
389+
t_a,
390+
r_b,
391+
&obligation.cause,
392+
);
397393
}
398394
ProcessResult::Changed(vec![])
399395
}

0 commit comments

Comments
 (0)