Add pattern matching API to OsStr, second attempt - #160971
Conversation
|
cc @Amanieu, @folkertdev, @sayantn Any special-casing of Miri in the standard library requires review. cc @rust-lang/miri |
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Pull request is feature complete and ready for review. I wanted to create it as a draft to get a CI run (original had problems with windows) without disturbing anyone, but github UI was not cooperative. So much for not disturbing... |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
r? @nia-e -- I probably won't have time to review this large patch set coherently soon. It may be best to start a thread on #t-libs on Zulip and try to find a dedicated reviewer there, and then split this into multiple PRs rather than trying to review this all at the same time. |
|
Each commit mostly makes sense by itself (compiles, tests are passing, etc). I can probably pull out most of the test changes and merge them independently. The rest is at least logically coupled together. Let me poke at #t-libs. |
|
Not seeing a link to rust-lang/libs-team#311 which would be relevant for this. |
std: reduce visibility of some internal OsStr related types
The std::sys::os_str::{Buf, Slice} types are only used within the std crate and not actually exported. Whole `sys` module is private. They don't need to be public. This might result in a better generated code, but more importantly it avoids some compile errors down the line.
This commit is extracted from rust-lang#160971
core: refactor tests/pattern.rs tests Firstly, combine functions and results lists into a single list with `'function => result' `pairs. This makes it easier to match function with its result. Secondly, eliminate `InRange` step so that it's easier to notice series of matches or rejects. I also added a variant to `test_stress_indices` that matches stuff with `|_| true` which wasn't covered. This commit is extracted from rust-lang#160971
std: reduce visibility of some internal OsStr related types
The std::sys::os_str::{Buf, Slice} types are only used within the std crate and not actually exported. Whole `sys` module is private. They don't need to be public. This might result in a better generated code, but more importantly it avoids some compile errors down the line.
This commit is extracted from rust-lang#160971
coretests: Add a few tests for backward multibyte predicate Surprisingly enough there's no rfind tests for multibyte needles, at least it is possible to break this test without breaking anything other test. This commit is extracted from rust-lang#160971
core: refactor tests/pattern.rs tests Firstly, combine functions and results lists into a single list with `'function => result' `pairs. This makes it easier to match function with its result. Secondly, eliminate `InRange` step so that it's easier to notice series of matches or rejects. I also added a variant to `test_stress_indices` that matches stuff with `|_| true` which wasn't covered. This commit is extracted from rust-lang#160971
std: reduce visibility of some internal OsStr related types
The std::sys::os_str::{Buf, Slice} types are only used within the std crate and not actually exported. Whole `sys` module is private. They don't need to be public. This might result in a better generated code, but more importantly it avoids some compile errors down the line.
This commit is extracted from rust-lang#160971
coretests: Add a few tests for backward multibyte predicate Surprisingly enough there's no rfind tests for multibyte needles, at least it is possible to break this test without breaking anything other test. This commit is extracted from rust-lang#160971
core: refactor tests/pattern.rs tests Firstly, combine functions and results lists into a single list with `'function => result' `pairs. This makes it easier to match function with its result. Secondly, eliminate `InRange` step so that it's easier to notice series of matches or rejects. I also added a variant to `test_stress_indices` that matches stuff with `|_| true` which wasn't covered. This commit is extracted from rust-lang#160971
std: reduce visibility of some internal OsStr related types
The std::sys::os_str::{Buf, Slice} types are only used within the std crate and not actually exported. Whole `sys` module is private. They don't need to be public. This might result in a better generated code, but more importantly it avoids some compile errors down the line.
This commit is extracted from rust-lang#160971
coretests: Add a few tests for backward multibyte predicate Surprisingly enough there's no rfind tests for multibyte needles, at least it is possible to break this test without breaking anything other test. This commit is extracted from rust-lang#160971
Rollup merge of #161589 - pacak:private-osstr, r=clarfonthey std: reduce visibility of some internal OsStr related types The std::sys::os_str::{Buf, Slice} types are only used within the std crate and not actually exported. Whole `sys` module is private. They don't need to be public. This might result in a better generated code, but more importantly it avoids some compile errors down the line. This commit is extracted from #160971
Rollup merge of #161592 - pacak:change-pattern-tests, r=nia-e core: refactor tests/pattern.rs tests Firstly, combine functions and results lists into a single list with `'function => result' `pairs. This makes it easier to match function with its result. Secondly, eliminate `InRange` step so that it's easier to notice series of matches or rejects. I also added a variant to `test_stress_indices` that matches stuff with `|_| true` which wasn't covered. This commit is extracted from #160971
|
☔ The latest upstream changes (presumably #161638) made this pull request unmergeable. Please resolve the merge conflicts by rebasing. |
Rollup merge of #161604 - pacak:test-multibyte, r=nia-e coretests: Add a few tests for backward multibyte predicate Surprisingly enough there's no rfind tests for multibyte needles, at least it is possible to break this test without breaking anything other test. This commit is extracted from #160971
View all comments
This is an attempt at reviving #109350
Description
As much as possible I left the original code and commit structure intact. There are a few places where rust code changed - that I had to fix.
Original attempt had several bugs in the implementation - I added tests before the commit that would break them and fixed the problem in the commit that would break them.
New instances are breaking diagnostics in an unexpected way: #160710 #160717, after poking at it I have a rough idea what's wrong. I guess I'll have to look into fixing that myself.Ended up replacing them with associated functions. Breaks too much unrelated code.Original description
This is a sizeable patchset so when reviewing looking at individual commits (rather than the whole changeset) is advisable.
The motivation for this PR is parsing command line arguments. It adds
{starts,ends}_with,strip_{prefix,suffix},{,r}split_onceand split methods to OsStr supportingchar,&strandFnMut(char) -> boolpatterns. (Other methods can be easily added once general consensus for this PR is reached).Note that this PR doesn’t implement #49802 and doesn’t allow OsStr to be a pattern. This is done because:
&OsStras a pattern it can be added at later time.This PR also sort of implements the new Pattern API. As I understand it’s no longer a thing, but I’ve decided to keep the change in because it does allow common interface and code sharing. (Though I have some doubts about the actual interface; for example I question existence of
Searcher::next method). Keep in mind this is just a means to an end so if messing about withcore::str::patternwould be a blocker I can undo those changes.The core idea with this PR is introduction of
core::str_bytes::Bytetype which handles byte slices which are possibly invalid UTF-8.strandOsStrare kind ofBytes. With that, pattern matching has to be implemented only once for Bytes type so that the same matching code doesn’t have to be duplicated forstrandOsStr. Bytes can have Flavours (UTF-8, WTF-8 or unstructured) which allow implementing optimization based onstrbeing valid UTF-8 orOsStron Windows being valid WTF-8.rust-lang/libs-team#311