Skip to content

Commit de6b3c2

Browse files
committed
Transition to the new object lifetime defaults, replacing the old
defaults completely.
1 parent 5708b1a commit de6b3c2

28 files changed

+97
-240
lines changed

src/librustc/metadata/tydecode.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -887,16 +887,9 @@ fn parse_existential_bounds_<'a,'tcx, F>(st: &mut PState<'a,'tcx>,
887887
}
888888
}
889889

890-
let region_bound_will_change = match next(st) {
891-
'y' => true,
892-
'n' => false,
893-
c => panic!("parse_ty: expected y/n not '{}'", c)
894-
};
895-
896890
return ty::ExistentialBounds { region_bound: region_bound,
897891
builtin_bounds: builtin_bounds,
898-
projection_bounds: projection_bounds,
899-
region_bound_will_change: region_bound_will_change };
892+
projection_bounds: projection_bounds };
900893
}
901894

902895
fn parse_builtin_bounds<F>(st: &mut PState, mut _conv: F) -> ty::BuiltinBounds where

src/librustc/metadata/tyencode.rs

-2
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,6 @@ pub fn enc_existential_bounds<'a,'tcx>(w: &mut Encoder,
390390
}
391391

392392
mywrite!(w, ".");
393-
394-
mywrite!(w, "{}", if bs.region_bound_will_change {'y'} else {'n'});
395393
}
396394

