Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions tests/ui/unboxed-closures/fn-traits-hrtb-coercion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//! Test for issue <github.com/rust-lang/rust/issues/30904>
//! Related to higher-ranked lifetime inference with unboxed closures and FnOnce.

#![feature(fn_traits, unboxed_closures)]

fn test<F: for<'x> FnOnce<(&'x str,)>>(_: F) {}

struct Compose<F, G>(F, G);

impl<T, F, G> FnOnce<(T,)> for Compose<F, G>
where
F: FnOnce<(T,)>,
G: FnOnce<(F::Output,)>,
{
type Output = G::Output;
extern "rust-call" fn call_once(self, (x,): (T,)) -> G::Output {
(self.1)((self.0)(x))
}
}

struct Str<'a>(&'a str);

fn mk_str<'a>(s: &'a str) -> Str<'a> {
Str(s)
}

fn main() {
let _: for<'a> fn(&'a str) -> Str<'a> = mk_str;
let _: for<'a> fn(&'a str) -> Str<'a> = Str;
//~^ ERROR: mismatched types

test(|_: &str| {});
test(mk_str);
test(Str);

test(Compose(|_: &str| {}, |_| {}));
test(Compose(mk_str, |_| {}));
test(Compose(Str, |_| {}));
}
14 changes: 14 additions & 0 deletions tests/ui/unboxed-closures/fn-traits-hrtb-coercion.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0308]: mismatched types
--> $DIR/fn-traits-hrtb-coercion.rs:29:45
|
LL | let _: for<'a> fn(&'a str) -> Str<'a> = Str;
| ------------------------------ ^^^ one type is more general than the other
| |
| expected due to this
|
= note: expected fn pointer `for<'a> fn(&'a _) -> Str<'a>`
found struct constructor `fn(&_) -> Str<'_> {Str::<'_>}`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0308`.
Loading