Skip to content

Commit 8d753cc

Browse files
committed
Additional lints
1 parent cf1668e commit 8d753cc

File tree

9 files changed

+91
-36
lines changed

9 files changed

+91
-36
lines changed

Cargo.toml

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@ private_intra_doc_links = "allow"
1212

1313
[lints.rust]
1414
absolute_paths_not_starting_with_crate = "warn"
15+
box_pointers = "warn"
1516
elided_lifetimes_in_paths = "warn"
1617
explicit_outlives_requirements = "warn"
1718
ffi_unwind_calls = "warn"
18-
invalid_reference_casting = "warn"
1919
keyword_idents = "warn"
2020
let_underscore_drop = "warn"
2121
macro_use_extern_crate = "warn"
2222
meta_variable_misuse = "warn"
2323
missing_abi = "warn"
2424
non_ascii_idents = "warn"
25-
noop_method_call = "warn"
2625
pointer_structural_match = "warn"
26+
private_bounds = "warn"
27+
private_interfaces = "warn"
2728
single_use_lifetimes = "warn"
2829
trivial_casts = "warn"
2930
trivial_numeric_casts = "warn"
@@ -41,34 +42,53 @@ variant_size_differences = "warn"
4142

4243
[lints.clippy]
4344
absolute_paths = "warn"
45+
alloc_instead_of_core = "warn"
46+
allow_attributes = "warn"
47+
as_underscore = "warn"
48+
assertions_on_result_states = "warn"
4449
bool_to_int_with_if = "warn"
4550
borrow_as_ptr = "warn"
4651
case_sensitive_file_extension_comparisons = "warn"
4752
cast_precision_loss = "warn"
4853
cast_ptr_alignment = "warn"
4954
checked_conversions = "warn"
55+
clone_on_ref_ptr = "warn"
5056
cloned_instead_of_copied = "warn"
5157
copy_iterator = "warn"
58+
create_dir = "warn"
59+
dbg_macro = "warn"
60+
decimal_literal_representation = "warn"
5261
default_trait_access = "warn"
62+
default_union_representation = "warn"
63+
disallowed_script_idents = "warn"
5364
doc_link_with_quotes = "warn"
5465
doc_markdown = "warn"
66+
empty_drop = "warn"
5567
empty_enum = "warn"
5668
empty_structs_with_brackets = "warn"
69+
error_impl_error = "warn"
70+
exit = "warn"
71+
expect_used = "warn"
5772
expl_impl_clone_on_copy = "warn"
5873
explicit_deref_methods = "warn"
5974
explicit_into_iter_loop = "warn"
6075
explicit_iter_loop = "warn"
76+
filetype_is_file = "warn"
6177
filter_map_next = "warn"
6278
flat_map_option = "warn"
6379
float_arithmetic = "warn"
6480
float_cmp = "warn"
81+
float_cmp_const = "warn"
6582
fn_params_excessive_bools = "warn"
83+
fn_to_numeric_cast_any = "warn"
84+
format_push_string = "warn"
6685
from_iter_instead_of_collect = "warn"
86+
get_unwrap = "warn"
6787
if_not_else = "warn"
6888
if_then_some_else_none = "warn"
6989
ignored_unit_patterns = "warn"
70-
implicit_clone = "warn"
7190
impl_trait_in_params = "warn"
91+
implicit_clone = "warn"
7292
inconsistent_struct_constructor = "warn"
7393
index_refutable_slice = "warn"
7494
inefficient_to_string = "warn"
@@ -78,57 +98,89 @@ items_after_statements = "warn"
7898
iter_not_returning_iterator = "warn"
7999
large_digit_groups = "warn"
80100
large_futures = "warn"
101+
large_include_file = "warn"
81102
large_stack_arrays = "warn"
82103
large_types_passed_by_value = "warn"
83104
linkedlist = "warn"
105+
lossy_float_literal = "warn"
84106
macro_use_imports = "warn"
85107
manual_assert = "warn"
86108
manual_instant_elapsed = "warn"
87109
manual_let_else = "warn"
88110
manual_ok_or = "warn"
89111
manual_string_new = "warn"
112+
map_err_ignore = "warn"
90113
map_unwrap_or = "warn"
91114
match_bool = "warn"
92115
match_same_arms = "warn"
93116
match_wild_err_arm = "warn"
94117
match_wildcard_for_single_variants = "warn"
95118
maybe_infinite_iter = "warn"
119+
mem_forget = "warn"
96120
mismatching_type_param_order = "warn"
121+
missing_enforced_import_renames = "warn"
97122
missing_errors_doc = "warn"
98123
missing_fields_in_debug = "warn"
124+
mixed_read_write_in_expression = "warn"
125+
mod_module_files = "warn"
126+
multiple_crate_versions = "warn"
127+
multiple_inherent_impl = "warn"
128+
multiple_unsafe_ops_per_block = "warn"
99129
mut_mut = "warn"
130+
mutex_atomic = "warn"
100131
needless_bitwise_bool = "warn"
101132
needless_continue = "warn"
102133
needless_for_each = "warn"
103134
needless_pass_by_value = "warn"
104135
needless_raw_strings = "warn"
136+
negative_feature_names = "warn"
105137
no_effect_underscore_binding = "warn"
106138
no_mangle_with_rust_abi = "warn"
107139
option_option = "warn"
140+
panic_in_result_fn = "warn"
141+
partial_pub_fields = "warn"
142+
print_stderr = "warn"
108143
ptr_as_ptr = "warn"
109144
ptr_cast_constness = "warn"
145+
pub_use = "warn"
146+
pub_with_shorthand = "warn"
110147
range_minus_one = "warn"
148+
rc_buffer = "warn"
149+
rc_mutex = "warn"
111150
redundant_closure_for_method_calls = "warn"
112151
redundant_else = "warn"
152+
redundant_feature_names = "warn"
113153
redundant_type_annotations = "warn"
114154
ref_binding_to_reference = "warn"
115155
ref_option_ref = "warn"
116156
rest_pat_in_fully_bound_structs = "warn"
117157
return_self_not_must_use = "warn"
118158
same_functions_in_if_condition = "warn"
119159
semicolon_if_nothing_returned = "warn"
160+
semicolon_inside_block = "warn"
161+
should_panic_without_expect = "warn"
120162
single_match_else = "warn"
121163
stable_sort_primitive = "warn"
164+
string_add = "warn"
122165
string_add_assign = "warn"
166+
string_lit_chars_any = "warn"
123167
struct_excessive_bools = "warn"
168+
suspicious_xor_used_as_pow = "warn"
169+
todo = "warn"
124170
too_many_lines = "warn"
125171
transmute_ptr_to_ptr = "warn"
126172
trivially_copy_pass_by_ref = "warn"
173+
try_err = "warn"
127174
unchecked_duration_subtraction = "warn"
175+
undocumented_unsafe_blocks = "warn"
128176
unicode_not_nfc = "warn"
177+
unimplemented = "warn"
129178
uninlined_format_args = "warn"
130179
unnecessary_box_returns = "warn"
131180
unnecessary_join = "warn"
181+
unnecessary_safety_comment = "warn"
182+
unnecessary_safety_doc = "warn"
183+
unnecessary_self_imports = "warn"
132184
unnecessary_wraps = "warn"
133185
unneeded_field_pattern = "warn"
134186
unnested_or_patterns = "warn"
@@ -138,4 +190,6 @@ unused_async = "warn"
138190
unused_self = "warn"
139191
used_underscore_binding = "warn"
140192
verbose_bit_mask = "warn"
193+
verbose_file_reads = "warn"
194+
wildcard_dependencies = "warn"
141195
zero_sized_map_values = "warn"

