Skip to content

Document From::from impls #137330

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

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open

Conversation

TimTheBig
Copy link

This resolves #51430 by documenting all from impls in lib std and core.
I still need someone to look over a few of the comments to see if the style is correct.

@rustbot
Copy link
Collaborator

rustbot commented Feb 20, 2025

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Amanieu (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added O-linux Operating system: Linux O-solid Operating System: SOLID O-unix Operating system: Unix-like O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Feb 20, 2025

The Miri subtree was changed

cc @rust-lang/miri

Portable SIMD is developed in its own repository. If possible, consider making this change to rust-lang/portable-simd instead.

cc @calebzulawski, @programmerjake

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@fmease fmease changed the title Document from Document From::from impls Feb 20, 2025
@TimTheBig
Copy link
Author

@rustbot label A-docs C-enhancement T-libs-api

@rustbot rustbot added A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Feb 20, 2025
@TimTheBig
Copy link
Author

TimTheBig commented Feb 20, 2025

Should I move Portable SIMD and rust-analyzer changes even though they are small?

@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member

It is generally a good idea to split up large changes. :) You changed a whole bunch of files in rust-analyzer, so yeah that should be split. Miri and clippy have fewer changes, but the fact that there are any changes at all there still contradicts the PR description.

It's too late now, but the best strategy for PRs like this is to start with just a few files, e.g. just core, take the review feedback, and then apply that to the next PRs. That avoids having to re-do large amounts of work when there is overarching feedback.

@rustbot
Copy link
Collaborator

rustbot commented Feb 20, 2025

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Portable SIMD is developed in its own repository. If possible, consider making this change to rust-lang/portable-simd instead.

cc @calebzulawski, @programmerjake

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

@TimTheBig
Copy link
Author

TimTheBig commented Feb 20, 2025

My mistake, I will revert the rust-analyzer changes.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 20, 2025
@rustbot

This comment has been minimized.

@rustbot rustbot removed has-merge-commits PR has merge commits, merge with caution. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 20, 2025
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR requires a lot of changes, I did not get far with reviews, but a lot of the doc comments only explain the body in its rawest form. I feel like fully reviewing this just makes the reviewer do the work of documenting things, so it may be easier to just write PRs with documentation.

Also please disclose whether you generated this documentation, even just partially or as an initial thing that you edited.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 25, 2025
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@Sky9x Sky9x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comments on:

  • Obvious/self explanatory conversions. These comments are redundant with the signature of the method.
  • Internal/private types. These do not need rustdocs.
  • Platform specific code. These do not need rustdocs.

@@ -204,6 +207,7 @@ impl Default for ByteString {
//
// #[unstable(feature = "bstr", issue = "134915")]
// impl From<Vec<u8>> for ByteString {
// /// Make a `ByteString` with `Vec<u8>` as inner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// /// Make a `ByteString` with `Vec<u8>` as inner

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clarifies that it is no copy

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All From conversions between owned buffers like String, Vec, ByteString, OsString, etc are no copy

@@ -212,6 +216,7 @@ impl Default for ByteString {

#[unstable(feature = "bstr", issue = "134915")]
impl From<ByteString> for Vec<u8> {
/// Return the inner `Vec` of the byte string.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Return the inner `Vec` of the byte string.

@@ -728,6 +742,7 @@ impl ExitStatus {

/// Converts a raw `u32` to a type-safe `ExitStatus` by wrapping it without copying.
impl From<u32> for ExitStatus {
/// Wrap `u32` in a type-safe `ExitStatus`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Wrap `u32` in a type-safe `ExitStatus`

@@ -777,12 +792,14 @@ impl ExitCode {
}

impl From<u8> for ExitCode {
/// Convert the `u8` to a `u32` then wrap it in a `ExitCode`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Convert the `u8` to a `u32` then wrap it in a `ExitCode`

fn from(code: u8) -> Self {
ExitCode(u32::from(code))
}
}

impl From<u32> for ExitCode {
/// Wrap the `u32` in a `ExitCode`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Wrap the `u32` in a `ExitCode`

@@ -1265,6 +1265,7 @@ mod thread_name_string {
}

impl From<String> for ThreadNameString {
/// Convert `String` to a `CString` then use that as the `ThreadNameString` inner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Convert `String` to a `CString` then use that as the `ThreadNameString` inner

Comment on lines +695 to +698
/// Try to allocate a `ByteStr`s bytes as a UTF-8 `String`.
///
/// # Errors
/// If `ByteStr` is not valid UTF-8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Try to allocate a `ByteStr`s bytes as a UTF-8 `String`.
///
/// # Errors
/// If `ByteStr` is not valid UTF-8

@@ -193,6 +195,7 @@ pub struct Connection(u32);

#[stable(feature = "rust1", since = "1.0.0")]
impl From<u32> for Connection {
/// Make a `Connection` with `u32` as inner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Make a `Connection` with `u32` as inner

Comment on lines +191 to +194
/// Use `PerformanceCounterInstant` to get instant in nano sec, then make a `Duration` from nanos.
///
/// ## Cost
/// This calls a function that makes an atomic oparation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Use `PerformanceCounterInstant` to get instant in nano sec, then make a `Duration` from nanos.
///
/// ## Cost
/// This calls a function that makes an atomic oparation

???

Co-authored-by: Sky <sky@sky9.dev>
@TimTheBig
Copy link
Author

@Sky9x Thank you for the suggestions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools C-enhancement Category: An issue proposing an enhancement or a PR with one. O-linux Operating system: Linux O-solid Operating System: SOLID O-unix Operating system: Unix-like O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Many From implementations are undocumented