Skip to content

Implement SliceIndex for ByteStr #138381

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 2 commits into from
Apr 5, 2025
Merged

Conversation

thaliaarchi
Copy link
Contributor

@thaliaarchi thaliaarchi commented Mar 12, 2025

Implement Index and IndexMut for ByteStr in terms of SliceIndex. Implement it for the same types that &[u8] supports (a superset of those supported for &str, which does not have usize and ops::IndexRange).

At the same time, move compare and index traits to a separate file in the bstr module, to give it more space to grow as more functionality is added (e.g., iterators and string-like ops). Order the items in bstr/traits.rs similarly to str/traits.rs.

cc @joshtriplett

ByteStr/ByteString tracking issue: #134915

This parallels the layout of `core::str`.
@rustbot
Copy link
Collaborator

rustbot commented Mar 12, 2025

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Mar 12, 2025
@rust-log-analyzer

This comment has been minimized.

@joshtriplett
Copy link
Member

LGTM, once it passes CI.

@thaliaarchi
Copy link
Contributor Author

thaliaarchi commented Mar 12, 2025

I needed to update snapshots for UI tests. Unfortunately, I think the diagnostics are now slightly worse. If these tests are on stable, they shouldn't be shown ByteStr.

I think it's also related to these impls being transitive: the index type implements SliceIndex<_>, then slice types implement Index for all types which implement SliceIndex<Self>. It would be better for suggestions to filter the index types to just those who implement SliceIndex<_> for the container.

@thaliaarchi
Copy link
Contributor Author

@joshtriplett CI passed

@Mark-Simulacrum
Copy link
Member

r? @joshtriplett

@thaliaarchi
Copy link
Contributor Author

@joshtriplett Hey, friendly two-week ping :). Would you mind taking a look at the update since your last review? Thanks!

@thaliaarchi
Copy link
Contributor Author

@joshtriplett Since you approved it, I was told I can r= it?

@bors r=joshtriplett rollup

@bors
Copy link
Collaborator

bors commented Apr 5, 2025

@thaliaarchi: 🔑 Insufficient privileges: Not in reviewers

@bors
Copy link
Collaborator

bors commented Apr 5, 2025

@thaliaarchi: 🔑 Insufficient privileges: not in try users

@Noratrieb
Copy link
Member

@bors r=joshtriplett rollup

can you open an issue for the diagnostics that got worse afterwards?

@bors
Copy link
Collaborator

bors commented Apr 5, 2025

📌 Commit 9d379e1 has been approved by joshtriplett

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 Apr 5, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 5, 2025
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#138368 (KCFI: Add KCFI arity indicator support)
 - rust-lang#138381 (Implement `SliceIndex` for `ByteStr`)
 - rust-lang#139092 (Move `fd` into `std::sys`)
 - rust-lang#139398 (Change notifications for Exploit Mitigations PG)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 56ffb43 into rust-lang:master Apr 5, 2025
6 checks passed
@rustbot rustbot added this to the 1.88.0 milestone Apr 5, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 5, 2025
Rollup merge of rust-lang#138381 - thaliaarchi:bstr-sliceindex, r=joshtriplett

Implement `SliceIndex` for `ByteStr`

Implement `Index` and `IndexMut` for `ByteStr` in terms of `SliceIndex`. Implement it for the same types that `&[u8]` supports (a superset of those supported for `&str`, which does not have `usize` and `ops::IndexRange`).

At the same time, move compare and index traits to a separate file in the `bstr` module, to give it more space to grow as more functionality is added (e.g., iterators and string-like ops). Order the items in `bstr/traits.rs` similarly to `str/traits.rs`.

cc `@joshtriplett`

`ByteStr`/`ByteString` tracking issue: rust-lang#134915
@thaliaarchi thaliaarchi deleted the bstr-sliceindex branch April 5, 2025 19:02
@thaliaarchi
Copy link
Contributor Author

can you open an issue for the diagnostics that got worse afterwards?

Opened as #139424.

github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this pull request Apr 10, 2025
…htriplett

Implement `SliceIndex` for `ByteStr`

Implement `Index` and `IndexMut` for `ByteStr` in terms of `SliceIndex`. Implement it for the same types that `&[u8]` supports (a superset of those supported for `&str`, which does not have `usize` and `ops::IndexRange`).

At the same time, move compare and index traits to a separate file in the `bstr` module, to give it more space to grow as more functionality is added (e.g., iterators and string-like ops). Order the items in `bstr/traits.rs` similarly to `str/traits.rs`.

cc `@joshtriplett`

`ByteStr`/`ByteString` tracking issue: rust-lang#134915
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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