Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove extraneous Input::Error trait bounds #353

Merged
merged 2 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions benches/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,13 @@ fn is_http_version(c: u8) -> bool {
fn end_of_line<'a, Input>() -> impl Parser<Input, Output = u8>
where
Input: RangeStream<Token = u8, Range = &'a [u8]>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
(token(b'\r'), token(b'\n')).map(|_| b'\r').or(token(b'\n'))
}

fn message_header<'a, Input>() -> impl Parser<Input, Output = Header<'a>>
where
Input: RangeStream<Token = u8, Range = &'a [u8]>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
let message_header_line = (
take_while1(is_horizontal_space),
Expand All @@ -103,7 +101,6 @@ type HttpRequest<'a> = (Request<'a>, Vec<Header<'a>>);
fn parse_http_request<'a, Input>(input: Input) -> Result<(HttpRequest<'a>, Input), Input::Error>
where
Input: RangeStream<Token = u8, Range = &'a [u8]>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
let http_version = range(&b"HTTP/"[..]).with(take_while1(is_http_version));

Expand Down Expand Up @@ -155,7 +152,7 @@ fn http_requests_large_cheap_error(b: &mut Bencher<'_>) {
fn http_requests_bench<'a, Input>(b: &mut Bencher<'_>, buffer: Input)
where
Input: RangeStream<Token = u8, Range = &'a [u8]> + Clone,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position> + fmt::Debug,
Input::Error: fmt::Debug,
{
b.iter(|| {
let mut buf = black_box(buffer.clone());
Expand Down
6 changes: 0 additions & 6 deletions benches/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ where
fn integer<Input>() -> impl Parser<Input, Output = i64>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
lex(many1(digit()))
.map(|s: String| {
Expand All @@ -71,7 +70,6 @@ where
fn number<Input>() -> impl Parser<Input, Output = f64>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
let i = char('0').map(|_| 0.0).or(integer().map(|x| x as f64));
let fractional = many(digit()).map(|digits: String| {
Expand Down Expand Up @@ -105,7 +103,6 @@ where
fn json_char<Input>() -> impl Parser<Input, Output = char>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
parser(|input: &mut Input| {
let (c, committed) = any().parse_lazy(input).into_result()?;
Expand Down Expand Up @@ -133,15 +130,13 @@ where
fn json_string<Input>() -> impl Parser<Input, Output = String>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
between(char('"'), lex(char('"')), many(json_char())).expected("string")
}

fn object<Input>() -> impl Parser<Input, Output = Value>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
let field = (json_string(), lex(char(':')), json_value()).map(|t| (t.0, t.2));
let fields = sep_by(field, lex(char(',')));
Expand All @@ -154,7 +149,6 @@ where
fn json_value<Input>() -> impl Parser<Input, Output = Value>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
json_value_()
}
Expand Down
2 changes: 0 additions & 2 deletions examples/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ fn decode_parser<'a, Input>(
) -> impl Parser<Input, Output = Vec<u8>, PartialState = AnyPartialState> + 'a
where
Input: RangeStream<Token = u8, Range = &'a [u8]> + 'a,
// Necessary due to rust-lang/rust#24159
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
let content_length = range(&b"Content-Length: "[..])
.with(recognize(skip_many1(digit())).and_then(|digits: &[u8]| {
Expand Down
7 changes: 0 additions & 7 deletions examples/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::{

use combine::{
choice,
error::ParseError,
many, optional,
parser::char::{char, digit},
stream::position,
Expand Down Expand Up @@ -63,8 +62,6 @@ pub struct DateTime {
fn two_digits<Input>() -> impl Parser<Input, Output = i32>
where
Input: Stream<Token = char>,
// Necessary due to rust-lang/rust#24159
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
(digit(), digit()).map(|(x, y): (char, char)| {
let x = x.to_digit(10).expect("digit");
Expand All @@ -81,7 +78,6 @@ where
fn time_zone<Input>() -> impl Parser<Input, Output = i32>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
let utc = char('Z').map(|_| 0);
let offset = (
Expand All @@ -106,7 +102,6 @@ where
fn date<Input>() -> impl Parser<Input, Output = Date>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
(
many::<String, _, _>(digit()),
Expand All @@ -130,7 +125,6 @@ where
fn time<Input>() -> impl Parser<Input, Output = Time>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
(
two_digits(),
Expand All @@ -156,7 +150,6 @@ where
fn date_time<Input>() -> impl Parser<Input, Output = DateTime>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
(date(), char('T'), time()).map(|(date, _, time)| DateTime { date, time })
}
Expand Down
6 changes: 0 additions & 6 deletions examples/ini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ pub struct Ini {
fn property<Input>() -> impl Parser<Input, Output = (String, String)>
where
Input: Stream<Token = char>,
// Necessary due to rust-lang/rust#24159
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
(
many1(satisfy(|c| c != '=' && c != '[' && c != ';')),
Expand All @@ -56,7 +54,6 @@ where
fn whitespace<Input>() -> impl Parser<Input>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
let comment = (token(';'), skip_many(satisfy(|c| c != '\n'))).map(|_| ());
// Wrap the `spaces().or(comment)` in `skip_many` so that it skips alternating whitespace and
Expand All @@ -67,7 +64,6 @@ where
fn properties<Input>() -> impl Parser<Input, Output = HashMap<String, String>>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
// After each property we skip any whitespace that followed it
many(property().skip(whitespace()))
Expand All @@ -76,7 +72,6 @@ where
fn section<Input>() -> impl Parser<Input, Output = (String, HashMap<String, String>)>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
(
between(token('['), token(']'), many(satisfy(|c| c != ']'))),
Expand All @@ -90,7 +85,6 @@ where
fn ini<Input>() -> impl Parser<Input, Output = Ini>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
(whitespace(), properties(), many(section()))
.map(|(_, global, sections)| Ini { global, sections })
Expand Down
1 change: 0 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,6 @@ impl<T> Commit<T> {
/// //and " respectively
/// fn char<Input>(input: &mut Input) -> StdParseResult<char, Input>
/// where Input: Stream<Token = char>,
/// Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
/// {
/// let (c, committed) = satisfy(|c| c != '"').parse_stream(input).into_result()?;
/// match c {
Expand Down
6 changes: 0 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,6 @@
//! // `impl Parser` can be used to create reusable parsers with zero overhead
//! fn expr_<Input>() -> impl Parser< Input, Output = Expr>
//! where Input: Stream<Token = char>,
//! // Necessary due to rust-lang/rust#24159
//! Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
//! {
//! let word = many1(letter());
//!
Expand Down Expand Up @@ -259,7 +257,6 @@ pub use crate::parser::token::tokens_cmp;
/// fn integer[Input]()(Input) -> i32
/// where [
/// Input: Stream<Token = char>,
/// Input::Error: ParseError<char, Input::Range, Input::Position>,
/// <Input::Error as ParseError<Input::Token, Input::Range, Input::Position>>::StreamError:
/// From<::std::num::ParseIntError>,
/// ]
Expand All @@ -283,7 +280,6 @@ pub use crate::parser::token::tokens_cmp;
/// pub fn integer_or_string[Input]()(Input) -> IntOrString
/// where [
/// Input: Stream<Token = char>,
/// Input::Error: ParseError<char, Input::Range, Input::Position>,
/// <Input::Error as ParseError<Input::Token, Input::Range, Input::Position>>::StreamError:
/// From<::std::num::ParseIntError>,
/// ]
Expand Down Expand Up @@ -709,7 +705,6 @@ mod std_tests {
fn integer<Input>(input: &mut Input) -> StdParseResult<i64, Input>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
let (s, input) = many1::<String, _, _>(digit())
.expected("integer")
Expand Down Expand Up @@ -834,7 +829,6 @@ mod std_tests {
fn term<Input>(input: &mut Input) -> StdParseResult<Expr, Input>
where
Input: Stream<Token = char>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
fn times(l: Expr, r: Expr) -> Expr {
Expr::Times(Box::new(l), Box::new(r))
Expand Down
19 changes: 1 addition & 18 deletions src/parser/byte.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Module containing parsers specialized on byte streams.

use crate::{
error::{self, ParseError, ParseResult::*},
error::{self, ParseResult::*},
parser::{
combinator::no_partial,
range::{take_fn, TakeRange},
Expand All @@ -24,7 +24,6 @@ use crate::{
pub fn byte<Input>(c: u8) -> Token<Input>
where
Input: Stream<Token = u8>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
token(c)
}
Expand All @@ -51,7 +50,6 @@ macro_rules! byte_parser {
pub fn digit<Input>() -> impl Parser<Input, Output = u8, PartialState = ()>
where
Input: Stream<Token = u8>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
byte_parser!(digit, Digit, is_ascii_digit())
}
Expand All @@ -69,7 +67,6 @@ where
pub fn space<Input>() -> impl Parser<Input, Output = u8, PartialState = ()>
where
Input: Stream<Token = u8>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
byte_parser!(space, Space, is_ascii_whitespace)
}
Expand All @@ -87,7 +84,6 @@ where
pub fn spaces<Input>() -> impl Parser<Input, Output = ()>
where
Input: Stream<Token = u8>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
skip_many(space()).expected("whitespaces")
}
Expand All @@ -103,7 +99,6 @@ where
pub fn newline<Input>() -> impl Parser<Input, Output = u8, PartialState = ()>
where
Input: Stream<Token = u8>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
satisfy(|ch: u8| ch == b'\n').expected("lf newline")
}
Expand All @@ -120,7 +115,6 @@ where
pub fn crlf<Input>() -> impl Parser<Input, Output = u8, PartialState = ()>
where
Input: Stream<Token = u8>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
no_partial(satisfy(|ch: u8| ch == b'\r').with(newline())).expected("crlf newline")
}
Expand All @@ -136,7 +130,6 @@ where
pub fn tab<Input>() -> impl Parser<Input, Output = u8, PartialState = ()>
where
Input: Stream<Token = u8>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
satisfy(|ch| ch == b'\t').expected("tab")
}
Expand All @@ -152,7 +145,6 @@ where
pub fn upper<Input>() -> impl Parser<Input, Output = u8, PartialState = ()>
where
Input: Stream<Token = u8>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
byte_parser!(upper, Upper, is_ascii_uppercase)
}
Expand All @@ -168,7 +160,6 @@ where
pub fn lower<Input>() -> impl Parser<Input, Output = u8, PartialState = ()>
where
Input: Stream<Token = u8>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
byte_parser!(lower, Lower, is_ascii_lowercase)
}
Expand All @@ -185,7 +176,6 @@ where
pub fn alpha_num<Input>() -> impl Parser<Input, Output = u8, PartialState = ()>
where
Input: Stream<Token = u8>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
byte_parser!(alpha_num, AlphaNum, is_ascii_alphanumeric)
}
Expand All @@ -202,7 +192,6 @@ where
pub fn letter<Input>() -> impl Parser<Input, Output = u8, PartialState = ()>
where
Input: Stream<Token = u8>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
byte_parser!(letter, Letter, is_ascii_alphabetic)
}
Expand All @@ -218,7 +207,6 @@ where
pub fn oct_digit<Input>() -> impl Parser<Input, Output = u8, PartialState = ()>
where
Input: Stream<Token = u8>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
satisfy(|ch| (b'0'..=b'7').contains(&ch)).expected("octal digit")
}
Expand All @@ -234,7 +222,6 @@ where
pub fn hex_digit<Input>() -> impl Parser<Input, Output = u8, PartialState = ()>
where
Input: Stream<Token = u8>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
byte_parser!(hex_digit, HexDigit, is_ascii_hexdigit())
}
Expand Down Expand Up @@ -262,7 +249,6 @@ parser! {
pub fn bytes['a, 'b, Input](s: &'static [u8])(Input) -> &'a [u8]
where [
Input: Stream<Token = u8, Range = &'b [u8]>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
]
{
bytes_cmp(s, |l: u8, r: u8| l == r)
Expand Down Expand Up @@ -293,7 +279,6 @@ pub fn bytes_cmp['a, 'b, C, Input](s: &'static [u8], cmp: C)(Input) -> &'a [u8]
where [
C: FnMut(u8, u8) -> bool,
Input: Stream<Token = u8, Range = &'b [u8]>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
]
{
let s = *s;
Expand Down Expand Up @@ -457,7 +442,6 @@ pub mod num {
pub fn $be_name<'a, Input>() -> impl Parser<Input, Output = $output_type, PartialState = ()>
where
Input: Stream<Token = u8>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
parser(|input: &mut Input| {
let checkpoint = input.checkpoint();
Expand All @@ -479,7 +463,6 @@ pub mod num {
pub fn $le_name<'a, Input>() -> impl Parser<Input, Output = $output_type, PartialState = ()>
where
Input: Stream<Token = u8>,
Input::Error: ParseError<Input::Token, Input::Range, Input::Position>,
{
parser(|input: &mut Input| {
let checkpoint = input.checkpoint();
Expand Down
Loading