Support constraining opaque types while trait upcasting with binders

This commit is contained in:
Oli Scherer 2024-04-17 10:48:20 +00:00
parent 7f292f41a0
commit 4387eea7f7
3 changed files with 3 additions and 11 deletions

View File

@ -2594,7 +2594,7 @@ fn match_upcast_principal(
self.infcx
.at(&obligation.cause, obligation.param_env)
.eq(
DefineOpaqueTypes::No,
DefineOpaqueTypes::Yes,
upcast_principal.map_bound(|trait_ref| {
ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref)
}),

View File

@ -1,5 +1,7 @@
#![feature(trait_upcasting, type_alias_impl_trait)]
//@ check-pass
type Tait = impl Sized;
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) {
let _ = x as &dyn Bar<'_, '_, ()>;
//~^ ERROR: non-primitive cast
}
fn main() {}

View File

@ -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`.