Skip to content

Commit

Permalink
Warn against rust_2018_idioms
Browse files Browse the repository at this point in the history
Nowadays, this is mostly a leftover that still includes
`elided_lifetimes_in_paths`, see
rust-lang/rust#91639 for the tracking
issue.
  • Loading branch information
Xanewok committed Dec 4, 2023
1 parent 0e38580 commit c933557
Show file tree
Hide file tree
Showing 33 changed files with 712 additions and 669 deletions.
4 changes: 4 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ rustflags = [
# rustc additional warnings:
"--warn",
"unused_crate_dependencies",
"--warn",
"nonstandard_style",
"--warn",
"rust_2018_idioms",
# clippy additional warnings:
"--warn",
"clippy::wildcard_imports",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub(crate) struct ParseOutput {

/// A wrapper around [syn::parse::Parse] to convert to/from our own error types.
impl Parse for ParseOutput {
fn parse(input: ParseStream) -> syn::Result<Self> {
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
let mut errors = ErrorsCollection::new();

match SpannedLanguage::parse_named_value(input, &mut errors) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ use std::{fmt::Debug, rc::Rc};
use syn::{parse::ParseStream, LitBool, LitChar, LitStr};

impl ParseInputTokens for bool {
fn parse_value(input: ParseStream, _: &mut ErrorsCollection) -> Result<Self> {
fn parse_value(input: ParseStream<'_>, _: &mut ErrorsCollection) -> Result<Self> {
let literal = ParseHelpers::syn::<LitBool>(input)?;

Ok(literal.value())
}
}

impl<T: ParseInputTokens> ParseInputTokens for Box<T> {
fn parse_value(input: ParseStream, errors: &mut ErrorsCollection) -> Result<Self> {
fn parse_value(input: ParseStream<'_>, errors: &mut ErrorsCollection) -> Result<Self> {
let value = T::parse_value(input, errors)?;

Ok(value.into())
}
}

impl ParseInputTokens for char {
fn parse_value(input: ParseStream, _: &mut ErrorsCollection) -> Result<Self> {
fn parse_value(input: ParseStream<'_>, _: &mut ErrorsCollection) -> Result<Self> {
let literal = ParseHelpers::syn::<LitChar>(input)?;

Ok(literal.value())
Expand All @@ -34,13 +34,13 @@ impl ParseInputTokens for char {
impl<K: ParseInputTokens + std::hash::Hash + Eq, V: ParseInputTokens> ParseInputTokens
for IndexMap<K, V>
{
fn parse_value(input: ParseStream, errors: &mut ErrorsCollection) -> Result<Self> {
fn parse_value(input: ParseStream<'_>, errors: &mut ErrorsCollection) -> Result<Self> {
ParseHelpers::map(input, errors)
}
}

impl<T: ParseInputTokens + std::hash::Hash + Ord> ParseInputTokens for IndexSet<Spanned<T>> {
fn parse_value(input: ParseStream, errors: &mut ErrorsCollection) -> Result<Self> {
fn parse_value(input: ParseStream<'_>, errors: &mut ErrorsCollection) -> Result<Self> {
let sequence: Vec<Spanned<T>> = ParseHelpers::sequence(input, errors)?;

let mut set = Self::new();
Expand All @@ -58,15 +58,19 @@ impl<T: ParseInputTokens + std::hash::Hash + Ord> ParseInputTokens for IndexSet<
}

impl<T: ParseInputTokens> ParseInputTokens for Option<T> {
fn parse_value(input: ParseStream, errors: &mut ErrorsCollection) -> Result<Self> {
fn parse_value(input: ParseStream<'_>, errors: &mut ErrorsCollection) -> Result<Self> {
if input.is_empty() {
Ok(None)
} else {
Ok(Some(T::parse_value(input, errors)?))
}
}

fn parse_field(name: &str, input: ParseStream, errors: &mut ErrorsCollection) -> Result<Self> {
fn parse_field(
name: &str,
input: ParseStream<'_>,
errors: &mut ErrorsCollection,
) -> Result<Self> {
match ParseHelpers::syn::<Ident>(&input.fork()) {
Ok(key) if key == name => Ok(Some(ParseHelpers::field(name, input, errors)?)),
_ => Ok(None),
Expand All @@ -75,15 +79,15 @@ impl<T: ParseInputTokens> ParseInputTokens for Option<T> {
}

impl<T: ParseInputTokens> ParseInputTokens for Rc<T> {
fn parse_value(input: ParseStream, errors: &mut ErrorsCollection) -> Result<Self> {
fn parse_value(input: ParseStream<'_>, errors: &mut ErrorsCollection) -> Result<Self> {
let value = T::parse_value(input, errors)?;

Ok(value.into())
}
}

impl ParseInputTokens for String {
fn parse_value(input: ParseStream, errors: &mut ErrorsCollection) -> Result<Self> {
fn parse_value(input: ParseStream<'_>, errors: &mut ErrorsCollection) -> Result<Self> {
let literal = ParseHelpers::syn::<LitStr>(input)?;
let value = literal.value();

Expand All @@ -96,21 +100,21 @@ impl ParseInputTokens for String {
}

impl ParseInputTokens for usize {
fn parse_value(input: ParseStream, _: &mut ErrorsCollection) -> Result<Self> {
fn parse_value(input: ParseStream<'_>, _: &mut ErrorsCollection) -> Result<Self> {
let literal = ParseHelpers::syn::<syn::LitInt>(input)?;

literal.base10_parse::<usize>().map_err(Error::from_syn)
}
}

impl<T: ParseInputTokens> ParseInputTokens for Vec<T> {
fn parse_value(input: ParseStream, errors: &mut ErrorsCollection) -> Result<Self> {
fn parse_value(input: ParseStream<'_>, errors: &mut ErrorsCollection) -> Result<Self> {
ParseHelpers::sequence(input, errors)
}
}

impl ParseInputTokens for Version {
fn parse_value(input: ParseStream, errors: &mut ErrorsCollection) -> Result<Self> {
fn parse_value(input: ParseStream<'_>, errors: &mut ErrorsCollection) -> Result<Self> {
let literal = ParseHelpers::syn::<LitStr>(input)?;

match Self::parse(&literal.value()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ use syn::{braced, bracketed, parenthesized, parse::ParseStream, Token};
pub struct ParseHelpers;

impl ParseHelpers {
pub fn syn<T: syn::parse::Parse>(input: ParseStream) -> Result<T> {
pub fn syn<T: syn::parse::Parse>(input: ParseStream<'_>) -> Result<T> {
input.parse::<T>().map_err(Error::from_syn)
}

pub fn delimited<T>(
delimiter: Delimiter,
input: ParseStream,
inner_parser: impl FnOnce(DelimSpan, ParseStream) -> Result<T>,
input: ParseStream<'_>,
inner_parser: impl FnOnce(DelimSpan, ParseStream<'_>) -> Result<T>,
) -> Result<T> {
delimited(delimiter, input, inner_parser).map_err(Error::from_syn)
}

pub fn sequence<T: ParseInputTokens>(
input: ParseStream,
input: ParseStream<'_>,
errors: &mut ErrorsCollection,
) -> Result<Vec<T>> {
match Self::delimited(Delimiter::Bracket, input, |_, inner_input| {
Expand Down Expand Up @@ -50,7 +50,7 @@ impl ParseHelpers {
}

pub fn map<K: ParseInputTokens + std::hash::Hash + Eq, V: ParseInputTokens>(
input: ParseStream,
input: ParseStream<'_>,
errors: &mut ErrorsCollection,
) -> Result<IndexMap<K, V>> {
match Self::delimited(Delimiter::Parenthesis, input, |_, inner_input| {
Expand Down Expand Up @@ -91,7 +91,7 @@ impl ParseHelpers {

pub fn field<T: ParseInputTokens>(
name: &str,
input: ParseStream,
input: ParseStream<'_>,
errors: &mut ErrorsCollection,
) -> Result<T> {
let span = input.span();
Expand Down Expand Up @@ -119,8 +119,8 @@ impl ParseHelpers {
/// A wrapper to convert error types in callsites, since the macros below requires returning [syn::Result].
fn delimited<T>(
delimiter: Delimiter,
input: ParseStream,
inner_parser: impl FnOnce(DelimSpan, ParseStream) -> Result<T>,
input: ParseStream<'_>,
inner_parser: impl FnOnce(DelimSpan, ParseStream<'_>) -> Result<T>,
) -> syn::Result<T> {
let inner_input;
let span = match delimiter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,21 @@ use syn::parse::ParseStream;

pub trait ParseInputTokens: Sized {
/// Main parser entrypoint, and should be implemented by all types.
fn parse_value(input: ParseStream, errors: &mut ErrorsCollection) -> Result<Self>;
fn parse_value(input: ParseStream<'_>, errors: &mut ErrorsCollection) -> Result<Self>;

/// Allows named types (structs) to parse the type name before its body.
/// By default, it will parse the value directly if not overriden.
fn parse_named_value(input: ParseStream, errors: &mut ErrorsCollection) -> Result<Self> {
fn parse_named_value(input: ParseStream<'_>, errors: &mut ErrorsCollection) -> Result<Self> {
Self::parse_value(input, errors)
}

/// Allows implementations (like 'Option<T>') to modify the parsing logic,
/// by checking if the field exists before attempting to parse it.
fn parse_field(name: &str, input: ParseStream, errors: &mut ErrorsCollection) -> Result<Self> {
fn parse_field(
name: &str,
input: ParseStream<'_>,
errors: &mut ErrorsCollection,
) -> Result<Self> {
ParseHelpers::field(name, input, errors)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ impl<T: PartialOrd> PartialOrd for Spanned<T> {
}

impl<T: ParseInputTokens> ParseInputTokens for Spanned<T> {
fn parse_value(input: ParseStream, errors: &mut ErrorsCollection) -> Result<Self> {
fn parse_value(input: ParseStream<'_>, errors: &mut ErrorsCollection) -> Result<Self> {
let span = input.span();
let value = T::parse_value(input, errors)?;

Ok(Self::new(span, value))
}

fn parse_named_value(input: ParseStream, errors: &mut ErrorsCollection) -> Result<Self> {
fn parse_named_value(input: ParseStream<'_>, errors: &mut ErrorsCollection) -> Result<Self> {
let span = input.span();
let value = ParseInputTokens::parse_named_value(input, errors)?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Serialize for Identifier {
}

impl ParseInputTokens for Identifier {
fn parse_value(input: ParseStream, _: &mut ErrorsCollection) -> Result<Self> {
fn parse_value(input: ParseStream<'_>, _: &mut ErrorsCollection) -> Result<Self> {
let value = ParseHelpers::syn::<Ident>(input)?.to_string();

Ok(value.into())
Expand Down
2 changes: 1 addition & 1 deletion crates/codegen/language/internal_macros/src/input_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum InputItem {
}

impl Parse for InputItem {
fn parse(input: ParseStream) -> Result<Self> {
fn parse(input: ParseStream<'_>) -> Result<Self> {
let input = DeriveInput::parse(input)?;

Self::from_syn(input)
Expand Down
22 changes: 11 additions & 11 deletions crates/codegen/parser/generator/src/precedence_parser_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl PrecedenceParserDefinitionNodeExtensions for PrecedenceParserDefinitionNode
match model {
PrecedenceOperatorModel::BinaryLeftAssociative => {
operator_closures.push(quote! {
let #closure_name = |input: &mut ParserContext|
let #closure_name = |input: &mut ParserContext<'_>|
PrecedenceHelper::to_binary_operator(
RuleKind::#rule_kind,
#binding_power,
Expand All @@ -118,7 +118,7 @@ impl PrecedenceParserDefinitionNodeExtensions for PrecedenceParserDefinitionNode
}
PrecedenceOperatorModel::BinaryRightAssociative => {
operator_closures.push(quote! {
let #closure_name = |input: &mut ParserContext|
let #closure_name = |input: &mut ParserContext<'_>|
PrecedenceHelper::to_binary_operator(
RuleKind::#rule_kind,
#binding_power + 1,
Expand All @@ -130,7 +130,7 @@ impl PrecedenceParserDefinitionNodeExtensions for PrecedenceParserDefinitionNode
}
PrecedenceOperatorModel::Prefix => {
operator_closures.push(quote! {
let #closure_name = |input: &mut ParserContext|
let #closure_name = |input: &mut ParserContext<'_>|
PrecedenceHelper::to_prefix_operator(
RuleKind::#rule_kind,
#binding_power,
Expand All @@ -141,7 +141,7 @@ impl PrecedenceParserDefinitionNodeExtensions for PrecedenceParserDefinitionNode
}
PrecedenceOperatorModel::Postfix => {
operator_closures.push(quote! {
let #closure_name = |input: &mut ParserContext|
let #closure_name = |input: &mut ParserContext<'_>|
PrecedenceHelper::to_postfix_operator(
RuleKind::#rule_kind,
#binding_power,
Expand Down Expand Up @@ -196,19 +196,19 @@ impl PrecedenceParserDefinitionNodeExtensions for PrecedenceParserDefinitionNode

if !prefix_operator_parsers.is_empty() {
let prefix_operator_parser = make_choice(prefix_operator_parsers);
operator_closures.push(quote! { let prefix_operator_parser = |input: &mut ParserContext| #prefix_operator_parser; });
operator_closures.push(quote! { let prefix_operator_parser = |input: &mut ParserContext<'_>| #prefix_operator_parser; });
binary_operand_terms.push(
quote! { ZeroOrMoreHelper::run(input, |input| prefix_operator_parser(input)) },
);
}

let primary_expression_parser = self.primary_expression.to_parser_code(context_name, false);
operator_closures.push(quote! { let primary_expression_parser = |input: &mut ParserContext| #primary_expression_parser; });
operator_closures.push(quote! { let primary_expression_parser = |input: &mut ParserContext<'_>| #primary_expression_parser; });
binary_operand_terms.push(quote! { primary_expression_parser(input) });

if !postfix_operator_parsers.is_empty() {
let postfix_operator_parser = make_choice(postfix_operator_parsers);
operator_closures.push(quote! { let postfix_operator_parser = |input: &mut ParserContext| #postfix_operator_parser; });
operator_closures.push(quote! { let postfix_operator_parser = |input: &mut ParserContext<'_>| #postfix_operator_parser; });
binary_operand_terms.push(
quote! { ZeroOrMoreHelper::run(input, |input| postfix_operator_parser(input)) },
);
Expand All @@ -217,12 +217,12 @@ impl PrecedenceParserDefinitionNodeExtensions for PrecedenceParserDefinitionNode
let binary_operand_parser = make_sequence(binary_operand_terms);

if binary_operator_parsers.is_empty() {
operator_closures.push(quote! { let linear_expression_parser = |input: &mut ParserContext| #binary_operand_parser; });
operator_closures.push(quote! { let linear_expression_parser = |input: &mut ParserContext<'_>| #binary_operand_parser; });
} else {
operator_closures.push(quote! { let binary_operand_parser = |input: &mut ParserContext| #binary_operand_parser; });
operator_closures.push(quote! { let binary_operand_parser = |input: &mut ParserContext<'_>| #binary_operand_parser; });

let binary_operator_parser = make_choice(binary_operator_parsers);
operator_closures.push(quote! { let binary_operator_parser = |input: &mut ParserContext| #binary_operator_parser; });
operator_closures.push(quote! { let binary_operator_parser = |input: &mut ParserContext<'_>| #binary_operator_parser; });

let linear_expression_parser =
make_sequence(vec![quote! { binary_operand_parser(input) }, {
Expand All @@ -233,7 +233,7 @@ impl PrecedenceParserDefinitionNodeExtensions for PrecedenceParserDefinitionNode
quote! { ZeroOrMoreHelper::run(input, |input| #pairs) }
}]);
operator_closures
.push(quote! { let linear_expression_parser = |input: &mut ParserContext| #linear_expression_parser; });
.push(quote! { let linear_expression_parser = |input: &mut ParserContext<'_>| #linear_expression_parser; });
}

let expression_kind_literal = if let Some(kind) = expression_kind {
Expand Down
20 changes: 13 additions & 7 deletions crates/codegen/parser/runtime/src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,24 @@ use crate::{
pub trait Lexer {
// Generated by the templating engine
#[doc(hidden)]
fn next_token<LexCtx: IsLexicalContext>(&self, input: &mut ParserContext) -> Option<TokenKind>;
fn next_token<LexCtx: IsLexicalContext>(
&self,
input: &mut ParserContext<'_>,
) -> Option<TokenKind>;
// NOTE: These are context-insensitive
#[doc(hidden)]
fn leading_trivia(&self, input: &mut ParserContext) -> ParserResult;
fn leading_trivia(&self, input: &mut ParserContext<'_>) -> ParserResult;
#[doc(hidden)]
fn trailing_trivia(&self, input: &mut ParserContext) -> ParserResult;
fn trailing_trivia(&self, input: &mut ParserContext<'_>) -> ParserResult;
#[doc(hidden)]
/// Returns valid grouping delimiters in the given lexical context.
fn delimiters<LexCtx: IsLexicalContext>() -> &'static [(TokenKind, TokenKind)];

/// Peeks the next token, including trivia. Does not advance the input.
fn peek_token<LexCtx: IsLexicalContext>(&self, input: &mut ParserContext) -> Option<TokenKind> {
fn peek_token<LexCtx: IsLexicalContext>(
&self,
input: &mut ParserContext<'_>,
) -> Option<TokenKind> {
let start = input.position();
let token = self.next_token::<LexCtx>(input);
input.set_position(start);
Expand All @@ -28,7 +34,7 @@ pub trait Lexer {
/// Peeks the next significant (i.e. non-trivia) token. Does not advance the input.
fn peek_token_with_trivia<LexCtx: IsLexicalContext>(
&self,
input: &mut ParserContext,
input: &mut ParserContext<'_>,
) -> Option<TokenKind> {
let start = input.position();

Expand All @@ -42,7 +48,7 @@ pub trait Lexer {
/// Attempts to consume the next expected token. Advances the input only if the token matches.
fn parse_token<LexCtx: IsLexicalContext>(
&self,
input: &mut ParserContext,
input: &mut ParserContext<'_>,
kind: TokenKind,
) -> ParserResult {
let start = input.position();
Expand All @@ -62,7 +68,7 @@ pub trait Lexer {
/// Advances the input only if the token matches.
fn parse_token_with_trivia<LexCtx: IsLexicalContext>(
&self,
input: &mut ParserContext,
input: &mut ParserContext<'_>,
kind: TokenKind,
) -> ParserResult {
let mut children = vec![];
Expand Down
Loading

0 comments on commit c933557

Please sign in to comment.