rust/tests/ui/fn/fn_def_opaque_coercion.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
971 B
Rust
Raw Normal View History

2024-04-11 09:14:15 -05:00
//! Test that coercing between function items of the same function,
//! but with different generic args works.
//@check-pass
2024-04-11 09:14:15 -05:00
#![feature(type_alias_impl_trait)]
fn foo<T>(t: T) -> T {
t
}
type F = impl Sized;
fn f(a: F) {
let mut x = foo::<F>;
x = foo::<()>;
x(a);
x(());
}
type G = impl Sized;
fn g(a: G) {
let x = foo::<()>;
let _: () = x(a);
}
type H = impl Sized;
fn h(a: H) {
let x = foo::<H>;
let _: H = x(());
}
type I = impl Sized;
fn i(a: I) {
let mut x = foo::<()>;
x = foo::<I>;
x(a);
x(());
}
type J = impl Sized;
fn j(a: J) {
let x = match true {
true => foo::<J>,
false => foo::<()>,
2024-04-11 09:14:15 -05:00
};
x(a);
x(());
}
fn k() -> impl Sized {
fn bind<T, F: FnOnce(T) -> T>(_: T, f: F) -> F {
f
}
let x = match true {
true => {
let f = foo;
bind(k(), f)
}
false => foo::<()>,
2024-04-11 09:14:15 -05:00
};
todo!()
}
fn main() {}