Skip to content

Commit 904a0bd

Browse files
committed
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.
1 parent 4170829 commit 904a0bd

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/librustc/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3268,10 +3268,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
32683268
);
32693269
tcx.mk_existential_predicates(iter)
32703270
});
3271-
let new_trait = tcx.mk_dynamic(existential_predicates, r_b);
3271+
let source_trait = tcx.mk_dynamic(existential_predicates, r_b);
32723272
let InferOk { obligations, .. } = self.infcx
32733273
.at(&obligation.cause, obligation.param_env)
3274-
.eq(target, new_trait)
3274+
.sup(target, source_trait)
32753275
.map_err(|_| Unimplemented)?;
32763276
nested.extend(obligations);
32773277

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn foo(
77
x: &for<'a, 'b> Foo<&'a u8, &'b u8>,
88
y: &for<'a> Foo<&'a u8, &'a u8>,
99
) {
10-
let z = match 22 { //~ ERROR incompatible types
10+
let z = match 22 { //~ ERROR cannot infer
1111
0 => x,
1212
_ => y,
1313
};
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
error[E0308]: match arms have incompatible types
22
--> $DIR/old-lub-glb-object.rs:10:13
33
|
4-
LL | let z = match 22 { //~ ERROR incompatible types
4+
LL | let z = match 22 { //~ ERROR cannot infer
55
| _____________^
66
LL | | 0 => x,
77
LL | | _ => y,
8-
| | - match arm with an incompatible type
98
LL | | };
10-
| |_____^ expected bound lifetime parameter 'a, found concrete lifetime
9+
| |_____^
1110
|
12-
= note: expected type `&dyn for<'a, 'b> Foo<&'a u8, &'b u8>`
13-
found type `&dyn for<'a> Foo<&'a u8, &'a u8>`
11+
= note: first, the lifetime cannot outlive lifetime RePlaceholder(Placeholder { universe: U5, name: BrNamed(crate0:DefIndex(1:11), 'a) })...
12+
= note: ...but the lifetime must also be valid for lifetime RePlaceholder(Placeholder { universe: U5, name: BrNamed(crate0:DefIndex(1:12), 'b) })...
13+
= note: ...so that the types are compatible:
14+
expected dyn for<'a, 'b> Foo<&'a u8, &'b u8>
15+
found dyn for<'a> Foo<&'a u8, &'a u8>
1416

1517
error: aborting due to previous error
1618

17-
For more information about this error, try `rustc --explain E0308`.
19+
For more information about this error, try `rustc --explain E0495`.

0 commit comments

Comments
 (0)