Skip to content

Cannot generically implement Function traits #17779

Closed
@Ericson2314

Description

@Ericson2314

My code:

pub struct LockedClosure<F>  {
    closure: Mutex<F>
}

impl<F, Args, Result> Fn<Args, Result> for LockedClosure<F>
    where F: FnMut<Args, Result>, F:Send
{
    #[rust_call_abi_hack]
    fn call(&self, args: Args) -> Result {
        self.closure.lock().deref_mut().call_mut(args)
    }
}

I get an ICE 'argument to function with "rust-call" ABI is neither a tuple nor unit', which is perfectly reasonable. This seems like a useful thing to do however, and due to the where clause, args will in fact be a tuple or unit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions