Skip to content

Commit ec45882

Browse files
committed
Add test for issue-30904
1 parent e3d9984 commit ec45882

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#![feature(fn_traits, unboxed_closures)]
2+
3+
fn test<F: for<'x> FnOnce<(&'x str,)>>(_: F) {}
4+
5+
struct Compose<F,G>(F,G);
6+
impl<T,F,G> FnOnce<(T,)> for Compose<F,G>
7+
where F: FnOnce<(T,)>, G: FnOnce<(F::Output,)> {
8+
type Output = G::Output;
9+
extern "rust-call" fn call_once(self, (x,): (T,)) -> G::Output {
10+
(self.1)((self.0)(x))
11+
}
12+
}
13+
14+
struct Str<'a>(&'a str);
15+
fn mk_str<'a>(s: &'a str) -> Str<'a> { Str(s) }
16+
17+
fn main() {
18+
let _: for<'a> fn(&'a str) -> Str<'a> = mk_str;
19+
// expected concrete lifetime, found bound lifetime parameter 'a
20+
let _: for<'a> fn(&'a str) -> Str<'a> = Str;
21+
//~^ ERROR: mismatched types
22+
23+
test(|_: &str| {});
24+
test(mk_str);
25+
// expected concrete lifetime, found bound lifetime parameter 'x
26+
test(Str); //~ ERROR: type mismatch in function arguments
27+
28+
test(Compose(|_: &str| {}, |_| {}));
29+
test(Compose(mk_str, |_| {}));
30+
// internal compiler error: cannot relate bound region:
31+
// ReLateBound(DebruijnIndex { depth: 2 },
32+
// BrNamed(DefId { krate: 0, node: DefIndex(6) => test::'x }, 'x(65)))
33+
//<= ReSkolemized(0,
34+
// BrNamed(DefId { krate: 0, node: DefIndex(6) => test::'x }, 'x(65)))
35+
test(Compose(Str, |_| {}));
36+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-30904.rs:20:45
3+
|
4+
LL | let _: for<'a> fn(&'a str) -> Str<'a> = Str;
5+
| ^^^ expected concrete lifetime, found bound lifetime parameter 'a
6+
|
7+
= note: expected type `for<'a> fn(&'a str) -> Str<'a>`
8+
found type `fn(&str) -> Str<'_> {Str::<'_>}`
9+
10+
error[E0631]: type mismatch in function arguments
11+
--> $DIR/issue-30904.rs:26:10
12+
|
13+
LL | fn test<F: for<'x> FnOnce<(&'x str,)>>(_: F) {}
14+
| ---- -------------------------- required by this bound in `test`
15+
...
16+
LL | struct Str<'a>(&'a str);
17+
| ------------------------ found signature of `fn(&str) -> _`
18+
...
19+
LL | test(Str);
20+
| ^^^ expected signature of `for<'x> fn(&'x str) -> _`
21+
22+
error: aborting due to 2 previous errors
23+
24+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)