-
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
Add documentation to more From::from
implementations.
#89869
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
The above test failure appears to be due to renaming the parameter of |
Hm. I I seem to recall a thread a while back discussing what we want out of the documentation comments on impls like this. I personally don't know that repeating the signature of the impl pretty much directly in the documentation is helpful to those reading it; if editors are able to show that documentation line it seems like they could be convinced to show the signature of the method (which I would guess is more useful, particularly for mostly trivial functions like this). Maybe we should have some policy work in this area so that we can better guide PRs like this -- I certainly have opinions, but it feels like individual PRs being approved/rejected based on the particular reviewer is not a great experience. This PR also adds the new documented constraint for deduplicating keys for the Set/Map From impls which seem pretty obviously like what we'd want to do, but I'd like at least one member of T-libs-api to weigh in there. r? @dtolnay |
For what it's worth, I agree that repeating the signature in the documentation by itself is not especially useful. However,
I believe this has been previously discussed in the context of new conversions to maps/sets, with the general consensus being “it would definitely be a breaking change to do anything else, and consistency is good”. Personally, I'm not a fan of silently discarding data, particularly since |
☔ The latest upstream changes (presumably #90067) made this pull request unmergeable. Please resolve the merge conflicts. |
438187a
to
1c034b7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please pull the BTreeMap
and BTreeSet
documentation about the behavior on duplicates out to a separate PR? I'll bring that up with T-libs-api. I agree with Mark it's likely this is the behavior we want to commit to but I don't think I can do that unilaterally.
For the rest, I'll bump this over to T-libs to work out whether the cost/benefit of maintaining this kind of documentation is the right tradeoff for them.
Thanks!
For users looking at documentation through IDE popups, this gives them relevant information rather than the generic trait documentation wording “Performs the conversion”. For users reading the documentation for a specific type for any reason, this informs them when the conversion may allocate or copy significant memory versus when it is always a move or cheap copy. Notes on specific cases: * The new documentation for `From<T> for T` explains that it is not a conversion at all. * Also documented `impl<T, U> Into<U> for T where U: From<T>`, the other central blanket implementation of conversion. * I did not add documentation to conversions of a specific error type to a more general error type. * I did not add documentation to unstable code. This change was prepared by searching for the text "From<... for" and so may have missed some cases that for whatever reason did not match. I also looked for `Into` impls but did not find any worth documenting by the above criteria.
I have removed the wording about duplicate items. |
Looks good, thank you again for the help! @bors r+ rollup |
📌 Commit 6fd5cf5 has been approved by |
Add documentation to more `From::from` implementations. For users looking at documentation through IDE popups, this gives them relevant information rather than the generic trait documentation wording “Performs the conversion”. For users reading the documentation for a specific type for any reason, this informs them when the conversion may allocate or copy significant memory versus when it is always a move or cheap copy. Notes on specific cases: * The new documentation for `From<T> for T` explains that it is not a conversion at all. * Also documented `impl<T, U> Into<U> for T where U: From<T>`, the other central blanket implementation of conversion. * The new documentation for construction of maps and sets from arrays of keys mentions the handling of duplicates. Future work could be to do this for *all* code paths that convert an iterable to a map or set. * I did not add documentation to conversions of a specific error type to a more general error type. * I did not add documentation to unstable code. This change was prepared by searching for the text "From<... for" and so may have missed some cases that for whatever reason did not match. I also looked for `Into` impls but did not find any worth documenting by the above criteria.
…askrgr Rollup of 8 pull requests Successful merges: - rust-lang#89869 (Add documentation to more `From::from` implementations.) - rust-lang#93479 (Use `optflag` for `--report-time`) - rust-lang#93693 (Suggest deriving required supertraits) - rust-lang#93981 (Fix suggestion to slice if scurtinee is a reference to `Result` or `Option`) - rust-lang#93996 (Do not suggest "is a function" for free variables) - rust-lang#94030 (Correctly mark the span of captured arguments in `format_args!()`) - rust-lang#94031 ([diagnostics] Add mentions to `Copy` types being valid for `union` fields) - rust-lang#94064 (Update dist-x86_64-musl to Ubuntu 20.04) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
For users looking at documentation through IDE popups, this gives them relevant information rather than the generic trait documentation wording “Performs the conversion”. For users reading the documentation for a specific type for any reason, this informs them when the conversion may allocate or copy significant memory versus when it is always a move or cheap copy.
Notes on specific cases:
From<T> for T
explains that it is not a conversion at all.impl<T, U> Into<U> for T where U: From<T>
, the other central blanket implementation of conversion.This change was prepared by searching for the text "From<... for" and so may have missed some cases that for whatever reason did not match. I also looked for
Into
impls but did not find any worth documenting by the above criteria.