Skip to content

Commit 5f95fc1

Browse files
committed
add test for Compiler panic using fn_traits rust-lang#81974
Fixes rust-lang#81974
1 parent 60b5ca6 commit 5f95fc1

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// ICE argument to function with "rust-call" ABI is not a tuple
2+
// issue: rust-lang/rust#81974
3+
4+
#![feature(unboxed_closures)]
5+
#![feature(fn_traits)]
6+
7+
use std::collections::HashMap;
8+
use std::hash::Hash;
9+
10+
struct CachedFun<A, B> {
11+
cache: HashMap<A, B>,
12+
fun: fn(&mut CachedFun<A, B>, A) -> B,
13+
}
14+
15+
impl<A: Eq + Hash, B> CachedFun<A, B> {
16+
fn new(fun: fn(&mut Self, A) -> B) -> Self {
17+
CachedFun {
18+
cache: HashMap::new(),
19+
fun,
20+
}
21+
}
22+
}
23+
24+
impl<A, B> FnOnce<A> for CachedFun<A, B>
25+
//~^ ERROR type parameter to bare `FnOnce` trait must be a tuple
26+
where
27+
A: Eq + Hash + Clone,
28+
B: Clone,
29+
{
30+
type Output = B;
31+
extern "rust-call" fn call_once(mut self, a: A) -> Self::Output {
32+
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
33+
self.call_mut(a)
34+
//~^ ERROR `A` is not a tuple
35+
}
36+
}
37+
38+
impl<A, B> FnMut<A> for CachedFun<A, B>
39+
//~^ ERROR type parameter to bare `FnMut` trait must be a tuple
40+
where
41+
A: Eq + Hash + Clone,
42+
B: Clone,
43+
{
44+
extern "rust-call" fn call_mut(&mut self, a: A) -> Self::Output {
45+
//~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
46+
self.cache.get(&a).map(|a| a.clone()).unwrap_or_else(|| {
47+
let b = (self.fun)(self, a.clone());
48+
self.cache.insert(a, b.clone());
49+
b
50+
})
51+
}
52+
}
53+
54+
fn main() -> () {
55+
let pesce = |y: &mut CachedFun<i32, i32>, x| x + 1;
56+
let cachedcoso = CachedFun::new(pesce);
57+
cachedcoso.call_once(1);
58+
//~^ ERROR `i32` is not a tuple
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
error[E0059]: type parameter to bare `FnOnce` trait must be a tuple
2+
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:24:12
3+
|
4+
LL | impl<A, B> FnOnce<A> for CachedFun<A, B>
5+
| ^^^^^^^^^ the trait `Tuple` is not implemented for `A`
6+
|
7+
note: required by a bound in `FnOnce`
8+
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
9+
help: consider further restricting this bound
10+
|
11+
LL | A: Eq + Hash + Clone + std::marker::Tuple,
12+
| ++++++++++++++++++++
13+
14+
error[E0059]: type parameter to bare `FnMut` trait must be a tuple
15+
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:38:12
16+
|
17+
LL | impl<A, B> FnMut<A> for CachedFun<A, B>
18+
| ^^^^^^^^ the trait `Tuple` is not implemented for `A`
19+
|
20+
note: required by a bound in `FnMut`
21+
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
22+
help: consider further restricting this bound
23+
|
24+
LL | A: Eq + Hash + Clone + std::marker::Tuple,
25+
| ++++++++++++++++++++
26+
27+
error[E0277]: functions with the "rust-call" ABI must take a single non-self tuple argument
28+
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:31:5
29+
|
30+
LL | extern "rust-call" fn call_once(mut self, a: A) -> Self::Output {
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Tuple` is not implemented for `A`
32+
|
33+
help: consider further restricting this bound
34+
|
35+
LL | A: Eq + Hash + Clone + std::marker::Tuple,
36+
| ++++++++++++++++++++
37+
38+
error[E0277]: functions with the "rust-call" ABI must take a single non-self tuple argument
39+
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:44:5
40+
|
41+
LL | extern "rust-call" fn call_mut(&mut self, a: A) -> Self::Output {
42+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Tuple` is not implemented for `A`
43+
|
44+
help: consider further restricting this bound
45+
|
46+
LL | A: Eq + Hash + Clone + std::marker::Tuple,
47+
| ++++++++++++++++++++
48+
49+
error[E0277]: `A` is not a tuple
50+
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:33:23
51+
|
52+
LL | self.call_mut(a)
53+
| -------- ^ the trait `Tuple` is not implemented for `A`
54+
| |
55+
| required by a bound introduced by this call
56+
|
57+
note: required by a bound in `call_mut`
58+
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
59+
help: consider further restricting this bound
60+
|
61+
LL | A: Eq + Hash + Clone + std::marker::Tuple,
62+
| ++++++++++++++++++++
63+
64+
error[E0277]: `i32` is not a tuple
65+
--> $DIR/rust-call-abi-not-a-tuple-ice-81974.rs:57:26
66+
|
67+
LL | cachedcoso.call_once(1);
68+
| --------- ^ the trait `Tuple` is not implemented for `i32`
69+
| |
70+
| required by a bound introduced by this call
71+
|
72+
note: required by a bound in `call_once`
73+
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
74+
75+
error: aborting due to 6 previous errors
76+
77+
Some errors have detailed explanations: E0059, E0277.
78+
For more information about an error, try `rustc --explain E0059`.

0 commit comments

Comments
 (0)