Skip to content

Commit

Permalink
Tune lints for 1.58 Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Jan 14, 2022
1 parent 73c0033 commit 935602b
Show file tree
Hide file tree
Showing 18 changed files with 121 additions and 19 deletions.
8 changes: 4 additions & 4 deletions book/src/architecture/writer.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl<W: 'static> cucumber::Writer<W> for CustomWriter {
event::Step::Passed(_) => println!("ok"),
event::Step::Skipped => println!("skip"),
event::Step::Failed(_, _, err) => {
println!("failed: {}", err)
println!("failed: {err}")
}
},
_ => {}
Expand All @@ -280,7 +280,7 @@ impl<W: 'static> cucumber::Writer<W> for CustomWriter {
},
_ => {}
},
Err(e) => println!("Error: {}", e),
Err(e) => println!("Error: {e}"),
}
}
}
Expand Down Expand Up @@ -450,7 +450,7 @@ async fn main() {
# event::Step::Passed(_) => println!("ok"),
# event::Step::Skipped => println!("skip"),
# event::Step::Failed(_, _, err) => {
# println!("failed: {}", err)
# println!("failed: {err}", )
# }
# },
# _ => {}
Expand All @@ -459,7 +459,7 @@ async fn main() {
# },
# _ => {}
# },
# Err(e) => println!("Error: {}", e),
# Err(e) => println!("Error: {e}"),
# }
# }
# }
Expand Down
6 changes: 3 additions & 3 deletions book/src/writing/capturing.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl FromStr for State {
Ok(match s {
"hungry" => Self::Hungry,
"satiated" => Self::Satiated,
invalid => return Err(format!("Invalid `State`: {}", invalid)),
invalid => return Err(format!("Invalid `State`: {invalid}")),
})
}
}
Expand Down Expand Up @@ -194,7 +194,7 @@ Alternatively, a [Cucumber Expression][expr] may be used to capture values. This
# Ok(match s {
# "hungry" => Self::Hungry,
# "satiated" => Self::Satiated,
# invalid => return Err(format!("Invalid `State`: {}", invalid)),
# invalid => return Err(format!("Invalid `State`: {invalid}")),
# })
# }
# }
Expand Down Expand Up @@ -285,7 +285,7 @@ impl FromStr for State {
Ok(match s {
"hungry" => Self::Hungry,
"satiated" => Self::Satiated,
invalid => return Err(format!("Invalid `State`: {}", invalid)),
invalid => return Err(format!("Invalid `State`: {invalid}")),
})
}
}
Expand Down
6 changes: 6 additions & 0 deletions codegen/src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ impl Step {

let regex = self.gen_regex()?;

// TODO: Use "{func_name}" syntax once MSRV bumps above 1.58.
let caller_name =
format_ident!("__cucumber_{}_{}", self.attr_name, func_name);
let awaiting = func.sig.asyncness.map(|_| quote! { .await });
// TODO: Use "{e}" syntax once MSRV bumps above 1.58.
let unwrapping = (!self.returns_unit())
.then(|| quote! { .unwrap_or_else(|e| panic!("{}", e)) });
let step_caller = quote! {
Expand Down Expand Up @@ -302,6 +304,7 @@ impl Step {
return Err(syn::Error::new(ty.span(), "Type path expected"));
};

// TODO: Use "{ident}" syntax once MSRV bumps above 1.58.
let not_found_err = format!("{} not found", ident);
let parsing_err = format!(
"{} can not be parsed to {}",
Expand Down Expand Up @@ -371,6 +374,7 @@ impl Step {
}
AttributeArgument::Regex(re) => {
drop(Regex::new(re.value().as_str()).map_err(|e| {
// TODO: Use "{e}" syntax once MSRV bumps above 1.58.
syn::Error::new(re.span(), format!("Invalid regex: {}", e))
})?);

Expand Down Expand Up @@ -455,6 +459,7 @@ impl<'p> Parameters<'p> {
let expr = Expression::parse(expr).map_err(|e| {
syn::Error::new(
expr.span(),
// TODO: Use "{e}" syntax once MSRV bumps above 1.58.
format!("Incorrect cucumber expression: {}", e),
)
})?;
Expand Down Expand Up @@ -580,6 +585,7 @@ impl<'p> Parameters<'p> {
} else {
// Here we use double escaping to properly render `{name}`
// in the assertion message of the generated code.
// TODO: Use "{name}" syntax once MSRV bumps above 1.58.
let assert_msg = format!(
"Type `{}` doesn't implement a custom parameter \
`{{{{{}}}}}`",
Expand Down
15 changes: 15 additions & 0 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
clippy::fallible_impl_from,
clippy::float_cmp_const,
clippy::fn_to_numeric_cast,
clippy::fn_to_numeric_cast_any,
clippy::get_unwrap,
clippy::if_then_some_else_none,
clippy::imprecise_flops,
Expand All @@ -63,11 +64,14 @@
clippy::str_to_string,
clippy::string_add,
clippy::string_lit_as_bytes,
clippy::string_slice,
clippy::string_to_string,
clippy::suboptimal_flops,
clippy::suspicious_operation_groupings,
clippy::todo,
clippy::trailing_empty_array,
clippy::trivial_regex,
clippy::undocumented_unsafe_blocks,
clippy::unimplemented,
clippy::unnecessary_self_imports,
clippy::unneeded_field_pattern,
Expand Down Expand Up @@ -101,6 +105,17 @@ mod world_init;

use proc_macro::TokenStream;

// TODO: Remove once tests run without complains about it.
#[cfg(test)]
mod actually_used_crates_in_tests {
use async_trait as _;
use cucumber as _;
use derive_more as _;
use futures as _;
use tempfile as _;
use tokio as _;
}

/// Helper macro for generating public shims for [`macro@given`], [`macro@when`]
/// and [`macro@then`] attributes.
macro_rules! step_attribute {
Expand Down
1 change: 1 addition & 0 deletions codegen/src/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl TryFrom<syn::DeriveInput> for Definition {
let attrs: Attrs = Attrs::parse_attrs("param", &input)?;

let regex = Regex::new(&attrs.regex.value()).map_err(|e| {
// TODO: Use "{e}" syntax once MSRV bumps above 1.58.
syn::Error::new(attrs.regex.span(), format!("Invalid regex: {}", e))
})?;
if regex.captures_len() > 1 {
Expand Down
1 change: 1 addition & 0 deletions codegen/src/world_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub(crate) fn derive(
///
/// [`syn::Ident`]: struct@syn::Ident
fn step_types(steps: &[&str], world: &syn::Ident) -> Vec<syn::Ident> {
// TODO: Use "{world}" syntax once MSRV bumps above 1.58.
steps
.iter()
.map(|step| format_ident!("Cucumber{}{}", to_pascal_case(step), world))
Expand Down
4 changes: 4 additions & 0 deletions src/cucumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,7 @@ where

let failed_steps = writer.failed_steps();
if failed_steps > 0 {
// TODO: Use "{failed_steps}" syntax once MSRV bumps above 1.58.
msg.push(format!(
"{} step{} failed",
failed_steps,
Expand All @@ -1282,6 +1283,8 @@ where

let parsing_errors = writer.parsing_errors();
if parsing_errors > 0 {
// TODO: Use "{parsing_errors}" syntax once MSRV bumps above
// 1.58.
msg.push(format!(
"{} parsing error{}",
parsing_errors,
Expand All @@ -1291,6 +1294,7 @@ where

let hook_errors = writer.hook_errors();
if hook_errors > 0 {
// TODO: Use "{hook_errors}" syntax once MSRV bumps above 1.58.
msg.push(format!(
"{} hook error{}",
hook_errors,
Expand Down
1 change: 1 addition & 0 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ pub enum HookType {

impl fmt::Display for HookType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// TODO: Use "{self}" syntax once MSRV bumps above 1.58.
write!(f, "{:?}", self)
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
clippy::filetype_is_file,
clippy::float_cmp_const,
clippy::fn_to_numeric_cast,
clippy::fn_to_numeric_cast_any,
clippy::get_unwrap,
clippy::if_then_some_else_none,
clippy::imprecise_flops,
Expand All @@ -65,11 +66,14 @@
clippy::str_to_string,
clippy::string_add,
clippy::string_lit_as_bytes,
clippy::string_slice,
clippy::string_to_string,
clippy::suboptimal_flops,
clippy::suspicious_operation_groupings,
clippy::todo,
clippy::trailing_empty_array,
clippy::trivial_regex,
clippy::undocumented_unsafe_blocks,
clippy::unimplemented,
clippy::unnecessary_self_imports,
clippy::unneeded_field_pattern,
Expand Down Expand Up @@ -112,6 +116,14 @@ pub mod writer;
#[cfg(feature = "macros")]
pub mod codegen;

// TODO: Remove once tests run without complains about it.
#[cfg(test)]
mod actually_used_crates_in_tests {
use humantime as _;
use tempfile as _;
use tokio as _;
}

use std::error::Error as StdError;

use async_trait::async_trait;
Expand Down
2 changes: 2 additions & 0 deletions src/parser/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ impl<I: AsRef<Path>> Parser<I> for Basic {
.case_insensitive(true)
.build()
.unwrap_or_else(|e| {
// TODO: Use "{e}" syntax once MSRV bumps above
// 1.58.
unreachable!("GlobWalkerBuilder panicked: {}", e)
});
walk(w)
Expand Down
4 changes: 4 additions & 0 deletions src/runner/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,8 @@ where
.map_err(Info::from)
.and_then(|r| {
r.map_err(|e| {
// TODO: Use "{step:p}" syntax once MSRV bumps above
// 1.58.
coerce_into_info(format!(
"failed to initialize World: {}",
e,
Expand Down Expand Up @@ -1018,6 +1020,8 @@ where
Ok(Ok(w)) => w,
Ok(Err(e)) => {
let e = event::StepError::Panic(coerce_into_info(
// TODO: Use "{step:p}" syntax once MSRV bumps above
// 1.58.
format!("failed to initialize World: {}", e),
));
return Err((e, None, None));
Expand Down
5 changes: 5 additions & 0 deletions src/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl<World> fmt::Debug for Collection<World> {
f.debug_struct("Collection")
.field(
"given",
// TODO: Use "{step:p}" syntax once MSRV bumps above 1.58.
&self
.given
.iter()
Expand All @@ -68,6 +69,7 @@ impl<World> fmt::Debug for Collection<World> {
)
.field(
"when",
// TODO: Use "{step:p}" syntax once MSRV bumps above 1.58.
&self
.when
.iter()
Expand All @@ -76,6 +78,7 @@ impl<World> fmt::Debug for Collection<World> {
)
.field(
"then",
// TODO: Use "{step:p}" syntax once MSRV bumps above 1.58.
&self
.then
.iter()
Expand Down Expand Up @@ -184,6 +187,8 @@ impl<World> Collection<World> {
}
};

// All indices here are obtained from the source string.
#[allow(clippy::string_slice)]
let matches = iter::once(whole_match.as_str().to_owned())
.chain((1..captures.len()).map(|group_id| {
captures
Expand Down
Loading

0 comments on commit 935602b

Please sign in to comment.