Skip to content

Clarify documentation for CStr #113220

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

Merged
merged 1 commit into from
Aug 3, 2023
Merged

Conversation

tgross35
Copy link
Contributor

@tgross35 tgross35 commented Jul 1, 2023

  • Better differentiate summaries for from_bytes_until_nul and from_bytes_with_nul
  • Add some links where they may be helpful

@rustbot
Copy link
Collaborator

rustbot commented Jul 1, 2023

r? @m-ou-se

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added 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 Jul 1, 2023
@tgross35
Copy link
Contributor Author

tgross35 commented Jul 1, 2023

@rustbot label +A-docs

@rustbot rustbot added the A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools label Jul 1, 2023
Copy link
Member

@workingjubilee workingjubilee left a comment

Choose a reason for hiding this comment

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

I like the idea of making these more specific but this shouldn't fudge what it means here.

Comment on lines 298 to 299
/// Creates a C string wrapper from a byte slice that includes one or more
/// nul bytes.
Copy link
Member

@workingjubilee workingjubilee Jul 30, 2023

Choose a reason for hiding this comment

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

Strictly speaking, it is valid to call this on a byte slice with zero \0 present, because the slice describes a safe bound to search in. That makes this technically incorrect. And yes, you can say "but that's the error case", but that's the problem! There's a Result!

In addition, this first line is shown first in many inline editor hints or row-by-row formatted lists and accordingly should be kept ultra-short, so I hesitate at making it so much longer. It's fine if you can't find a way to express that in fewer characters, though.

Comment on lines 345 to 346
/// Creates a C string wrapper from a byte slice terminated by exactly one
/// nul byte.
Copy link
Member

Choose a reason for hiding this comment

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

Same comment on length, though if it really does need to be this long that's okay.

@@ -197,8 +197,8 @@ impl CStr {
///
/// This function will wrap the provided `ptr` with a `CStr` wrapper, which
/// allows inspection and interoperation of non-owned C strings. The total
/// size of the raw C string must be smaller than `isize::MAX` **bytes**
/// in memory due to calling the `slice::from_raw_parts` function.
/// size of the raw C string must be smaller than [`isize::MAX`] **bytes**
Copy link
Member

Choose a reason for hiding this comment

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

The phrase "raw C string" feels weird to me, I don't feel like this documentation adequately describes what it means. That's preexisting though so you don't have to fix it, just noticing.

@workingjubilee
Copy link
Member

workingjubilee commented Jul 30, 2023

r? workingjubilee
@rustbot author

@rustbot rustbot assigned workingjubilee and unassigned m-ou-se Jul 30, 2023
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 30, 2023
* Better differentiate summaries for `from_bytes_until_nul` and
  `from_bytes_with_nul`
* Add some links where they may be helpful
@tgross35
Copy link
Contributor Author

tgross35 commented Aug 2, 2023

Okiedoke I tried to improve some of the things you mentioned, should be ready for another look

@rustbot ready

@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 Aug 2, 2023
@workingjubilee
Copy link
Member

Thanks!

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Aug 2, 2023

📌 Commit c94dc72 has been approved by workingjubilee

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 2, 2023
@bors
Copy link
Collaborator

bors commented Aug 3, 2023

⌛ Testing commit c94dc72 with merge d8bbef5...

@bors
Copy link
Collaborator

bors commented Aug 3, 2023

☀️ Test successful - checks-actions
Approved by: workingjubilee
Pushing d8bbef5 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 3, 2023
@bors bors merged commit d8bbef5 into rust-lang:master Aug 3, 2023
@rustbot rustbot added this to the 1.73.0 milestone Aug 3, 2023
@tgross35 tgross35 deleted the cstr-bytes-docs branch August 3, 2023 04:50
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d8bbef5): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.2%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.7% [-0.7%, -0.7%] 3
Improvements ✅
(secondary)
-0.4% [-0.6%, -0.3%] 3
All ❌✅ (primary) -0.5% [-0.7%, 0.2%] 4

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.5% [1.4%, 3.7%] 2
Regressions ❌
(secondary)
2.5% [2.5%, 2.5%] 1
Improvements ✅
(primary)
-2.0% [-2.2%, -1.8%] 2
Improvements ✅
(secondary)
-3.0% [-3.0%, -3.0%] 1
All ❌✅ (primary) 0.3% [-2.2%, 3.7%] 4

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 647.209s -> 650.497s (0.51%)

@rustbot rustbot added the perf-regression Performance regression. label Aug 3, 2023
@lqd
Copy link
Member

lqd commented Aug 3, 2023

This is a documentation change on libcore/libstd. That does affect metadata during regular compilation, but there's nothing we could do here until this is taken care of, and the single regression is fine if not noise.

@rustbot label: +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Aug 3, 2023
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 merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

7 participants