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

Implement ByteStr and ByteString types #135073

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

Conversation

joshtriplett
Copy link
Member

Approved ACP: rust-lang/libs-team#502
Tracking issue: #134915

These types represent human-readable strings that are conventionally,
but not always, UTF-8. The Debug impl prints non-UTF-8 bytes using
escape sequences, and the Display impl uses the Unicode replacement
character.

This is a minimal implementation of these types and associated trait
impls. It does not add any helper methods to other types such as [u8]
or Vec<u8>.

I've omitted a few implementations of AsRef, AsMut, and Borrow,
when those would be the second implementation for a type (counting the
T impl), to avoid potential inference failures. We can attempt to add
more impls later in standalone commits, and run them through crater.

In addition to the bstr feature, I've added a bstr_internals feature
for APIs provided by core for use by alloc but not currently
intended for stabilization.

This API and its implementation are based heavily on the bstr crate
by Andrew Gallant (@BurntSushi).

r? @BurntSushi

@joshtriplett joshtriplett added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jan 3, 2025
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 3, 2025
@rust-log-analyzer

This comment has been minimized.

@joshtriplett

This comment was marked as resolved.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@joshtriplett

This comment was marked as resolved.

@rust-log-analyzer

This comment has been minimized.

@Mark-Simulacrum

This comment was marked as resolved.

@joshtriplett joshtriplett added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. needs-crater This change needs a crater run to check for possible breakage in the ecosystem. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 5, 2025
@joshtriplett joshtriplett force-pushed the bstr branch 2 times, most recently from b539a8c to f035281 Compare January 5, 2025 16:51
@rust-log-analyzer

This comment has been minimized.

@craterbot
Copy link
Collaborator

