Skip to content

Commit

Permalink
some more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
farooqkz committed Feb 17, 2024
1 parent b3a0f71 commit f8ba2fe
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions src/parser/parse_from_text/link_element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ fn ipv4(input: &str) -> IResult<&str, &str> {
Ok((input, ipv4_))
}

fn is_ireg_name(c: char) -> bool {
is_iunreserved(c) || is_pct_encoded(c) || is_sub_delim(c)
fn is_ireg_name_not_pct_encoded(c: char) -> bool {
is_iunreserved(c) || is_sub_delim(c)
}

fn h16(input: &str) -> IResult<&str, &str> {
Expand Down Expand Up @@ -189,18 +189,18 @@ fn parse_host(input: &str) -> IResult<&str, (&str, bool)> {
Ok((input, (host, true)))
}
Err(..) => {
let (input, host) = alt((ipv4, take_while(is_ireg_name)))(input)?;
let (input, host) = alt((ipv4, many0(alt((take_while(is_ireg_name_not_pct_encoded)))))(input)?;

Check failure on line 192 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

expected one of `)`, `,`, `.`, `?`, or an operator, found `;`

Check failure on line 192 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

expected one of `)`, `,`, `.`, `?`, or an operator, found `;`

Check failure on line 192 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / Rust doc comments

mismatched closing delimiter: `}`

Check failure on line 192 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / clippy

mismatched types

error[E0308]: mismatched types --> src/parser/parse_from_text/link_element.rs:192:17 | 192 | let (input, host) = alt((ipv4, many0(alt((take_while(is_ireg_name_not_pct_encoded)))))(input)?; | ^^^^^^^^^^^^^ -------------------------------------------------------------------------- this expression has type `impl FnMut(_) -> std::result::Result<(_, _), nom::Err<_>>` | | | expected opaque type, found tuple | ::: /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-7.1.3/src/branch/mod.rs:49:6 | 49 | ) -> impl FnMut(I) -> IResult<I, O, E> { | --------------------------------- the expected opaque type | = note: expected opaque type `impl FnMut(_) -> std::result::Result<(_, _), nom::Err<_>>` found tuple `(_, _)`

Check failure on line 192 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / clippy

expected function, found `(for<'r> fn(&'r str) -> std::result::Result<(&'r str, &'r str), nom::Err<nom::error::Error<&'r str>>> {parser::parse_from_text::link_element::ipv4}, impl FnMut(_) -> std::result::Result<(_, std::vec::Vec<_>), nom::Err<_>>)`

error[E0618]: expected function, found `(for<'r> fn(&'r str) -> std::result::Result<(&'r str, &'r str), nom::Err<nom::error::Error<&'r str>>> {parser::parse_from_text::link_element::ipv4}, impl FnMut(_) -> std::result::Result<(_, std::vec::Vec<_>), nom::Err<_>>)` --> src/parser/parse_from_text/link_element.rs:192:37 | 192 | let (input, host) = alt((ipv4, many0(alt((take_while(is_ireg_name_not_pct_encoded)))))(input)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------- | | | call expression requires function

Check failure on line 192 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / clippy

the trait bound `impl Fn(_) -> std::result::Result<(_, _), nom::Err<_>>: nom::branch::Alt<_, _, _>` is not satisfied

error[E0277]: the trait bound `impl Fn(_) -> std::result::Result<(_, _), nom::Err<_>>: nom::branch::Alt<_, _, _>` is not satisfied --> src/parser/parse_from_text/link_element.rs:192:54 | 192 | let (input, host) = alt((ipv4, many0(alt((take_while(is_ireg_name_not_pct_encoded)))))(input)?; | --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `nom::branch::Alt<_, _, _>` is not implemented for `impl Fn(_) -> std::result::Result<(_, _), nom::Err<_>>` | | | required by a bound introduced by this call | = help: the following other types implement trait `nom::branch::Alt<I, O, E>`: (A, B) (A, B, C) (A, B, C, D) (A, B, C, D, E) (A, B, C, D, E, F) (A, B, C, D, E, F, G) (A, B, C, D, E, F, G, H) (A, B, C, D, E, F, G, H, I) and 13 others note: required by a bound in `nom::branch::alt` --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-7.1.3/src/branch/mod.rs:47:49 | 47 | pub fn alt<I: Clone, O, E: ParseError<I>, List: Alt<I, O, E>>( | ^^^^^^^^^^^^ required by this bound in `nom::branch::alt`

Check warning on line 192 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / clippy

consider removing unnecessary double parentheses

warning: consider removing unnecessary double parentheses --> src/parser/parse_from_text/link_element.rs:192:54 | 192 | let (input, host) = alt((ipv4, many0(alt((take_while(is_ireg_name_not_pct_encoded)))))(input)?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(clippy::double_parens)]` on by default = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#double_parens

Check warning on line 192 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary parentheses around function argument

warning: unnecessary parentheses around function argument --> src/parser/parse_from_text/link_element.rs:192:54 | 192 | let (input, host) = alt((ipv4, many0(alt((take_while(is_ireg_name_not_pct_encoded)))))(input)?; | ^ ^ | = note: `#[warn(unused_parens)]` on by default help: remove these parentheses | 192 - let (input, host) = alt((ipv4, many0(alt((take_while(is_ireg_name_not_pct_encoded)))))(input)?; 192 + let (input, host) = alt((ipv4, many0(alt(take_while(is_ireg_name_not_pct_encoded))))(input)?; |

Check failure on line 192 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, 1.64.0)

expected one of `)`, `,`, `.`, `?`, or an operator, found `;`
Ok((input, (host, false)))
}

Check failure on line 194 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

expected one of `.`, `;`, `?`, `}`, or an operator, found `)`

Check failure on line 194 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / Rustfmt

expected one of `.`, `;`, `?`, `}`, or an operator, found `)`

Check failure on line 194 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, 1.64.0)

expected one of `.`, `;`, `?`, `}`, or an operator, found `)`
}
}

fn is_userinfo(c: char) -> bool {
is_iunreserved(c) || is_pct_encoded(c) || is_sub_delim(c)
fn is_userinfo_not_pct_encoded(c: char) -> bool {
is_iunreserved(c) || is_sub_delim(c)
}

fn iauthority(input: &str) -> IResult<&str, (&str, &str, &str, bool)> {
let (input, userinfo) = opt(recognize(tuple((take_while(is_userinfo), char('@')))))(input)?;
let (input, userinfo) = opt(recognize(alt((take_while_pct_encoded, tuple((take_while(is_userinfo), char('@')))))))(input)?;

Check failure on line 203 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / clippy

type mismatch resolving `<impl FnMut(&str) -> std::result::Result<(&str, (&str, char)), nom::Err<_>> as std::ops::FnOnce<(&str,)>>::Output == std::result::Result<(&str, &str), nom::Err<nom::error::Error<&str>>>`

error[E0271]: type mismatch resolving `<impl FnMut(&str) -> std::result::Result<(&str, (&str, char)), nom::Err<_>> as std::ops::FnOnce<(&str,)>>::Output == std::result::Result<(&str, &str), nom::Err<nom::error::Error<&str>>>` --> src/parser/parse_from_text/link_element.rs:203:47 | 203 | let (input, userinfo) = opt(recognize(alt((take_while_pct_encoded, tuple((take_while(is_userinfo), char('@')))))))(input)?; | --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&str`, found tuple | | | required by a bound introduced by this call | = note: expected enum `std::result::Result<(&str, &str), nom::Err<nom::error::Error<&str>>>` found enum `std::result::Result<(&str, (&str, char)), nom::Err<_>>` = note: required because of the requirements on the impl of `nom::Parser<&str, &str, nom::error::Error<&str>>` for `impl FnMut(&str) -> std::result::Result<(&str, (&str, char)), nom::Err<_>>` = note: required because of the requirements on the impl of `nom::branch::Alt<&str, &str, nom::error::Error<&str>>` for `(for<'r> fn(&'r str) -> std::result::Result<(&'r str, &'r str), nom::Err<nom::error::Error<&'r str>>> {parser::parse_from_text::link_element::take_while_pct_encoded}, impl FnMut(&str) -> std::result::Result<(&str, (&str, char)), nom::Err<_>>)` note: required by a bound in `nom::branch::alt` --> /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/nom-7.1.3/src/branch/mod.rs:47:49 | 47 | pub fn alt<I: Clone, O, E: ParseError<I>, List: Alt<I, O, E>>( | ^^^^^^^^^^^^ required by this bound in `nom::branch::alt`

Check failure on line 203 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / clippy

cannot find value `is_userinfo` in this scope

error[E0425]: cannot find value `is_userinfo` in this scope --> src/parser/parse_from_text/link_element.rs:203:90 | 203 | let (input, userinfo) = opt(recognize(alt((take_while_pct_encoded, tuple((take_while(is_userinfo), char('@')))))))(input)?; | ^^^^^^^^^^^ not found in this scope

Check failure on line 203 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, 1.64.0)

cannot find value `is_userinfo` in this scope
let (input, (host, is_ipv6_or_future)) = parse_host(input)?;
let (input, port) = preceded(char(':'), take_while(is_digit))(input)?;
let userinfo = userinfo.unwrap_or("");
Expand All @@ -215,12 +215,12 @@ fn ihier_part(input: &str) -> IResult<&str, (&str, &str, &str, &str, bool)> {
char('/'),
opt(tuple((
take_while1(is_ipchar),

Check failure on line 217 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / clippy

cannot find value `is_ipchar` in this scope

error[E0425]: cannot find value `is_ipchar` in this scope --> src/parser/parse_from_text/link_element.rs:217:29 | 52 | fn is_ucschar(c: char) -> bool { | ------------------------------ similarly named function `is_ucschar` defined here ... 217 | take_while1(is_ipchar), | ^^^^^^^^^ help: a function with a similar name exists: `is_ucschar`

Check failure on line 217 in src/parser/parse_from_text/link_element.rs

View workflow job for this annotation

GitHub Actions / Build and test (ubuntu-latest, 1.64.0)

cannot find value `is_ipchar` in this scope
many0(tuple((char('/'), take_while(is_ipchar)))),
many0(tuple((char('/'), take_while_ipchar))),
))),
))), // ipath-absolute
recognize(tuple((
take_while_ipchar,
many0(tuple((char('/'), take_while(is_ipchar)))),
many0(tuple((char('/'), take_while_ipchar))),
))), // ipath_rootless
)))(input)?;
let path = path.unwrap_or(""); // it's ipath_empty
Expand All @@ -232,11 +232,7 @@ fn is_ipchar_not_pct_encoded(c: char) -> bool {
}

fn take_while_ipchar(input: &str) -> IResult<&str, &str> {
many0(alt((take_while(is_ipchar_not_pct_encoded), take_while(is_pct_encoded)))(input)
}

fn is_pct_encoded(c: [char; 3]) -> bool {
c[0] == '%' && is_hex_digit(c[1]) && is_hex_digit(c[2])
recognize(many0(alt((take_while(is_ipchar_not_pct_encoded), take_while_pct_encoded))))(input)
}

const IPRIVATE_RANGES: [RangeInclusive<u32>; 3] =
Expand Down Expand Up @@ -273,7 +269,7 @@ fn is_alphanum_or_hyphen_minus(char: char) -> bool {
}
}

fn pct_encoded(input: &str) -> IResult<&str, &str> {
fn take_while_pct_encoded(input: &str) -> IResult<&str, &str> {
recognize(tuple((char('%'), take_while_m_n(2, 2, is_hex_digit))))(input)
}

Expand Down

0 comments on commit f8ba2fe

Please sign in to comment.