Skip to content

Commit d17db68

Browse files
committed
clippy cleanups
1 parent 18ceab8 commit d17db68

File tree

24 files changed

+106
-135
lines changed

24 files changed

+106
-135
lines changed

calc/bc_util/interpreter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl Interpreter {
201201
.ok_or("array index is too large")? as usize;
202202
if let Some(call_frame) = self.call_frames.last_mut() {
203203
if let Some(array) = &mut call_frame.array_variables[name_index(*name)] {
204-
return Ok(get_or_extend(array, index as usize));
204+
return Ok(get_or_extend(array, index));
205205
}
206206
}
207207
Ok(get_or_extend(

calc/expr.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ fn token_display(t: &Token) -> String {
6666

6767
// is token an lval?
6868
fn token_is_lval(t: &Token) -> bool {
69-
match t {
70-
Token::Integer(_) => true,
71-
Token::Str(_) => true,
72-
_ => false,
73-
}
69+
matches!(t, Token::Integer(_) | Token::Str(_))
7470
}
7571

7672
// is token zero?

display/more.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ impl SeekPositions {
591591
let reader = BufReader::new(&mut self.buffer).lines();
592592
for line in reader {
593593
if let Ok(line) = line {
594-
seek_pos += line.as_bytes().len();
594+
seek_pos += line.len();
595595
}
596596
i += 1;
597597
if i >= n {

file/magic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl RawMagicFileLine {
426426
fn string_test(&self, tf_reader: &mut BufReader<File>) -> bool {
427427
if let Value::String(val) = &self.value {
428428
let mut buf = vec![0u8; val.len()];
429-
if let Err(_) = tf_reader.read_exact(&mut buf) {
429+
if tf_reader.read_exact(&mut buf).is_err() {
430430
return false;
431431
}
432432

@@ -439,7 +439,7 @@ impl RawMagicFileLine {
439439

440440
fn number_test(&self, size: u64, mask: Option<u64>, tf_reader: &mut BufReader<File>) -> bool {
441441
let mut buf = vec![0; size as usize];
442-
if let Err(_) = tf_reader.read_exact(&mut buf) {
442+
if tf_reader.read_exact(&mut buf).is_err() {
443443
return false;
444444
}
445445

i18n/iconv_lib/utf_16.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,13 @@ pub fn from_ucs4<I: Iterator<Item = u32> + 'static>(
170170
let high_surrogate = ((code_point >> 10) as u16) + 0xD800;
171171
let low_surrogate = ((code_point & 0x3FF) as u16) + 0xDC00;
172172
utf16.extend_from_slice(&[high_surrogate, low_surrogate]);
173+
} else if !omit_invalid {
174+
return Vec::new();
173175
} else {
174-
if !omit_invalid {
175-
return Vec::new();
176-
} else {
177-
if !suppress_error {
178-
eprintln!("Error: Invalid Unicode code point U+{:X}", code_point);
179-
}
180-
exit(1)
176+
if !suppress_error {
177+
eprintln!("Error: Invalid Unicode code point U+{:X}", code_point);
181178
}
179+
exit(1)
182180
}
183181

184182
to_bytes(&utf16, variant)

i18n/iconv_lib/utf_32.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,20 @@ pub fn to_ucs4<I: Iterator<Item = u8> + 'static>(
4242

4343
if !bom_checked {
4444
let first_word = BigEndian::read_u32(&buffer);
45-
match variant {
46-
UTF32Variant::UTF32 => {
47-
if first_word == BOM {
48-
variant = UTF32Variant::UTF32BE;
49-
buffer.clear();
50-
} else if first_word == BOM_OE {
51-
variant = UTF32Variant::UTF32LE;
52-
buffer.clear();
45+
if variant == UTF32Variant::UTF32 {
46+
if first_word == BOM {
47+
variant = UTF32Variant::UTF32BE;
48+
buffer.clear();
49+
} else if first_word == BOM_OE {
50+
variant = UTF32Variant::UTF32LE;
51+
buffer.clear();
52+
} else {
53+
variant = if cfg!(target_endian = "little") {
54+
UTF32Variant::UTF32LE
5355
} else {
54-
variant = if cfg!(target_endian = "little") {
55-
UTF32Variant::UTF32LE
56-
} else {
57-
UTF32Variant::UTF32BE
58-
};
59-
}
56+
UTF32Variant::UTF32BE
57+
};
6058
}
61-
_ => {}
6259
}
6360
bom_checked = true;
6461
if buffer.is_empty() {

i18n/iconv_lib/utf_8.rs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -168,16 +168,14 @@ pub fn to_ucs4<I: Iterator<Item = u8> + 'static>(
168168
}
169169
buffer.drain(0..4);
170170
return Some(code_point);
171+
} else if omit_invalid {
172+
buffer.drain(0..1);
173+
continue;
171174
} else {
172-
if omit_invalid {
173-
buffer.drain(0..1);
174-
continue;
175-
} else {
176-
if !suppress_error {
177-
eprintln!("Error: Invalid byte");
178-
}
179-
exit(1);
175+
if !suppress_error {
176+
eprintln!("Error: Invalid byte");
180177
}
178+
exit(1);
181179
}
182180
}
183181
});
@@ -225,19 +223,17 @@ pub fn from_ucs4<I: Iterator<Item = u32> + 'static>(
225223
0x80 | (((code_point >> 6) & 0x3F) as u8),
226224
0x80 | ((code_point & 0x3F) as u8),
227225
])
226+
} else if omit_invalid {
227+
None
228228
} else {
229-
if omit_invalid {
230-
None
231-
} else {
232-
if !suppress_error {
233-
eprintln!(
234-
"Error: Code point U+{:X} is out of valid Unicode range",
235-
code_point
236-
);
237-
exit(1)
238-
}
239-
Some(vec![])
229+
if !suppress_error {
230+
eprintln!(
231+
"Error: Code point U+{:X} is out of valid Unicode range",
232+
code_point
233+
);
234+
exit(1)
240235
}
236+
Some(vec![])
241237
}
242238
});
243239
Box::new(iter.flatten())

m4/src/lexer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! REQUIEREMENTS:
22
//!
33
//! * Because m4 supports streaming input and output, it seems like we should probably support
4-
//! streaming lexing/parsing so that we don't run out of RAM.
4+
//! streaming lexing/parsing so that we don't run out of RAM.
55
//! * For good performance it seems like the lexer should probably take into account the current state of the macro
6-
//! definitions, otherwise potentially any input word not matching builtin macros could be a macro and we will need to re-analyze it in a second phase. Also I think there is the possibility to undefine builtin macros? in which case this is absolutely necessary. This seems relevant for nom https://github.com/rust-bakery/nom/issues/1419
7-
//! So it seems like a good optimization that once we know a word is not a current macro name, to
8-
//! forget trying to parse the rest of it as a macro.
6+
//! definitions, otherwise potentially any input word not matching builtin macros could be a macro and we will need to re-analyze it in a second phase. Also I think there is the possibility to undefine builtin macros? in which case this is absolutely necessary. This seems relevant for nom https://github.com/rust-bakery/nom/issues/1419
7+
//! So it seems like a good optimization that once we know a word is not a current macro name, to
8+
//! forget trying to parse the rest of it as a macro.
99
//! * Perhaps this might be useful https://github.com/fflorent/nom_locate/blob/master/README.md
1010
//!
1111
//! Taking a look at this BSD licensed code

m4/src/precedence.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ where
151151
/// * It reads, left-to-right, the first two operators `-a++`.
152152
/// * Because the minus takes precedence over the increment it is evaluated immediately `(-a)++`.
153153
/// * It then reads the remaining input and evaluates the increment next in order to preserve its
154-
/// position in the expression \
155-
/// `((-a)++)**b`.
154+
/// position in the expression \
155+
/// `((-a)++)**b`.
156156
pub fn precedence<I, O, E, E2, F, G, H1, H3, H2, P1, P2, P3, Q>(
157157
mut prefix: H1,
158158
mut postfix: H2,

m4/test-manager/src/main.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@ fn update_snapshots(args: &Args, update: &UpdateSnapshots) {
5959
dir.map(|result| result.unwrap())
6060
.filter(|entry| {
6161
if !(entry.path().is_file()
62-
&& match entry.path().extension().map(|e| e.as_bytes()) {
63-
Some(b"m4") => true,
64-
Some(b"args") => true,
65-
_ => false,
66-
})
62+
&& matches!(
63+
entry.path().extension().map(|e| e.as_bytes()),
64+
Some(b"m4") | Some(b"args")
65+
))
6766
{
6867
return false;
6968
}

0 commit comments

Comments
 (0)