Skip to content

Commit

Permalink
partially revert 904a0bd
Browse files Browse the repository at this point in the history
This preserves the error you currently get on stable for the
old-lub-glb-object.rs test.
  • Loading branch information
nikomatsakis committed Feb 22, 2019
1 parent b0fd835 commit c820008
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
20 changes: 19 additions & 1 deletion src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3254,9 +3254,27 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
tcx.mk_existential_predicates(iter)
});
let source_trait = tcx.mk_dynamic(existential_predicates, r_b);

// Require that the traits involved in this upcast are **equal**;
// only the **lifetime bound** is changed.
//
// FIXME: This condition is arguably too strong -- it
// would suffice for the source trait to be a
// *subtype* of the target trait. In particular
// changing from something like `for<'a, 'b> Foo<'a,
// 'b>` to `for<'a> Foo<'a, 'a>` should be
// permitted. And, indeed, in the in commit
// 904a0bde93f0348f69914ee90b1f8b6e4e0d7cbc, this
// condition was loosened. However, when the leak check was added
// back, using subtype here actually guies the coercion code in
// such a way that it accepts `old-lub-glb-object.rs`. This is probably
// a good thing, but I've modified this to `.eq` because I want
// to continue rejecting that test (as we have done for quite some time)
// before we are firmly comfortable with what our behavior
// should be there. -nikomatsakis
let InferOk { obligations, .. } = self.infcx
.at(&obligation.cause, obligation.param_env)
.sup(target, source_trait)
.eq(target, source_trait) // FIXME -- see below
.map_err(|_| Unimplemented)?;
nested.extend(obligations);

Expand Down
6 changes: 1 addition & 5 deletions src/test/ui/lub-glb/old-lub-glb-object.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
// Test that we give a note when the old LUB/GLB algorithm would have
// succeeded but the new code (which is stricter) gives an error.
//
// compile-pass
//
// TODO -- why does this test pass?

trait Foo<T, U> { }

fn foo(
x: &for<'a, 'b> Foo<&'a u8, &'b u8>,
y: &for<'a> Foo<&'a u8, &'a u8>,
) {
let z = match 22 {
let z = match 22 { //~ ERROR match arms have incompatible types
0 => x,
_ => y,
};
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/lub-glb/old-lub-glb-object.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error[E0308]: match arms have incompatible types
--> $DIR/old-lub-glb-object.rs:10:13
|
LL | let z = match 22 { //~ ERROR match arms have incompatible types
| _____________^
LL | | 0 => x,
LL | | _ => y,
| | - match arm with an incompatible type
LL | | };
| |_____^ expected bound lifetime parameter 'a, found concrete lifetime
|
= note: expected type `&dyn for<'a, 'b> Foo<&'a u8, &'b u8>`
found type `&dyn for<'a> Foo<&'a u8, &'a u8>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.

0 comments on commit c820008

Please sign in to comment.