Skip to content

Commit 29ef4c8

Browse files
Rollup merge of #142183 - Kivooeo:30904-test, r=compiler-errors
Added test for 30904 Test that was deleted by mistake in this commit 564c78a#diff-85d65712084246fc61f287664eef63b0b25ba0a5c8b69a4a59a9454b6a3ebac4 The original issue is still open and the problem is not solved (if this is even a problem, but the error is still here at least)
2 parents 48667dd + 143354c commit 29ef4c8

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! Test for issue <github.com/rust-lang/rust/issues/30904>
2+
//! Related to higher-ranked lifetime inference with unboxed closures and FnOnce.
3+
4+
#![feature(fn_traits, unboxed_closures)]
5+
6+
fn test<F: for<'x> FnOnce<(&'x str,)>>(_: F) {}
7+
8+
struct Compose<F, G>(F, G);
9+
10+
impl<T, F, G> FnOnce<(T,)> for Compose<F, G>
11+
where
12+
F: FnOnce<(T,)>,
13+
G: FnOnce<(F::Output,)>,
14+
{
15+
type Output = G::Output;
16+
extern "rust-call" fn call_once(self, (x,): (T,)) -> G::Output {
17+
(self.1)((self.0)(x))
18+
}
19+
}
20+
21+
struct Str<'a>(&'a str);
22+
23+
fn mk_str<'a>(s: &'a str) -> Str<'a> {
24+
Str(s)
25+
}
26+
27+
fn main() {
28+
let _: for<'a> fn(&'a str) -> Str<'a> = mk_str;
29+
let _: for<'a> fn(&'a str) -> Str<'a> = Str;
30+
//~^ ERROR: mismatched types
31+
32+
test(|_: &str| {});
33+
test(mk_str);
34+
test(Str);
35+
36+
test(Compose(|_: &str| {}, |_| {}));
37+
test(Compose(mk_str, |_| {}));
38+
test(Compose(Str, |_| {}));
39+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/fn-traits-hrtb-coercion.rs:29:45
3+
|
4+
LL | let _: for<'a> fn(&'a str) -> Str<'a> = Str;
5+
| ------------------------------ ^^^ one type is more general than the other
6+
| |
7+
| expected due to this
8+
|
9+
= note: expected fn pointer `for<'a> fn(&'a _) -> Str<'a>`
10+
found struct constructor `fn(&_) -> Str<'_> {Str::<'_>}`
11+
12+
error: aborting due to 1 previous error
13+
14+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)