Skip to content

Commit 551aafc

Browse files
committed
partially revert 904a0bd
This preserves the error you currently get on stable for the old-lub-glb-object.rs test.
1 parent 542ad5e commit 551aafc

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

src/librustc/traits/select.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -3254,9 +3254,27 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
32543254
tcx.mk_existential_predicates(iter)
32553255
});
32563256
let source_trait = tcx.mk_dynamic(existential_predicates, r_b);
3257+
3258+
// Require that the traits involved in this upcast are **equal**;
3259+
// only the **lifetime bound** is changed.
3260+
//
3261+
// FIXME: This condition is arguably too strong -- it
3262+
// would suffice for the source trait to be a
3263+
// *subtype* of the target trait. In particular
3264+
// changing from something like `for<'a, 'b> Foo<'a,
3265+
// 'b>` to `for<'a> Foo<'a, 'a>` should be
3266+
// permitted. And, indeed, in the in commit
3267+
// 904a0bde93f0348f69914ee90b1f8b6e4e0d7cbc, this
3268+
// condition was loosened. However, when the leak check was added
3269+
// back, using subtype here actually guies the coercion code in
3270+
// such a way that it accepts `old-lub-glb-object.rs`. This is probably
3271+
// a good thing, but I've modified this to `.eq` because I want
3272+
// to continue rejecting that test (as we have done for quite some time)
3273+
// before we are firmly comfortable with what our behavior
3274+
// should be there. -nikomatsakis
32573275
let InferOk { obligations, .. } = self.infcx
32583276
.at(&obligation.cause, obligation.param_env)
3259-
.sup(target, source_trait)
3277+
.eq(target, source_trait) // FIXME -- see below
32603278
.map_err(|_| Unimplemented)?;
32613279
nested.extend(obligations);
32623280

src/test/ui/lub-glb/old-lub-glb-object.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
// Test that we give a note when the old LUB/GLB algorithm would have
22
// succeeded but the new code (which is stricter) gives an error.
3-
//
4-
// compile-pass
5-
//
6-
// TODO -- why does this test pass?
73

84
trait Foo<T, U> { }
95

106
fn foo(
117
x: &for<'a, 'b> Foo<&'a u8, &'b u8>,
128
y: &for<'a> Foo<&'a u8, &'a u8>,
139
) {
14-
let z = match 22 {
10+
let z = match 22 { //~ ERROR match arms have incompatible types
1511
0 => x,
1612
_ => y,
1713
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error[E0308]: match arms have incompatible types
2+
--> $DIR/old-lub-glb-object.rs:10:13
3+
|
4+
LL | let z = match 22 { //~ ERROR match arms have incompatible types
5+
| _____________^
6+
LL | | 0 => x,
7+
LL | | _ => y,
8+
| | - match arm with an incompatible type
9+
LL | | };
10+
| |_____^ expected bound lifetime parameter 'a, found concrete lifetime
11+
|
12+
= note: expected type `&dyn for<'a, 'b> Foo<&'a u8, &'b u8>`
13+
found type `&dyn for<'a> Foo<&'a u8, &'a u8>`
14+
15+
error: aborting due to previous error
16+
17+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)