File: rust-call-abi-not-a-tuple-ice-81974.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (59 lines) | stat: -rw-r--r-- 1,584 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// ICE argument to function with "rust-call" ABI is not a tuple
// issue: rust-lang/rust#81974

#![feature(unboxed_closures)]
#![feature(fn_traits)]

use std::collections::HashMap;
use std::hash::Hash;

struct CachedFun<A, B> {
    cache: HashMap<A, B>,
    fun: fn(&mut CachedFun<A, B>, A) -> B,
}

impl<A: Eq + Hash, B> CachedFun<A, B> {
    fn new(fun: fn(&mut Self, A) -> B) -> Self {
        CachedFun {
            cache: HashMap::new(),
            fun,
        }
    }
}

impl<A, B> FnOnce<A> for CachedFun<A, B>
//~^ ERROR type parameter to bare `FnOnce` trait must be a tuple
where
    A: Eq + Hash + Clone,
    B: Clone,
{
    type Output = B;
    extern "rust-call" fn call_once(mut self, a: A) -> Self::Output {
    //~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
        self.call_mut(a)
        //~^ ERROR `A` is not a tuple
    }
}

impl<A, B> FnMut<A> for CachedFun<A, B>
//~^ ERROR type parameter to bare `FnMut` trait must be a tuple
where
    A: Eq + Hash + Clone,
    B: Clone,
{
    extern "rust-call" fn call_mut(&mut self, a: A) -> Self::Output {
    //~^ ERROR functions with the "rust-call" ABI must take a single non-self tuple argument
        self.cache.get(&a).map(|a| a.clone()).unwrap_or_else(|| {
            let b = (self.fun)(self, a.clone());
            self.cache.insert(a, b.clone());
            b
        })
    }
}

fn main() -> () {
    let pesce = |y: &mut CachedFun<i32, i32>, x| x + 1;
    let cachedcoso = CachedFun::new(pesce);
    cachedcoso.call_once(1);
    //~^ ERROR `i32` is not a tuple
}