Skip to content

Commit 87fb0dc

Browse files
committed
[base] Enable and fix some extra clippy warnings.
1 parent d95ac4e commit 87fb0dc

File tree

9 files changed

+55
-21
lines changed

9 files changed

+55
-21
lines changed

base/src/bitselect.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ pub struct BitSelector {
4545
}
4646

4747
impl BitSelector {
48+
#[must_use]
4849
pub const fn raw_mask(&self) -> u64 {
4950
let shift = (self.quarter as u32) * 9 + (self.bitpos as u32);
5051
1_u64 << shift
5152
}
5253

54+
#[must_use]
5355
pub fn mask(&self) -> Unsigned36Bit {
5456
Unsigned36Bit::try_from(self.raw_mask())
5557
.expect("bit selector mask values cannot be outside the range of Unsigned36Bit")
@@ -284,6 +286,7 @@ fn all_bit_selectors() -> Vec<BitSelector> {
284286
result
285287
}
286288

289+
#[must_use]
287290
pub const fn bit_select(value: Unsigned36Bit, selector: BitSelector) -> bool {
288291
value.bits & selector.raw_mask() != 0
289292
}

base/src/charset.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,14 @@ impl Display for NoSubscriptKnown {
5151

5252
impl Error for NoSubscriptKnown {}
5353

54-
pub fn subscript_char(ch: char) -> Result<char, NoSubscriptKnown> {
54+
/// Return the corresponding subscript representation for `ch`.
55+
///
56+
/// # Errors
57+
/// `NoSubscriptKnown` when no corresponding subscript is known,
58+
pub const fn subscript_char(ch: char) -> Result<char, NoSubscriptKnown> {
59+
// The cases here are ordered so as to make it obvious when an
60+
// item is missing, and so we expect that some of the failure
61+
// cases will have the same bodies.
5562
match ch {
5663
'0' => Ok('\u{2080}'), // ₀
5764
'1' => Ok('\u{2081}'), // ₁
@@ -85,7 +92,15 @@ impl Display for NoSuperscriptKnown {
8592

8693
impl Error for NoSuperscriptKnown {}
8794

95+
/// Return the corresponding superscript representation for `ch`.
96+
///
97+
/// # Errors
98+
/// `NoSuperscriptKnown` when no corresponding superscript is known,
8899
pub fn superscript_char(ch: char) -> Result<char, NoSuperscriptKnown> {
100+
// The cases here are ordered so as to make it obvious when an
101+
// item is missing, and so we expect that some of the failure
102+
// cases will have the same bodies.
103+
#[allow(clippy::match_same_arms)]
89104
match ch {
90105
'0' => Ok('\u{2070}'),
91106
'1' => Ok('\u{00B9}'),
@@ -174,6 +189,7 @@ pub enum Script {
174189
}
175190

176191
impl Script {
192+
#[must_use]
177193
pub fn shift(&self) -> u32 {
178194
match self {
179195
Script::Super => 30, // This is a config value.
@@ -209,7 +225,7 @@ pub enum LwKeyboardCase {
209225
}
210226

211227
impl LwKeyboardCase {
212-
fn as_str(&self) -> &'static str {
228+
fn as_str(self) -> &'static str {
213229
match self {
214230
LwKeyboardCase::Lower => "lower",
215231
LwKeyboardCase::Upper => "upper",
@@ -305,7 +321,7 @@ pub struct DescribedChar {
305321
/// or normal character, and what colour it is.
306322
pub base_char: LincolnChar,
307323
/// If the character has a direct Unicode translation, that is in
308-
/// unicode_representation. Some characters, for example
324+
/// `unicode_representation`. Some characters, for example
309325
/// superscript Y, have no Unicode representation.
310326
pub unicode_representation: Option<char>,
311327
/// Specifies whether the character is upper-case, lower-case
@@ -330,7 +346,7 @@ fn unprintable(c: Unsigned6Bit, state: LincolnState) -> DescribedChar {
330346
label_matches_unicode: false,
331347
}
332348
}
333-
fn bycase(lower: char, upper: char, state: &LincolnState) -> Option<char> {
349+
const fn bycase(lower: char, upper: char, state: LincolnState) -> Option<char> {
334350
Some(match state.case {
335351
LwKeyboardCase::Upper => upper,
336352
LwKeyboardCase::Lower => lower,
@@ -408,7 +424,7 @@ pub fn lincoln_char_to_described_char(
408424
) -> Option<DescribedChar> {
409425
lincoln_writer_state_update(lin_ch, state);
410426
let advance: bool = lin_ch != 0o12 && lin_ch != 0o13;
411-
let by_case = |lower, upper: char| -> Option<char> { bycase(lower, upper, state) };
427+
let by_case = |lower, upper: char| -> Option<char> { bycase(lower, upper, *state) };
412428
let base_char: Option<char> = match u8::from(lin_ch) {
413429
0o00 => by_case('0', '☛'), // \U261B, black hand pointing right
414430
0o01 => by_case('1', 'Σ'), // \U03A3, Greek capital letter Sigma

base/src/instruction.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ mod tests {
712712

713713
#[test]
714714
fn test_instruction_jmp() {
715-
let inst = Instruction(Unsigned36Bit::from(0o0500377750_u32));
715+
let inst = Instruction(Unsigned36Bit::from(0o0_500_377_750_u32));
716716
assert_eq!(
717717
inst.operand_address(),
718718
OperandAddress::direct(Address::from(u18!(0o377_750u32))),
@@ -750,7 +750,7 @@ mod tests {
750750
assert_eq!(
751751
disassemble_word(u36!(0o000_500_377_750)),
752752
Ok(SymbolicInstruction {
753-
operand_address: OperandAddress::direct(Address::from(u18!(0o0377750))),
753+
operand_address: OperandAddress::direct(Address::from(u18!(0o_377_750))),
754754
index: Unsigned6Bit::ZERO,
755755
opcode: Opcode::Jmp,
756756
configuration: config_value(0),
@@ -767,7 +767,7 @@ mod tests {
767767
.expect("test data should be in range")
768768
),
769769
Ok(SymbolicInstruction {
770-
operand_address: OperandAddress::direct(Address::from(u18!(0o0377752))),
770+
operand_address: OperandAddress::direct(Address::from(u18!(0o0_377_752))),
771771
index: Unsigned6Bit::try_from(3_u8).unwrap(),
772772
opcode: Opcode::Jpx,
773773
configuration: config_value(24), // -7
@@ -781,7 +781,7 @@ mod tests {
781781
.expect("test data should be in range")
782782
),
783783
Ok(SymbolicInstruction {
784-
operand_address: OperandAddress::direct(Address::from(u18!(0o0377751))),
784+
operand_address: OperandAddress::direct(Address::from(u18!(0o0_377_751))),
785785
index: Unsigned6Bit::ONE,
786786
opcode: Opcode::Jpx,
787787
configuration: config_value(30),

base/src/instruction/format.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ mod tests {
342342
#[test]
343343
fn test_display_jmp() {
344344
let sinst = SymbolicInstruction {
345-
operand_address: OperandAddress::direct(Address::from(u18!(0o0377750))),
345+
operand_address: OperandAddress::direct(Address::from(u18!(0o0_377_750))),
346346
index: Unsigned6Bit::ZERO,
347347
opcode: Opcode::Jmp,
348348
configuration: Unsigned5Bit::ZERO,
@@ -401,7 +401,7 @@ mod tests {
401401

402402
// Example from Program I, address 377 765, instruction word 36 06 01 377 751.
403403
let sinst1 = SymbolicInstruction {
404-
operand_address: OperandAddress::direct(Address::from(u18!(0o0377751))),
404+
operand_address: OperandAddress::direct(Address::from(u18!(0o0_377_751))),
405405
index: Unsigned6Bit::ONE,
406406
opcode: Opcode::Jpx,
407407
// 036 = 30 decimal = 0b11110, which is one's complement -1.
@@ -427,7 +427,7 @@ mod tests {
427427

428428
// Example from Program II ("Inchworm"), address 15, instruction word not stated,
429429
let sinst2 = SymbolicInstruction {
430-
operand_address: OperandAddress::direct(Address::from(u18!(0o0377752))),
430+
operand_address: OperandAddress::direct(Address::from(u18!(0o0_377_752))),
431431
index: Unsigned6Bit::try_from(3_u8).unwrap(),
432432
opcode: Opcode::Jpx,
433433
// In the Program II example, the configuration value is
@@ -447,7 +447,7 @@ mod tests {
447447
// indicating the hold bit. We use 'h' instead since ':' is
448448
// not actually part of the Lincoln Writer character set.
449449
let sinst = SymbolicInstruction {
450-
operand_address: OperandAddress::direct(Address::from(u18!(0o377762))),
450+
operand_address: OperandAddress::direct(Address::from(u18!(0o377_762))),
451451
index: Unsigned6Bit::try_from(0o71_u8).unwrap(),
452452
opcode: Opcode::Rsx,
453453
configuration: config_value(0o34),

base/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@
66
#![deny(unreachable_pub)]
77
#![deny(unsafe_code)]
88
#![deny(unused_crate_dependencies)]
9+
//#![warn(clippy::as_conversions)]
10+
//#![warn(clippy::cast_lossless)]
11+
//#![warn(clippy::pedantic)] // enable later
12+
#![warn(clippy::cast_possible_truncation)]
13+
#![warn(clippy::cast_possible_wrap)]
14+
#![warn(clippy::cast_precision_loss)]
15+
#![warn(clippy::cast_ptr_alignment)]
16+
#![warn(clippy::clone_on_ref_ptr)]
17+
#![warn(clippy::cloned_instead_of_copied)]
18+
#![warn(clippy::unreadable_literal)]
19+
#![allow(clippy::cast_possible_wrap)]
20+
#![allow(clippy::cast_sign_loss)]
21+
#![allow(clippy::needless_continue)] // fix these later
22+
#![allow(clippy::redundant_else)] // fix these later
23+
#![allow(clippy::missing_panics_doc)] // fix these later
924

1025
pub mod bitselect;
1126
pub mod charset;

base/src/onescomplement/signed/tests18.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ fn test_signed18bit_checked_add() {
405405
assert!(dbg!(minus_one) < Signed18Bit::ZERO);
406406
assert_eq!(
407407
i32::from(Signed18Bit::MAX.checked_add(minus_one).unwrap()),
408-
0o377776_i32
408+
0o377_776_i32
409409
);
410410
assert_eq!(Signed18Bit::ZERO.checked_add(minus_one).unwrap(), minus_one);
411411
}
@@ -442,7 +442,7 @@ fn test_signed18bit_checked_sub() {
442442

443443
assert_eq!(
444444
i32::from(Signed18Bit::MAX.checked_sub(Signed18Bit::ONE).unwrap()),
445-
0o377776_i32
445+
0o377_776_i32
446446
);
447447
assert_eq!(
448448
Signed18Bit::ZERO.checked_sub(Signed18Bit::ONE).unwrap(),

base/src/onescomplement/unsigned.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ pub struct Unsigned12Bit {
548548
#[cfg_attr(test, derive(Arbitrary))]
549549
#[derive(Clone, Copy, Serialize)]
550550
pub struct Unsigned18Bit {
551-
#[cfg_attr(test, strategy(0..262143u32))]
551+
#[cfg_attr(test, strategy(0..262_143u32))]
552552
pub(crate) bits: u32,
553553
}
554554

@@ -559,7 +559,7 @@ pub struct Unsigned18Bit {
559559
#[cfg_attr(test, derive(Arbitrary))]
560560
#[derive(Clone, Copy, Serialize)]
561561
pub struct Unsigned36Bit {
562-
#[cfg_attr(test, strategy(0..68719476735u64))]
562+
#[cfg_attr(test, strategy(0..68_719_476_735u64))]
563563
pub(crate) bits: u64,
564564
}
565565

base/src/onescomplement/unsigned/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ mod u18_proptests {
649649

650650
#[derive(Debug, Arbitrary)]
651651
struct U18SubtractionTestInput {
652-
#[strategy(0..0o1000000u32)]
652+
#[strategy(0..0o1_000_000u32)]
653653
greater: u32,
654654
#[strategy(0..=#greater)]
655655
lesser: u32,
@@ -692,7 +692,7 @@ mod u36_proptests {
692692

693693
#[derive(Debug, Arbitrary)]
694694
struct U36SubtractionTestInput {
695-
#[strategy(0..0o1000000000000u64)]
695+
#[strategy(0..0o1_000_000_000_000u64)]
696696
greater: u64,
697697
#[strategy(0..=#greater)]
698698
lesser: u64,

base/src/splay.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn cycle_and_splay(target: Unsigned36Bit, bits: Unsigned6Bit) -> Unsigned36B
2323
// bit 5 (4 counting from 0) goes to 3.7 = 1 << 24 (dec)
2424
// bit 6 (5 counting from 0) goes to 4.4 = 1 << 30 (dec)
2525
let src = u64::from(bits);
26-
let lowest_bits = Unsigned36Bit::from(0o010101010101_u32);
26+
let lowest_bits = Unsigned36Bit::from(0o010_101_010_101_u32);
2727
let newbits: u64 = (src & 1)
2828
| ((src & 0o2) << 5)
2929
| ((src & 0o4) << 10)
@@ -177,7 +177,7 @@ fn test_round_trip_selected() {
177177
Unsigned36Bit::from(0o77_u32),
178178
Unsigned36Bit::from(0o7700_u32),
179179
Unsigned36Bit::MAX,
180-
Unsigned36Bit::from(0o23574373_u32),
180+
Unsigned36Bit::from(0o23_574_373_u32),
181181
] {
182182
if let Err(e) = round_trip(value) {
183183
panic!("round_trip failed for {value:012o}: {e}");

0 commit comments

Comments
 (0)