Skip to content

Commit 1c6c85d

Browse files
authored
Fix clippy (nushell#15489)
# Description There are some clippy(version 0.1.86) errors on nushell repo. This pr is trying to fix it. # User-Facing Changes Hopefully none. # Tests + Formatting NaN # After Submitting NaN
1 parent 67ea25a commit 1c6c85d

File tree

19 files changed

+30
-35
lines changed

19 files changed

+30
-35
lines changed

crates/nu-cmd-extra/src/extra/bits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ where
135135
(min, max) => (rhs, lhs, max, min),
136136
};
137137

138-
let pad = iter::repeat(0).take(max_len - min_len);
138+
let pad = iter::repeat_n(0, max_len - min_len);
139139

140140
let mut a;
141141
let mut b;

crates/nu-cmd-extra/src/extra/bits/shift_left.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ fn shift_bytes_and_bits_left(data: &[u8], byte_shift: usize, bit_shift: usize) -
249249
Last | Only => lhs << bit_shift,
250250
_ => (lhs << bit_shift) | (rhs >> (8 - bit_shift)),
251251
})
252-
.chain(iter::repeat(0).take(byte_shift))
252+
.chain(iter::repeat_n(0, byte_shift))
253253
.collect::<Vec<u8>>()
254254
}
255255

crates/nu-command/src/debug/inspect_table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn increase_string_width(text: &mut String, total: usize) {
118118
let rest = total - width;
119119

120120
if rest > 0 {
121-
text.extend(std::iter::repeat(' ').take(rest));
121+
text.extend(std::iter::repeat_n(' ', rest));
122122
}
123123
}
124124

crates/nu-command/src/filesystem/ls.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,7 @@ fn ls_for_one_pattern(
378378
.par_bridge()
379379
.filter_map(move |x| match x {
380380
Ok(path) => {
381-
let metadata = match std::fs::symlink_metadata(&path) {
382-
Ok(metadata) => Some(metadata),
383-
Err(_) => None,
384-
};
381+
let metadata = std::fs::symlink_metadata(&path).ok();
385382
let hidden_dir_clone = Arc::clone(&hidden_dirs);
386383
let mut hidden_dir_mutex = hidden_dir_clone
387384
.lock()

crates/nu-command/src/filters/chunks.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ mod test {
243243
let chunks = chunk_read.map(|e| e.unwrap()).collect::<Vec<_>>();
244244
assert_eq!(
245245
chunks,
246-
[s[..4].as_bytes(), s[4..8].as_bytes(), s[8..].as_bytes()]
246+
[&s.as_bytes()[..4], &s.as_bytes()[4..8], &s.as_bytes()[8..]]
247247
);
248248
}
249249

@@ -260,7 +260,7 @@ mod test {
260260
let chunks = chunk_read.map(|e| e.unwrap()).collect::<Vec<_>>();
261261
assert_eq!(
262262
chunks,
263-
[s[..4].as_bytes(), s[4..8].as_bytes(), s[8..].as_bytes()]
263+
[&s.as_bytes()[..4], &s.as_bytes()[4..8], &s.as_bytes()[8..]]
264264
);
265265
}
266266

crates/nu-command/src/math/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub fn calculate(
102102
mf(&new_vals?, span, name)
103103
}
104104
PipelineData::Value(val, ..) => mf(&[val], span, name),
105-
PipelineData::Empty { .. } => Err(ShellError::PipelineEmpty { dst_span: name }),
105+
PipelineData::Empty => Err(ShellError::PipelineEmpty { dst_span: name }),
106106
val => Err(ShellError::UnsupportedInput {
107107
msg: "Only ints, floats, lists, records, or ranges are supported".into(),
108108
input: "value originates from here".into(),

crates/nu-command/src/network/http/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ fn transform_response_using_content_type(
723723
)
724724
})?
725725
.path_segments()
726-
.and_then(|segments| segments.last())
726+
.and_then(|mut segments| segments.next_back())
727727
.and_then(|name| if name.is_empty() { None } else { Some(name) })
728728
.and_then(|name| {
729729
PathBuf::from(name)

crates/nu-command/src/path/join.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ fn run(call: &Call, args: &Arguments, input: PipelineData) -> Result<PipelineDat
175175
handle_value(stream.into_value(), args, head),
176176
metadata,
177177
)),
178-
PipelineData::Empty { .. } => Err(ShellError::PipelineEmpty { dst_span: head }),
178+
PipelineData::Empty => Err(ShellError::PipelineEmpty { dst_span: head }),
179179
_ => Err(ShellError::UnsupportedInput {
180180
msg: "Input value cannot be joined".to_string(),
181181
input: "value originates from here".into(),

crates/nu-engine/src/compile/redirect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ pub(crate) fn finish_redirection(
9898
if !matches!(
9999
modes.err,
100100
Some(Spanned {
101-
item: RedirectMode::Pipe { .. },
101+
item: RedirectMode::Pipe,
102102
..
103103
})
104104
) {

crates/nu-explore/src/views/binary/binary_widget.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,7 @@ fn repeat_vertical(
323323
c: char,
324324
style: TextStyle,
325325
) {
326-
let text = std::iter::repeat(c)
327-
.take(width as usize)
328-
.collect::<String>();
326+
let text = std::iter::repeat_n(c, width as usize).collect::<String>();
329327
let style = text_style_to_tui_style(style);
330328
let span = Span::styled(text, style);
331329

0 commit comments

Comments
 (0)