select.rs: unsizing coercion should use a subtype

When we coerce `dyn Foo` to `dyn Bar`, that is OK as long as `Foo` is
usable in all contexts where `Bar` is usable (hence using the source
must be a subtype of the target).

This is needed for the universe-based code to handle
`old-lub-glb-object`; that test used to work sort of by accident
before with the old code.
This commit is contained in:
Niko Matsakis 2018-12-27 10:22:55 -05:00
parent 4170829e53
commit 904a0bde93
3 changed files with 11 additions and 9 deletions

View File

@ -3268,10 +3268,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
);
tcx.mk_existential_predicates(iter)
});
let new_trait = tcx.mk_dynamic(existential_predicates, r_b);
let source_trait = tcx.mk_dynamic(existential_predicates, r_b);
let InferOk { obligations, .. } = self.infcx
.at(&obligation.cause, obligation.param_env)
.eq(target, new_trait)
.sup(target, source_trait)
.map_err(|_| Unimplemented)?;
nested.extend(obligations);

View File

@ -7,7 +7,7 @@ fn foo(
x: &for<'a, 'b> Foo<&'a u8, &'b u8>,
y: &for<'a> Foo<&'a u8, &'a u8>,
) {
let z = match 22 { //~ ERROR incompatible types
let z = match 22 { //~ ERROR cannot infer
0 => x,
_ => y,
};

View File

@ -1,17 +1,19 @@
error[E0308]: match arms have incompatible types
--> $DIR/old-lub-glb-object.rs:10:13
|
LL | let z = match 22 { //~ ERROR incompatible types
LL | let z = match 22 { //~ ERROR cannot infer
| _____________^
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>`
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U5, name: BrNamed(crate0:DefIndex(1:11), 'a) })...
= note: ...but the lifetime must also be valid for lifetime RePlaceholder(Placeholder { universe: U5, name: BrNamed(crate0:DefIndex(1:12), 'b) })...
= note: ...so that the types are compatible:
expected dyn for<'a, 'b> Foo<&'a u8, &'b u8>
found dyn for<'a> Foo<&'a u8, &'a u8>
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.
For more information about this error, try `rustc --explain E0495`.