From d84136e1e4da054f74f207c7841ed624ce0d8462 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Sat, 30 Nov 2024 16:53:48 +0100 Subject: [PATCH] Centralize lint configuration (#3055) --- Cargo.toml | 38 ++++++++++++++++++++++++++++ axum-core/Cargo.toml | 3 +++ axum-core/src/lib.rs | 37 --------------------------- axum-extra/Cargo.toml | 3 +++ axum-extra/src/lib.rs | 37 --------------------------- axum-macros/Cargo.toml | 3 +++ axum-macros/src/attr_parsing.rs | 4 +-- axum-macros/src/axum_test.rs | 2 +- axum-macros/src/debug_handler.rs | 2 +- axum-macros/src/from_ref.rs | 2 +- axum-macros/src/from_request/attr.rs | 4 +-- axum-macros/src/lib.rs | 37 --------------------------- axum-macros/src/typed_path.rs | 2 +- axum/Cargo.toml | 9 ++++--- axum/benches/benches.rs | 2 ++ axum/src/box_clone_service.rs | 2 +- axum/src/lib.rs | 36 -------------------------- axum/src/routing/tests/mod.rs | 2 +- axum/src/routing/url_params.rs | 2 +- 19 files changed, 66 insertions(+), 161 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f9c9d027b2..298b9b3b3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,41 @@ resolver = "2" [workspace.package] rust-version = "1.75" + +[workspace.lints.rust] +unsafe_code = "forbid" + +rust_2018_idioms = { level = "warn", priority = -1 } +missing_debug_implementations = "warn" +missing_docs = "warn" +unreachable_pub = "warn" + +[workspace.lints.clippy] +type_complexity = "allow" + +await_holding_lock = "warn" +dbg_macro = "warn" +empty_enum = "warn" +enum_glob_use = "warn" +exit = "warn" +filter_map_next = "warn" +fn_params_excessive_bools = "warn" +if_let_mutex = "warn" +imprecise_flops = "warn" +inefficient_to_string = "warn" +linkedlist = "warn" +lossy_float_literal = "warn" +macro_use_imports = "warn" +match_on_vec_items = "warn" +match_wildcard_for_single_variants = "warn" +mem_forget = "warn" +needless_borrow = "warn" +needless_continue = "warn" +option_option = "warn" +rest_pat_in_fully_bound_structs = "warn" +str_to_string = "warn" +suboptimal_flops = "warn" +todo = "warn" +unnested_or_patterns = "warn" +unused_self = "warn" +verbose_file_reads = "warn" diff --git a/axum-core/Cargo.toml b/axum-core/Cargo.toml index d8207e1399..adfe5b3a16 100644 --- a/axum-core/Cargo.toml +++ b/axum-core/Cargo.toml @@ -42,6 +42,9 @@ hyper = "1.0.0" tokio = { version = "1.25.0", features = ["macros"] } tower-http = { version = "0.6.0", features = ["limit"] } +[lints] +workspace = true + [package.metadata.cargo-public-api-crates] allowed = [ # not 1.0 diff --git a/axum-core/src/lib.rs b/axum-core/src/lib.rs index 134c566b30..60f0dcfcd3 100644 --- a/axum-core/src/lib.rs +++ b/axum-core/src/lib.rs @@ -8,43 +8,6 @@ //! [`axum`]: https://crates.io/crates/axum //! [`axum-core`]: http://crates.io/crates/axum-core -#![warn( - clippy::all, - clippy::dbg_macro, - clippy::todo, - clippy::empty_enum, - clippy::enum_glob_use, - clippy::mem_forget, - clippy::unused_self, - clippy::filter_map_next, - clippy::needless_continue, - clippy::needless_borrow, - clippy::match_wildcard_for_single_variants, - clippy::if_let_mutex, - clippy::await_holding_lock, - clippy::match_on_vec_items, - clippy::imprecise_flops, - clippy::suboptimal_flops, - clippy::lossy_float_literal, - clippy::rest_pat_in_fully_bound_structs, - clippy::fn_params_excessive_bools, - clippy::exit, - clippy::inefficient_to_string, - clippy::linkedlist, - clippy::macro_use_imports, - clippy::option_option, - clippy::verbose_file_reads, - clippy::unnested_or_patterns, - clippy::str_to_string, - rust_2018_idioms, - future_incompatible, - nonstandard_style, - missing_debug_implementations, - missing_docs -)] -#![deny(unreachable_pub)] -#![allow(elided_lifetimes_in_paths, clippy::type_complexity)] -#![forbid(unsafe_code)] #![cfg_attr(test, allow(clippy::float_cmp))] #![cfg_attr(not(test), warn(clippy::print_stdout, clippy::dbg_macro))] diff --git a/axum-extra/Cargo.toml b/axum-extra/Cargo.toml index c357975ad4..6bfe835a13 100644 --- a/axum-extra/Cargo.toml +++ b/axum-extra/Cargo.toml @@ -84,6 +84,9 @@ tokio = { version = "1.14", features = ["full"] } tower = { version = "0.5.1", features = ["util"] } tower-http = { version = "0.6.0", features = ["map-response-body", "timeout"] } +[lints] +workspace = true + [package.metadata.docs.rs] all-features = true diff --git a/axum-extra/src/lib.rs b/axum-extra/src/lib.rs index 473c42742c..5bdab167a9 100644 --- a/axum-extra/src/lib.rs +++ b/axum-extra/src/lib.rs @@ -28,43 +28,6 @@ //! //! [`axum`]: https://crates.io/crates/axum -#![warn( - clippy::all, - clippy::dbg_macro, - clippy::todo, - clippy::empty_enum, - clippy::enum_glob_use, - clippy::mem_forget, - clippy::unused_self, - clippy::filter_map_next, - clippy::needless_continue, - clippy::needless_borrow, - clippy::match_wildcard_for_single_variants, - clippy::if_let_mutex, - clippy::await_holding_lock, - clippy::match_on_vec_items, - clippy::imprecise_flops, - clippy::suboptimal_flops, - clippy::lossy_float_literal, - clippy::rest_pat_in_fully_bound_structs, - clippy::fn_params_excessive_bools, - clippy::exit, - clippy::inefficient_to_string, - clippy::linkedlist, - clippy::macro_use_imports, - clippy::option_option, - clippy::verbose_file_reads, - clippy::unnested_or_patterns, - clippy::str_to_string, - rust_2018_idioms, - future_incompatible, - nonstandard_style, - missing_debug_implementations, - missing_docs -)] -#![deny(unreachable_pub)] -#![allow(elided_lifetimes_in_paths, clippy::type_complexity)] -#![forbid(unsafe_code)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(test, allow(clippy::float_cmp))] #![cfg_attr(not(test), warn(clippy::print_stdout, clippy::dbg_macro))] diff --git a/axum-macros/Cargo.toml b/axum-macros/Cargo.toml index 1960a465da..8ba7c099db 100644 --- a/axum-macros/Cargo.toml +++ b/axum-macros/Cargo.toml @@ -38,6 +38,9 @@ syn = { version = "2.0", features = ["full", "extra-traits"] } tokio = { version = "1.25.0", features = ["full"] } trybuild = "1.0.63" +[lints] +workspace = true + [package.metadata.cargo-public-api-crates] allowed = [] diff --git a/axum-macros/src/attr_parsing.rs b/axum-macros/src/attr_parsing.rs index 67da01eb68..9e3b4bca7a 100644 --- a/axum-macros/src/attr_parsing.rs +++ b/axum-macros/src/attr_parsing.rs @@ -5,7 +5,7 @@ use syn::{ }; pub(crate) fn parse_parenthesized_attribute( - input: ParseStream, + input: ParseStream<'_>, out: &mut Option<(K, T)>, ) -> syn::Result<()> where @@ -30,7 +30,7 @@ where } pub(crate) fn parse_assignment_attribute( - input: ParseStream, + input: ParseStream<'_>, out: &mut Option<(K, T)>, ) -> syn::Result<()> where diff --git a/axum-macros/src/axum_test.rs b/axum-macros/src/axum_test.rs index bc664fd8f3..0e881ef2da 100644 --- a/axum-macros/src/axum_test.rs +++ b/axum-macros/src/axum_test.rs @@ -16,7 +16,7 @@ pub(crate) fn expand(_attr: Attrs, mut item_fn: ItemFn) -> TokenStream { pub(crate) struct Attrs; impl Parse for Attrs { - fn parse(_input: syn::parse::ParseStream) -> syn::Result { + fn parse(_input: syn::parse::ParseStream<'_>) -> syn::Result { Ok(Self) } } diff --git a/axum-macros/src/debug_handler.rs b/axum-macros/src/debug_handler.rs index 456bd643ea..82f383286a 100644 --- a/axum-macros/src/debug_handler.rs +++ b/axum-macros/src/debug_handler.rs @@ -122,7 +122,7 @@ pub(crate) struct Attrs { } impl Parse for Attrs { - fn parse(input: syn::parse::ParseStream) -> syn::Result { + fn parse(input: syn::parse::ParseStream<'_>) -> syn::Result { let mut state_ty = None; while !input.is_empty() { diff --git a/axum-macros/src/from_ref.rs b/axum-macros/src/from_ref.rs index 1a27765a4f..9cf317da97 100644 --- a/axum-macros/src/from_ref.rs +++ b/axum-macros/src/from_ref.rs @@ -73,7 +73,7 @@ pub(super) struct FieldAttrs { } impl Parse for FieldAttrs { - fn parse(input: ParseStream) -> syn::Result { + fn parse(input: ParseStream<'_>) -> syn::Result { let mut skip = None; while !input.is_empty() { diff --git a/axum-macros/src/from_request/attr.rs b/axum-macros/src/from_request/attr.rs index 77dfc470ae..ae56075a25 100644 --- a/axum-macros/src/from_request/attr.rs +++ b/axum-macros/src/from_request/attr.rs @@ -18,7 +18,7 @@ pub(super) struct FromRequestContainerAttrs { } impl Parse for FromRequestContainerAttrs { - fn parse(input: ParseStream) -> syn::Result { + fn parse(input: ParseStream<'_>) -> syn::Result { let mut via = None; let mut rejection = None; let mut state = None; @@ -66,7 +66,7 @@ pub(super) struct FromRequestFieldAttrs { } impl Parse for FromRequestFieldAttrs { - fn parse(input: ParseStream) -> syn::Result { + fn parse(input: ParseStream<'_>) -> syn::Result { let mut via = None; while !input.is_empty() { diff --git a/axum-macros/src/lib.rs b/axum-macros/src/lib.rs index f5aeaab748..86b2c1c21b 100644 --- a/axum-macros/src/lib.rs +++ b/axum-macros/src/lib.rs @@ -2,43 +2,6 @@ //! //! [`axum`]: https://crates.io/crates/axum -#![warn( - clippy::all, - clippy::dbg_macro, - clippy::todo, - clippy::empty_enum, - clippy::enum_glob_use, - clippy::mem_forget, - clippy::unused_self, - clippy::filter_map_next, - clippy::needless_continue, - clippy::needless_borrow, - clippy::match_wildcard_for_single_variants, - clippy::if_let_mutex, - clippy::await_holding_lock, - clippy::match_on_vec_items, - clippy::imprecise_flops, - clippy::suboptimal_flops, - clippy::lossy_float_literal, - clippy::rest_pat_in_fully_bound_structs, - clippy::fn_params_excessive_bools, - clippy::exit, - clippy::inefficient_to_string, - clippy::linkedlist, - clippy::macro_use_imports, - clippy::option_option, - clippy::verbose_file_reads, - clippy::unnested_or_patterns, - clippy::str_to_string, - rust_2018_idioms, - future_incompatible, - nonstandard_style, - missing_debug_implementations, - missing_docs -)] -#![deny(unreachable_pub)] -#![allow(elided_lifetimes_in_paths, clippy::type_complexity)] -#![forbid(unsafe_code)] #![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(test, allow(clippy::float_cmp))] #![cfg_attr(not(test), warn(clippy::print_stdout, clippy::dbg_macro))] diff --git a/axum-macros/src/typed_path.rs b/axum-macros/src/typed_path.rs index fa272252be..397cc94c0d 100644 --- a/axum-macros/src/typed_path.rs +++ b/axum-macros/src/typed_path.rs @@ -55,7 +55,7 @@ struct Attrs { } impl Parse for Attrs { - fn parse(input: syn::parse::ParseStream) -> syn::Result { + fn parse(input: syn::parse::ParseStream<'_>) -> syn::Result { let mut path = None; let mut rejection = None; diff --git a/axum/Cargo.toml b/axum/Cargo.toml index ef113c335b..5ede7517c1 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -131,9 +131,6 @@ tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["json"] } uuid = { version = "1.0", features = ["serde", "v4"] } -[package.metadata.docs.rs] -all-features = true - [dev-dependencies.tower] package = "tower" version = "0.5.1" @@ -180,6 +177,12 @@ features = [ "validate-request", ] +[lints] +workspace = true + +[package.metadata.docs.rs] +all-features = true + [package.metadata.playground] features = [ "http1", diff --git a/axum/benches/benches.rs b/axum/benches/benches.rs index bb1c303dd1..445f5de03e 100644 --- a/axum/benches/benches.rs +++ b/axum/benches/benches.rs @@ -1,3 +1,5 @@ +#![allow(missing_docs)] + use axum::{ extract::State, routing::{get, post}, diff --git a/axum/src/box_clone_service.rs b/axum/src/box_clone_service.rs index 25c0b205b8..298bf2894a 100644 --- a/axum/src/box_clone_service.rs +++ b/axum/src/box_clone_service.rs @@ -74,7 +74,7 @@ where } impl fmt::Debug for BoxCloneService { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { fmt.debug_struct("BoxCloneService").finish() } } diff --git a/axum/src/lib.rs b/axum/src/lib.rs index fcc929a6ab..2eab2af58c 100644 --- a/axum/src/lib.rs +++ b/axum/src/lib.rs @@ -420,42 +420,6 @@ //! [`axum-core`]: http://crates.io/crates/axum-core //! [`State`]: crate::extract::State -#![warn( - clippy::all, - clippy::todo, - clippy::empty_enum, - clippy::enum_glob_use, - clippy::mem_forget, - clippy::unused_self, - clippy::filter_map_next, - clippy::needless_continue, - clippy::needless_borrow, - clippy::match_wildcard_for_single_variants, - clippy::if_let_mutex, - clippy::await_holding_lock, - clippy::match_on_vec_items, - clippy::imprecise_flops, - clippy::suboptimal_flops, - clippy::lossy_float_literal, - clippy::rest_pat_in_fully_bound_structs, - clippy::fn_params_excessive_bools, - clippy::exit, - clippy::inefficient_to_string, - clippy::linkedlist, - clippy::macro_use_imports, - clippy::option_option, - clippy::verbose_file_reads, - clippy::unnested_or_patterns, - clippy::str_to_string, - rust_2018_idioms, - future_incompatible, - nonstandard_style, - missing_debug_implementations, - missing_docs -)] -#![deny(unreachable_pub)] -#![allow(elided_lifetimes_in_paths, clippy::type_complexity)] -#![forbid(unsafe_code)] #![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))] #![cfg_attr(test, allow(clippy::float_cmp))] #![cfg_attr(not(test), warn(clippy::print_stdout, clippy::dbg_macro))] diff --git a/axum/src/routing/tests/mod.rs b/axum/src/routing/tests/mod.rs index 1993373e8c..8851738667 100644 --- a/axum/src/routing/tests/mod.rs +++ b/axum/src/routing/tests/mod.rs @@ -981,7 +981,7 @@ async fn logging_rejections() { .await; assert_eq!( - dbg!(events), + events, Vec::from([ TracingEvent { fields: RejectionEvent { diff --git a/axum/src/routing/url_params.rs b/axum/src/routing/url_params.rs index eb5a08a330..1649a9e4cf 100644 --- a/axum/src/routing/url_params.rs +++ b/axum/src/routing/url_params.rs @@ -9,7 +9,7 @@ pub(crate) enum UrlParams { InvalidUtf8InPathParam { key: Arc }, } -pub(super) fn insert_url_params(extensions: &mut Extensions, params: Params) { +pub(super) fn insert_url_params(extensions: &mut Extensions, params: Params<'_, '_>) { let current_params = extensions.get_mut(); if let Some(UrlParams::InvalidUtf8InPathParam { .. }) = current_params {