Uh oh!
There was an error while loading. Please reload this page.
Remove recommendation about idiomatic syntax for Arc::clone - #63252
Conversation
Signed-off-by: Nick Cameron <nrc@ncameron.org>
SimonSapin
commented
Aug 4, 2019
FWIW you call this an advantage but this same criteria also is subjectively considered a disadvantage as part of the motivation for #42137. |
nrc
commented
Aug 4, 2019
Indeed! I believe reasonable people can differ on this point. But I don't think the docs are the right place to discuss it. |
Centril
commented
Aug 4, 2019
I have a few thoughts:
traitCloneRef:Clone{fnclone_ref(&self) -> Self{self.clone()}}impl<'a,T: ?Sized>CloneReffor&'aT{}impl<T: ?Sized>CloneReffor std::rc::Rc<T>{}impl<T: ?Sized>CloneReffor std::rc::Weak<T>{}impl<T: ?Sized>CloneReffor std::sync::Arc<T>{}impl<T: ?Sized>CloneReffor std::sync::Weak<T>{} |
nical
commented
Aug 4, 2019
I can't think of a better place to document the idiomatic use of something than the official documentation of that thing. Now clippy or some official style guide doc would probably do as well. In my opinion, since this is not about re-litigating the decision from rust-lang/rfcs#1954 about idiomatic use of the |
nrc
commented
Aug 4, 2019
I think adding some discussion to either the book or API guidelines would be best (although it is not part of the API as such). We could also add something to the style guide - that is mostly concerned with formatting style, but does have a few recommendations which are close to this one. |
I'm kind of indifferent, though I do think the existing advice is hard to follow (I just forget about it and expect to be able to |
It might be worth just softening the language, to say it may be more readable for smart pointer types to use fully-qualified function names. Or, if clippy/rustfmt doesn't just do this transform for you, maybe it should. |
alexcrichton
commented
Aug 6, 2019
Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
nical
commented
Aug 7, 2019
I would have appreciated if you had moved the recommendation to the API guidelines and/or the style guide as suggested by @nrcbefore going ahead and removing it from the standard doc, or at least filed issues there. |
Gankra
commented
Aug 7, 2019
Drive-by alumni team chime in: I am genuinely surprised that we still haven't grown an inherent method with a different name, like Like yeah it's cute that Clone is the same and that's good to know for composition, but, just let people write what they mean. It's not even that weird, we have plenty of inherent methods which incidentally exactly match the signature of common traits. See: |
rfcbot
commented
Aug 7, 2019
🔔 This is now entering its final comment period, as per the review above. 🔔 |
scottmcm
commented
Aug 9, 2019
I'm 👍 for the idiomatic status to be removed. But I think there'd be value in still talking about the UFCS-style in docs here, especially since it's still in the doctest example with this PR. Strawman: (And since I was pinged above, I would like |
nugend
commented
Aug 14, 2019
Is the |
rfcbot
commented
Aug 17, 2019
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
alexcrichton
commented
Aug 19, 2019
@bors: r+ |
bors
commented
Aug 19, 2019
📌 Commit 47b16b6 has been approved by |
bors
commented
Aug 19, 2019
⌛ Testing commit 47b16b6 with merge 925328e38185508eb8204eccac780d3f4bfaec5a... |
Centril
commented
Aug 19, 2019
@bors retry yielding prio to lockfile PR. |
rust-highfive
commented
Aug 19, 2019
Your PR failed (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
bors
commented
Aug 19, 2019
⌛ Testing commit 47b16b6 with merge f2bb6e7ff023582325c23cd8c4e1363aa2bde701... |
Remove recommendation about idiomatic syntax for Arc::clone I believe we should not make this recommendation. I don't want to argue that `Arc::clone` is less idiomatic than `arc.clone`, but that the choice is not clear cut and that we should not be making this kind of call in the docs. The `.clone()` form has advantages too: it is more succinct, it is more likely to be understood by beginners, and it is more uniform with other `clone` calls, indeed with most other method calls. Whichever approach is better, I think that this discussion belongs in a style guide or textbook, rather than the library docs. We don't talk much about idiomatic code in the docs, this place is pretty exceptional. The recommendation is also not followed in this repo. It is hard to figure out how many calls there are of the `.clone()` form, but there are 1550 uses of `Arc` and only 65 uses of `Arc::clone`. The recommendation has existed for over two years. The recommendation was added in rust-lang#42137, as a result of rust-lang/rfcs#1954. However, note that that RFC was closed because it was not necessary to change the docs (the original RFC proposed a new function instead). So I don't think an RFC is necessary here (and I'm not trying to re-litigate the discussion on that RFC (which favoured `Arc::clone` as idiomatic) in any case). cc @nical (who added the docs in the first place; sorry :-) ) r? @alexcrichton (or someone else on @rust-lang/libs )
Centril
commented
Aug 19, 2019
@bors retry rolled up. |
Rollup of 5 pull requests Successful merges: - #63252 (Remove recommendation about idiomatic syntax for Arc::clone) - #63376 (use different lifetime name for object-lifetime-default elision) - #63620 (Use constraint span when lowering associated types) - #63699 (Fix suggestion from incorrect `move async` to `async move`.) - #63704 ( Fixed: error: unnecessary trailing semicolon) Failed merges: r? @ghost
I believe we should not make this recommendation. I don't want to argue that
Arc::cloneis less idiomatic thanarc.clone, but that the choice is not clear cut and that we should not be making this kind of call in the docs.The
.clone()form has advantages too: it is more succinct, it is more likely to be understood by beginners, and it is more uniform with otherclonecalls, indeed with most other method calls.Whichever approach is better, I think that this discussion belongs in a style guide or textbook, rather than the library docs. We don't talk much about idiomatic code in the docs, this place is pretty exceptional.
The recommendation is also not followed in this repo. It is hard to figure out how many calls there are of the
.clone()form, but there are 1550 uses ofArcand only 65 uses ofArc::clone. The recommendation has existed for over two years.The recommendation was added in #42137, as a result of rust-lang/rfcs#1954. However, note that that RFC was closed because it was not necessary to change the docs (the original RFC proposed a new function instead). So I don't think an RFC is necessary here (and I'm not trying to re-litigate the discussion on that RFC (which favoured
Arc::cloneas idiomatic) in any case).cc @nical (who added the docs in the first place; sorry :-) )
r? @alexcrichton (or someone else on @rust-lang/libs )