Skip to content

Commit e05ac39

Browse files
committed
Auto merge of #27045 - nikomatsakis:better-object-defaults-error, r=pnkfelix
Transition to the new object lifetime defaults, replacing the old defaults completely. r? @pnkfelix This is a [breaking-change] as specified by [RFC 1156][1156] (though all cases that would break should have been receiving warnings starting in Rust 1.2). Types like `&'a Box<Trait>` (or `&'a Rc<Trait>`, etc) will change from being interpreted as `&'a Box<Trait+'a>` to `&'a Box<Trait+'static>`. To restore the old behavior, write the `+'a` explicitly. For example, the function: ```rust trait Trait { } fn foo(x: &Box<Trait>) { ... } ``` would be rewritten as: ```rust trait Trait { } fn foo(x: &'a Box<Trait+'a>) { ... } ``` if one wanted to preserve the current typing. [1156]: https://github.com/rust-lang/rfcs/blob/master/text/1156-adjust-default-object-bounds.md
2 parents d4432b3 + de6b3c2 commit e05ac39

28 files changed

+97
-240
lines changed

src/librustc/metadata/tydecode.rs

Lines changed: 1 addition & 8 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 5 deletions
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

Lines changed: 0 additions & 5 deletions
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

Lines changed: 2 additions & 4 deletions
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

Lines changed: 0 additions & 10 deletions
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

Lines changed: 0 additions & 5 deletions
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

Lines changed: 0 additions & 4 deletions
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

Lines changed: 0 additions & 47 deletions
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

Lines changed: 4 additions & 14 deletions
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
}

0 commit comments

Comments
 (0)