diff --git a/Cargo.toml b/Cargo.toml index 5ae27278f..f2a64e4b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,120 @@ version = "0.1.0" [workspace] members = ["tools/check-cpp-code-format", "tools/progress-tracker", "xtask"] +[workspace.lints.rust] +absolute_paths_not_starting_with_crate = "warn" +explicit_outlives_requirements = "warn" +let_underscore_drop = "warn" +macro_use_extern_crate = "warn" +meta_variable_misuse = "warn" +missing_abi = "warn" +missing_docs = "allow" +noop_method_call = "warn" +pointer_structural_match = "warn" +single_use_lifetimes = "warn" +trivial_casts = "allow" +trivial_numeric_casts = "warn" +unsafe_code = "warn" +unsafe_op_in_unsafe_fn = "warn" +unused_crate_dependencies = "warn" +unused_extern_crates = "warn" +unused_import_braces = "warn" +unused_lifetimes = "warn" +unused_macro_rules = "warn" +unused_qualifications = "warn" +unused_tuple_struct_fields = "warn" +variant_size_differences = "warn" + +[workspace.lints.clippy] +alloc_instead_of_core = "warn" +allow_attributes_without_reason = "warn" +as_ptr_cast_mut = "warn" +branches_sharing_code = "warn" +cargo_common_metadata = "allow" +cast_possible_truncation = "allow" +cast_possible_wrap = "allow" +cast_sign_loss = "allow" +clone_on_ref_ptr = "warn" +cognitive_complexity = "warn" +create_dir = "warn" +dbg_macro = "warn" +debug_assert_with_mut_call = "warn" +decimal_literal_representation = "allow" +deref_by_slicing = "warn" +derive_partial_eq_without_eq = "warn" +empty_drop = "warn" +empty_line_after_outer_attr = "warn" +empty_structs_with_brackets = "warn" +equatable_if_let = "warn" +fallible_impl_from = "warn" +filetype_is_file = "warn" +float_cmp_const = "warn" +format_push_string = "warn" +get_unwrap = "warn" +if_then_some_else_none = "warn" +imprecise_flops = "warn" +iter_on_empty_collections = "warn" +iter_on_single_items = "warn" +iter_with_drain = "warn" +large_include_file = "warn" +let_underscore_must_use = "warn" +lossy_float_literal = "warn" +manual_clamp = "warn" +map_err_ignore = "warn" +missing_panics_doc = "allow" +mixed_read_write_in_expression = "warn" +multiple_inherent_impl = "warn" +must_use_candidate = "allow" +mutex_atomic = "warn" +mutex_integer = "warn" +needless_collect = "warn" +needless_pass_by_value = "allow" +negative_feature_names = "warn" +non_send_fields_in_send_ty = "warn" +nonstandard_macro_braces = "warn" +option_if_let_else = "warn" +or_fun_call = "warn" +panic = "warn" +panic_in_result_fn = "warn" +partial_pub_fields = "warn" +path_buf_push_overwrite = "warn" +pedantic = "warn" +print_stderr = "warn" +print_stdout = "warn" +rc_buffer = "warn" +rc_mutex = "warn" +redundant_feature_names = "warn" +redundant_locals = "allow" # False positive. +redundant_pub_crate = "warn" +rest_pat_in_fully_bound_structs = "warn" +same_name_method = "allow" +self_named_module_files = "warn" +significant_drop_in_scrutinee = "warn" +string_lit_as_bytes = "warn" +string_to_string = "warn" +suboptimal_flops = "warn" +suspicious_operation_groupings = "warn" +todo = "warn" +trailing_empty_array = "warn" +trait_duplication_in_bounds = "warn" +transmute_undefined_repr = "warn" +trivial_regex = "warn" +try_err = "warn" +type_repetition_in_bounds = "warn" +undocumented_unsafe_blocks = "warn" +unimplemented = "warn" +unnecessary_safety_comment = "warn" +unnecessary_safety_doc = "warn" +unnecessary_self_imports = "warn" +unneeded_field_pattern = "warn" +unused_peekable = "warn" +unused_rounding = "warn" +use_debug = "warn" +use_self = "warn" +useless_let_if_seq = "warn" +verbose_file_reads = "warn" +wildcard_dependencies = "allow" + [dependencies] rand = "0.6" diff --git a/src/lib.rs b/src/lib.rs index 805146df1..e5c06ea7c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,124 +1,3 @@ -#![warn( - absolute_paths_not_starting_with_crate, - explicit_outlives_requirements, - let_underscore_drop, - macro_use_extern_crate, - meta_variable_misuse, - missing_abi, - missing_docs, - noop_method_call, - pointer_structural_match, - single_use_lifetimes, - trivial_casts, - trivial_numeric_casts, - unsafe_code, - unsafe_op_in_unsafe_fn, - unused_crate_dependencies, - unused_extern_crates, - unused_import_braces, - unused_lifetimes, - unused_macro_rules, - unused_qualifications, - unused_tuple_struct_fields, - variant_size_differences, - clippy::alloc_instead_of_core, - clippy::allow_attributes_without_reason, - clippy::as_ptr_cast_mut, - clippy::branches_sharing_code, - clippy::cargo_common_metadata, - clippy::clone_on_ref_ptr, - clippy::cognitive_complexity, - clippy::create_dir, - clippy::dbg_macro, - clippy::debug_assert_with_mut_call, - clippy::decimal_literal_representation, - clippy::deref_by_slicing, - clippy::derive_partial_eq_without_eq, - clippy::empty_drop, - clippy::empty_line_after_outer_attr, - clippy::empty_structs_with_brackets, - clippy::equatable_if_let, - clippy::fallible_impl_from, - clippy::filetype_is_file, - clippy::float_cmp_const, - clippy::format_push_string, - clippy::get_unwrap, - clippy::if_then_some_else_none, - clippy::imprecise_flops, - clippy::iter_on_empty_collections, - clippy::iter_on_single_items, - clippy::iter_with_drain, - clippy::large_include_file, - clippy::let_underscore_must_use, - clippy::lossy_float_literal, - clippy::manual_clamp, - clippy::map_err_ignore, - clippy::mixed_read_write_in_expression, - clippy::multiple_inherent_impl, - clippy::mutex_atomic, - clippy::mutex_integer, - clippy::needless_collect, - clippy::negative_feature_names, - clippy::non_send_fields_in_send_ty, - clippy::nonstandard_macro_braces, - clippy::option_if_let_else, - clippy::or_fun_call, - clippy::panic, - clippy::panic_in_result_fn, - clippy::partial_pub_fields, - clippy::path_buf_push_overwrite, - clippy::pedantic, - clippy::print_stderr, - clippy::print_stdout, - clippy::rc_buffer, - clippy::rc_mutex, - clippy::redundant_feature_names, - clippy::redundant_pub_crate, - clippy::rest_pat_in_fully_bound_structs, - clippy::same_name_method, - clippy::self_named_module_files, - clippy::significant_drop_in_scrutinee, - clippy::string_lit_as_bytes, - clippy::string_to_string, - clippy::suboptimal_flops, - clippy::suspicious_operation_groupings, - clippy::todo, - clippy::trailing_empty_array, - clippy::trait_duplication_in_bounds, - clippy::transmute_undefined_repr, - clippy::trivial_regex, - clippy::try_err, - clippy::type_repetition_in_bounds, - clippy::undocumented_unsafe_blocks, - clippy::unimplemented, - clippy::unnecessary_safety_comment, - clippy::unnecessary_safety_doc, - clippy::unnecessary_self_imports, - clippy::unneeded_field_pattern, - clippy::unused_peekable, - clippy::unused_rounding, - clippy::use_debug, - clippy::use_self, - clippy::useless_let_if_seq, - clippy::verbose_file_reads, - clippy::wildcard_dependencies -)] -#![allow( - missing_docs, - trivial_casts, - clippy::cargo_common_metadata, - clippy::cast_possible_truncation, - clippy::cast_possible_wrap, - clippy::cast_sign_loss, - clippy::decimal_literal_representation, - clippy::missing_panics_doc, - clippy::must_use_candidate, - clippy::needless_pass_by_value, - clippy::redundant_locals, // False positive. - clippy::same_name_method, - clippy::wildcard_dependencies -)] - pub(crate) mod data_structures; pub mod problem_0001_two_sum; pub mod problem_0002_add_two_numbers; diff --git a/src/problem_0374_guess_number_higher_or_lower/binary_search.rs b/src/problem_0374_guess_number_higher_or_lower/binary_search.rs index c39903a8f..1f6cb7c10 100644 --- a/src/problem_0374_guess_number_higher_or_lower/binary_search.rs +++ b/src/problem_0374_guess_number_higher_or_lower/binary_search.rs @@ -1,4 +1,4 @@ -#![allow(non_snake_case)] +#![allow(non_snake_case)] // Expected. use super::guess; diff --git a/src/problem_0405_convert_a_number_to_hexadecimal/mod.rs b/src/problem_0405_convert_a_number_to_hexadecimal/mod.rs index 66b6e6f1f..9b62a5809 100644 --- a/src/problem_0405_convert_a_number_to_hexadecimal/mod.rs +++ b/src/problem_0405_convert_a_number_to_hexadecimal/mod.rs @@ -1,4 +1,4 @@ -#![allow(clippy::wrong_self_convention)] +#![allow(clippy::wrong_self_convention)] // Expected. pub mod cheating; pub mod iterative; diff --git a/src/problem_0778_swim_in_rising_water/bidirectional_bfs.rs b/src/problem_0778_swim_in_rising_water/bidirectional_bfs.rs index ec9d393dc..f53df3be9 100644 --- a/src/problem_0778_swim_in_rising_water/bidirectional_bfs.rs +++ b/src/problem_0778_swim_in_rising_water/bidirectional_bfs.rs @@ -37,7 +37,6 @@ impl Solution { } pub fn swim_in_water(grid: Vec>) -> i32 { - let grid = grid; let n = grid.len(); if n < 2 { diff --git a/src/problem_0992_subarrays_with_k_different_integers/sliding_window.rs b/src/problem_0992_subarrays_with_k_different_integers/sliding_window.rs index d13c7253e..4060b2e17 100644 --- a/src/problem_0992_subarrays_with_k_different_integers/sliding_window.rs +++ b/src/problem_0992_subarrays_with_k_different_integers/sliding_window.rs @@ -108,7 +108,7 @@ mod tests { } #[test] - #[should_panic] + #[should_panic(expected = "internal error: entered unreachable code")] fn test_unwrap_occupied_failure() { super::Solution::unwrap_occupied(HashMap::from([(2, (3_u16, 5_u16))]).entry(5)); } diff --git a/src/problem_1001_grid_illumination/iterative.rs b/src/problem_1001_grid_illumination/iterative.rs index 7e3affcfa..8dac196e4 100644 --- a/src/problem_1001_grid_illumination/iterative.rs +++ b/src/problem_1001_grid_illumination/iterative.rs @@ -117,7 +117,7 @@ mod tests { } #[test] - #[should_panic] + #[should_panic(expected = "internal error: entered unreachable code")] fn test_unwrap_occupied_failure() { super::Counter::unwrap_occupied(HashMap::from([(2_u32, 5_u16)]).entry(5)); } diff --git a/src/problem_1036_escape_a_large_maze/bfs.rs b/src/problem_1036_escape_a_large_maze/bfs.rs index d58940032..b0e965a48 100644 --- a/src/problem_1036_escape_a_large_maze/bfs.rs +++ b/src/problem_1036_escape_a_large_maze/bfs.rs @@ -15,18 +15,14 @@ impl Solution { pub fn is_escape_possible(blocked: Vec>, source: Vec, target: Vec) -> bool { const MAZE_SIZE: u32 = 1_000_000; - let blocked = { - let blocked = blocked; - - blocked - .iter() - .map(|point| { - let [x, y]: [_; 2] = point.as_slice().try_into().unwrap(); - - (x as u32, y as u32) - }) - .collect::>() - }; + let blocked = blocked + .into_iter() + .map(|point| { + let [x, y]: [_; 2] = point.try_into().ok().unwrap(); + + (x as u32, y as u32) + }) + .collect::>(); let source = Self::unwrap_point(source); let target = Self::unwrap_point(target); diff --git a/src/problem_1105_filling_bookcase_shelves/dynamic_programming.rs b/src/problem_1105_filling_bookcase_shelves/dynamic_programming.rs index 296322a3d..7c791e272 100644 --- a/src/problem_1105_filling_bookcase_shelves/dynamic_programming.rs +++ b/src/problem_1105_filling_bookcase_shelves/dynamic_programming.rs @@ -6,18 +6,14 @@ use std::convert::TryInto; impl Solution { pub fn min_height_shelves(books: Vec>, shelf_width: i32) -> i32 { - let books = { - let books = books; - - books - .iter() - .map(|book| { - let [thickness, height]: [_; 2] = book.as_slice().try_into().unwrap(); - - (thickness as u32, height as u32) - }) - .collect::>() - }; + let books = books + .into_iter() + .map(|book| { + let [thickness, height]: [_; 2] = book.try_into().ok().unwrap(); + + (thickness as u32, height as u32) + }) + .collect::>(); let shelf_width = shelf_width as u32; let mut cache = Vec::with_capacity(books.len()); diff --git a/src/problem_1599_maximum_profit_of_operating_a_centennial_wheel/iterative.rs b/src/problem_1599_maximum_profit_of_operating_a_centennial_wheel/iterative.rs index 1b89605ee..992d16e34 100644 --- a/src/problem_1599_maximum_profit_of_operating_a_centennial_wheel/iterative.rs +++ b/src/problem_1599_maximum_profit_of_operating_a_centennial_wheel/iterative.rs @@ -11,8 +11,6 @@ impl Solution { let mut waiting = 0; for (i, customer) in (1..).zip(customers) { - let customer = customer; - waiting += customer; let onboard = waiting.min(4); diff --git a/tools/check-cpp-code-format/src/main.rs b/tools/check-cpp-code-format/src/main.rs index 073ce4362..a02ebf850 100644 --- a/tools/check-cpp-code-format/src/main.rs +++ b/tools/check-cpp-code-format/src/main.rs @@ -1,66 +1,3 @@ -#![warn( - explicit_outlives_requirements, - macro_use_extern_crate, - meta_variable_misuse, - missing_abi, - // missing_docs, - noop_method_call, - pointer_structural_match, - single_use_lifetimes, - trivial_casts, - trivial_numeric_casts, - unsafe_code, - unsafe_op_in_unsafe_fn, - unused_crate_dependencies, - unused_extern_crates, - unused_import_braces, - unused_lifetimes, - unused_qualifications, - variant_size_differences, - // clippy::cargo_common_metadata, - clippy::clone_on_ref_ptr, - clippy::cognitive_complexity, - clippy::create_dir, - clippy::dbg_macro, - clippy::debug_assert_with_mut_call, - clippy::empty_line_after_outer_attr, - clippy::fallible_impl_from, - clippy::filetype_is_file, - clippy::float_cmp_const, - clippy::get_unwrap, - clippy::if_then_some_else_none, - clippy::imprecise_flops, - clippy::let_underscore_must_use, - clippy::lossy_float_literal, - clippy::multiple_inherent_impl, - clippy::mutex_integer, - clippy::nonstandard_macro_braces, - clippy::panic_in_result_fn, - clippy::path_buf_push_overwrite, - clippy::pedantic, - clippy::print_stderr, - clippy::print_stdout, - clippy::rc_buffer, - clippy::rc_mutex, - clippy::rest_pat_in_fully_bound_structs, - clippy::string_lit_as_bytes, - clippy::string_to_string, - clippy::suboptimal_flops, - clippy::suspicious_operation_groupings, - clippy::todo, - clippy::trivial_regex, - clippy::unimplemented, - clippy::unnecessary_self_imports, - clippy::unneeded_field_pattern, - clippy::use_debug, - clippy::use_self, - clippy::useless_let_if_seq, - clippy::useless_transmute, - clippy::verbose_file_reads, - // clippy::wildcard_dependencies, -)] -#![allow(clippy::non_ascii_literal)] - use regex::Regex; use std::path::PathBuf; use std::{env, fs}; diff --git a/tools/progress-tracker/src/main.rs b/tools/progress-tracker/src/main.rs index adab681ba..5e1c54d9c 100644 --- a/tools/progress-tracker/src/main.rs +++ b/tools/progress-tracker/src/main.rs @@ -1,66 +1,3 @@ -#![warn( - explicit_outlives_requirements, - macro_use_extern_crate, - meta_variable_misuse, - missing_abi, - // missing_docs, - noop_method_call, - pointer_structural_match, - single_use_lifetimes, - trivial_casts, - trivial_numeric_casts, - unsafe_code, - unsafe_op_in_unsafe_fn, - unused_crate_dependencies, - unused_extern_crates, - unused_import_braces, - unused_lifetimes, - unused_qualifications, - variant_size_differences, - // clippy::cargo_common_metadata, - clippy::clone_on_ref_ptr, - clippy::cognitive_complexity, - clippy::create_dir, - clippy::dbg_macro, - clippy::debug_assert_with_mut_call, - clippy::empty_line_after_outer_attr, - clippy::fallible_impl_from, - clippy::filetype_is_file, - clippy::float_cmp_const, - clippy::get_unwrap, - clippy::if_then_some_else_none, - clippy::imprecise_flops, - clippy::let_underscore_must_use, - clippy::lossy_float_literal, - clippy::multiple_inherent_impl, - clippy::mutex_integer, - clippy::nonstandard_macro_braces, - clippy::panic_in_result_fn, - clippy::path_buf_push_overwrite, - clippy::pedantic, - clippy::print_stderr, - clippy::print_stdout, - clippy::rc_buffer, - clippy::rc_mutex, - clippy::rest_pat_in_fully_bound_structs, - clippy::string_lit_as_bytes, - clippy::string_to_string, - clippy::suboptimal_flops, - clippy::suspicious_operation_groupings, - clippy::todo, - clippy::trivial_regex, - clippy::unimplemented, - clippy::unnecessary_self_imports, - clippy::unneeded_field_pattern, - clippy::use_debug, - clippy::use_self, - clippy::useless_let_if_seq, - clippy::useless_transmute, - clippy::verbose_file_reads, - // clippy::wildcard_dependencies, -)] -#![allow(clippy::non_ascii_literal)] - use git2::Repository; use problems::Problems; use reqwest::blocking; diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 39ed76a94..2b631c65b 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,66 +1,3 @@ -#![warn( - explicit_outlives_requirements, - macro_use_extern_crate, - meta_variable_misuse, - missing_abi, - // missing_docs, - noop_method_call, - pointer_structural_match, - single_use_lifetimes, - trivial_casts, - trivial_numeric_casts, - unsafe_code, - unsafe_op_in_unsafe_fn, - unused_crate_dependencies, - unused_extern_crates, - unused_import_braces, - unused_lifetimes, - unused_qualifications, - variant_size_differences, - // clippy::cargo_common_metadata, - clippy::clone_on_ref_ptr, - clippy::cognitive_complexity, - clippy::create_dir, - clippy::dbg_macro, - clippy::debug_assert_with_mut_call, - clippy::empty_line_after_outer_attr, - clippy::fallible_impl_from, - clippy::filetype_is_file, - clippy::float_cmp_const, - clippy::get_unwrap, - clippy::if_then_some_else_none, - clippy::imprecise_flops, - clippy::let_underscore_must_use, - clippy::lossy_float_literal, - clippy::multiple_inherent_impl, - clippy::mutex_integer, - clippy::nonstandard_macro_braces, - clippy::panic_in_result_fn, - clippy::path_buf_push_overwrite, - clippy::pedantic, - clippy::print_stderr, - clippy::print_stdout, - clippy::rc_buffer, - clippy::rc_mutex, - clippy::rest_pat_in_fully_bound_structs, - clippy::string_lit_as_bytes, - clippy::string_to_string, - clippy::suboptimal_flops, - clippy::suspicious_operation_groupings, - clippy::todo, - clippy::trivial_regex, - clippy::unimplemented, - clippy::unnecessary_self_imports, - clippy::unneeded_field_pattern, - clippy::use_debug, - clippy::use_self, - clippy::useless_let_if_seq, - clippy::useless_transmute, - clippy::verbose_file_reads, - // clippy::wildcard_dependencies, -)] -#![allow(clippy::non_ascii_literal)] - use crate::coverage::Subcommand; use clap::Parser; use std::env;