Skip to content

Commit 86d40be

Browse files
jayvdbtyranron
andauthored
Upgrade derive_more crate from 0.99.17 to 2.0 version (#13)
Co-authored-by: Kai Ren <tyranron@gmail.com>
1 parent a20562c commit 86d40be

File tree

7 files changed

+98
-131
lines changed

7 files changed

+98
-131
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ All user visible changes to `cucumber-expressions` crate will be documented in t
1616
- Bumped up [MSRV] to 1.81 because for `#[expect]` attribute usage. ([e1bb9266])
1717
- Upgraded [`nom`] to 8.0 version and [`nom_locate`] to 5.0 version. ([#14], [todo])
1818

19+
### Updated
20+
21+
- [`derive_more`] to 2.0 version. ([#13])
22+
23+
[#13]: /../../pull/13
1924
[#14]: /../../pull/14
2025
[e1bb9266]: /../../commit/e1bb92668617432948ab0faa32232b67d6c530e7
2126
[todo]: /../../commit/todo
@@ -97,7 +102,6 @@ All user visible changes to `cucumber-expressions` crate will be documented in t
97102
- [`derive_more`] minimal version to `0.99.17`. ([#5])
98103

99104
[#5]: /../../pull/5
100-
[`derive_more`]: https://docs.rs/derive_more
101105

102106

103107

@@ -120,7 +124,9 @@ All user visible changes to `cucumber-expressions` crate will be documented in t
120124

121125

122126

127+
[`derive_more`]: https://docs.rs/derive_more
123128
[`nom`]: https://docs.rs/nom
129+
[`nom_locate`]: https://docs.rs/nom_locate
124130
[`regex`]: https://docs.rs/regex
125131
[`Regex`]: https://docs.rs/regex
126132
[`regex-syntax`]: https://docs.rs/regex-syntax

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ rustdoc-args = ["--cfg", "docsrs"]
2626
into-regex = ["dep:either", "dep:regex", "dep:regex-syntax"]
2727

2828
[dependencies]
29-
derive_more = { version = "0.99.17", features = ["as_ref", "deref", "deref_mut", "display", "error", "from", "into"], default-features = false }
29+
derive_more = { version = "2.0", features = ["as_ref", "debug", "deref", "deref_mut", "display", "error", "from"] }
3030
nom = "8.0"
3131
nom_locate = "5.0"
3232

src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//! [1]: https://github.com/cucumber/cucumber-expressions#readme
1717
//! [AST]: https://en.wikipedia.org/wiki/Abstract_syntax_tree
1818
19-
use derive_more::{AsRef, Deref, DerefMut};
19+
use derive_more::with_trait::{AsRef, Deref, DerefMut};
2020
use nom::{error::ErrorKind, Err, Input};
2121
use nom_locate::LocatedSpan;
2222

src/expand/mod.rs

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
2020
pub mod parameters;
2121

22-
use std::{fmt, iter, str, vec};
22+
use std::{iter, str, vec};
2323

24-
use derive_more::{Display, Error, From};
24+
use derive_more::with_trait::{Debug, Display, Error as StdError, From};
2525
use either::Either;
2626
use nom::{AsChar, Input};
2727
use regex::Regex;
@@ -139,41 +139,32 @@ impl<'s> Expression<Spanned<'s>> {
139139
/// [Cucumber Expression][0] and expanding it into a [`Regex`].
140140
///
141141
/// [0]: https://github.com/cucumber/cucumber-expressions#readme
142-
#[derive(Clone, Debug, Display, Error, From)]
143-
pub enum Error<Input>
144-
where
145-
Input: fmt::Display,
146-
{
142+
#[derive(Clone, Debug, Display, From, StdError)]
143+
pub enum Error<Input> {
147144
/// Parsing error.
148-
#[display(fmt = "Parsing failed: {}", _0)]
145+
#[display("Parsing failed: {_0}")]
149146
Parsing(parse::Error<Input>),
150147

151148
/// Expansion error.
152-
#[display(fmt = "Failed to expand regex: {}", _0)]
149+
#[display("Failed to expand regex: {_0}")]
153150
Expansion(ParameterError<Input>),
154151

155152
/// [`Regex`] creation error.
156-
#[display(fmt = "Regex creation failed: {}", _0)]
153+
#[display("Regex creation failed: {_0}")]
157154
Regex(regex::Error),
158155
}
159156

160157
/// Possible [`Parameter`] errors being used in an [`Expression`].
161-
#[derive(Clone, Debug, Display, Error)]
162-
pub enum ParameterError<Input>
163-
where
164-
Input: fmt::Display,
165-
{
158+
#[derive(Clone, Debug, Display, StdError)]
159+
pub enum ParameterError<Input> {
166160
/// [`Parameter`] not found.
167-
#[display(fmt = "Parameter `{}` not found.", _0)]
161+
#[display("Parameter `{_0}` not found")]
168162
NotFound(Input),
169163

170164
/// Failed to rename [`Regex`] capturing group.
171165
#[display(
172-
fmt = "Failed to rename capturing groups in regex `{}` of \
173-
parameter `{}`: {}",
174-
re,
175-
parameter,
176-
err
166+
"Failed to rename capturing groups in regex `{re}` of \
167+
parameter `{parameter}`: {err}"
177168
)]
178169
RenameRegexGroup {
179170
/// [`Parameter`] name.
@@ -195,8 +186,8 @@ where
195186
/// [0]: https://github.com/cucumber/cucumber-expressions#readme
196187
/// [1]: https://git.io/J159T
197188
/// [AST]: https://en.wikipedia.org/wiki/Abstract_syntax_tree
198-
pub trait IntoRegexCharIter<I: fmt::Display> {
199-
/// Type of an [`Iterator`] performing the expansion.
189+
pub trait IntoRegexCharIter<I> {
190+
/// Type of [`Iterator`] performing the expansion.
200191
type Iter: Iterator<Item = Result<char, ParameterError<I>>>;
201192

202193
/// Consumes this [AST] element returning an [`Iterator`] over [`char`]s
@@ -208,7 +199,7 @@ pub trait IntoRegexCharIter<I: fmt::Display> {
208199

209200
impl<I> IntoRegexCharIter<I> for Expression<I>
210201
where
211-
I: Clone + fmt::Display + Input,
202+
I: Clone + Display + Input,
212203
<I as Input>::Item: AsChar,
213204
{
214205
type Iter = ExpressionIter<I>;
@@ -243,7 +234,7 @@ type ExpressionIter<I> = iter::Chain<
243234

244235
impl<I> IntoRegexCharIter<I> for SingleExpression<I>
245236
where
246-
I: Clone + fmt::Display + Input,
237+
I: Clone + Display + Input,
247238
<I as Input>::Item: AsChar,
248239
{
249240
type Iter = SingleExpressionIter<I>;
@@ -289,7 +280,7 @@ type SingleExpressionIter<I> = Either<
289280

290281
impl<I> IntoRegexCharIter<I> for Alternation<I>
291282
where
292-
I: fmt::Display + Input,
283+
I: Display + Input,
293284
<I as Input>::Item: AsChar,
294285
{
295286
type Iter = AlternationIter<I>;
@@ -344,7 +335,7 @@ type AlternationIterInner<I> = iter::Chain<
344335

345336
impl<I> IntoRegexCharIter<I> for Alternative<I>
346337
where
347-
I: fmt::Display + Input,
338+
I: Display + Input,
348339
<I as Input>::Item: AsChar,
349340
{
350341
type Iter = AlternativeIter<I>;
@@ -378,7 +369,7 @@ type AlternativeIter<I> = Either<
378369

379370
impl<I> IntoRegexCharIter<I> for Optional<I>
380371
where
381-
I: fmt::Display + Input,
372+
I: Display + Input,
382373
<I as Input>::Item: AsChar,
383374
{
384375
type Iter = OptionalIter<I>;
@@ -415,7 +406,7 @@ type MapOkChar<I> = fn(char) -> Result<char, ParameterError<I>>;
415406

416407
impl<I> IntoRegexCharIter<I> for Parameter<I>
417408
where
418-
I: Clone + fmt::Display + Input,
409+
I: Clone + Display + Input,
419410
<I as Input>::Item: AsChar,
420411
{
421412
type Iter = ParameterIter<I>;
@@ -483,6 +474,7 @@ type ParameterIter<I> = Either<
483474
/// [`Iterator`] for skipping a last [`Item`].
484475
///
485476
/// [`Item`]: Iterator::Item
477+
#[derive(Debug)]
486478
pub struct SkipLast<Iter: Iterator> {
487479
/// Inner [`Iterator`] to skip the last [`Item`] from.
488480
///
@@ -502,18 +494,6 @@ where
502494
}
503495
}
504496

505-
impl<Iter> fmt::Debug for SkipLast<Iter>
506-
where
507-
Iter: fmt::Debug + Iterator,
508-
Iter::Item: fmt::Debug,
509-
{
510-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
511-
f.debug_struct("SkipLast")
512-
.field("iter", &self.iter)
513-
.finish()
514-
}
515-
}
516-
517497
impl<Iter: Iterator> SkipLast<Iter> {
518498
/// Creates a new [`SkipLast`] [`Iterator`].
519499
pub fn new(iter: Iter) -> Self {

src/expand/parameters.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,8 @@ mod regex_hir {
345345
HirKind::Look(l) => Hir::look(l),
346346
HirKind::Repetition(rep) => Hir::repetition(rep),
347347
HirKind::Capture(mut capture) => {
348-
capture.name = Some(
349-
format!("__{parameter_id}_{}", *group_id_indexer).into(),
350-
);
348+
capture.name =
349+
Some(format!("__{parameter_id}_{group_id_indexer}").into());
351350
*group_id_indexer += 1;
352351

353352
let inner_hir =

src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@
165165
unused_results,
166166
variant_size_differences
167167
)]
168-
// TODO: Remove on next `derive_more` major version.
169-
#![expect(clippy::uninlined_format_args, reason = "`derive_more` expansion")]
170168

171169
pub mod ast;
172170
mod combinator;

0 commit comments

Comments
 (0)