Skip to content

Commit

Permalink
Tune lints for 1.73 Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranron committed Oct 6, 2023
1 parent 62579b0 commit f4ff0db
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 29 deletions.
9 changes: 9 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
# See full lints list at:
# https://rust-lang.github.io/rust-clippy/master/index.html

absolute-paths-allowed-crates = [
"base64",
"clap",
"gherkin",
"syn",
"tracing",
"tracing_subscriber",
]

doc-valid-idents = ["JUnit"]

standard-macro-braces = [
Expand Down
7 changes: 4 additions & 3 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
)]
#![forbid(non_ascii_idents, unsafe_code)]
#![warn(
clippy::absolute_paths,
clippy::as_conversions,
clippy::as_ptr_cast_mut,
clippy::assertions_on_result_states,
Expand Down Expand Up @@ -71,6 +72,7 @@
clippy::mutex_atomic,
clippy::mutex_integer,
clippy::needless_collect,
clippy::needless_pass_by_ref_mut,
clippy::needless_raw_strings,
clippy::nonstandard_macro_braces,
clippy::option_if_let_else,
Expand All @@ -83,6 +85,7 @@
clippy::pub_without_shorthand,
clippy::rc_buffer,
clippy::rc_mutex,
clippy::readonly_write_lock,
clippy::redundant_clone,
clippy::redundant_type_annotations,
clippy::ref_patterns,
Expand All @@ -95,6 +98,7 @@
clippy::str_to_string,
clippy::string_add,
clippy::string_lit_as_bytes,
clippy::string_lit_chars_any,
clippy::string_slice,
clippy::string_to_string,
clippy::suboptimal_flops,
Expand All @@ -106,7 +110,6 @@
clippy::transmute_undefined_repr,
clippy::trivial_regex,
clippy::try_err,
clippy::tuple_array_conversions,
clippy::undocumented_unsafe_blocks,
clippy::unimplemented,
clippy::unnecessary_safety_comment,
Expand All @@ -123,13 +126,11 @@
clippy::verbose_file_reads,
clippy::wildcard_enum_match_arm,
future_incompatible,
invalid_reference_casting,
let_underscore_drop,
meta_variable_misuse,
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
noop_method_call,
semicolon_in_expressions_from_macros,
unreachable_pub,
unused_crate_dependencies,
Expand Down
23 changes: 11 additions & 12 deletions src/cucumber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use std::{
borrow::Cow,
fmt::{Debug, Formatter},
fmt::{self, Debug},
marker::PhantomData,
mem,
path::Path,
Expand Down Expand Up @@ -201,7 +201,7 @@ where
/// </script>
///
/// [`Scenario`]: gherkin::Scenario
/// [`Skipped`]: crate::event::Step::Skipped
/// [`Skipped`]: event::Step::Skipped
#[must_use]
pub fn repeat_skipped(
self,
Expand Down Expand Up @@ -266,7 +266,7 @@ where
/// async data-autoplay="true" data-rows="24">
/// </script>
///
/// [`Failed`]: crate::event::Step::Failed
/// [`Failed`]: event::Step::Failed
#[must_use]
pub fn repeat_failed(
self,
Expand Down Expand Up @@ -365,7 +365,7 @@ where
/// async data-autoplay="true" data-rows="24">
/// </script>
///
/// [`Failed`]: crate::event::Step::Failed
/// [`Failed`]: event::Step::Failed
#[must_use]
pub fn repeat_if<F>(
self,
Expand Down Expand Up @@ -438,9 +438,9 @@ where
/// ```
///
/// [`Background`]: gherkin::Background
/// [`Failed`]: crate::event::Step::Failed
/// [`Failed`]: event::Step::Failed
/// [`Scenario`]: gherkin::Scenario
/// [`Skipped`]: crate::event::Step::Skipped
/// [`Skipped`]: event::Step::Skipped
/// [`Step`]: gherkin::Step
#[must_use]
pub fn fail_on_skipped(
Expand Down Expand Up @@ -520,9 +520,9 @@ where
/// ```
///
/// [`Background`]: gherkin::Background
/// [`Failed`]: crate::event::Step::Failed
/// [`Failed`]: event::Step::Failed
/// [`Scenario`]: gherkin::Scenario
/// [`Skipped`]: crate::event::Step::Skipped
/// [`Skipped`]: event::Step::Skipped
/// [`Step`]: gherkin::Step
#[must_use]
pub fn fail_on_skipped_with<Filter>(
Expand Down Expand Up @@ -829,7 +829,7 @@ where
<Wr as Writer<W>>::Cli: Debug,
Cli: clap::Args + Debug,
{
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Cucumber")
.field("parser", &self.parser)
.field("runner", &self.runner)
Expand Down Expand Up @@ -1193,7 +1193,7 @@ where
/// If encountered errors while parsing [`Feature`]s or at least one
/// [`Step`] [`Failed`].
///
/// [`Failed`]: crate::event::Step::Failed
/// [`Failed`]: event::Step::Failed
/// [`Feature`]: gherkin::Feature
/// [`Step`]: gherkin::Step
pub async fn run_and_exit(self, input: I) {
Expand Down Expand Up @@ -1249,10 +1249,9 @@ where
/// async data-autoplay="true" data-rows="14">
/// </script>
///
/// [`Failed`]: crate::event::Step::Failed
/// [`Failed`]: event::Step::Failed
/// [`Feature`]: gherkin::Feature
/// [`Scenario`]: gherkin::Scenario
/// [`Step`]: crate::Step
pub async fn filter_run_and_exit<Filter>(self, input: I, filter: Filter)
where
Filter: Fn(
Expand Down
10 changes: 7 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)]
#![forbid(non_ascii_idents, unsafe_code)]
#![warn(
clippy::absolute_paths,
clippy::as_conversions,
clippy::as_ptr_cast_mut,
clippy::assertions_on_result_states,
Expand Down Expand Up @@ -72,6 +73,7 @@
clippy::mutex_atomic,
clippy::mutex_integer,
clippy::needless_collect,
clippy::needless_pass_by_ref_mut,
clippy::needless_raw_strings,
clippy::nonstandard_macro_braces,
clippy::option_if_let_else,
Expand All @@ -84,6 +86,7 @@
clippy::pub_without_shorthand,
clippy::rc_buffer,
clippy::rc_mutex,
clippy::readonly_write_lock,
clippy::redundant_clone,
clippy::redundant_type_annotations,
clippy::ref_patterns,
Expand All @@ -96,6 +99,7 @@
clippy::str_to_string,
clippy::string_add,
clippy::string_lit_as_bytes,
clippy::string_lit_chars_any,
clippy::string_slice,
clippy::string_to_string,
clippy::suboptimal_flops,
Expand All @@ -107,7 +111,6 @@
clippy::transmute_undefined_repr,
clippy::trivial_regex,
clippy::try_err,
clippy::tuple_array_conversions,
clippy::undocumented_unsafe_blocks,
clippy::unimplemented,
clippy::unnecessary_safety_comment,
Expand All @@ -124,13 +127,11 @@
clippy::verbose_file_reads,
clippy::wildcard_enum_match_arm,
future_incompatible,
invalid_reference_casting,
let_underscore_drop,
meta_variable_misuse,
missing_copy_implementations,
missing_debug_implementations,
missing_docs,
noop_method_call,
semicolon_in_expressions_from_macros,
unreachable_pub,
unused_crate_dependencies,
Expand All @@ -145,6 +146,9 @@
)]
// TODO: Remove on next `derive_more` major version.
#![allow(clippy::uninlined_format_args)]
// TODO: Massive false positives on `.await` points. Try remove on next Rust
// version.
#![allow(clippy::multiple_unsafe_ops_per_block)]

pub mod cli;
mod cucumber;
Expand Down
2 changes: 1 addition & 1 deletion src/parser/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<I: AsRef<Path>> Parser<I> for Basic {
.case_insensitive(true)
.build()
.unwrap_or_else(|e| {
unreachable!("GlobWalkerBuilder panicked: {e}")
unreachable!("`GlobWalkerBuilder` panicked: {e}")
});
walk(w)
}
Expand Down
1 change: 1 addition & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub trait Parser<I> {
/// Result of parsing [Gherkin] files.
///
/// [Gherkin]: https://cucumber.io/docs/gherkin/reference
#[allow(clippy::absolute_paths)]
pub type Result<T> = std::result::Result<T, Error>;

/// [`Parser`] error.
Expand Down
3 changes: 2 additions & 1 deletion src/runner/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//! Default [`Runner`] implementation.

use std::{
any::Any,
cmp,
collections::HashMap,
fmt, iter, mem,
Expand Down Expand Up @@ -2392,7 +2393,7 @@ impl Features {
}

/// Coerces the given `value` into a type-erased [`Info`].
fn coerce_into_info<T: std::any::Any + Send + 'static>(val: T) -> Info {
fn coerce_into_info<T: Any + Send + 'static>(val: T) -> Info {
Arc::new(val)
}

Expand Down
2 changes: 1 addition & 1 deletion src/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl Eq for HashableRegex {}

impl PartialOrd for HashableRegex {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.0.as_str().partial_cmp(other.0.as_str())
Some(self.cmp(other))
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/writer/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,8 @@ fn format_str_with_indent(str: impl AsRef<str>, indent: usize) -> String {
/// Formats the given [`gherkin::Table`] and adds `indent`s to each line to
/// prettify the output.
fn format_table(table: &gherkin::Table, indent: usize) -> String {
use std::fmt::Write as _;

let max_row_len = table
.rows
.iter()
Expand All @@ -1063,10 +1065,13 @@ fn format_table(table: &gherkin::Table, indent: usize) -> String {
.rows
.iter()
.map(|row| {
row.iter()
.zip(&max_row_len)
.map(|(cell, len)| format!("| {cell:len$} "))
.collect::<String>()
row.iter().zip(&max_row_len).fold(
String::new(),
|mut out, (cell, len)| {
_ = write!(out, "| {cell:len$} ");
out
},
)
})
.map(|row| format!("{}{row}", " ".repeat(indent + 1)))
.join("|\n");
Expand Down
6 changes: 3 additions & 3 deletions src/writer/discard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use async_trait::async_trait;
use derive_more::{Deref, DerefMut};

use crate::{event::Cucumber, writer, Event, World, Writer};
use crate::{event::Cucumber, parser, writer, Event, World, Writer};

/// Wrapper providing a no-op [`ArbitraryWriter`] implementation.
///
Expand All @@ -31,7 +31,7 @@ impl<W: World, Wr: Writer<W> + ?Sized> Writer<W> for Arbitrary<Wr> {

async fn handle_event(
&mut self,
ev: crate::parser::Result<Event<Cucumber<W>>>,
ev: parser::Result<Event<Cucumber<W>>>,
cli: &Self::Cli,
) {
self.0.handle_event(ev, cli).await;
Expand Down Expand Up @@ -122,7 +122,7 @@ impl<W: World, Wr: Writer<W> + ?Sized> Writer<W> for Stats<Wr> {

async fn handle_event(
&mut self,
ev: crate::parser::Result<Event<Cucumber<W>>>,
ev: parser::Result<Event<Cucumber<W>>>,
cli: &Self::Cli,
) {
self.0.handle_event(ev, cli).await;
Expand Down
2 changes: 1 addition & 1 deletion src/writer/out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub trait WriteStrExt: io::Write {
/// If this writer fails to write the given `string`.
fn write_line(&mut self, string: impl AsRef<str>) -> io::Result<()> {
self.write_str(string.as_ref())
.and_then(|_| self.write_str("\n"))
.and_then(|()| self.write_str("\n"))
.map(drop)
}

Expand Down

0 comments on commit f4ff0db

Please sign in to comment.