Skip to content

Commit 7901820

Browse files
committed
fix some clippy lints
1 parent e60cb01 commit 7901820

File tree

7 files changed

+22
-9
lines changed

7 files changed

+22
-9
lines changed

src/board/grid_state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct GridState([CellState; 81]);
2222
impl std::fmt::Display for GridState {
2323
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
2424
let mut column_widths = [0; 9];
25+
#[allow(clippy::needless_range_loop)]
2526
for col in 0..9 {
2627
let max_width = (0..9)
2728
.map(|row| match self.0[row * 9 + col] {

src/board/positions.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,12 @@ define_types!(
274274
Chute: 6,
275275
);
276276

277+
impl Cell {
278+
pub(crate) fn from_coords(row: u8, col: u8) -> Self {
279+
Cell::new(row * 9 + col)
280+
}
281+
}
282+
277283
/// A [`Row`] or [`Col`]
278284
#[derive(Copy, Clone, Eq, PartialEq, Debug, Hash)]
279285
pub enum LineType {
@@ -604,13 +610,13 @@ pub trait CellAt: Sized {
604610

605611
impl CellAt for Row {
606612
fn cell_at(self, pos: Position<Row>) -> Cell {
607-
Cell::new(self.0 * 9 + pos.0)
613+
Cell::from_coords(self.0, pos.0)
608614
}
609615
}
610616

611617
impl CellAt for Col {
612618
fn cell_at(self, pos: Position<Col>) -> Cell {
613-
Cell::new(pos.0 * 9 + self.0)
619+
Cell::from_coords(pos.0, self.0)
614620
}
615621
}
616622

@@ -623,7 +629,7 @@ impl CellAt for Block {
623629
let col_in_stack = pos.0 % 3;
624630
let row = band * 3 + row_in_band;
625631
let col = stack * 3 + col_in_stack;
626-
Cell::new(row * 9 + col)
632+
Cell::from_coords(row, col)
627633
}
628634
}
629635

src/board/sudoku.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ impl Sudoku {
583583
let mut nums_contained: u16 = 0;
584584
// same with less than 17 clues
585585
let mut n_clues = 0;
586-
self.iter().filter_map(|id| id).for_each(|num| {
586+
self.iter().flatten().for_each(|num| {
587587
nums_contained |= 1 << num;
588588
n_clues += 1;
589589
});

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
clippy::unreadable_literal,
77
clippy::wrong_self_convention,
88
clippy::inconsistent_digit_grouping,
9+
clippy::unusual_byte_groupings,
910
clippy::too_many_arguments
1011
)]
1112
//! Utilities for classical 9x9 sudokus.

src/strategy/solver.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub struct StrategySolver {
4949
// AvoidableRectangles
5050
// We can't assume that this struct is created only from clues nor that the information about them
5151
// will always be present for the caller
52+
#[allow(unused)]
5253
pub(crate) clues: Option<Sudoku>,
5354
// current state of the sudoku
5455
// for when it's faster to recompute from the end state
@@ -234,6 +235,7 @@ impl StrategySolver {
234235

235236
/// Try to solve the sudoku using the given `strategies`. Returns a `Result` of the sudoku and a struct containing the series of deductions.
236237
/// If a solution was found, `Ok(..)` is returned, otherwise `Err(..)`.
238+
#[allow(clippy::result_large_err)] // nonsense, Ok and Err are the same size.
237239
pub fn solve(mut self, strategies: &[Strategy]) -> Result<(Sudoku, Deductions), (Sudoku, Deductions)> {
238240
self.try_solve(strategies);
239241
self.update_grid();

src/strategy/strategies/xy_wing.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,13 @@ mod test {
7777
} = deductions.get(0).unwrap()
7878
{
7979
assert_eq!(hinge.get(), 1);
80-
assert_eq!(pincers, Cell::new(1 * 9 + 2).as_set() | Cell::new(8 * 9 + 1));
80+
assert_eq!(
81+
pincers,
82+
Cell::from_coords(1, 2).as_set() | Cell::from_coords(8, 1)
83+
);
8184

8285
let conflict = Candidate {
83-
cell: Cell::new(7 * 9 + 2),
86+
cell: Cell::from_coords(7, 2),
8487
digit: Digit::new(4),
8588
};
8689
assert_eq!(conflicts, &[conflict]);

src/strategy/strategies/xyz_wing.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ mod test {
8484
assert_eq!(
8585
deductions.get(0).unwrap(),
8686
crate::strategy::Deduction::Wing {
87-
hinge: Cell::new(5 * 9 + 8),
87+
hinge: Cell::from_coords(5, 8),
8888
hinge_digits: Digit::new(1).as_set() | Digit::new(2) | Digit::new(4),
89-
pincers: Cell::new(3 * 9 + 8).as_set() | Cell::new(5 * 9 + 0),
89+
pincers: Cell::from_coords(3, 8).as_set() | Cell::from_coords(5, 0),
9090
conflicts: &[Candidate {
91-
cell: Cell::new(5 * 9 + 6),
91+
cell: Cell::from_coords(5, 6),
9292
digit: Digit::new(1),
9393
}][..],
9494
}

0 commit comments

Comments
 (0)