src/util/grid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct Grid<T> {
3535
}
3636

3737
impl Grid<u8> {
38-
pub fn parse(input: &str) -> Grid<u8> {
38+
pub fn parse(input: &str) -> Self {
3939
let raw: Vec<_> = input.lines().map(str::as_bytes).collect();
4040
let width = raw[0].len() as i32;
4141
let height = raw.len() as i32;

src/util/hash.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ pub trait FastSetBuilder<T> {
2020

2121
impl<T: Eq + Hash> FastSetBuilder<T> for FastSet<T> {
2222
fn new() -> Self {
23-
HashSet::with_hasher(BuildFxHasher)
23+
Self::with_hasher(BuildFxHasher)
2424
}
2525

2626
fn with_capacity(capacity: usize) -> Self {
27-
HashSet::with_capacity_and_hasher(capacity, BuildFxHasher)
27+
Self::with_capacity_and_hasher(capacity, BuildFxHasher)
2828
}
2929

3030
fn build<const N: usize>(array: [T; N]) -> Self {
@@ -46,11 +46,11 @@ pub trait FastMapBuilder<K, V> {
4646

4747
impl<K: Eq + Hash, V> FastMapBuilder<K, V> for FastMap<K, V> {
4848
fn new() -> Self {
49-
HashMap::with_hasher(BuildFxHasher)
49+
Self::with_hasher(BuildFxHasher)
5050
}
5151

5252
fn with_capacity(capacity: usize) -> Self {
53-
HashMap::with_capacity_and_hasher(capacity, BuildFxHasher)
53+
Self::with_capacity_and_hasher(capacity, BuildFxHasher)
5454
}
5555

5656
fn build<const N: usize>(array: [(K, V); N]) -> Self {

src/util/point.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ impl Point {
6262

6363
#[inline]
6464
#[must_use]
65-
pub fn manhattan(self, other: Point) -> i32 {
65+
pub fn manhattan(self, other: Self) -> i32 {
6666
(self.x - other.x).abs() + (self.y - other.y).abs()
6767
}
6868

6969
#[inline]
7070
#[must_use]
71-
pub fn signum(self, other: Point) -> Self {
71+
pub fn signum(self, other: Self) -> Self {
7272
Point::new((self.x - other.x).signum(), (self.y - other.y).signum())
7373
}
7474
}
@@ -100,7 +100,7 @@ impl Add for Point {
100100

101101
#[inline]
102102
#[must_use]
103-
fn add(self, rhs: Point) -> Self {
103+
fn add(self, rhs: Self) -> Self {
104104
Point::new(self.x + rhs.x, self.y + rhs.y)
105105
}
106106
}
@@ -114,7 +114,7 @@ impl AddAssign for Point {
114114
}
115115

116116
impl Mul<i32> for Point {
117-
type Output = Point;
117+
type Output = Self;
118118

119119
#[inline]
120120
#[must_use]
@@ -124,7 +124,7 @@ impl Mul<i32> for Point {
124124
}
125125

126126
impl Sub for Point {
127-
type Output = Point;
127+
type Output = Self;
128128

129129
#[inline]
130130
#[must_use]

src/year2015/day12.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
//! [`iter_signed`]: crate::util::parse
2525
use crate::util::parse::*;
2626

27-
const RED: &[u8] = "red".as_bytes();
27+
const RED: &[u8] = b"red";
2828

2929
struct Result {
3030
next: usize,

src/year2019/day13.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ pub fn part2(input: &[i64]) -> i64 {
9292
#[cfg(feature = "frivolity")]
9393
fn draw(tiles: &[i64], score: i64, blocks: i64) {
9494
use crate::util::ansi::*;
95+
use std::fmt::Write;
9596
use std::thread::sleep;
9697
use std::time::Duration;
9798

@@ -100,20 +101,20 @@ fn draw(tiles: &[i64], score: i64, blocks: i64) {
100101
return;
101102
}
102103

103-
let mut s = String::new();
104-
s.push_str(&format!("{WHITE}{BOLD}Blocks: {blocks}\tScore: {score} {RESET}\n"));
104+
let s = &mut String::new();
105+
let _ = writeln!(s, "{WHITE}{BOLD}Blocks: {blocks}\tScore: {score} {RESET}");
105106

106107
for y in 0..20 {
107108
for x in 0..44 {
108-
match tiles[44 * y + x] {
109-
0 => s.push(' '),
110-
1 if y == 0 => s.push_str(&format!("{GREEN}_{RESET}")),
111-
1 => s.push_str(&format!("{GREEN}|{RESET}")),
112-
2 => s.push_str(&format!("{BLUE}#{RESET}")),
113-
3 => s.push_str(&format!("{WHITE}{BOLD}={RESET}")),
114-
4 => s.push_str(&format!("{YELLOW}{BOLD}o{RESET}")),
109+
let _ = match tiles[44 * y + x] {
110+
0 => write!(s, " "),
111+
1 if y == 0 => write!(s, "{GREEN}_{RESET}"),
112+
1 => write!(s, "{GREEN}|{RESET}"),
113+
2 => write!(s, "{BLUE}#{RESET}"),
114+
3 => write!(s, "{WHITE}{BOLD}={RESET}"),
115+
4 => write!(s, "{YELLOW}{BOLD}o{RESET}"),
115116
_ => unreachable!(),
116-
}
117+
};
117118
}
118119
s.push('\n');
119120
}

src/year2019/day17.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use super::intcode::*;
1818
use crate::util::hash::*;
1919
use crate::util::parse::*;
2020
use crate::util::point::*;
21+
use std::fmt::Write;
2122
use std::ops::ControlFlow;
2223

2324
pub struct Input {
@@ -150,7 +151,7 @@ fn build_path(input: &Input) -> String {
150151
}
151152

152153
let direction = if direction == left { 'L' } else { 'R' };
153-
path.push_str(&format!("{direction},{magnitude},"));
154+
let _ = write!(path, "{direction},{magnitude},");
154155
}
155156
}
156157

@@ -241,7 +242,9 @@ fn visit(mut computer: Computer) -> i64 {
241242

242243
// Highlight the robot's position
243244
match ascii {
244-
'^' | 'v' | '<' | '>' => buffer.push_str(&format!("{BOLD}{YELLOW}{ascii}{RESET}")),
245+
'^' | 'v' | '<' | '>' => {
246+
let _ = write!(&mut buffer, "{BOLD}{YELLOW}{ascii}{RESET}");
247+
}
245248
_ => buffer.push(ascii),
246249
}
247250

src/year2019/day25.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use super::intcode::*;
2020
use crate::util::hash::*;
2121
use crate::util::parse::*;
22+
use std::fmt::Write;
2223

2324
pub fn parse(input: &str) -> Vec<i64> {
2425
input.iter_signed().collect()
@@ -75,9 +76,9 @@ fn pretty_print(output: &str) {
7576

7677
for line in output.lines() {
7778
if line.starts_with('=') {
78-
buffer.push_str(&format!("{BOLD}{WHITE}{line}{RESET}"));
79+
let _ = write!(&mut buffer, "{BOLD}{WHITE}{line}{RESET}");
7980
} else if line.starts_with('-') {
80-
buffer.push_str(&format!("{item}{line}{RESET}"));
81+
let _ = write!(&mut buffer, "{item}{line}{RESET}");
8182
} else if line.starts_with("Items here:") {
8283
item = YELLOW;
8384
buffer.push_str(line);
@@ -139,7 +140,7 @@ fn play_automatically(input: &[i64]) -> String {
139140
}
140141
};
141142

142-
if let State::Halted = movement_noisy(&mut computer, &last, &mut output) {
143+
if matches!(movement_noisy(&mut computer, &last, &mut output), State::Halted) {
143144
// Keep only the password digits from Santa's response.
144145
output.retain(|b| b.is_ascii_digit());
145146
break;

src/year2020/day24.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,14 @@ pub fn parse(input: &str) -> FastSet<Hex> {
3535
b'n' => {
3636
if b'e' == iter.next().unwrap() {
3737
q += 1;
38-
r -= 1;
39-
} else {
40-
r -= 1;
4138
}
39+
r -= 1;
4240
}
4341
b's' => {
44-
if b'e' == iter.next().unwrap() {
45-
r += 1;
46-
} else {
42+
if b'e' != iter.next().unwrap() {
4743
q -= 1;
48-
r += 1;
4944
}
45+
r += 1;
5046
}
5147
_ => unreachable!(),
5248
}

0 commit comments

Comments
 (0)