Skip to content

Commit

Permalink
select.rs: unsizing coercion should use a subtype
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nikomatsakis committed Jan 2, 2019
1 parent 4170829 commit 904a0bd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/lub-glb/old-lub-glb-object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
14 changes: 8 additions & 6 deletions src/test/ui/lub-glb/old-lub-glb-object.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 904a0bd

Please sign in to comment.