Support constraining opaque types while trait upcasting with binders
This commit is contained in:
parent
7f292f41a0
commit
4387eea7f7
3 changed files with 3 additions and 11 deletions
|
@ -2594,7 +2594,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
||||||
self.infcx
|
self.infcx
|
||||||
.at(&obligation.cause, obligation.param_env)
|
.at(&obligation.cause, obligation.param_env)
|
||||||
.eq(
|
.eq(
|
||||||
DefineOpaqueTypes::No,
|
DefineOpaqueTypes::Yes,
|
||||||
upcast_principal.map_bound(|trait_ref| {
|
upcast_principal.map_bound(|trait_ref| {
|
||||||
ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
|
ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
|
||||||
}),
|
}),
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#![feature(trait_upcasting, type_alias_impl_trait)]
|
#![feature(trait_upcasting, type_alias_impl_trait)]
|
||||||
|
|
||||||
|
//@ check-pass
|
||||||
|
|
||||||
type Tait = impl Sized;
|
type Tait = impl Sized;
|
||||||
|
|
||||||
trait Foo<'a>: Bar<'a, 'a, Tait> {}
|
trait Foo<'a>: Bar<'a, 'a, Tait> {}
|
||||||
|
@ -15,7 +17,6 @@ fn test_correct2<'a>(x: &dyn Foo<'a>) {
|
||||||
|
|
||||||
fn test_correct3<'a>(x: &dyn Foo<'a>, _: Tait) {
|
fn test_correct3<'a>(x: &dyn Foo<'a>, _: Tait) {
|
||||||
let _ = x as &dyn Bar<'_, '_, ()>;
|
let _ = x as &dyn Bar<'_, '_, ()>;
|
||||||
//~^ ERROR: non-primitive cast
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
error[E0605]: non-primitive cast: `&dyn Foo<'a>` as `&dyn Bar<'_, '_, ()>`
|
|
||||||
--> $DIR/type-checking-test-opaques.rs:17:13
|
|
||||||
|
|
|
||||||
LL | let _ = x as &dyn Bar<'_, '_, ()>;
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
|
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0605`.
|
|
Loading…
Add table
Add a link
Reference in a new issue