Skip to content

Unboxed closure + traits bug #18453

Closed
@carllerche

Description

@carllerche

I am not exactly sure what is going on in this bug, so sorry for the vague title. I do have a repro though. The highlighted clone is what causes the issue here.

#![feature(unboxed_closures)]

use std::sync::Arc;

pub trait Foo<M: Send> : Send {
    fn foo(&mut self, msg: M);
}

impl<M: Send, F: Send + FnMut(M)> Foo<M> for F {
    fn foo(&mut self, msg: M) {
        self.call_mut((msg,));
    }
}

pub struct Both<M, F> {
    inner: Arc<(M, F)>,
}

impl<M: Send, F: Foo<M>> Clone for Both<M, F> {
    fn clone(&self) -> Both<M, F> {
        Both { inner: self.inner.clone() }
    }
}

fn repro1<M: Send, F: Foo<M>>(_both: Both<M, F>) {
}

fn repro2<M: Send + Sync, F: Sync + Foo<M>>(msg: M, foo: F) {
    let both = Both { inner: Arc::new((msg, foo)) };
    repro1(both.clone()); // <--- This clone causes problem
}

pub fn main() {
    println!("hello");
}

Gives me the following output:

rustc fnmut.rs
fnmut.rs:30:5: 30:11 error: the trait `core::ops::FnMut<(M),()>` is not implemented for the type `F`
fnmut.rs:30     repro1(both.clone()); // <--- This clone causes problem
                ^~~~~~
fnmut.rs:30:5: 30:11 note: the trait `core::ops::FnMut` must be implemented because it is required by `repro1`
fnmut.rs:30     repro1(both.clone()); // <--- This clone causes problem
                ^~~~~~
error: aborting due to previous error

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions