Skip to content

Commit

Permalink
clean up warnings (#1791)
Browse files Browse the repository at this point in the history
* clean up warnings

* clippy

* fix
  • Loading branch information
Geal authored Dec 8, 2024
1 parent 9745930 commit c5c8f49
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
4 changes: 2 additions & 2 deletions src/bytes/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,13 @@ where
/// assert_eq!(esc(r#"12\"34;"#), Ok((";", r#"12\"34"#)));
/// ```
///
pub fn escaped<'a, I: 'a, Error, F, G>(
pub fn escaped<'a, I, Error, F, G>(
normal: F,
control_char: char,
escapable: G,
) -> impl FnMut(I) -> IResult<I, I, Error>
where
I: Clone + crate::traits::Offset + Input,
I: Clone + crate::traits::Offset + Input + 'a,
<I as Input>::Item: crate::traits::AsChar,
F: Parser<I, Error = Error>,
G: Parser<I, Error = Error>,
Expand Down
11 changes: 7 additions & 4 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
//! Parsers are generic over their error type, requiring that it implements
//! the `error::ParseError<Input>` trait.
use crate::internal::{Mode, OutputMode, PResult, Parser};
use crate::internal::{Err, Mode, OutputMode, PResult, Parser};
use crate::lib::std::fmt;

#[cfg(feature = "alloc")]
use crate::alloc::borrow::ToOwned;

#[cfg(feature = "std")]
use crate::internal::IResult;

/// This trait must be implemented by the error type of a nom parser.
///
/// There are already implementations of it for `(Input, ErrorKind)`
Expand Down Expand Up @@ -320,8 +323,6 @@ impl From<VerboseError<&str>> for VerboseError<crate::lib::std::string::String>
}
}

use crate::internal::{Err, IResult};

/// Create a new error from an input position, a static string and an existing error.
/// This is used mainly in the [context] combinator, to add user friendly information
/// to errors when backtracking through a parse tree
Expand Down Expand Up @@ -733,7 +734,6 @@ where
#[cfg(test)]
mod tests {
use super::*;
use crate::character::complete::char;

#[test]
fn context_test() {
Expand Down Expand Up @@ -794,6 +794,9 @@ mod tests {
#[cfg(feature = "alloc")]
#[test]
fn convert_error_panic() {
use crate::character::complete::char;
use crate::internal::IResult;

let input = "";

let _result: IResult<_, _, VerboseError<&str>> = char('x')(input);
Expand Down
24 changes: 12 additions & 12 deletions src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ pub trait Finish<I, O, E> {
/// *warning*: if the result is `Err(Err::Incomplete(_))`, this method will panic.
/// - "complete" parsers: It will not be an issue, `Incomplete` is never used
/// - "streaming" parsers: `Incomplete` will be returned if there's not enough data
/// for the parser to decide, and you should gather more data before parsing again.
/// Once the parser returns either `Ok(_)`, `Err(Err::Error(_))` or `Err(Err::Failure(_))`,
/// you can get out of the parsing loop and call `finish()` on the parser's result
/// for the parser to decide, and you should gather more data before parsing again.
/// Once the parser returns either `Ok(_)`, `Err(Err::Error(_))` or `Err(Err::Failure(_))`,
/// you can get out of the parsing loop and call `finish()` on the parser's result
fn finish(self) -> Result<(I, O), E>;
}

Expand Down Expand Up @@ -83,14 +83,14 @@ impl Needed {
/// It has three cases:
///
/// * `Incomplete` indicates that more data is needed to decide. The `Needed` enum
/// can contain how many additional bytes are necessary. If you are sure your parser
/// is working on full data, you can wrap your parser with the `complete` combinator
/// to transform that case in `Error`
/// can contain how many additional bytes are necessary. If you are sure your parser
/// is working on full data, you can wrap your parser with the `complete` combinator
/// to transform that case in `Error`
/// * `Error` means some parser did not succeed, but another one might (as an example,
/// when testing different branches of an `alt` combinator)
/// when testing different branches of an `alt` combinator)
/// * `Failure` indicates an unrecoverable error. For example, when a prefix has been
/// recognised and the next parser has been confirmed, if that parser fails, then the
/// entire process fails; there are no more parsers to try.
/// recognised and the next parser has been confirmed, if that parser fails, then the
/// entire process fails; there are no more parsers to try.
///
/// Distinguishing `Failure` this from `Error` is only relevant inside the parser's code. For
/// external consumers, both mean that parsing failed.
Expand Down Expand Up @@ -316,10 +316,10 @@ impl Mode for Check {
/// Parser result type
///
/// * `Ok` branch: a tuple of the remaining input data, and the output value.
/// The output value is of the `O` type if the output mode was [Emit], and `()`
/// if the mode was [Check]
/// The output value is of the `O` type if the output mode was [Emit], and `()`
/// if the mode was [Check]
/// * `Err` branch: an error of the `E` type if the erroor mode was [Emit], and `()`
/// if the mode was [Check]
/// if the mode was [Check]
pub type PResult<OM, I, O, E> = Result<
(I, <<OM as OutputMode>::Output as Mode>::Output<O>),
Err<E, <<OM as OutputMode>::Error as Mode>::Output<E>>,
Expand Down
4 changes: 2 additions & 2 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ impl NomRange<usize> for RangeFrom<usize> {
}

fn bounded_iter(&self) -> Self::Bounded {
0..core::usize::MAX
0..usize::MAX
}
}

Expand Down Expand Up @@ -1616,7 +1616,7 @@ impl NomRange<usize> for RangeFull {
}

fn bounded_iter(&self) -> Self::Bounded {
0..core::usize::MAX
0..usize::MAX
}
}

Expand Down
3 changes: 1 addition & 2 deletions tests/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ use nom::number::complete::f32;
use nom::number::complete::f64;
use nom::number::Endianness;
use nom::sequence::{delimited, pair};
use nom::{Err, Needed};
use nom::Err;
use nom::{IResult, Parser};
use std::num::NonZeroUsize;
use std::str;
use std::str::FromStr;

Expand Down

0 comments on commit c5c8f49

Please sign in to comment.