Skip to content

Commit f2bc9c5

Browse files
committed
add test for #106874 ICE BoundUniversalRegionError
Fixes #106874
1 parent cc422ce commit f2bc9c5

File tree

2 files changed

+138
-0
lines changed

2 files changed

+138
-0
lines changed

tests/ui/nll/ice-106874.rs

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// issue: rust-lang/rust#106874
2+
// ICE BoundUniversalRegionError
3+
4+
use std::marker::PhantomData;
5+
use std::rc::Rc;
6+
7+
pub fn func<V, F: Fn(&mut V)>(f: F) -> A<impl X> {
8+
A(B(C::new(D::new(move |st| f(st)))))
9+
//~^ ERROR implementation of `FnOnce` is not general enough
10+
//~^^ ERROR implementation of `Fn` is not general enough
11+
//~^^^ ERROR implementation of `FnOnce` is not general enough
12+
//~^^^^ ERROR implementation of `FnOnce` is not general enough
13+
//~^^^^^ ERROR implementation of `Fn` is not general enough
14+
//~^^^^^^ ERROR implementation of `FnOnce` is not general enough
15+
//~^^^^^^^ ERROR implementation of `Fn` is not general enough
16+
//~^^^^^^^^ ERROR implementation of `FnOnce` is not general enough
17+
//~^^^^^^^^^ ERROR higher-ranked subtype error
18+
//~^^^^^^^^^^ ERROR higher-ranked subtype error
19+
}
20+
21+
trait X {}
22+
trait Y {
23+
type V;
24+
}
25+
26+
struct A<T>(T);
27+
28+
struct B<T>(Rc<T>);
29+
impl<T> X for B<T> {}
30+
31+
struct C<T: Y>(T::V);
32+
impl<T: Y> C<T> {
33+
fn new(_: T) -> Rc<Self> {
34+
todo!()
35+
}
36+
}
37+
struct D<V, F>(F, PhantomData<fn(&mut V)>);
38+
39+
impl<V, F> D<V, F> {
40+
fn new(_: F) -> Self {
41+
todo!()
42+
}
43+
}
44+
impl<V, F: Fn(&mut V)> Y for D<V, F> {
45+
type V = V;
46+
}
47+
48+
pub fn main() {}

tests/ui/nll/ice-106874.stderr

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
error: implementation of `FnOnce` is not general enough
2+
--> $DIR/ice-106874.rs:8:5
3+
|
4+
LL | A(B(C::new(D::new(move |st| f(st)))))
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
6+
|
7+
= note: closure with signature `fn(&'0 mut V)` must implement `FnOnce<(&mut V,)>`, for some specific lifetime `'0`...
8+
= note: ...but it actually implements `FnOnce<(&'1 mut V,)>`, for some specific lifetime `'1`
9+
10+
error: implementation of `FnOnce` is not general enough
11+
--> $DIR/ice-106874.rs:8:5
12+
|
13+
LL | A(B(C::new(D::new(move |st| f(st)))))
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
15+
|
16+
= note: closure with signature `fn(&'0 mut V)` must implement `FnOnce<(&mut V,)>`, for some specific lifetime `'0`...
17+
= note: ...but it actually implements `FnOnce<(&'1 mut V,)>`, for some specific lifetime `'1`
18+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
19+
20+
error: implementation of `Fn` is not general enough
21+
--> $DIR/ice-106874.rs:8:7
22+
|
23+
LL | A(B(C::new(D::new(move |st| f(st)))))
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Fn` is not general enough
25+
|
26+
= note: closure with signature `fn(&'2 mut V)` must implement `Fn<(&'1 mut V,)>`, for any lifetime `'1`...
27+
= note: ...but it actually implements `Fn<(&'2 mut V,)>`, for some specific lifetime `'2`
28+
29+
error: implementation of `FnOnce` is not general enough
30+
--> $DIR/ice-106874.rs:8:7
31+
|
32+
LL | A(B(C::new(D::new(move |st| f(st)))))
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
34+
|
35+
= note: closure with signature `fn(&'2 mut V)` must implement `FnOnce<(&'1 mut V,)>`, for any lifetime `'1`...
36+
= note: ...but it actually implements `FnOnce<(&'2 mut V,)>`, for some specific lifetime `'2`
37+
38+
error: implementation of `Fn` is not general enough
39+
--> $DIR/ice-106874.rs:8:7
40+
|
41+
LL | A(B(C::new(D::new(move |st| f(st)))))
42+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Fn` is not general enough
43+
|
44+
= note: closure with signature `fn(&'2 mut V)` must implement `Fn<(&'1 mut V,)>`, for any lifetime `'1`...
45+
= note: ...but it actually implements `Fn<(&'2 mut V,)>`, for some specific lifetime `'2`
46+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
47+
48+
error: implementation of `FnOnce` is not general enough
49+
--> $DIR/ice-106874.rs:8:9
50+
|
51+
LL | A(B(C::new(D::new(move |st| f(st)))))
52+
| ^^^^^^ implementation of `FnOnce` is not general enough
53+
|
54+
= note: closure with signature `fn(&'2 mut V)` must implement `FnOnce<(&'1 mut V,)>`, for any lifetime `'1`...
55+
= note: ...but it actually implements `FnOnce<(&'2 mut V,)>`, for some specific lifetime `'2`
56+
57+
error: implementation of `Fn` is not general enough
58+
--> $DIR/ice-106874.rs:8:9
59+
|
60+
LL | A(B(C::new(D::new(move |st| f(st)))))
61+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Fn` is not general enough
62+
|
63+
= note: closure with signature `fn(&'2 mut V)` must implement `Fn<(&'1 mut V,)>`, for any lifetime `'1`...
64+
= note: ...but it actually implements `Fn<(&'2 mut V,)>`, for some specific lifetime `'2`
65+
66+
error: implementation of `FnOnce` is not general enough
67+
--> $DIR/ice-106874.rs:8:9
68+
|
69+
LL | A(B(C::new(D::new(move |st| f(st)))))
70+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
71+
|
72+
= note: closure with signature `fn(&'2 mut V)` must implement `FnOnce<(&'1 mut V,)>`, for any lifetime `'1`...
73+
= note: ...but it actually implements `FnOnce<(&'2 mut V,)>`, for some specific lifetime `'2`
74+
75+
error: higher-ranked subtype error
76+
--> $DIR/ice-106874.rs:8:41
77+
|
78+
LL | A(B(C::new(D::new(move |st| f(st)))))
79+
| ^
80+
81+
error: higher-ranked subtype error
82+
--> $DIR/ice-106874.rs:8:41
83+
|
84+
LL | A(B(C::new(D::new(move |st| f(st)))))
85+
| ^
86+
|
87+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
88+
89+
error: aborting due to 10 previous errors
90+

0 commit comments

Comments
 (0)