Skip to content

Conflicting implementations with fn_traits and From #142037

Open
@Nobody-alias-N

Description

@Nobody-alias-N
#![feature(unboxed_closures)]
#![feature(fn_traits)]
#![allow(unused)]
use std::rc::Rc;

struct MyFn {
    cb: Rc<dyn Fn()>,
}

impl FnOnce<()> for MyFn {
    type Output = ();

    extern "rust-call" fn call_once(self, _args: ()) -> Self::Output {
        (self.cb)()
    }
}

impl FnMut<()> for MyFn {
    extern "rust-call" fn call_mut(&mut self, _args: ()) {
        (self.cb)()
    }
}

// // Uncomment this to see the conflict From<F> implementation makes
// impl Fn<()> for MyFn {
//     extern "rust-call" fn call(&self, _args: ()) {
//         (self.cb)()
//     }
// }

// When MyFn implements Fn<()>
// From<F> will also 
// impl From<MyFn> for MyFn {}
impl<F> From<F> for MyFn
where
    F: Fn() + 'static, 
{
    fn from(f: F) -> Self {
        MyFn {
            cb: Rc::new(f),
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.F-unboxed_closures`#![feature(unboxed_closures)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions