diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 000000000..87702c79e --- /dev/null +++ b/.clippy.toml @@ -0,0 +1,21 @@ +msrv = "1.67" + +missing-docs-in-crate-items = true +disallowed-macros = [ + "std::column", + "std::env", + "std::file", + "std::include_bytes", + "std::include_str", + "std::include", + "std::line", + "std::module_path", + "std::option_env", +] +disallowed-names = ["alpha", "beta", "gamma", "delta"] +matches-for-let-else = "AllTypes" +enforced-import-renames = [ + { path = "std::time::Duration", rename = "StdDuration" }, + { path = "std::time::Instant", rename = "StdInstant" }, +] +semicolon-outside-block-ignore-multiline = true diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index fd925bca6..81f1f21c0 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -260,7 +260,9 @@ jobs: uses: actions/checkout@v3 - name: Install toolchain - uses: dtolnay/rust-toolchain@stable + uses: dtolnay/rust-toolchain@nightly + with: + components: clippy - name: Install targets run: | @@ -272,8 +274,8 @@ jobs: x86_64-unknown-illumos \ wasm32-wasi - - name: Cache cargo output - uses: Swatinem/rust-cache@v2 + # - name: Cache cargo output + # uses: Swatinem/rust-cache@v2 - name: Run clippy run: | @@ -286,7 +288,8 @@ jobs: --target x86_64-pc-windows-gnu \ --target x86_64-unknown-netbsd \ --target x86_64-unknown-illumos \ - --target wasm32-wasi + --target wasm32-wasi \ + -Zlints env: RUSTFLAGS: --cfg bench diff --git a/Cargo.toml b/Cargo.toml index 3d785629e..381122f79 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,3 +27,95 @@ debug = 0 [profile.test] debug = 2 + +# Deny-by-default lints: These are lints that indicate a lack of compiler guarantees, future +# incompatibility (with no guarantees in the meantime) introduce surprising behavior, or are likely +# to cause undesired behavior. Code that trigger these lints should only be allowed with a +# compelling reason that is clearly documented. + +# Warn-by-default lints: These are lints that indicate possible errors, future incompatibility +# (with guaranteed behavior in the meantime), or other stylistic issues (including idioms). Code +# that trigger these lints should not cause undesired behavior and may be allowed as necessary. + +# All overrides need higher priority. Any overrides that are for a specific crate need to be done +# the "traditional" way of using attributes at the crate root. + +[workspace.lints.rust] +ambiguous-glob-reexports = "deny" +clashing-extern-declarations = "deny" +const-item-mutation = "deny" +deref-nullptr = "deny" +drop-bounds = "deny" +future-incompatible = "deny" +hidden-glob-reexports = "deny" +improper-ctypes = "deny" +improper-ctypes-definitions = "deny" +invalid-from-utf8 = "deny" +invalid-macro-export-arguments = "deny" +invalid-nan-comparisons = "deny" +invalid-reference-casting = "deny" +invalid-value = "deny" +named-arguments-used-positionally = "deny" +non-ascii-idents = "deny" +opaque-hidden-inferred-bound = "deny" +overlapping-range-endpoints = "deny" +suspicious-double-ref-op = "deny" +temporary-cstring-as-ptr = "deny" +unconditional-recursion = "deny" +unnameable-test-items = "deny" +unsafe-op-in-unsafe-fn = "deny" +unstable-syntax-pre-expansion = "deny" + +keyword-idents = "warn" +let-underscore = "warn" +macro-use-extern-crate = "warn" +meta-variable-misuse = "warn" +missing-abi = "warn" +missing-copy-implementations = "warn" +missing-debug-implementations = "warn" +missing-docs = "warn" +noop-method-call = "warn" +single-use-lifetimes = "warn" +trivial-casts = "warn" +trivial-numeric-casts = "warn" +unreachable-pub = "warn" +unstable-name-collisions = { level = "warn", priority = 1 } # overrides #![deny(future_incompatible)] +unused = "warn" +unused-import-braces = "warn" +unused-lifetimes = "warn" +unused-qualifications = "warn" +# unused-results = "warn" +unused-tuple-struct-fields = "warn" +variant-size-differences = "warn" + +[workspace.lints.clippy] +alloc-instead-of-core = "deny" +std-instead-of-core = "deny" +undocumented-unsafe-blocks = "deny" + +all = "warn" +dbg-macro = "warn" +decimal-literal-representation = "warn" +explicit-auto-deref = "warn" +get-unwrap = "warn" +manual-let-else = "warn" +missing-docs-in-private-items = "warn" +missing-enforced-import-renames = "warn" +nursery = "warn" +obfuscated-if-else = "warn" +print-stdout = "warn" +semicolon-outside-block = "warn" +todo = "warn" +unimplemented = "warn" +uninlined-format-args = "warn" +unnested-or-patterns = "warn" +unwrap-in-result = "warn" +unwrap-used = "warn" +use-debug = "warn" + +option-if-let-else = { level = "allow", priority = 1 } # suggests terrible code, overrides #![warn(clippy::nursery)] +redundant-pub-crate = { level = "allow", priority = 1 } # rust-lang/rust-clippy#5369, overrides #![warn(clippy::nursery)] + +[workspace.lints.rustdoc] +private-doc-tests = "warn" +unescaped-backticks = "warn" diff --git a/benchmarks/main.rs b/benchmarks/main.rs index f4abb6860..bbb52c821 100644 --- a/benchmarks/main.rs +++ b/benchmarks/main.rs @@ -1,34 +1,10 @@ -#![deny( - anonymous_parameters, - clippy::all, - illegal_floating_point_literal_pattern, - late_bound_lifetime_arguments, - path_statements, - patterns_in_fns_without_body, - rust_2018_idioms, - trivial_casts, - trivial_numeric_casts, - unreachable_pub, - unsafe_code, - unused_extern_crates +#![allow( + missing_docs, + clippy::missing_docs_in_private_items, + clippy::std_instead_of_core, // irrelevant for benchmarks + clippy::std_instead_of_alloc, // irrelevant for benchmarks + clippy::alloc_instead_of_core, // irrelevant for benchmarks )] -#![warn( - clippy::dbg_macro, - clippy::decimal_literal_representation, - clippy::get_unwrap, - clippy::nursery, - clippy::print_stdout, - clippy::todo, - clippy::unimplemented, - clippy::unwrap_in_result, - clippy::unwrap_used, - clippy::use_debug, - missing_copy_implementations, - missing_debug_implementations, - unused_qualifications, - variant_size_differences -)] -#![allow(clippy::many_single_char_names)] #[cfg(not(all( feature = "default", diff --git a/tests/main.rs b/tests/main.rs index 3714042a6..9959a7d7d 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -1,38 +1,10 @@ -#![deny( - anonymous_parameters, - clippy::all, - clippy::undocumented_unsafe_blocks, - illegal_floating_point_literal_pattern, - late_bound_lifetime_arguments, - path_statements, - patterns_in_fns_without_body, - rust_2018_idioms, - trivial_casts, - trivial_numeric_casts, - unreachable_pub, - unused_extern_crates -)] -#![warn( - clippy::dbg_macro, - clippy::decimal_literal_representation, - clippy::get_unwrap, - clippy::missing_docs_in_private_items, - clippy::nursery, - clippy::print_stdout, - clippy::todo, - clippy::unimplemented, - clippy::unwrap_in_result, - clippy::unwrap_used, - clippy::use_debug, - unused_qualifications, - variant_size_differences -)] #![allow( - clippy::clone_on_copy, - clippy::cmp_owned, - clippy::cognitive_complexity, - clippy::missing_const_for_fn, - clippy::unwrap_used + clippy::missing_const_for_fn, // irrelevant for tests + clippy::std_instead_of_core, // irrelevant for tests + clippy::std_instead_of_alloc, // irrelevant for tests + clippy::alloc_instead_of_core, // irrelevant for tests + clippy::cognitive_complexity, // TODO split up tests as necessary + clippy::unwrap_used, // TODO convert to expect or better error handling )] #[cfg(not(all( diff --git a/time-core/Cargo.toml b/time-core/Cargo.toml index f8587686e..a9c32b8d3 100644 --- a/time-core/Cargo.toml +++ b/time-core/Cargo.toml @@ -13,4 +13,7 @@ description = "This crate is an implementation detail and should not be relied u [package.metadata.docs.rs] rustdoc-args = ["--generate-link-to-definition"] +[lints] +workspace = true + [dependencies] diff --git a/time-core/src/lib.rs b/time-core/src/lib.rs index 4f1c53b12..b806a0c9f 100644 --- a/time-core/src/lib.rs +++ b/time-core/src/lib.rs @@ -3,47 +3,7 @@ //! This crate is an implementation detail of `time` and should not be relied upon directly. #![no_std] -#![deny( - anonymous_parameters, - clippy::all, - clippy::alloc_instead_of_core, - clippy::explicit_auto_deref, - clippy::obfuscated_if_else, - clippy::std_instead_of_core, - clippy::undocumented_unsafe_blocks, - illegal_floating_point_literal_pattern, - late_bound_lifetime_arguments, - path_statements, - patterns_in_fns_without_body, - rust_2018_idioms, - trivial_casts, - trivial_numeric_casts, - unreachable_pub, - unsafe_op_in_unsafe_fn, - unused_extern_crates, - rustdoc::broken_intra_doc_links, - rustdoc::private_intra_doc_links -)] -#![warn( - clippy::dbg_macro, - clippy::decimal_literal_representation, - clippy::get_unwrap, - clippy::missing_docs_in_private_items, - clippy::nursery, - clippy::print_stdout, - clippy::todo, - clippy::unimplemented, - clippy::unnested_or_patterns, - clippy::unwrap_in_result, - clippy::unwrap_used, - clippy::use_debug, - deprecated_in_future, - missing_copy_implementations, - missing_debug_implementations, - unused_qualifications, - variant_size_differences -)] -#![allow(clippy::redundant_pub_crate)] +#![allow(missing_docs)] // TODO remove #![doc(html_favicon_url = "https://avatars0.githubusercontent.com/u/55999857")] #![doc(html_logo_url = "https://avatars0.githubusercontent.com/u/55999857")] #![doc(test(attr(deny(warnings))))] diff --git a/time-macros/Cargo.toml b/time-macros/Cargo.toml index 567fea980..e886eb808 100644 --- a/time-macros/Cargo.toml +++ b/time-macros/Cargo.toml @@ -25,5 +25,8 @@ proc-macro = true [package.metadata.docs.rs] rustdoc-args = ["--generate-link-to-definition"] +[lints] +workspace = true + [dependencies] time-core = { workspace = true } diff --git a/time-macros/src/lib.rs b/time-macros/src/lib.rs index 0e8568cda..5cb72a647 100644 --- a/time-macros/src/lib.rs +++ b/time-macros/src/lib.rs @@ -1,37 +1,12 @@ -#![deny( - anonymous_parameters, - clippy::all, - illegal_floating_point_literal_pattern, - late_bound_lifetime_arguments, - path_statements, - patterns_in_fns_without_body, - rust_2018_idioms, - trivial_casts, - trivial_numeric_casts, - unreachable_pub, - unsafe_code, - unused_extern_crates -)] -#![warn( - clippy::dbg_macro, - clippy::decimal_literal_representation, - clippy::get_unwrap, - clippy::nursery, - clippy::print_stdout, - clippy::todo, - clippy::unimplemented, - clippy::unnested_or_patterns, - clippy::unwrap_used, - clippy::use_debug, - single_use_lifetimes, - unused_qualifications, - variant_size_differences -)] #![allow( - clippy::missing_const_for_fn, // useless in proc macro - clippy::redundant_pub_crate, // suggests bad style - clippy::option_if_let_else, // suggests terrible code + clippy::missing_const_for_fn, // irrelevant for proc macros + clippy::missing_docs_in_private_items, // TODO remove + clippy::std_instead_of_core, // irrelevant for proc macros + clippy::std_instead_of_alloc, // irrelevant for proc macros + clippy::alloc_instead_of_core, // irrelevant for proc macros + missing_docs, // TODO remove )] + #[allow(unused_macros)] macro_rules! bug { () => { compile_error!("provide an error message to help fix a possible bug") }; diff --git a/time-macros/src/to_tokens.rs b/time-macros/src/to_tokens.rs index 7e7321153..7802158ce 100644 --- a/time-macros/src/to_tokens.rs +++ b/time-macros/src/to_tokens.rs @@ -2,6 +2,7 @@ use std::num::NonZeroU16; use proc_macro::{Group, Ident, Literal, Punct, Span, TokenStream, TokenTree}; +/// Turn a type into a [`TokenStream`]. pub(crate) trait ToTokenStream: Sized { fn append_to(self, ts: &mut TokenStream); } diff --git a/time/Cargo.toml b/time/Cargo.toml index f1b0f99b6..696c6af26 100644 --- a/time/Cargo.toml +++ b/time/Cargo.toml @@ -21,6 +21,9 @@ include = ["src/**/*", "LICENSE-*", "README.md"] [lib] bench = false +[lints] +workspace = true + [package.metadata.docs.rs] all-features = true targets = ["x86_64-unknown-linux-gnu"] diff --git a/time/src/lib.rs b/time/src/lib.rs index 212107de6..256a070d4 100644 --- a/time/src/lib.rs +++ b/time/src/lib.rs @@ -78,53 +78,6 @@ #![cfg_attr(__time_03_docs, feature(doc_auto_cfg, doc_notable_trait))] #![cfg_attr(coverage_nightly, feature(no_coverage))] #![cfg_attr(not(feature = "std"), no_std)] -#![deny( - anonymous_parameters, - clippy::all, - clippy::alloc_instead_of_core, - clippy::explicit_auto_deref, - clippy::obfuscated_if_else, - clippy::std_instead_of_core, - clippy::undocumented_unsafe_blocks, - illegal_floating_point_literal_pattern, - late_bound_lifetime_arguments, - path_statements, - patterns_in_fns_without_body, - rust_2018_idioms, - trivial_casts, - trivial_numeric_casts, - unreachable_pub, - unsafe_op_in_unsafe_fn, - unused_extern_crates, - rustdoc::broken_intra_doc_links, - rustdoc::private_intra_doc_links -)] -#![warn( - clippy::dbg_macro, - clippy::decimal_literal_representation, - clippy::get_unwrap, - clippy::missing_docs_in_private_items, - clippy::nursery, - clippy::print_stdout, - clippy::todo, - clippy::unimplemented, - clippy::uninlined_format_args, - clippy::unnested_or_patterns, - clippy::unwrap_in_result, - clippy::unwrap_used, - clippy::use_debug, - deprecated_in_future, - missing_copy_implementations, - missing_debug_implementations, - unused_qualifications, - variant_size_differences -)] -#![allow( - clippy::redundant_pub_crate, // suggests bad style - clippy::option_if_let_else, // suggests terrible code - clippy::unused_peekable, // temporary due to bug: remove when Rust 1.66 is released - clippy::std_instead_of_core, // temporary due to bug: remove when Rust 1.66 is released -)] #![doc(html_favicon_url = "https://avatars0.githubusercontent.com/u/55999857")] #![doc(html_logo_url = "https://avatars0.githubusercontent.com/u/55999857")] #![doc(test(attr(deny(warnings))))]