diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:50 +0000 |
commit | 9835e2ae736235810b4ea1c162ca5e65c547e770 (patch) | |
tree | 3fcebf40ed70e581d776a8a4c65923e8ec20e026 /vendor/nom/src/sequence | |
parent | Releasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff) | |
download | rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/nom/src/sequence')
-rw-r--r-- | vendor/nom/src/sequence/mod.rs | 11 | ||||
-rw-r--r-- | vendor/nom/src/sequence/tests.rs | 18 |
2 files changed, 27 insertions, 2 deletions
diff --git a/vendor/nom/src/sequence/mod.rs b/vendor/nom/src/sequence/mod.rs index 100c63f90..735ab45cc 100644 --- a/vendor/nom/src/sequence/mod.rs +++ b/vendor/nom/src/sequence/mod.rs @@ -252,8 +252,17 @@ macro_rules! tuple_trait_inner( tuple_trait!(FnA A, FnB B, FnC C, FnD D, FnE E, FnF F, FnG G, FnH H, FnI I, FnJ J, FnK K, FnL L, FnM M, FnN N, FnO O, FnP P, FnQ Q, FnR R, FnS S, FnT T, FnU U); +// Special case: implement `Tuple` for `()`, the unit type. +// This can come up in macros which accept a variable number of arguments. +// Literally, `()` is an empty tuple, so it should simply parse nothing. +impl<I, E: ParseError<I>> Tuple<I, (), E> for () { + fn parse(&mut self, input: I) -> IResult<I, (), E> { + Ok((input, ())) + } +} + ///Applies a tuple of parsers one by one and returns their results as a tuple. -/// +///There is a maximum of 21 parsers /// ```rust /// # use nom::{Err, error::ErrorKind}; /// use nom::sequence::tuple; diff --git a/vendor/nom/src/sequence/tests.rs b/vendor/nom/src/sequence/tests.rs index 201579be4..30ad0d678 100644 --- a/vendor/nom/src/sequence/tests.rs +++ b/vendor/nom/src/sequence/tests.rs @@ -1,6 +1,6 @@ use super::*; use crate::bytes::streaming::{tag, take}; -use crate::error::ErrorKind; +use crate::error::{Error, ErrorKind}; use crate::internal::{Err, IResult, Needed}; use crate::number::streaming::be_u16; @@ -272,3 +272,19 @@ fn tuple_test() { Err(Err::Error(error_position!(&b"jk"[..], ErrorKind::Tag))) ); } + +#[test] +fn unit_type() { + assert_eq!( + tuple::<&'static str, (), Error<&'static str>, ()>(())("abxsbsh"), + Ok(("abxsbsh", ())) + ); + assert_eq!( + tuple::<&'static str, (), Error<&'static str>, ()>(())("sdfjakdsas"), + Ok(("sdfjakdsas", ())) + ); + assert_eq!( + tuple::<&'static str, (), Error<&'static str>, ()>(())(""), + Ok(("", ())) + ); +} |