🚧 Experiment pr-135073-1 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-135073-1 is completed!
📊 106 regressed and 0 fixed (2028 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Jan 7, 2025
Approved ACP: rust-lang/libs-team#502
Tracking issue: rust-lang#134915

These types represent human-readable strings that are conventionally,
but not always, UTF-8. The `Debug` impl prints non-UTF-8 bytes using
escape sequences, and the `Display` impl uses the Unicode replacement
character.

This is a minimal implementation of these types and associated trait
impls. It does not add any helper methods to other types such as `[u8]`
or `Vec<u8>`.

I've omitted a few implementations of `AsRef`, `AsMut`, `Borrow`,
`From`, and `PartialOrd`, when those would be the second implementation
for a type (counting the `T` impl) or otherwise may cause inference
failures. These impls are important, but we can attempt to add them
later in standalone commits, and run them through crater.

In addition to the `bstr` feature, I've added a `bstr_internals` feature
for APIs provided by `core` for use by `alloc` but not currently
intended for stabilization.

This API and its implementation are based *heavily* on the `bstr` crate
by Andrew Gallant (@BurntSushi).
The Deref brings in the documentation from slice, so it has the same
issue as slice.
For now, apply `no_global_oom_handling` to all of
library/alloc/src/bstr.rs . We can make it more fine-grained later.
@joshtriplett
Copy link
Member Author

@bors try

@bors
Copy link
Contributor

bors commented Jan 12, 2025

⌛ Trying commit 76780fa with merge cd474b1...

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 12, 2025
Implement `ByteStr` and `ByteString` types

Approved ACP: rust-lang/libs-team#502
Tracking issue: rust-lang#134915

These types represent human-readable strings that are conventionally,
but not always, UTF-8. The `Debug` impl prints non-UTF-8 bytes using
escape sequences, and the `Display` impl uses the Unicode replacement
character.

This is a minimal implementation of these types and associated trait
impls. It does not add any helper methods to other types such as `[u8]`
or `Vec<u8>`.

I've omitted a few implementations of `AsRef`, `AsMut`, and `Borrow`,
when those would be the second implementation for a type (counting the
`T` impl), to avoid potential inference failures. We can attempt to add
more impls later in standalone commits, and run them through crater.

In addition to the `bstr` feature, I've added a `bstr_internals` feature
for APIs provided by `core` for use by `alloc` but not currently
intended for stabilization.

This API and its implementation are based *heavily* on the `bstr` crate
by Andrew Gallant (`@BurntSushi).`

r? `@BurntSushi`
@bors
Copy link
Contributor

bors commented Jan 12, 2025

☀️ Try build successful - checks-actions
Build commit: cd474b1 (cd474b13e69f2f8e9a16c20b9cc28edd1f4110e7)

@joshtriplett
Copy link
Member Author

Some analysis on some of the remaining crater items:

Note that some of these manifest as an error about Borrow or AsRef, but they're actually about From impls.

Under build failed (unknown):

  • Several old git repos use an old git commit version of MoonZoon that has unnecessary .into() calls; the current version no longer seems to have those.
  • argparse-rs (used by a couple of crates) contains unnecessary .into() calls. This is a ten-year-old argument parsing crate that unconditionally prints its arguments when run. I don't think it's a blocker.
  • One project uses an old non-upstream git branch of yew that has unnecessary .into() calls. This doesn't appear to be an issue in any released version.
  • A couple of crates use rust_json, which has unnecessary .into() calls; this is already fixed in the current git version and I've requested a publish of that version.
  • One project uses an old version of a crate bevy_gltf_components from Blenvy which has unnecessary .into() calls. The current version has fixed this.
  • One project uses boilerpipe, which has one unnecessary .into() call. I've submitted a PR to fix this.

Under build compiler-error(E0283):

  • index_alloc has a function with a very broad signature that accepts any impl of From, and code using it can break with the introduction of any new impl of From. I've reported this.
  • PyPirv has an unnecessary .into() call; I've submitted a PR for this.

I'm going to go ahead and remove some more From impls for now, even though those impls are going to be annoying to do without.

@joshtriplett
Copy link
Member Author

@bors try

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 12, 2025
Implement `ByteStr` and `ByteString` types

Approved ACP: rust-lang/libs-team#502
Tracking issue: rust-lang#134915

These types represent human-readable strings that are conventionally,
but not always, UTF-8. The `Debug` impl prints non-UTF-8 bytes using
escape sequences, and the `Display` impl uses the Unicode replacement
character.

This is a minimal implementation of these types and associated trait
impls. It does not add any helper methods to other types such as `[u8]`
or `Vec<u8>`.

I've omitted a few implementations of `AsRef`, `AsMut`, and `Borrow`,
when those would be the second implementation for a type (counting the
`T` impl), to avoid potential inference failures. We can attempt to add
more impls later in standalone commits, and run them through crater.

In addition to the `bstr` feature, I've added a `bstr_internals` feature
for APIs provided by `core` for use by `alloc` but not currently
intended for stabilization.

This API and its implementation are based *heavily* on the `bstr` crate
by Andrew Gallant (`@BurntSushi).`

r? `@BurntSushi`
@bors
Copy link
Contributor

bors commented Jan 12, 2025

⌛ Trying commit 22a4ec3 with merge 94d9044...

@bors
Copy link
Contributor

bors commented Jan 12, 2025

☀️ Try build successful - checks-actions
Build commit: 94d9044 (94d9044c53e7ebf518ede2bec35f06c51ca83f62)

@joshtriplett
Copy link
Member Author

@craterbot
Copy link
Collaborator

👌 Experiment pr-135073-2 created and queued.
🤖 Automatically detected try build 94d9044
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 12, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-135073-2 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-135073-2 is completed!
📊 0 regressed and 0 fixed (167 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Jan 13, 2025
@joshtriplett
Copy link
Member Author

joshtriplett commented Jan 13, 2025

Well, that's definitive.

This is ready for review.

@joshtriplett joshtriplett removed the needs-crater This change needs a crater run to check for possible breakage in the ecosystem. label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants