Closed
Description
I tried this code:
#![feature(pattern)]
use core::str::pattern::{Pattern, Searcher, SearchStep};
fn main() {
let mut searcher = "".into_searcher("");
assert_eq!(searcher.next(), SearchStep::Match(0, 0));
assert_eq!(searcher.next(), SearchStep::Done);
assert_eq!(searcher.next(), SearchStep::Done); // <- panics here
assert_eq!(searcher.next(), SearchStep::Done);
}
I expected to see this happen:
The searcher should not return matches after SearchStep::Done
, because the entire haystack has been already covered.
To quote from the documentation:
Returns
Done
if every byte of the haystack has been visited.The stream of
Match
andReject
values up to aDone
will contain index ranges that are adjacent, non-overlapping, covering the whole haystack, and laying on utf8 boundaries.
https://doc.rust-lang.org/std/str/pattern/trait.Searcher.html
Instead, this happened:
Compiling playground v0.0.1 (/playground)
Finished dev [unoptimized + debuginfo] target(s) in 2.10s
Running `target/debug/playground`
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `Match(0, 0)`,
right: `Done`', src/main.rs:9:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Meta
rustc --version --verbose
:
rustc 1.54.0-nightly (79e50bf77 2021-05-10)
binary: rustc
commit-hash: 79e50bf77928f374921a6bcafee3fcff1915f062
commit-date: 2021-05-10
host: x86_64-unknown-linux-gnu
release: 1.54.0-nightly
LLVM version: 12.0.1
Backtrace
Compiling playground v0.0.1 (/playground)
Finished dev [unoptimized + debuginfo] target(s) in 1.91s
Running `target/debug/playground`
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `Match(0, 0)`,
right: `Done`', src/main.rs:9:5
stack backtrace:
0: rust_begin_unwind
at /rustc/4e3e6db011c5b482d2bef8ba02274657f93b5e0d/library/std/src/panicking.rs:515:5
1: core::panicking::panic_fmt
at /rustc/4e3e6db011c5b482d2bef8ba02274657f93b5e0d/library/core/src/panicking.rs:92:14
2: core::panicking::assert_failed_inner
3: core::panicking::assert_failed
at /rustc/4e3e6db011c5b482d2bef8ba02274657f93b5e0d/library/core/src/panicking.rs:117:5
4: playground::main
at ./src/main.rs:9:5
5: core::ops::function::FnOnce::call_once
at /rustc/4e3e6db011c5b482d2bef8ba02274657f93b5e0d/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.