diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 9ebb5f95f05fd..4165fa7f07d10 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1139,7 +1139,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // are the same function and their parameters have a LUB. match self.commit_if_ok(|_| { self.at(cause, self.param_env).lub( - DefineOpaqueTypes::No, + DefineOpaqueTypes::Yes, prev_ty, new_ty, ) diff --git a/tests/ui/fn/fn_def_opaque_coercion.rs b/tests/ui/fn/fn_def_opaque_coercion.rs index af7f65c2e3b70..0a8810cf4f8ac 100644 --- a/tests/ui/fn/fn_def_opaque_coercion.rs +++ b/tests/ui/fn/fn_def_opaque_coercion.rs @@ -1,5 +1,7 @@ //! Test that coercing between function items of the same function, -//! but with different args works. +//! but with different generic args works. + +//@check-pass #![feature(type_alias_impl_trait)] @@ -44,7 +46,7 @@ type J = impl Sized; fn j(a: J) { let x = match true { true => foo::, - false => foo::<()>, //~ ERROR: incompatible types + false => foo::<()>, }; x(a); x(()); @@ -59,7 +61,7 @@ fn k() -> impl Sized { let f = foo; bind(k(), f) } - false => foo::<()>, //~ ERROR: incompatible types + false => foo::<()>, }; todo!() } diff --git a/tests/ui/fn/fn_def_opaque_coercion.stderr b/tests/ui/fn/fn_def_opaque_coercion.stderr deleted file mode 100644 index 521b0277eac46..0000000000000 --- a/tests/ui/fn/fn_def_opaque_coercion.stderr +++ /dev/null @@ -1,42 +0,0 @@ -error[E0308]: `match` arms have incompatible types - --> $DIR/fn_def_opaque_coercion.rs:47:18 - | -LL | type J = impl Sized; - | ---------- the expected opaque type -... -LL | let x = match true { - | _____________- -LL | | true => foo::, - | | -------- this is found to be of type `fn(J) -> J {foo::}` -LL | | false => foo::<()>, - | | ^^^^^^^^^ expected opaque type, found `()` -LL | | }; - | |_____- `match` arms have incompatible types - | - = note: expected fn item `fn(J) -> J {foo::}` - found fn item `fn(()) {foo::<()>}` - -error[E0308]: `match` arms have incompatible types - --> $DIR/fn_def_opaque_coercion.rs:62:18 - | -LL | fn k() -> impl Sized { - | ---------- the expected opaque type -... -LL | let x = match true { - | _____________- -LL | | true => { -LL | | let f = foo; -LL | | bind(k(), f) - | | ------------ this is found to be of type `fn(impl Sized) -> impl Sized {foo::}` -LL | | } -LL | | false => foo::<()>, - | | ^^^^^^^^^ expected opaque type, found `()` -LL | | }; - | |_____- `match` arms have incompatible types - | - = note: expected fn item `fn(impl Sized) -> impl Sized {foo::}` - found fn item `fn(()) {foo::<()>}` - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`.