Uh oh!
There was an error while loading. Please reload this page.
Implement Fn traits for Rc/Arc - #34118
Conversation
rust-highfive
commented
Jun 6, 2016
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
/cc @bluss |
aturon
commented
Jun 7, 2016
Nice! cc @rust-lang/libs, I feel like we considered something like this before but ran into trouble; any concerns? |
alexcrichton
commented
Jun 7, 2016
Note that in the strictest sense this is a breaking change because these traits are |
brson
commented
Jun 10, 2016
I want to object to this feature, but can't think of any technical reasons. What are the parallels to |
@brson there are coherence issues with implementing this for My technical reason for wanting this is that it provides a way to create immutable (owned) closures that can be cloned (currently impossible, see #23501). |
bluss
commented
Jun 10, 2016
It makes sense, cloning closures is a good reason. I haven't needed it since you can clone |
alexcrichton
commented
Jun 21, 2016
The libs team was able to discuss this PR during triage today, but unfortunately we were unable to reach a conclusion. The stickler point was that these traits are |
aturon
commented
Jun 21, 2016
@alexcrichton We should consider a crater run, just to gauge how much impact there actually is. While |
Stebalien
commented
Jun 21, 2016
Also note, unless I'm mistaken, this can't break stable code ( |
sfackler
commented
Jun 21, 2016
Won't this break anything that involves a blanket impl on Fn and an impl on Rc/Arc? |
aturon
commented
Jun 21, 2016
@Stebalien It affects stable code because downstream code gets the effect of @sfackler Yes, that's roughly correct: traitMyTrait{}impl<T:FnOnce()>MyTraitforT{}impl<T>MyTraitforRc<T>{}This code compiles today, and would break if we provided the proposed impls. What I'm trying to find out is how common this situation is. (I imagine in most cases the breakage would be handled by essentially deleting the |
Stebalien
commented
Jun 21, 2016
@aturon, I see. I misunderstood fundamental. |
sfackler
commented
Jun 23, 2016
@aturon but that solution would then break its use by older versions of rustc, right? This seems pretty explicitly like something that we were very aware would be a breaking change when introducing I honestly cringe a bit every time someone sees a breaking change and says "let's run crater". Crater can compile some fraction of the Rust code that is uploaded to crates.io, which is some fraction of Rust code that is publicly available, which is itself some fraction of Rust code that actually exists. It is incredibly useful to ease the transition for changes we have explicitly outlined as causing acceptable breakage (new trait impls etc), but if we keep relying to crater to find all of the breakage that exists when making arbitrary changes, we are going to get bit at some point. I'm worried our stability story is slowly drifting from what was outlined a year ago to "if a tree falls in the woods and I don't personally see anyone standing nearby, did it really make a sound?". |
alexcrichton
commented
Jun 28, 2016
Looks like this causes breakage on crates.io, breaking both iron and rustful. |
Stebalien
commented
Jun 28, 2016
😿 However, iron actually does something that this PR would have made impossible. |
impl Fn/FnMut/FnOnce for Arc/Rc This PR introduces the ability to have `Rc/Arc<F>: Fn(A) -> B where F: Fn(A) -> B` and `Rc/Arc<Fn(A) -> B`. This was previously tried (and failed) in #34118 (comment) due to breakage with crater. But now that the new edition is approaching we might want to try this in edition 2018. We should probably do a new crater run to see how much the breakage has changed since the previous attempt. cc @aturon
This allows one to, e.g., use an
Rcwrapped closure inIterator::map. I would have implementedFnandFnMutforBoxas well but ran into coherence problems (see #33811).