Conflicting implementations with `fn_traits` and `From`
Open
Nobody has claimed this yet.
A-trait-system
C-bug
F-unboxed_closures
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
#![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),
}
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by compiling the minimal reproducer in the issue with and without the Fn implementation, then inspect the compiler's conflicting-implementation diagnostic. Determine the intended coherence behavior for the Fn and From implementations; done means the issue's expected behavior is established and covered by an appropriate compiler test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100