From ca04d2e00c1baf2e2f99ee460fe939c1772f4915 Mon Sep 17 00:00:00 2001 From: fromtaoyuanhsinchuuuu Date: Thu, 3 Dec 2026 04:06:58 +0800 Subject: [PATCH] Document the Pattern safety guarantee in string challenges --- doc/src/challenges/0010-string.md | 5 +++++ doc/src/challenges/0020-str-pattern-pt1.md | 7 ++++++- doc/src/challenges/0021-str-pattern-pt2.md | 7 ++++++- doc/src/challenges/0022-str-iter.md | 5 ++++- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/doc/src/challenges/0010-string.md b/doc/src/challenges/0010-string.md index 26e493f8dfb8c..e62e38c19cc81 100644 --- a/doc/src/challenges/0010-string.md +++ b/doc/src/challenges/0010-string.md @@ -51,6 +51,11 @@ Verify the memory safety of all public functions that are safe abstractions over 1. `pop` 1. `remove` 1. `remove_matches` (unbounded) + + Any `Pattern` implementation used to verify `remove_matches` must uphold the + [safety contract of `Pattern`](https://doc.rust-lang.org/nightly/std/str/pattern/trait.Pattern.html#safety). + Its searcher's `haystack()` must return the same slice passed to `into_searcher`. + 1. `retain` (unbounded) 1. `insert` 1. `insert_str` (unbounded) diff --git a/doc/src/challenges/0020-str-pattern-pt1.md b/doc/src/challenges/0020-str-pattern-pt1.md index a551ef74bcf90..8d841410e610a 100644 --- a/doc/src/challenges/0020-str-pattern-pt1.md +++ b/doc/src/challenges/0020-str-pattern-pt1.md @@ -47,7 +47,12 @@ Those functions are implemented in (library/core/src/str/mod.rs), but the core o **Important note:** for this challenge, you can assume: 1. The safety and functional correctness of all functions in `slice` module. 2. That all functions in (library/core/src/str/validations.rs) are functionally correct (consistent with the UTF-8 encoding description in https://en.wikipedia.org/wiki/UTF-8). -3. That all the Searchers in (library/core/src/str/iter.rs) are created by the into_searcher(_, haystack) with haystack being a valid UTF-8 string (str). You can assume any UTF-8 string property of haystack. + +The [safety contract of `Pattern`](https://doc.rust-lang.org/nightly/std/str/pattern/trait.Pattern.html#safety) +requires a searcher returned by `into_searcher` to search the supplied haystack. +In particular, `Searcher::haystack()` must return the same `&str` slice passed to +`into_searcher`. Any `Pattern` implementation used in a proof harness must +uphold this guarantee. Verify the safety of the functions in (library/core/src/str/pattern.rs) listed in the next section. diff --git a/doc/src/challenges/0021-str-pattern-pt2.md b/doc/src/challenges/0021-str-pattern-pt2.md index bd209eb072a9c..712b2394d72bf 100644 --- a/doc/src/challenges/0021-str-pattern-pt2.md +++ b/doc/src/challenges/0021-str-pattern-pt2.md @@ -46,7 +46,12 @@ Those functions are implemented in (library/core/src/str/mod.rs), but the core o **Important note:** for this challenge, you can assume: 1. The safety and functional correctness of all functions in `slice` module. 2. That all functions in (library/core/src/str/validations.rs) are functionally correct (consistent with the UTF8 encoding description in https://en.wikipedia.org/wiki/UTF-8). -3. That all the Searchers in (library/core/src/str/iter.rs) are created by the into_searcher(_, haystack) with haystack is a valid utf8 string (str). You can assume any utf8 string property of haystack. + +The [safety contract of `Pattern`](https://doc.rust-lang.org/nightly/std/str/pattern/trait.Pattern.html#safety) +requires a searcher returned by `into_searcher` to search the supplied haystack. +In particular, `Searcher::haystack()` must return the same `&str` slice passed to +`into_searcher`. Any `Pattern` implementation used in a proof harness must +uphold this guarantee. Verify the safety of the functions in (library/core/src/str/pattern.rs) listed in the next section. diff --git a/doc/src/challenges/0022-str-iter.md b/doc/src/challenges/0022-str-iter.md index 8b01d82b6e60e..3d4dfec0bc9f7 100644 --- a/doc/src/challenges/0022-str-iter.md +++ b/doc/src/challenges/0022-str-iter.md @@ -19,7 +19,10 @@ String and `str` types are widely used in Rust programs, so it is important that **Important note:** for this challenge, you can assume: 1. The safety and functional correctness of all functions in `slice` module. -2. The safety and functional correctness of all functions in (library/core/src/str/pattern.rs). +2. The safety and functional correctness of all functions in (library/core/src/str/pattern.rs), + including the [safety contract of `Pattern`](https://doc.rust-lang.org/nightly/std/str/pattern/trait.Pattern.html#safety). + A `Pattern` implementation used in a proof harness must ensure that + `Searcher::haystack()` returns the same slice passed to `into_searcher`. 3. That all functions in (library/core/src/str/validations.rs) are functionally correct (consistent with the UTF-8 encoding description in https://en.wikipedia.org/wiki/UTF-8). 4. That all the Iterators in (library/core/src/str/iter.rs) are derived from a valid UTF-8 string (str) (You can assume any property of valid UTF-8 encoded string).