Skip to content

Commit f4e18de

Browse files
committed
chore: resolve winnow deprecations
1 parent 994da48 commit f4e18de

File tree

6 files changed

+48
-70
lines changed

6 files changed

+48
-70
lines changed

src/patch/parse/locator.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use winnow::{
66
ascii::hex_digit1,
77
combinator::{alt, opt, repeat},
8-
PResult, Parser,
8+
ModalResult, Parser,
99
};
1010

1111
use super::{
@@ -15,7 +15,7 @@ use super::{
1515
};
1616
use crate::patch::{PatchId, PatchLocator, PatchOffsetAtom, PatchOffsets};
1717

18-
pub(in super::super) fn patch_locator(input: &mut &str) -> PResult<PatchLocator> {
18+
pub(in super::super) fn patch_locator(input: &mut &str) -> ModalResult<PatchLocator> {
1919
alt((
2020
patch_locator_name,
2121
patch_locator_from_last,
@@ -25,7 +25,7 @@ pub(in super::super) fn patch_locator(input: &mut &str) -> PResult<PatchLocator>
2525
.parse_next(input)
2626
}
2727

28-
fn patch_locator_name(input: &mut &str) -> PResult<PatchLocator> {
28+
fn patch_locator_name(input: &mut &str) -> ModalResult<PatchLocator> {
2929
(patch_name, patch_offsets)
3030
.map(|(patchname, offsets)| PatchLocator {
3131
id: PatchId::Name(patchname),
@@ -34,7 +34,7 @@ fn patch_locator_name(input: &mut &str) -> PResult<PatchLocator> {
3434
.parse_next(input)
3535
}
3636

37-
fn patch_locator_from_last(input: &mut &str) -> PResult<PatchLocator> {
37+
fn patch_locator_from_last(input: &mut &str) -> ModalResult<PatchLocator> {
3838
('^', opt(nonplussed_int), patch_offsets)
3939
.map(|(_, below_last, offsets)| PatchLocator {
4040
id: PatchId::BelowLast(below_last),
@@ -43,7 +43,7 @@ fn patch_locator_from_last(input: &mut &str) -> PResult<PatchLocator> {
4343
.parse_next(input)
4444
}
4545

46-
pub(in super::super) fn patch_locator_top(input: &mut &str) -> PResult<PatchLocator> {
46+
pub(in super::super) fn patch_locator_top(input: &mut &str) -> ModalResult<PatchLocator> {
4747
alt((
4848
('@', patch_offsets).map(|(_, offsets)| PatchLocator {
4949
id: PatchId::Top,
@@ -57,7 +57,7 @@ pub(in super::super) fn patch_locator_top(input: &mut &str) -> PResult<PatchLoca
5757
.parse_next(input)
5858
}
5959

60-
pub(in super::super) fn patch_locator_base(input: &mut &str) -> PResult<PatchLocator> {
60+
pub(in super::super) fn patch_locator_base(input: &mut &str) -> ModalResult<PatchLocator> {
6161
("{base}", patch_offsets)
6262
.map(|(_, offsets)| PatchLocator {
6363
id: PatchId::Base,
@@ -66,48 +66,48 @@ pub(in super::super) fn patch_locator_base(input: &mut &str) -> PResult<PatchLoc
6666
.parse_next(input)
6767
}
6868

69-
pub(in super::super) fn patch_offsets(input: &mut &str) -> PResult<PatchOffsets> {
69+
pub(in super::super) fn patch_offsets(input: &mut &str) -> ModalResult<PatchOffsets> {
7070
repeat::<_, _, Vec<PatchOffsetAtom>, _, _>(0.., patch_offset_atom)
7171
.take()
7272
.map(|s: &str| PatchOffsets(s.to_string()))
7373
.parse_next(input)
7474
}
7575

76-
pub(in super::super) fn patch_offset_atoms(input: &mut &str) -> PResult<Vec<PatchOffsetAtom>> {
76+
pub(in super::super) fn patch_offset_atoms(input: &mut &str) -> ModalResult<Vec<PatchOffsetAtom>> {
7777
repeat(0.., patch_offset_atom).parse_next(input)
7878
}
7979

80-
pub(in super::super) fn patch_offset_atom(input: &mut &str) -> PResult<PatchOffsetAtom> {
80+
pub(in super::super) fn patch_offset_atom(input: &mut &str) -> ModalResult<PatchOffsetAtom> {
8181
alt((patch_offset_atom_plus, patch_offset_atom_tilde)).parse_next(input)
8282
}
8383

84-
fn patch_offset_atom_plus(input: &mut &str) -> PResult<PatchOffsetAtom> {
84+
fn patch_offset_atom_plus(input: &mut &str) -> ModalResult<PatchOffsetAtom> {
8585
('+', opt(unsigned_int))
8686
.map(|(_, n)| PatchOffsetAtom::Plus(n))
8787
.parse_next(input)
8888
}
8989

90-
fn patch_offset_atom_tilde(input: &mut &str) -> PResult<PatchOffsetAtom> {
90+
fn patch_offset_atom_tilde(input: &mut &str) -> ModalResult<PatchOffsetAtom> {
9191
('~', opt(unsigned_int))
9292
.map(|(_, n)| PatchOffsetAtom::Tilde(n))
9393
.parse_next(input)
9494
}
9595

9696
pub(in super::super) fn oid_prefix_offsets(
9797
input: &mut &str,
98-
) -> PResult<(gix::hash::Prefix, PatchOffsets)> {
98+
) -> ModalResult<(gix::hash::Prefix, PatchOffsets)> {
9999
(oid_prefix, patch_offsets).parse_next(input)
100100
}
101101

102-
fn oid_prefix(input: &mut &str) -> PResult<gix::hash::Prefix> {
102+
fn oid_prefix(input: &mut &str) -> ModalResult<gix::hash::Prefix> {
103103
hex_digit1
104104
.try_map(gix::hash::Prefix::from_hex)
105105
.parse_next(input)
106106
}
107107

108108
pub(in super::super) fn sign_number_offsets(
109109
input: &mut &str,
110-
) -> PResult<(Option<Sign>, Option<usize>, PatchOffsets)> {
110+
) -> ModalResult<(Option<Sign>, Option<usize>, PatchOffsets)> {
111111
alt((
112112
(negative_int, patch_offsets)
113113
.map(|(n, offsets)| (Some(Sign::Minus), Some(n.unsigned_abs()), offsets)),

src/patch/parse/name.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
//! Parsing support for [`PatchName`].
44
55
use winnow::{
6-
error::{ContextError, ErrMode, ErrorKind, ParserError},
6+
error::{ContextError, ErrMode, ParserError},
77
stream::Stream,
8-
PResult,
8+
ModalResult,
99
};
1010

1111
use crate::patch::PatchName;
1212

13-
pub(super) fn patch_name(input: &mut &str) -> PResult<PatchName> {
13+
pub(super) fn patch_name(input: &mut &str) -> ModalResult<PatchName> {
1414
let mut iter = input.char_indices().peekable();
1515
let mut start_index = 0;
1616

@@ -50,21 +50,12 @@ pub(super) fn patch_name(input: &mut &str) -> PResult<PatchName> {
5050
let name = input.next_slice(split_offset);
5151

5252
if name.is_empty() {
53-
Err(ErrMode::Backtrack(ContextError::from_error_kind(
54-
input,
55-
ErrorKind::Eof,
56-
)))
53+
Err(ErrMode::Backtrack(ContextError::from_input(input)))
5754
} else if name.ends_with(".lock") {
5855
// Names ending with ".lock" are invalid and there is no recovery.
59-
Err(ErrMode::Cut(ContextError::from_error_kind(
60-
input,
61-
ErrorKind::Verify,
62-
)))
56+
Err(ErrMode::Cut(ContextError::from_input(input)))
6357
} else if name == "@" || name == "{base}" {
64-
Err(ErrMode::Backtrack(ContextError::from_error_kind(
65-
input,
66-
ErrorKind::Verify,
67-
)))
58+
Err(ErrMode::Backtrack(ContextError::from_input(input)))
6859
} else {
6960
// This should be detected above.
7061
debug_assert!(!name.ends_with('.'));

src/patch/parse/numbers.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,44 @@
55
use winnow::{
66
ascii::digit1,
77
combinator::{alt, opt},
8-
PResult, Parser,
8+
ModalResult, Parser,
99
};
1010

1111
use super::Sign;
1212

1313
/// Parse a sign character, i.e. `-` or `+`.
14-
pub(super) fn sign(input: &mut &str) -> PResult<Sign> {
14+
pub(super) fn sign(input: &mut &str) -> ModalResult<Sign> {
1515
alt(('-'.map(|_| Sign::Minus), '+'.map(|_| Sign::Plus))).parse_next(input)
1616
}
1717

1818
/// Parse unsigned int.
1919
///
2020
/// Although the returned value is a [`usize`], it is validated as an [`isize`]. This
2121
/// ensures that potential sign conversions are more likely to succeed.
22-
pub(super) fn unsigned_int(input: &mut &str) -> PResult<usize> {
22+
pub(super) fn unsigned_int(input: &mut &str) -> ModalResult<usize> {
2323
digit1
2424
.try_map(|s: &str| s.parse::<isize>().map(|n| n as usize))
2525
.parse_next(input)
2626
}
2727

2828
/// Parse a negative int. I.e. an int with a leading `-` sign.
29-
pub(super) fn negative_int(input: &mut &str) -> PResult<isize> {
29+
pub(super) fn negative_int(input: &mut &str) -> ModalResult<isize> {
3030
('-', digit1)
3131
.take()
3232
.try_map(|s: &str| s.parse::<isize>())
3333
.parse_next(input)
3434
}
3535

3636
/// Parse a positive int with a leading `+` sign.
37-
pub(super) fn plusative_int(input: &mut &str) -> PResult<isize> {
37+
pub(super) fn plusative_int(input: &mut &str) -> ModalResult<isize> {
3838
('+', digit1)
3939
.take()
4040
.try_map(|s: &str| s.parse::<isize>())
4141
.parse_next(input)
4242
}
4343

4444
/// Parse a signed int, but disallow an explicit `+` sign.
45-
pub(super) fn nonplussed_int(input: &mut &str) -> PResult<isize> {
45+
pub(super) fn nonplussed_int(input: &mut &str) -> ModalResult<isize> {
4646
(opt('-'), digit1)
4747
.take()
4848
.try_map(|s: &str| s.parse::<isize>())

src/patch/parse/range.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@
44
55
use winnow::{
66
combinator::{alt, opt, separated_pair},
7-
PResult, Parser,
7+
ModalResult, Parser,
88
};
99

1010
use super::patch_locator;
1111
use crate::patch::{PatchRange, PatchRangeBounds};
1212

13-
pub(in super::super) fn patch_range(input: &mut &str) -> PResult<PatchRange> {
13+
pub(in super::super) fn patch_range(input: &mut &str) -> ModalResult<PatchRange> {
1414
alt((
1515
patch_range_bounds.map(PatchRange::Range),
1616
patch_locator.map(PatchRange::Single),
1717
))
1818
.parse_next(input)
1919
}
2020

21-
pub(super) fn patch_range_bounds(input: &mut &str) -> PResult<PatchRangeBounds> {
21+
pub(super) fn patch_range_bounds(input: &mut &str) -> ModalResult<PatchRangeBounds> {
2222
separated_pair(opt(patch_locator), "..", opt(patch_locator))
2323
.map(|(begin, end)| PatchRangeBounds { begin, end })
2424
.parse_next(input)

src/patch/parse/revision.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use winnow::{
99
combinator::{alt, delimited, opt, preceded, repeat, terminated},
1010
stream::Stream,
1111
token::{none_of, one_of},
12-
PResult, Parser,
12+
ModalResult, Parser,
1313
};
1414

1515
use super::{
@@ -20,7 +20,7 @@ use super::{
2020
};
2121
use crate::{branchloc::BranchLocator, wrap::partial_ref_name};
2222

23-
pub(in super::super) fn range_revision_spec(input: &mut &str) -> PResult<RangeRevisionSpec> {
23+
pub(in super::super) fn range_revision_spec(input: &mut &str) -> ModalResult<RangeRevisionSpec> {
2424
alt((
2525
(branch_prefix, patch_range_bounds)
2626
.map(|(branch_loc, bounds)| RangeRevisionSpec::BranchRange { branch_loc, bounds }),
@@ -30,7 +30,7 @@ pub(in super::super) fn range_revision_spec(input: &mut &str) -> PResult<RangeRe
3030
.parse_next(input)
3131
}
3232

33-
pub(in super::super) fn single_revision_spec(input: &mut &str) -> PResult<SingleRevisionSpec> {
33+
pub(in super::super) fn single_revision_spec(input: &mut &str) -> ModalResult<SingleRevisionSpec> {
3434
alt((
3535
(branch_prefix, patch_like_spec).map(|(branch_loc, patch_like)| {
3636
SingleRevisionSpec::Branch {
@@ -43,7 +43,7 @@ pub(in super::super) fn single_revision_spec(input: &mut &str) -> PResult<Single
4343
.parse_next(input)
4444
}
4545

46-
fn branch_prefix(input: &mut &str) -> PResult<BranchLocator> {
46+
fn branch_prefix(input: &mut &str) -> ModalResult<BranchLocator> {
4747
terminated(branch_locator, ':').parse_next(input)
4848
}
4949

@@ -58,7 +58,7 @@ impl std::fmt::Display for PrevCheckoutError {
5858

5959
impl std::error::Error for PrevCheckoutError {}
6060

61-
pub(crate) fn branch_locator(input: &mut &str) -> PResult<BranchLocator> {
61+
pub(crate) fn branch_locator(input: &mut &str) -> ModalResult<BranchLocator> {
6262
alt((
6363
delimited("@{-", digit1, "}")
6464
.try_map(|s: &str| s.parse::<usize>())
@@ -77,7 +77,7 @@ pub(crate) fn branch_locator(input: &mut &str) -> PResult<BranchLocator> {
7777
.parse_next(input)
7878
}
7979

80-
fn patch_and_or_git_like_spec(input: &mut &str) -> PResult<SingleRevisionSpec> {
80+
fn patch_and_or_git_like_spec(input: &mut &str) -> ModalResult<SingleRevisionSpec> {
8181
use std::cmp::Ordering;
8282

8383
let start_checkpoint = input.checkpoint();
@@ -111,20 +111,20 @@ fn patch_and_or_git_like_spec(input: &mut &str) -> PResult<SingleRevisionSpec> {
111111
}
112112
}
113113

114-
pub(in super::super) fn patch_like_spec(input: &mut &str) -> PResult<PatchLikeSpec> {
114+
pub(in super::super) fn patch_like_spec(input: &mut &str) -> ModalResult<PatchLikeSpec> {
115115
(patch_locator, git_revision_suffix)
116116
.map(|(patch_loc, suffix)| PatchLikeSpec { patch_loc, suffix })
117117
.parse_next(input)
118118
}
119119

120-
fn git_like_spec(input: &mut &str) -> PResult<String> {
120+
fn git_like_spec(input: &mut &str) -> ModalResult<String> {
121121
(partial_ref_name, git_revision_suffix)
122122
.take()
123123
.map(|s| s.to_string())
124124
.parse_next(input)
125125
}
126126

127-
fn git_revision_suffix(input: &mut &str) -> PResult<GitRevisionSuffix> {
127+
fn git_revision_suffix(input: &mut &str) -> ModalResult<GitRevisionSuffix> {
128128
repeat::<_, _, Vec<&str>, _, _>(
129129
0..,
130130
alt((
@@ -139,23 +139,23 @@ fn git_revision_suffix(input: &mut &str) -> PResult<GitRevisionSuffix> {
139139
.map(|suffix: &str| GitRevisionSuffix(suffix.to_string()))
140140
}
141141

142-
fn at_braced<'s>(input: &mut &'s str) -> PResult<&'s str> {
142+
fn at_braced<'s>(input: &mut &'s str) -> ModalResult<&'s str> {
143143
preceded('@', braced).parse_next(input)
144144
}
145145

146-
fn caret_braced<'s>(input: &mut &'s str) -> PResult<&'s str> {
146+
fn caret_braced<'s>(input: &mut &'s str) -> ModalResult<&'s str> {
147147
preceded('^', braced).parse_next(input)
148148
}
149149

150-
fn caret_number(input: &mut &str) -> PResult<Option<usize>> {
150+
fn caret_number(input: &mut &str) -> ModalResult<Option<usize>> {
151151
preceded('^', opt(unsigned_int)).parse_next(input)
152152
}
153153

154-
pub(crate) fn tilde_number(input: &mut &str) -> PResult<Option<usize>> {
154+
pub(crate) fn tilde_number(input: &mut &str) -> ModalResult<Option<usize>> {
155155
preceded('~', opt(unsigned_int)).parse_next(input)
156156
}
157157

158-
fn braced<'s>(input: &mut &'s str) -> PResult<&'s str> {
158+
fn braced<'s>(input: &mut &'s str) -> ModalResult<&'s str> {
159159
delimited(
160160
'{',
161161
take_escaped(none_of(['\\', '{', '}']), '\\', one_of(['\\', '{', '}'])),

src/wrap/partialrefname.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
use std::str::FromStr;
44

55
use winnow::{
6-
error::{ContextError, ErrMode, ErrorKind, ParserError},
6+
error::{ContextError, ErrMode, ParserError},
77
stream::Stream,
8-
PResult, Parser,
8+
ModalResult, Parser,
99
};
1010

1111
/// A partial git reference name.
@@ -53,7 +53,7 @@ impl FromStr for PartialRefName {
5353
}
5454
}
5555

56-
pub(crate) fn partial_ref_name(input: &mut &str) -> PResult<PartialRefName> {
56+
pub(crate) fn partial_ref_name(input: &mut &str) -> ModalResult<PartialRefName> {
5757
let mut iter = input.iter_offsets().peekable();
5858
let mut start_index = 0;
5959
let mut prev = None;
@@ -101,22 +101,9 @@ pub(crate) fn partial_ref_name(input: &mut &str) -> PResult<PartialRefName> {
101101

102102
let name = input.next_slice(split_offset);
103103

104-
if name.is_empty() {
105-
Err(ErrMode::Backtrack(ContextError::from_error_kind(
106-
input,
107-
ErrorKind::Eof,
108-
)))
109-
} else if name == "-" {
110-
Err(ErrMode::Backtrack(ContextError::from_error_kind(
111-
input,
112-
ErrorKind::Verify,
113-
)))
114-
} else if name.ends_with(".lock") {
104+
if name.is_empty() || name == "-" || name.ends_with(".lock") {
115105
// Names ending with ".lock" are invalid and there is no recovery.
116-
Err(ErrMode::Cut(ContextError::from_error_kind(
117-
input,
118-
ErrorKind::Verify,
119-
)))
106+
Err(ErrMode::Cut(ContextError::from_input(input)))
120107
} else {
121108
gix::refs::PartialName::try_from(name).expect("parser only allows valid names");
122109
Ok(PartialRefName(name.to_string()))

0 commit comments

Comments
 (0)