-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove recommendation about idiomatic syntax for Arc::clone #63252
Conversation
Signed-off-by: Nick Cameron <nrc@ncameron.org>
FWIW you call this an advantage but this same criteria also is subjectively considered a disadvantage as part of the motivation for #42137. |
Indeed! I believe reasonable people can differ on this point. But I don't think the docs are the right place to discuss it. |
I have a few thoughts:
trait CloneRef : Clone {
fn clone_ref(&self) -> Self { self.clone() }
}
impl<'a, T: ?Sized> CloneRef for &'a T {}
impl<T: ?Sized> CloneRef for std::rc::Rc<T> {}
impl<T: ?Sized> CloneRef for std::rc::Weak<T> {}
impl<T: ?Sized> CloneRef for std::sync::Arc<T> {}
impl<T: ?Sized> CloneRef for std::sync::Weak<T> {} |
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 |
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. |
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. |
I would have appreciated if you had moved the recommendation to the API guidelines and/or the style guide as suggested by @nrc before going ahead and removing it from the standard doc, or at least filed issues there. |
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: |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
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 |
Is the |
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. |
@bors: r+ |
📌 Commit 47b16b6 has been approved by |
⌛ Testing commit 47b16b6 with merge 925328e38185508eb8204eccac780d3f4bfaec5a... |
@bors retry yielding prio to lockfile PR. |
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 |
⌛ 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 )
@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::clone
is 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 otherclone
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 ofArc
and 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::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 )