397395
pub fn enc_region_bounds<'a, 'tcx>(w: &mut Encoder,

src/librustc/middle/infer/bivariate.rs

-5
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Bivariate<'a, 'tcx> {
4949

5050
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
5151

52-
fn will_change(&mut self, _: bool, _: bool) -> bool {
53-
// since we are not comparing regions, we don't care
54-
false
55-
}
56-
5752
fn relate_with_variance<T:Relate<'a,'tcx>>(&mut self,
5853
variance: ty::Variance,
5954
a: &T,

src/librustc/middle/infer/equate.rs

-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ impl<'a, 'tcx> TypeRelation<'a,'tcx> for Equate<'a, 'tcx> {
3434

3535
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
3636

37-
fn will_change(&mut self, a: bool, b: bool) -> bool {
38-
// if either side changed from what it was, that could cause equality to fail
39-
a || b
40-
}
41-
4237
fn relate_with_variance<T:Relate<'a,'tcx>>(&mut self,
4338
_: ty::Variance,
4439
a: &T,

src/librustc/middle/infer/error_reporting.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
593593
sub: Region,
594594
sup: Region) {
595595
match origin {
596-
infer::Subtype(trace) |
597-
infer::DefaultExistentialBound(trace) => {
596+
infer::Subtype(trace) => {
598597
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
599598
self.report_and_explain_type_error(trace, &terr);
600599
}
@@ -1570,8 +1569,7 @@ impl<'a, 'tcx> ErrorReportingHelpers<'tcx> for InferCtxt<'a, 'tcx> {
15701569

15711570
fn note_region_origin(&self, origin: &SubregionOrigin<'tcx>) {
15721571
match *origin {
1573-
infer::Subtype(ref trace) |
1574-
infer::DefaultExistentialBound(ref trace) => {
1572+
infer::Subtype(ref trace) => {
15751573
let desc = match trace.origin {
15761574
infer::Misc(_) => {
15771575
"types are compatible"

src/librustc/middle/infer/glb.rs

-10
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,6 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Glb<'a, 'tcx> {
3535

3636
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
3737

38-
fn will_change(&mut self, a: bool, b: bool) -> bool {
39-
// Hmm, so the result of GLB will still be a LB if one or both
40-
// sides change to 'static, but it may no longer be the GLB.
41-
// I'm going to go with `a || b` here to be conservative,
42-
// since the result of this operation may be affected, though
43-
// I think it would mostly be more accepting than before (since the result
44-
// would be a bigger region).
45-
a || b
46-
}
47-
4838
fn relate_with_variance<T:Relate<'a,'tcx>>(&mut self,
4939
variance: ty::Variance,
5040
a: &T,

src/librustc/middle/infer/lub.rs

-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Lub<'a, 'tcx> {
3535

3636
fn a_is_expected(&self) -> bool { self.fields.a_is_expected }
3737

38-
fn will_change(&mut self, a: bool, b: bool) -> bool {
39-
// result will be 'static if a || b
40-
a || b
41-
}
42-
4338
fn relate_with_variance<T:Relate<'a,'tcx>>(&mut self,
4439
variance: ty::Variance,
4540
a: &T,

src/librustc/middle/infer/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,6 @@ pub enum SubregionOrigin<'tcx> {
191191
// Arose from a subtyping relation
192192
Subtype(TypeTrace<'tcx>),
193193

194-
// Arose from a subtyping relation
195-
DefaultExistentialBound(TypeTrace<'tcx>),
196-
197194
// Stack-allocated closures cannot outlive innermost loop
198195
// or function so as to ensure we only require finite stack
199196
InfStackClosure(Span),
@@ -1466,7 +1463,6 @@ impl<'tcx> SubregionOrigin<'tcx> {
14661463
pub fn span(&self) -> Span {
14671464
match *self {
14681465
Subtype(ref a) => a.span(),
1469-
DefaultExistentialBound(ref a) => a.span(),
14701466
InfStackClosure(a) => a,
14711467
InvokeClosure(a) => a,
14721468
DerefPointer(a) => a,

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

-47
Original file line numberDiff line numberDiff line change
@@ -1357,56 +1357,9 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
13571357
}
13581358
}
13591359

1360-
// Check for future hostile edges tied to a bad default
1361-
self.report_future_hostility(&graph);
1362-
13631360
(0..self.num_vars() as usize).map(|idx| var_data[idx].value).collect()
13641361
}
13651362

1366-
fn report_future_hostility(&self, graph: &RegionGraph) {
1367-
let constraints = self.constraints.borrow();
1368-
for edge in graph.all_edges() {
1369-
match constraints[&edge.data] {
1370-
SubregionOrigin::DefaultExistentialBound(_) => {
1371-
// this will become 'static in the future
1372-
}
1373-
_ => { continue; }
1374-
}
1375-
1376-
// this constraint will become a 'static constraint in the
1377-
// future, so walk outward and see if we have any hard
1378-
// bounds that could not be inferred to 'static
1379-
for nid in graph.depth_traverse(edge.target()) {
1380-
for (_, succ) in graph.outgoing_edges(nid) {
1381-
match succ.data {
1382-
ConstrainVarSubReg(_, r) => {
1383-
match r {
1384-
ty::ReStatic | ty::ReInfer(_) => {
1385-
/* OK */
1386-
}
1387-
ty::ReFree(_) | ty::ReScope(_) | ty::ReEmpty => {
1388-
span_warn!(
1389-
self.tcx.sess,
1390-
constraints[&edge.data].span(),
1391-
E0398,
1392-
"this code may fail to compile in Rust 1.3 due to \
1393-
the proposed change in object lifetime bound defaults");
1394-
return; // only issue the warning once per fn
1395-
}
1396-
ty::ReEarlyBound(..) | ty::ReLateBound(..) => {
1397-
self.tcx.sess.span_bug(
1398-
constraints[&succ.data].span(),
1399-
"relation to bound region");
1400-
}
1401-
}
1402-
}
1403-
_ => { }
1404-
}
1405-
}
1406-
}
1407-
}
1408-
}
1409-
14101363
fn construct_graph(&self) -> RegionGraph {
14111364
let num_vars = self.num_vars();
14121365

src/librustc/middle/infer/sub.rs

+4-14
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Sub<'a, 'tcx> {
4545
r
4646
}
4747

48-
fn will_change(&mut self, a: bool, b: bool) -> bool {
49-
// if we have (Foo+'a) <: (Foo+'b), this requires that 'a:'b.
50-
// So if 'a becomes 'static, no additional errors can occur.
51-
// OTOH, if 'a stays the same, but 'b becomes 'static, we
52-
// could have a problem.
53-
!a && b
54-
}
55-
5648
fn relate_with_variance<T:Relate<'a,'tcx>>(&mut self,
5749
variance: ty::Variance,
5850
a: &T,
@@ -106,12 +98,10 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Sub<'a, 'tcx> {
10698
fn regions(&mut self, a: ty::Region, b: ty::Region) -> RelateResult<'tcx, ty::Region> {
10799
debug!("{}.regions({:?}, {:?}) self.cause={:?}",
108100
self.tag(), a, b, self.fields.cause);
109-
let origin = match self.fields.cause {
110-
Some(Cause::ExistentialRegionBound(true)) =>
111-
SubregionOrigin::DefaultExistentialBound(self.fields.trace.clone()),
112-
_ =>
113-
SubregionOrigin::Subtype(self.fields.trace.clone()),
114-
};
101+
// FIXME -- we have more fine-grained information available
102+
// from the "cause" field, we could perhaps give more tailored
103+
// error messages.
104+
let origin = SubregionOrigin::Subtype(self.fields.trace.clone());
115105
self.fields.infcx.region_vars.make_subregion(origin, a, b);
116106
Ok(a)
117107
}

src/librustc/middle/traits/select.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2462,7 +2462,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
24622462
region_bound: data_b.bounds.region_bound,
24632463
builtin_bounds: data_b.bounds.builtin_bounds,
24642464
projection_bounds: data_a.bounds.projection_bounds.clone(),
2465-
region_bound_will_change: data_b.bounds.region_bound_will_change,
24662465
};
24672466

24682467
let new_trait = tcx.mk_trait(data_a.principal.clone(), bounds);

src/librustc/middle/ty.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1989,11 +1989,6 @@ pub struct ExistentialBounds<'tcx> {
19891989
pub region_bound: ty::Region,
19901990
pub builtin_bounds: BuiltinBounds,
19911991
pub projection_bounds: Vec<PolyProjectionPredicate<'tcx>>,
1992-
1993-
// If true, this TyTrait used a "default bound" in the surface
1994-
// syntax. This makes no difference to the type system but is
1995-
// handy for error reporting.
1996-
pub region_bound_will_change: bool,
19971992
}
19981993

19991994
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]

src/librustc/middle/ty_fold.rs

-1
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,6 @@ pub fn super_fold_existential_bounds<'tcx, T: TypeFolder<'tcx>>(
700700
region_bound: bounds.region_bound.fold_with(this),
701701
builtin_bounds: bounds.builtin_bounds,
702702
projection_bounds: bounds.projection_bounds.fold_with(this),
703-
region_bound_will_change: bounds.region_bound_will_change,
704703
}
705704
}
706705

src/librustc/middle/ty_match.rs

-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Match<'a, 'tcx> {
4242
fn tcx(&self) -> &'a ty::ctxt<'tcx> { self.tcx }
4343
fn a_is_expected(&self) -> bool { true } // irrelevant
4444

45-
fn will_change(&mut self, _: bool, _: bool) -> bool {
46-
// we're ignoring regions in this code
47-
false
48-
}
49-
5045
fn relate_with_variance<T:Relate<'a,'tcx>>(&mut self,
5146
_: ty::Variance,
5247
a: &T,

src/librustc/middle/ty_relate/mod.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub type RelateResult<'tcx, T> = Result<T, ty::TypeError<'tcx>>;
2424

2525
#[derive(Clone, Debug)]
2626
pub enum Cause {
27-
ExistentialRegionBound(bool), // if true, this is a default, else explicit
27+
ExistentialRegionBound, // relating an existential region bound
2828
}
2929

3030
pub trait TypeRelation<'a,'tcx> : Sized {
@@ -43,13 +43,6 @@ pub trait TypeRelation<'a,'tcx> : Sized {
4343
f(self)
4444
}
4545

46-
/// Hack for deciding whether the lifetime bound defaults change
47-
/// will be a breaking change or not. The bools indicate whether
48-
/// `a`/`b` have a default that will change to `'static`; the
49-
/// result is true if this will potentially affect the affect of
50-
/// relating `a` and `b`.
51-
fn will_change(&mut self, a: bool, b: bool) -> bool;
52-
5346
/// Generic relation routine suitable for most anything.
5447
fn relate<T:Relate<'a,'tcx>>(&mut self, a: &T, b: &T) -> RelateResult<'tcx, T> {
5548
Relate::relate(self, a, b)
@@ -384,21 +377,17 @@ impl<'a,'tcx:'a> Relate<'a,'tcx> for ty::ExistentialBounds<'tcx> {
384377
-> RelateResult<'tcx, ty::ExistentialBounds<'tcx>>
385378
where R: TypeRelation<'a,'tcx>
386379
{
387-
let will_change = relation.will_change(a.region_bound_will_change,
388-
b.region_bound_will_change);
389-
390380
let r =
391381
try!(relation.with_cause(
392-
Cause::ExistentialRegionBound(will_change),
382+
Cause::ExistentialRegionBound,
393383
|relation| relation.relate_with_variance(ty::Contravariant,
394384
&a.region_bound,
395385
&b.region_bound)));
396386
let nb = try!(relation.relate(&a.builtin_bounds, &b.builtin_bounds));
397387
let pb = try!(relation.relate(&a.projection_bounds, &b.projection_bounds));
398388
Ok(ty::ExistentialBounds { region_bound: r,
399389
builtin_bounds: nb,
400-
projection_bounds: pb,
401-
region_bound_will_change: will_change })
390+
projection_bounds: pb })
402391
}
403392
}
404393

src/librustc/util/ppaux.rs

-4
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,6 @@ impl<'tcx> fmt::Display for ty::TraitTy<'tcx> {
300300
try!(write!(f, " + {}", bound));
301301
}
302302

303-
if bounds.region_bound_will_change && verbose() {
304-
try!(write!(f, " [WILL-CHANGE]"));
305-
}
306-
307303
Ok(())
308304
}
309305
}

src/librustc_trans/trans/common.rs

-10
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,6 @@ pub fn erase_regions<'tcx,T>(cx: &ty::ctxt<'tcx>, value: &T) -> T
8282
return t_norm;
8383
}
8484

85-
fn fold_existential_bounds(&mut self, s: &ty::ExistentialBounds<'tcx>)
86-
-> ty::ExistentialBounds<'tcx> {
87-
let mut s = ty_fold::super_fold_existential_bounds(self, s);
88-
89-
// this annoying flag messes up trans normalization
90-
s.region_bound_will_change = false;
91-
92-
s
93-
}
94-
9585
fn fold_binder<T>(&mut self, t: &ty::Binder<T>) -> ty::Binder<T>
9686
where T : TypeFoldable<'tcx>
9787
{

src/librustc_typeck/astconv.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -2040,31 +2040,29 @@ pub fn conv_existential_bounds_from_partitioned_bounds<'tcx>(
20402040
principal_trait_ref,
20412041
builtin_bounds);
20422042

2043-
let (region_bound, will_change) = match region_bound {
2044-
Some(r) => (r, false),
2043+
let region_bound = match region_bound {
2044+
Some(r) => r,
20452045
None => {
20462046
match rscope.object_lifetime_default(span) {
2047-
Some(r) => (r, rscope.object_lifetime_default_will_change_in_1_3()),
2047+
Some(r) => r,
20482048
None => {
20492049
span_err!(this.tcx().sess, span, E0228,
20502050
"the lifetime bound for this object type cannot be deduced \
20512051
from context; please supply an explicit bound");
2052-
(ty::ReStatic, false)
2052+
ty::ReStatic
20532053
}
20542054
}
20552055
}
20562056
};
20572057

2058-
debug!("region_bound: {:?} will_change: {:?}",
2059-
region_bound, will_change);
2058+
debug!("region_bound: {:?}", region_bound);
20602059

20612060
ty::sort_bounds_list(&mut projection_bounds);
20622061

20632062
ty::ExistentialBounds {
20642063
region_bound: region_bound,
20652064
builtin_bounds: builtin_bounds,
20662065
projection_bounds: projection_bounds,
2067-
region_bound_will_change: will_change,
20682066
}
20692067
}
20702068

0 commit comments

Comments
 (0)