Skip to content

Commit 33d3598

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 21e9478 commit 33d3598

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

src/librustc/traits/select.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -3315,9 +3315,27 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
33153315
tcx.mk_existential_predicates(iter)
33163316
});
33173317
let source_trait = tcx.mk_dynamic(existential_predicates, r_b);
3318+
3319+
// Require that the traits involved in this upcast are **equal**;
3320+
// only the **lifetime bound** is changed.
3321+
//
3322+
// FIXME: This condition is arguably too strong -- it
3323+
// would suffice for the source trait to be a
3324+
// *subtype* of the target trait. In particular
3325+
// changing from something like `for<'a, 'b> Foo<'a,
3326+
// 'b>` to `for<'a> Foo<'a, 'a>` should be
3327+
// permitted. And, indeed, in the in commit
3328+
// 904a0bde93f0348f69914ee90b1f8b6e4e0d7cbc, this
3329+
// condition was loosened. However, when the leak check was added
3330+
// back, using subtype here actually guies the coercion code in
3331+
// such a way that it accepts `old-lub-glb-object.rs`. This is probably
3332+
// a good thing, but I've modified this to `.eq` because I want
3333+
// to continue rejecting that test (as we have done for quite some time)
3334+
// before we are firmly comfortable with what our behavior
3335+
// should be there. -nikomatsakis
33183336
let InferOk { obligations, .. } = self.infcx
33193337
.at(&obligation.cause, obligation.param_env)
3320-
.sup(target, source_trait)
3338+
.eq(target, source_trait) // FIXME -- see below
33213339
.map_err(|_| Unimplemented)?;
33223340
nested.extend(obligations);
33233341

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
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

@@ -13,7 +9,7 @@ fn foo(
139
) {
1410
let z = match 22 {
1511
0 => x,
16-
_ => y,
12+
_ => y, //~ ERROR match arms have incompatible types
1713
};
1814
}
1915

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

0 commit comments

Comments
 (0)