Skip to content

Commit

Permalink
Minor refactoring (#36)
Browse files Browse the repository at this point in the history
Some minor compiler error and parsing refactoring.
  • Loading branch information
DunnAnDusted authored Dec 15, 2022
2 parents d9764bb + 48922cf commit 3df6f27
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl Parse for TestHelper {
.parse()
.map_err(|err| Error::new(err.span(), "expected helper function"))?;
let static_args = input.peek(Paren).then(|| input.parse()).transpose()?;
let static_return_type = ReturnType::try_parse(input).transpose()?;
let static_return_type = input.call(ReturnType::try_parse)?;
let farrow = input.parse::<Token![=>]>()?;
let cases;
let braces = braced!(cases in input);
Expand Down Expand Up @@ -405,7 +405,7 @@ impl Parse for CaseArgs {
}

let args = inner.parse()?;
let return_type = ReturnType::try_parse(&inner).transpose()?;
let return_type = inner.call(ReturnType::try_parse)?;

let out = CaseArgs {
braces,
Expand Down Expand Up @@ -444,8 +444,9 @@ impl Parse for FnArgs {
// Using `punctuated::parse_separated_nonempty` in this case,
// because if this type is being parsed, arguments should be expected,
// and trailing commas look sloppy...
let args = Punctuated::parse_separated_nonempty(&inner)
.map_err(|err| Error::new(err.span(), "missing function arguments"))?;
let args = inner
.call(Punctuated::parse_separated_nonempty)
.map_err(|err| Error::new(err.span(), "expected function arguments"))?;

Ok(Self { parens, args })
}
Expand All @@ -469,8 +470,8 @@ impl ReturnType {
/// Conditionally parses the type, if a right-arrow is peeked from the stream.
///
/// Included, due to the optional nature of return types in this macro.
fn try_parse(input: ParseStream) -> Option<Result<Self>> {
input.peek(Token![->]).then(|| input.parse())
fn try_parse(input: ParseStream) -> Result<Option<Self>> {
input.peek(Token![->]).then(|| input.parse()).transpose()
}
}

Expand Down

0 comments on commit 3df6f27

Please sign in to comment.