Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.

Commit e591b82

Browse files
authored
fix: not generates the wrong location for the error (#824) (#825)
* fix: `not` generates the wrong location for the error (#824) * fix: use `peek_maybe` instead of `peek_inner`
1 parent a283b15 commit e591b82

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/combinator.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,12 +2352,8 @@ where
23522352

23532353
match result {
23542354
Ok(()) => {
2355-
let found = inp.next_inner();
2356-
inp.add_alt(
2357-
[DefaultExpected::SomethingElse],
2358-
found.map(|f| f.into()),
2359-
result_span,
2360-
);
2355+
let found = inp.peek_maybe();
2356+
inp.add_alt([DefaultExpected::SomethingElse], found, result_span);
23612357
Err(())
23622358
}
23632359
Err(()) => Ok(M::bind(|| ())),

src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4001,6 +4001,21 @@ mod tests {
40014001
);
40024002
}
40034003

4004+
#[test]
4005+
fn labelled_not() {
4006+
use crate::{DefaultExpected, LabelError};
4007+
4008+
let parser = any::<_, extra::Err<Rich<_>>>().not().labelled("label");
4009+
4010+
let mut err = LabelError::<&str, _>::expected_found(
4011+
[DefaultExpected::SomethingElse],
4012+
Some('b'.into()),
4013+
SimpleSpan::new((), 0..1),
4014+
);
4015+
LabelError::<&str, _>::label_with(&mut err, "label");
4016+
assert_eq!(parser.parse("b").into_output_errors(), (None, vec![err]));
4017+
}
4018+
40044019
#[test]
40054020
fn state_rewind() {
40064021
use crate::{extra::Full, inspector::TruncateState};

0 commit comments

Comments
 (0)