Skip to content
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 slice to the stack allocated string comment #104436

Merged

Conversation

ismailmaj
Copy link
Contributor

Precise that the "stack allocated string" is not a string but a string slice.

@rustbot label +A-docs

@rustbot
Copy link
Collaborator

rustbot commented Nov 15, 2022

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Mark-Simulacrum (or someone else) soon.

Please see the contribution instructions for more information.

@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 Nov 15, 2022
@rustbot
Copy link
Collaborator

rustbot commented Nov 15, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rustbot rustbot added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Nov 15, 2022
@CryZe
Copy link
Contributor

CryZe commented Nov 15, 2022

I'm not sure that I would agree that it's wrong. A byte array on the stack that's valid UTF-8 is a stack allocated string, just not a "String".

@ismailmaj
Copy link
Contributor Author

I'm not sure that I would agree that it's wrong. A byte array on the stack that's valid UTF-8 is a stack allocated string, just not a "String".

The code example doesn't mention &str anywhere so I got confused by "stack allocated string".
I assumed, for a moment, that it was a stack allocated String.

Type hinting sparkle_heart could also help.

@Mark-Simulacrum
Copy link
Member

I would prefer the explicitly annotated type if that helps you, I think; I'm not convinced this is a good clarification. In particular the string slice is very frequently stack "allocated" (i.e., the (ptr, len) pair), this is specifically describing the backing bytes, which I would not call a string slice.

@Mark-Simulacrum Mark-Simulacrum 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 Nov 20, 2022
@ismailmaj
Copy link
Contributor Author

This makes sense, I wouldn't think this is wanted if from_utf8 wasn't also implemented for String.

The str version also comes first when searching for from_utf8 on Google.

That comment made me think an owned String can be stack allocated.

I think this change could help people that might experience my situation.

@Mark-Simulacrum Mark-Simulacrum 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 Nov 21, 2022
@Mark-Simulacrum
Copy link
Member

r=me with commits squashed, thanks!

https://rustc-dev-guide.rust-lang.org/git.html#advanced-rebasing has some guidance on how to squash if you want it.

@ismailmaj ismailmaj force-pushed the add-slice-to-stack-allocated-string-comment branch from c962e49 to 005c6df Compare November 21, 2022 09:38
@Mark-Simulacrum
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 29, 2022

📌 Commit 005c6df has been approved by Mark-Simulacrum

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 Nov 29, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 29, 2022
…ated-string-comment, r=Mark-Simulacrum

Add slice to the stack allocated string comment

Precise that the "stack allocated string" is not a string but a string slice.

`@rustbot` label +A-docs
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 30, 2022
…iaskrgr

Rollup of 14 pull requests

Successful merges:

 - rust-lang#103876 (type alias impl trait: add tests showing that hidden type only outlives lifetimes that occur in bounds)
 - rust-lang#104427 (Explain why `rematch_impl` fails to be infallible)
 - rust-lang#104436 (Add slice to the stack allocated string comment)
 - rust-lang#104523 (Don't use periods in target names)
 - rust-lang#104627 (Print all features with --print target-features)
 - rust-lang#104911 (Make inferred_outlives_crate return Clause)
 - rust-lang#105002 (Add `PathBuf::as_mut_os_string` and `Path::as_mut_os_str`)
 - rust-lang#105023 (Statics used in reachable function's inline asm are reachable)
 - rust-lang#105045 (`rustc_ast_{passes,pretty}`: remove `ref` patterns)
 - rust-lang#105049 (Hermit: Minor build fixes)
 - rust-lang#105051 (Replace a macro with a function)
 - rust-lang#105062 (rustdoc: use shorthand background for rustdoc toggle CSS)
 - rust-lang#105066 (move `candidate_from_obligation` out of assembly)
 - rust-lang#105068 (Run patchelf also on rust-analyzer-proc-macro-srv.)

Failed merges:

 - rust-lang#105050 (Remove useless borrows and derefs)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit e4d1fe7 into rust-lang:master Nov 30, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 30, 2022
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 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.

5 participants