Skip to content

Commit a9046ed

Browse files
committed
---
yaml --- r: 195554 b: refs/heads/master c: 4b0edb9 h: refs/heads/master v: v3
1 parent ff80890 commit a9046ed

File tree

14 files changed

+82
-96
lines changed

14 files changed

+82
-96
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 0939837867e77f478dcd3735f3a6ce8823f5fd48
2+
refs/heads/master: 4b0edb96d080fadccc542dad50e6576c8e11bd85
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: b3317d68910900f135f9f38e43a7a699bc736b4a
55
refs/heads/try: 961e0358e1a5c0faaef606e31e9965742c1643bf

trunk/src/librustc/middle/infer/higher_ranked/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C
6060

6161
// Start a snapshot so we can examine "all bindings that were
6262
// created as part of this type comparison".
63-
return self.infcx().try(|snapshot| {
63+
return self.infcx().commit_if_ok(|snapshot| {
6464
// First, we instantiate each bound region in the subtype with a fresh
6565
// region variable.
6666
let (a_prime, _) =
@@ -109,7 +109,7 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C
109109
{
110110
// Start a snapshot so we can examine "all bindings that were
111111
// created as part of this type comparison".
112-
return self.infcx().try(|snapshot| {
112+
return self.infcx().commit_if_ok(|snapshot| {
113113
// Instantiate each bound region with a fresh region variable.
114114
let span = self.trace().origin.span();
115115
let (a_with_fresh, a_map) =
@@ -202,7 +202,7 @@ impl<'tcx,C> HigherRankedRelations<'tcx> for C
202202

203203
// Make a snapshot so we can examine "all bindings that were
204204
// created as part of this type comparison".
205-
return self.infcx().try(|snapshot| {
205+
return self.infcx().commit_if_ok(|snapshot| {
206206
// Instantiate each bound region with a fresh region variable.
207207
let (a_with_fresh, a_map) =
208208
self.infcx().replace_late_bound_regions_with_fresh_var(

trunk/src/librustc/middle/infer/mod.rs

Lines changed: 37 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ pub enum LateBoundRegionConversionTime {
265265
///
266266
/// See `error_reporting.rs` for more details
267267
#[derive(Clone, Debug)]
268-
pub enum RegionVariableOrigin<'tcx> {
268+
pub enum RegionVariableOrigin {
269269
// Region variables created for ill-categorized reasons,
270270
// mostly indicates places in need of refactoring
271271
MiscVariable(Span),
@@ -280,7 +280,7 @@ pub enum RegionVariableOrigin<'tcx> {
280280
Autoref(Span),
281281

282282
// Regions created as part of an automatic coercion
283-
Coercion(TypeTrace<'tcx>),
283+
Coercion(Span),
284284

285285
// Region variables created as the values for early-bound regions
286286
EarlyBoundRegion(Span, ast::Name),
@@ -343,8 +343,7 @@ pub fn common_supertype<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
343343
values: Types(expected_found(a_is_expected, a, b))
344344
};
345345

346-
let result =
347-
cx.commit_if_ok(|| cx.lub(a_is_expected, trace.clone()).tys(a, b));
346+
let result = cx.commit_if_ok(|_| cx.lub(a_is_expected, trace.clone()).tys(a, b));
348347
match result {
349348
Ok(t) => t,
350349
Err(ref err) => {
@@ -362,9 +361,7 @@ pub fn mk_subty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
362361
-> UnitResult<'tcx>
363362
{
364363
debug!("mk_subty({} <: {})", a.repr(cx.tcx), b.repr(cx.tcx));
365-
cx.commit_if_ok(|| {
366-
cx.sub_types(a_is_expected, origin, a, b)
367-
})
364+
cx.sub_types(a_is_expected, origin, a, b)
368365
}
369366

370367
pub fn can_mk_subty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
@@ -404,8 +401,7 @@ pub fn mk_eqty<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
404401
-> UnitResult<'tcx>
405402
{
406403
debug!("mk_eqty({} <: {})", a.repr(cx.tcx), b.repr(cx.tcx));
407-
cx.commit_if_ok(
408-
|| cx.eq_types(a_is_expected, origin, a, b))
404+
cx.commit_if_ok(|_| cx.eq_types(a_is_expected, origin, a, b))
409405
}
410406

411407
pub fn mk_sub_poly_trait_refs<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
@@ -417,8 +413,7 @@ pub fn mk_sub_poly_trait_refs<'a, 'tcx>(cx: &InferCtxt<'a, 'tcx>,
417413
{
418414
debug!("mk_sub_trait_refs({} <: {})",
419415
a.repr(cx.tcx), b.repr(cx.tcx));
420-
cx.commit_if_ok(
421-
|| cx.sub_poly_trait_refs(a_is_expected, origin, a.clone(), b.clone()))
416+
cx.commit_if_ok(|_| cx.sub_poly_trait_refs(a_is_expected, origin, a.clone(), b.clone()))
422417
}
423418

424419
fn expected_found<T>(a_is_expected: bool,
@@ -476,25 +471,25 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
476471
}
477472
}
478473

479-
pub fn combine_fields<'b>(&'b self, a_is_expected: bool, trace: TypeTrace<'tcx>)
480-
-> CombineFields<'b, 'tcx> {
474+
fn combine_fields<'b>(&'b self, a_is_expected: bool, trace: TypeTrace<'tcx>)
475+
-> CombineFields<'b, 'tcx> {
481476
CombineFields {infcx: self,
482477
a_is_expected: a_is_expected,
483478
trace: trace}
484479
}
485480

486-
pub fn equate<'b>(&'b self, a_is_expected: bool, trace: TypeTrace<'tcx>)
487-
-> Equate<'b, 'tcx> {
481+
fn equate<'b>(&'b self, a_is_expected: bool, trace: TypeTrace<'tcx>)
482+
-> Equate<'b, 'tcx> {
488483
Equate(self.combine_fields(a_is_expected, trace))
489484
}
490485

491-
pub fn sub<'b>(&'b self, a_is_expected: bool, trace: TypeTrace<'tcx>)
492-
-> Sub<'b, 'tcx> {
486+
fn sub<'b>(&'b self, a_is_expected: bool, trace: TypeTrace<'tcx>)
487+
-> Sub<'b, 'tcx> {
493488
Sub(self.combine_fields(a_is_expected, trace))
494489
}
495490

496-
pub fn lub<'b>(&'b self, a_is_expected: bool, trace: TypeTrace<'tcx>)
497-
-> Lub<'b, 'tcx> {
491+
fn lub<'b>(&'b self, a_is_expected: bool, trace: TypeTrace<'tcx>)
492+
-> Lub<'b, 'tcx> {
498493
Lub(self.combine_fields(a_is_expected, trace))
499494
}
500495

@@ -558,11 +553,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
558553
r
559554
}
560555

561-
/// Execute `f` and commit the bindings if successful
556+
/// Execute `f` and commit the bindings if closure `f` returns `Ok(_)`
562557
pub fn commit_if_ok<T, E, F>(&self, f: F) -> Result<T, E> where
563-
F: FnOnce() -> Result<T, E>
558+
F: FnOnce(&CombinedSnapshot) -> Result<T, E>
564559
{
565-
self.commit_unconditionally(move || self.try(move |_| f()))
560+
debug!("commit_if_ok()");
561+
let snapshot = self.start_snapshot();
562+
let r = f(&snapshot);
563+
debug!("commit_if_ok() -- r.is_ok() = {}", r.is_ok());
564+
match r {
565+
Ok(_) => { self.commit_from(snapshot); }
566+
Err(_) => { self.rollback_to(snapshot); }
567+
}
568+
r
566569
}
567570

568571
/// Execute `f` and commit only the region bindings if successful.
@@ -577,7 +580,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
577580
float_snapshot,
578581
region_vars_snapshot } = self.start_snapshot();
579582

580-
let r = self.try(move |_| f());
583+
let r = self.commit_if_ok(|_| f());
581584

582585
// Roll back any non-region bindings - they should be resolved
583586
// inside `f`, with, e.g. `resolve_type_vars_if_possible`.
@@ -598,25 +601,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
598601
r
599602
}
600603

601-
/// Execute `f`, unroll bindings on panic
602-
pub fn try<T, E, F>(&self, f: F) -> Result<T, E> where
603-
F: FnOnce(&CombinedSnapshot) -> Result<T, E>
604-
{
605-
debug!("try()");
606-
let snapshot = self.start_snapshot();
607-
let r = f(&snapshot);
608-
debug!("try() -- r.is_ok() = {}", r.is_ok());
609-
match r {
610-
Ok(_) => {
611-
self.commit_from(snapshot);
612-
}
613-
Err(_) => {
614-
self.rollback_to(snapshot);
615-
}
616-
}
617-
r
618-
}
619-
620604
/// Execute `f` then unroll any bindings it creates
621605
pub fn probe<R, F>(&self, f: F) -> R where
622606
F: FnOnce(&CombinedSnapshot) -> R,
@@ -643,7 +627,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
643627
-> UnitResult<'tcx>
644628
{
645629
debug!("sub_types({} <: {})", a.repr(self.tcx), b.repr(self.tcx));
646-
self.commit_if_ok(|| {
630+
self.commit_if_ok(|_| {
647631
let trace = TypeTrace::types(origin, a_is_expected, a, b);
648632
self.sub(a_is_expected, trace).tys(a, b).map(|_| ())
649633
})
@@ -656,7 +640,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
656640
b: Ty<'tcx>)
657641
-> UnitResult<'tcx>
658642
{
659-
self.commit_if_ok(|| {
643+
self.commit_if_ok(|_| {
660644
let trace = TypeTrace::types(origin, a_is_expected, a, b);
661645
self.equate(a_is_expected, trace).tys(a, b).map(|_| ())
662646
})
@@ -672,7 +656,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
672656
debug!("sub_trait_refs({} <: {})",
673657
a.repr(self.tcx),
674658
b.repr(self.tcx));
675-
self.commit_if_ok(|| {
659+
self.commit_if_ok(|_| {
676660
let trace = TypeTrace {
677661
origin: origin,
678662
values: TraitRefs(expected_found(a_is_expected, a.clone(), b.clone()))
@@ -691,7 +675,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
691675
debug!("sub_poly_trait_refs({} <: {})",
692676
a.repr(self.tcx),
693677
b.repr(self.tcx));
694-
self.commit_if_ok(|| {
678+
self.commit_if_ok(|_| {
695679
let trace = TypeTrace {
696680
origin: origin,
697681
values: PolyTraitRefs(expected_found(a_is_expected, a.clone(), b.clone()))
@@ -749,7 +733,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
749733
span: Span,
750734
predicate: &ty::PolyEquatePredicate<'tcx>)
751735
-> UnitResult<'tcx> {
752-
self.try(|snapshot| {
736+
self.commit_if_ok(|snapshot| {
753737
let (ty::EquatePredicate(a, b), skol_map) =
754738
self.skolemize_late_bound_regions(predicate, snapshot);
755739
let origin = EquatePredicate(span);
@@ -762,7 +746,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
762746
span: Span,
763747
predicate: &ty::PolyRegionOutlivesPredicate)
764748
-> UnitResult<'tcx> {
765-
self.try(|snapshot| {
749+
self.commit_if_ok(|snapshot| {
766750
let (ty::OutlivesPredicate(r_a, r_b), skol_map) =
767751
self.skolemize_late_bound_regions(predicate, snapshot);
768752
let origin = RelateRegionParamBound(span);
@@ -801,7 +785,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
801785
.new_key(None)
802786
}
803787

804-
pub fn next_region_var(&self, origin: RegionVariableOrigin<'tcx>) -> ty::Region {
788+
pub fn next_region_var(&self, origin: RegionVariableOrigin) -> ty::Region {
805789
ty::ReInfer(ty::ReVar(self.region_vars.new_region_var(origin)))
806790
}
807791

@@ -1253,14 +1237,14 @@ impl<'tcx> Repr<'tcx> for SubregionOrigin<'tcx> {
12531237
}
12541238
}
12551239

1256-
impl<'tcx> RegionVariableOrigin<'tcx> {
1240+
impl RegionVariableOrigin {
12571241
pub fn span(&self) -> Span {
12581242
match *self {
12591243
MiscVariable(a) => a,
12601244
PatternRegion(a) => a,
12611245
AddrOfRegion(a) => a,
12621246
Autoref(a) => a,
1263-
Coercion(ref a) => a.span(),
1247+
Coercion(a) => a,
12641248
EarlyBoundRegion(a, _) => a,
12651249
LateBoundRegion(a, _, _) => a,
12661250
BoundRegionInCoherence(_) => codemap::DUMMY_SP,
@@ -1269,7 +1253,7 @@ impl<'tcx> RegionVariableOrigin<'tcx> {
12691253
}
12701254
}
12711255

1272-
impl<'tcx> Repr<'tcx> for RegionVariableOrigin<'tcx> {
1256+
impl<'tcx> Repr<'tcx> for RegionVariableOrigin {
12731257
fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
12741258
match *self {
12751259
MiscVariable(a) => {
@@ -1282,7 +1266,7 @@ impl<'tcx> Repr<'tcx> for RegionVariableOrigin<'tcx> {
12821266
format!("AddrOfRegion({})", a.repr(tcx))
12831267
}
12841268
Autoref(a) => format!("Autoref({})", a.repr(tcx)),
1285-
Coercion(ref a) => format!("Coercion({})", a.repr(tcx)),
1269+
Coercion(a) => format!("Coercion({})", a.repr(tcx)),
12861270
EarlyBoundRegion(a, b) => {
12871271
format!("EarlyBoundRegion({},{})", a.repr(tcx), b.repr(tcx))
12881272
}

trunk/src/librustc/middle/infer/region_inference/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub enum RegionResolutionError<'tcx> {
115115
/// Could not infer a value for `v` because `sub_r <= v` (due to
116116
/// `sub_origin`) but `v <= sup_r` (due to `sup_origin`) and
117117
/// `sub_r <= sup_r` does not hold.
118-
SubSupConflict(RegionVariableOrigin<'tcx>,
118+
SubSupConflict(RegionVariableOrigin,
119119
SubregionOrigin<'tcx>, Region,
120120
SubregionOrigin<'tcx>, Region),
121121

@@ -124,15 +124,15 @@ pub enum RegionResolutionError<'tcx> {
124124
/// Could not infer a value for `v` because `v <= r1` (due to
125125
/// `origin1`) and `v <= r2` (due to `origin2`) and
126126
/// `r1` and `r2` have no intersection.
127-
SupSupConflict(RegionVariableOrigin<'tcx>,
127+
SupSupConflict(RegionVariableOrigin,
128128
SubregionOrigin<'tcx>, Region,
129129
SubregionOrigin<'tcx>, Region),
130130

131131
/// For subsets of `ConcreteFailure` and `SubSupConflict`, we can derive
132132
/// more specific errors message by suggesting to the user where they
133133
/// should put a lifetime. In those cases we process and put those errors
134134
/// into `ProcessedErrors` before we do any reporting.
135-
ProcessedErrors(Vec<RegionVariableOrigin<'tcx>>,
135+
ProcessedErrors(Vec<RegionVariableOrigin>,
136136
Vec<(TypeTrace<'tcx>, ty::type_err<'tcx>)>,
137137
Vec<SameRegions>),
138138
}
@@ -168,7 +168,7 @@ pub type CombineMap = FnvHashMap<TwoRegions, RegionVid>;
168168

169169
pub struct RegionVarBindings<'a, 'tcx: 'a> {
170170
tcx: &'a ty::ctxt<'tcx>,
171-
var_origins: RefCell<Vec<RegionVariableOrigin<'tcx>>>,
171+
var_origins: RefCell<Vec<RegionVariableOrigin>>,
172172

173173
// Constraints of the form `A <= B` introduced by the region
174174
// checker. Here at least one of `A` and `B` must be a region
@@ -316,7 +316,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
316316
len as u32
317317
}
318318

319-
pub fn new_region_var(&self, origin: RegionVariableOrigin<'tcx>) -> RegionVid {
319+
pub fn new_region_var(&self, origin: RegionVariableOrigin) -> RegionVid {
320320
let id = self.num_vars();
321321
self.var_origins.borrow_mut().push(origin.clone());
322322
let vid = RegionVid { index: id };

trunk/src/librustc/middle/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn poly_project_and_unify_type<'cx,'tcx>(
8181
obligation.repr(selcx.tcx()));
8282

8383
let infcx = selcx.infcx();
84-
infcx.try(|snapshot| {
84+
infcx.commit_if_ok(|snapshot| {
8585
let (skol_predicate, skol_map) =
8686
infcx.skolemize_late_bound_regions(&obligation.predicate, snapshot);
8787

trunk/src/librustc/middle/traits/select.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12421242
return;
12431243
}
12441244

1245-
self.infcx.try(|snapshot| {
1245+
self.infcx.commit_if_ok(|snapshot| {
12461246
let bound_self_ty =
12471247
self.infcx.resolve_type_vars_if_possible(&obligation.self_ty());
12481248
let (self_ty, _) =
@@ -1778,7 +1778,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17781778

17791779
// For each type, produce a vector of resulting obligations
17801780
let obligations: Result<Vec<Vec<_>>, _> = bound_types.iter().map(|nested_ty| {
1781-
self.infcx.try(|snapshot| {
1781+
self.infcx.commit_if_ok(|snapshot| {
17821782
let (skol_ty, skol_map) =
17831783
self.infcx().skolemize_late_bound_regions(nested_ty, snapshot);
17841784
let Normalized { value: normalized_ty, mut obligations } =
@@ -1888,7 +1888,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18881888
obligation: &TraitObligation<'tcx>)
18891889
{
18901890
let _: Result<(),()> =
1891-
self.infcx.try(|snapshot| {
1891+
self.infcx.commit_if_ok(|snapshot| {
18921892
let result =
18931893
self.match_projection_obligation_against_bounds_from_trait(obligation,
18941894
snapshot);
@@ -2043,7 +2043,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
20432043
trait_def_id,
20442044
nested);
20452045

2046-
let trait_obligations: Result<VecPerParamSpace<_>,()> = self.infcx.try(|snapshot| {
2046+
let trait_obligations: Result<VecPerParamSpace<_>,()> = self.infcx.commit_if_ok(|snapshot| {
20472047
let poly_trait_ref = obligation.predicate.to_poly_trait_ref();
20482048
let (trait_ref, skol_map) =
20492049
self.infcx().skolemize_late_bound_regions(&poly_trait_ref, snapshot);
@@ -2077,7 +2077,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
20772077

20782078
// First, create the substitutions by matching the impl again,
20792079
// this time not in a probe.
2080-
self.infcx.try(|snapshot| {
2080+
self.infcx.commit_if_ok(|snapshot| {
20812081
let (skol_obligation_trait_ref, skol_map) =
20822082
self.infcx().skolemize_late_bound_regions(&obligation.predicate, snapshot);
20832083
let substs =

0 commit comments

Comments
 (0)