Skip to content

Commit cfb0aa7

Browse files
authored
Merge pull request #265 from rustcoreutils/cleanups
Cleanups
2 parents 7bd5e32 + 110e0a3 commit cfb0aa7

File tree

14 files changed

+31
-40
lines changed

14 files changed

+31
-40
lines changed

file/dd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,15 @@ fn convert_swab(data: &mut [u8]) {
148148
fn convert_lcase(data: &mut [u8]) {
149149
for byte in data.iter_mut() {
150150
if *byte >= b'A' && *byte <= b'Z' {
151-
*byte = *byte + 32;
151+
*byte += 32;
152152
}
153153
}
154154
}
155155

156156
fn convert_ucase(data: &mut [u8]) {
157157
for byte in data.iter_mut() {
158158
if *byte >= b'a' && *byte <= b'z' {
159-
*byte = *byte - 32;
159+
*byte -= 32;
160160
}
161161
}
162162
}

file/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl RawMagicFileLine {
484484
let mut tf_val = u64::from_be_bytes(array_buf);
485485

486486
if let Some(mask) = mask {
487-
tf_val = mask & tf_val;
487+
tf_val &= mask;
488488
}
489489

490490
match &self.value {

file/split.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl OutputState {
105105
if i == 0 {
106106
break;
107107
}
108-
i = i - 1;
108+
i -= 1;
109109
}
110110

111111
Err("maximum suffix reached")
@@ -141,7 +141,7 @@ impl OutputState {
141141
}
142142

143143
fn incr_output(&mut self, n: u64) {
144-
self.count = self.count + n;
144+
self.count += n;
145145
assert!(self.count <= self.boundary);
146146

147147
if self.count == self.boundary {
@@ -170,7 +170,7 @@ impl OutputState {
170170
let slice = &buf[consumed..consumed + wlen];
171171
self.write(slice)?;
172172

173-
consumed = consumed + wlen;
173+
consumed += wlen;
174174

175175
self.incr_output(wlen as u64);
176176
}

misc/test.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,9 @@ fn parse_binary_op(s: &str) -> Option<BinOp> {
182182
}
183183
}
184184

185-
fn parse_int(s: &str) -> i64 {
186-
match s.parse::<i64>() {
187-
Ok(i) => i,
188-
Err(_) => 0,
189-
}
190-
}
191-
192185
fn eval_binary_int(op: &BinOp, s1: &str, s2: &str) -> bool {
193-
let i1 = parse_int(s1);
194-
let i2 = parse_int(s2);
186+
let i1: i64 = s1.parse().unwrap_or(0);
187+
let i2: i64 = s2.parse().unwrap_or(0);
195188

196189
match op {
197190
BinOp::IntEq => i1 == i2,

plib/src/lzw.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ impl UnixLZWReader {
163163
}
164164
}
165165

166+
#[allow(clippy::assign_op_pattern)]
166167
fn getcode(&mut self) -> i32 {
167168
if self.clear || self.roffset >= self.size || self.free_ent > self.maxcode {
168169
// as free_ent represents the index of the next available entry that can be made

screen/stty.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ fn set_ti_flag(
307307

308308
// set flag bits (unless negation)
309309
if !negate {
310-
newflags = newflags | val_set;
310+
newflags |= val_set;
311311
}
312312

313313
// commit flag bits to termio struct, if changed
@@ -461,7 +461,7 @@ fn stty_set_long(mut ti: Termios, args: &Args) -> io::Result<()> {
461461
if operand.parse::<u64>().is_ok() {
462462
set_ti_speed(&mut ti, &speedmap, true, operand)?;
463463
set_ti_speed(&mut ti, &speedmap, false, operand)?;
464-
idx = idx + 1;
464+
idx += 1;
465465
continue;
466466
}
467467

@@ -489,7 +489,7 @@ fn stty_set_long(mut ti: Termios, args: &Args) -> io::Result<()> {
489489

490490
let mut op_arg = String::new();
491491
if (flags & PARG) != 0 {
492-
idx = idx + 1;
492+
idx += 1;
493493

494494
if idx == args.operands.len() {
495495
let errstr = format!("Missing operand for {}", operand);
@@ -530,7 +530,7 @@ fn stty_set_long(mut ti: Termios, args: &Args) -> io::Result<()> {
530530
}
531531
}
532532

533-
idx = idx + 1;
533+
idx += 1;
534534
}
535535

536536
// finally, commit new termio settings (if any)

text/asa.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn asa_file(pathname: &PathBuf) -> io::Result<()> {
7272
let mut state = AsaState::new();
7373

7474
loop {
75-
line_no = line_no + 1;
75+
line_no += 1;
7676

7777
let mut raw_line = String::new();
7878
let n_read = reader.read_line(&mut raw_line)?;
@@ -90,7 +90,7 @@ fn asa_file(pathname: &PathBuf) -> io::Result<()> {
9090
// exclude first char, and trailing newline
9191
let mut line_len = raw_line.len() - 1;
9292
if raw_line.ends_with('\n') {
93-
line_len = line_len - 1;
93+
line_len -= 1;
9494
}
9595
let line = &raw_line[1..line_len];
9696

text/expand.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn parse_tablist(tablist: &str) -> Result<TabList, &'static str> {
5757
}
5858

5959
fn space_out(column: &mut usize, writer: &mut BufWriter<dyn Write>) -> io::Result<()> {
60-
*column = *column + 1;
60+
*column += 1;
6161

6262
writer.write_all(b" ")?;
6363

@@ -89,14 +89,14 @@ fn expand_file(tablist: &TabList, pathname: &PathBuf) -> io::Result<()> {
8989
// backspace
9090
writer.write_all(&[byte])?;
9191
if column > 1 {
92-
column = column - 1;
92+
column -= 1;
9393
}
9494
} else if byte == b'\r' || byte == b'\n' {
9595
writer.write_all(&[byte])?;
9696
column = 1;
9797
} else if byte != b'\t' {
9898
writer.write_all(&[byte])?;
99-
column = column + 1;
99+
column += 1;
100100
} else {
101101
match tablist {
102102
TabList::UniStop(n) => {
@@ -115,7 +115,7 @@ fn expand_file(tablist: &TabList, pathname: &PathBuf) -> io::Result<()> {
115115
while column < next_tab {
116116
space_out(&mut column, &mut writer)?;
117117
}
118-
cur_stop = cur_stop + 1;
118+
cur_stop += 1;
119119
space_out(&mut column, &mut writer)?;
120120
}
121121
}

text/head.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ fn head_file(args: &Args, pathname: &PathBuf, first: bool, want_header: bool) ->
5656
for chv in buf {
5757
// LF character encountered
5858
if *chv == 10 {
59-
nl = nl + 1;
59+
nl += 1;
6060
}
6161

62-
pos = pos + 1;
62+
pos += 1;
6363

6464
// if user-specified limit reached, stop
6565
if nl >= args.n {

text/pr_util/args.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,10 @@ impl Parameters {
355355

356356
let (first_page, last_page) = args.pages.unwrap_or((1, None));
357357

358-
let num_columns = {
359-
if args.merge {
360-
args.file.len()
361-
} else if let Some(n) = args.columns {
362-
n
363-
} else {
364-
1
365-
}
358+
let num_columns = if args.merge {
359+
args.file.len()
360+
} else {
361+
args.columns.unwrap_or(1)
366362
};
367363

368364
let form_feed = args.form_feed || args.form_feed_with_pause;

0 commit comments

Comments
 (0)