Closed
Description
Code
#![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> where
A: Eq + Hash + Clone,
B: Clone,
{
type Output = B;
extern "rust-call" fn call_once(mut self, a: A) -> Self::Output {
self.call_mut(a)
}
}
impl<A, B> FnMut<A> for CachedFun<A, B> where
A: Eq + Hash + Clone,
B: Clone,
{
extern "rust-call" fn call_mut(&mut self, a: A) -> Self::Output {
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);
}
Meta
rustc --version --verbose
:
Build using the Nightly version: 1.52.0-nightly (2021-02-09 097bc6a84f2280a889b9)
Error output
error: internal compiler error: /rustc/097bc6a84f2280a889b9ab4b544f27851a978927/compiler/rustc_middle/src/ty/layout.rs:2693:21: argument to function with "rust-call" ABI is not a tuple
thread 'rustc' panicked at 'Box<Any>', /rustc/097bc6a84f2280a889b9ab4b544f27851a978927/library/std/src/panic.rs:59:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Note: I have the same issue even without a closure or by using the mut call
Metadata
Metadata
Assignees
Labels
Area: Closures (`|…| { … }`)Category: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.`#![feature(unboxed_closures)]`Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Relevant to the compiler team, which will review and decide on the PR/issue.This issue requires a nightly compiler in some way.