diff --git a/crates/nu-cmd-extra/src/extra/bits/mod.rs b/crates/nu-cmd-extra/src/extra/bits/mod.rs index 437313960e..cbac833896 100644 --- a/crates/nu-cmd-extra/src/extra/bits/mod.rs +++ b/crates/nu-cmd-extra/src/extra/bits/mod.rs @@ -135,7 +135,7 @@ where (min, max) => (rhs, lhs, max, min), }; - let pad = iter::repeat(0).take(max_len - min_len); + let pad = iter::repeat_n(0, max_len - min_len); let mut a; let mut b; diff --git a/crates/nu-cmd-extra/src/extra/bits/shift_left.rs b/crates/nu-cmd-extra/src/extra/bits/shift_left.rs index 0f1f0114e1..5b8e6a5ae6 100644 --- a/crates/nu-cmd-extra/src/extra/bits/shift_left.rs +++ b/crates/nu-cmd-extra/src/extra/bits/shift_left.rs @@ -249,7 +249,7 @@ fn shift_bytes_and_bits_left(data: &[u8], byte_shift: usize, bit_shift: usize) - Last | Only => lhs << bit_shift, _ => (lhs << bit_shift) | (rhs >> (8 - bit_shift)), }) - .chain(iter::repeat(0).take(byte_shift)) + .chain(iter::repeat_n(0, byte_shift)) .collect::>() } diff --git a/crates/nu-command/src/debug/inspect_table.rs b/crates/nu-command/src/debug/inspect_table.rs index 5f18eb5be3..6bd5a3cce8 100644 --- a/crates/nu-command/src/debug/inspect_table.rs +++ b/crates/nu-command/src/debug/inspect_table.rs @@ -118,7 +118,7 @@ fn increase_string_width(text: &mut String, total: usize) { let rest = total - width; if rest > 0 { - text.extend(std::iter::repeat(' ').take(rest)); + text.extend(std::iter::repeat_n(' ', rest)); } } diff --git a/crates/nu-command/src/filesystem/ls.rs b/crates/nu-command/src/filesystem/ls.rs index cda0fc0826..4a188429f3 100644 --- a/crates/nu-command/src/filesystem/ls.rs +++ b/crates/nu-command/src/filesystem/ls.rs @@ -378,10 +378,7 @@ fn ls_for_one_pattern( .par_bridge() .filter_map(move |x| match x { Ok(path) => { - let metadata = match std::fs::symlink_metadata(&path) { - Ok(metadata) => Some(metadata), - Err(_) => None, - }; + let metadata = std::fs::symlink_metadata(&path).ok(); let hidden_dir_clone = Arc::clone(&hidden_dirs); let mut hidden_dir_mutex = hidden_dir_clone .lock() diff --git a/crates/nu-command/src/filters/chunks.rs b/crates/nu-command/src/filters/chunks.rs index bfac65e358..2ff9b1b0a7 100644 --- a/crates/nu-command/src/filters/chunks.rs +++ b/crates/nu-command/src/filters/chunks.rs @@ -243,7 +243,7 @@ mod test { let chunks = chunk_read.map(|e| e.unwrap()).collect::>(); assert_eq!( chunks, - [s[..4].as_bytes(), s[4..8].as_bytes(), s[8..].as_bytes()] + [&s.as_bytes()[..4], &s.as_bytes()[4..8], &s.as_bytes()[8..]] ); } @@ -260,7 +260,7 @@ mod test { let chunks = chunk_read.map(|e| e.unwrap()).collect::>(); assert_eq!( chunks, - [s[..4].as_bytes(), s[4..8].as_bytes(), s[8..].as_bytes()] + [&s.as_bytes()[..4], &s.as_bytes()[4..8], &s.as_bytes()[8..]] ); } diff --git a/crates/nu-command/src/math/utils.rs b/crates/nu-command/src/math/utils.rs index 3035e78e02..9041f23ffa 100644 --- a/crates/nu-command/src/math/utils.rs +++ b/crates/nu-command/src/math/utils.rs @@ -102,7 +102,7 @@ pub fn calculate( mf(&new_vals?, span, name) } PipelineData::Value(val, ..) => mf(&[val], span, name), - PipelineData::Empty { .. } => Err(ShellError::PipelineEmpty { dst_span: name }), + PipelineData::Empty => Err(ShellError::PipelineEmpty { dst_span: name }), val => Err(ShellError::UnsupportedInput { msg: "Only ints, floats, lists, records, or ranges are supported".into(), input: "value originates from here".into(), diff --git a/crates/nu-command/src/network/http/client.rs b/crates/nu-command/src/network/http/client.rs index 271c521715..c4fe4f9486 100644 --- a/crates/nu-command/src/network/http/client.rs +++ b/crates/nu-command/src/network/http/client.rs @@ -723,7 +723,7 @@ fn transform_response_using_content_type( ) })? .path_segments() - .and_then(|segments| segments.last()) + .and_then(|mut segments| segments.next_back()) .and_then(|name| if name.is_empty() { None } else { Some(name) }) .and_then(|name| { PathBuf::from(name) diff --git a/crates/nu-command/src/path/join.rs b/crates/nu-command/src/path/join.rs index 9f055589d3..c36b51fb99 100644 --- a/crates/nu-command/src/path/join.rs +++ b/crates/nu-command/src/path/join.rs @@ -175,7 +175,7 @@ fn run(call: &Call, args: &Arguments, input: PipelineData) -> Result Err(ShellError::PipelineEmpty { dst_span: head }), + PipelineData::Empty => Err(ShellError::PipelineEmpty { dst_span: head }), _ => Err(ShellError::UnsupportedInput { msg: "Input value cannot be joined".to_string(), input: "value originates from here".into(), diff --git a/crates/nu-engine/src/compile/redirect.rs b/crates/nu-engine/src/compile/redirect.rs index 101cc9077c..8d780177d9 100644 --- a/crates/nu-engine/src/compile/redirect.rs +++ b/crates/nu-engine/src/compile/redirect.rs @@ -98,7 +98,7 @@ pub(crate) fn finish_redirection( if !matches!( modes.err, Some(Spanned { - item: RedirectMode::Pipe { .. }, + item: RedirectMode::Pipe, .. }) ) { diff --git a/crates/nu-explore/src/views/binary/binary_widget.rs b/crates/nu-explore/src/views/binary/binary_widget.rs index d100774be5..859661ca02 100644 --- a/crates/nu-explore/src/views/binary/binary_widget.rs +++ b/crates/nu-explore/src/views/binary/binary_widget.rs @@ -323,9 +323,7 @@ fn repeat_vertical( c: char, style: TextStyle, ) { - let text = std::iter::repeat(c) - .take(width as usize) - .collect::(); + let text = std::iter::repeat_n(c, width as usize).collect::(); let style = text_style_to_tui_style(style); let span = Span::styled(text, style); diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index ec971639c5..9c4d2b30c4 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -2678,7 +2678,7 @@ pub fn parse_unit_value<'res>( if let Some((unit, name, convert)) = unit_groups.iter().find(|x| value.ends_with(x.1)) { let lhs_len = value.len() - name.len(); - let lhs = strip_underscores(value[..lhs_len].as_bytes()); + let lhs = strip_underscores(&value.as_bytes()[..lhs_len]); let lhs_span = Span::new(span.start, span.start + lhs_len); let unit_span = Span::new(span.start + lhs_len, span.end); if lhs.ends_with('$') { diff --git a/crates/nu-path/src/dots.rs b/crates/nu-path/src/dots.rs index 97a7deac02..bfbb027d9a 100644 --- a/crates/nu-path/src/dots.rs +++ b/crates/nu-path/src/dots.rs @@ -46,7 +46,7 @@ pub fn expand_ndots(path: impl AsRef) -> PathBuf { pub fn expand_dots(path: impl AsRef) -> PathBuf { // Check if the last component of the path is a normal component. fn last_component_is_normal(path: &Path) -> bool { - matches!(path.components().last(), Some(Component::Normal(_))) + matches!(path.components().next_back(), Some(Component::Normal(_))) } let path = path.as_ref(); @@ -61,7 +61,7 @@ pub fn expand_dots(path: impl AsRef) -> PathBuf { // no-op } _ => { - let prev_component = result.components().last(); + let prev_component = result.components().next_back(); if prev_component == Some(Component::RootDir) && component == Component::ParentDir { continue; } diff --git a/crates/nu-path/src/tilde.rs b/crates/nu-path/src/tilde.rs index 5bae92424a..59c14e5986 100644 --- a/crates/nu-path/src/tilde.rs +++ b/crates/nu-path/src/tilde.rs @@ -29,7 +29,7 @@ fn expand_tilde_with_home(path: impl AsRef, home: Option) -> Path }; } - let path_last_char = path.as_os_str().to_string_lossy().chars().last(); + let path_last_char = path.as_os_str().to_string_lossy().chars().next_back(); let need_trailing_slash = path_last_char == Some('/') || path_last_char == Some('\\'); match home { @@ -94,7 +94,7 @@ fn user_home_dir(username: &str) -> PathBuf { if !cfg!(target_os = "android") && expected_path .components() - .last() + .next_back() .map(|last| last != Component::Normal(username.as_ref())) .unwrap_or(false) { diff --git a/crates/nu-protocol/src/engine/state_working_set.rs b/crates/nu-protocol/src/engine/state_working_set.rs index 11be80efb9..fb32d54231 100644 --- a/crates/nu-protocol/src/engine/state_working_set.rs +++ b/crates/nu-protocol/src/engine/state_working_set.rs @@ -884,7 +884,7 @@ impl<'a> StateWorkingSet<'a> { .active_overlay_names(&mut removed_overlays) .iter() .rev() - .last() + .next_back() { return last_name; } @@ -900,7 +900,7 @@ impl<'a> StateWorkingSet<'a> { if let Some(last_overlay) = scope_frame .active_overlays(&mut removed_overlays) .rev() - .last() + .next_back() { return last_overlay; } diff --git a/crates/nu-protocol/src/lev_distance.rs b/crates/nu-protocol/src/lev_distance.rs index 51dc856d86..77bc20fd65 100644 --- a/crates/nu-protocol/src/lev_distance.rs +++ b/crates/nu-protocol/src/lev_distance.rs @@ -88,7 +88,7 @@ pub fn lev_distance_with_substrings(a: &str, b: &str, limit: usize) -> Option() .split(':') - .last() + .next_back() .expect("str::split returns an iterator with at least one element") .to_string() .into_boxed_str(), diff --git a/crates/nu-table/src/unstructured_table.rs b/crates/nu-table/src/unstructured_table.rs index be722c5e51..1ce5f164ee 100644 --- a/crates/nu-table/src/unstructured_table.rs +++ b/crates/nu-table/src/unstructured_table.rs @@ -119,7 +119,7 @@ fn build_vertical_map(record: Record, config: &Config) -> TableValue { fn string_append_to_width(key: &mut String, max: usize) { let width = string_width(key); let rest = max - width; - key.extend(std::iter::repeat(' ').take(rest)); + key.extend(std::iter::repeat_n(' ', rest)); } fn build_vertical_array(vals: Vec, config: &Config) -> TableValue { diff --git a/crates/nu-term-grid/src/grid.rs b/crates/nu-term-grid/src/grid.rs index 4c92d6003d..f7881a3383 100644 --- a/crates/nu-term-grid/src/grid.rs +++ b/crates/nu-term-grid/src/grid.rs @@ -39,15 +39,15 @@ //! that dictate how the grid is formatted: //! //! - `filling`: what to put in between two columns — either a number of -//! spaces, or a text string; +//! spaces, or a text string; //! - `direction`, which specifies whether the cells should go along -//! rows, or columns: +//! rows, or columns: //! - `Direction::LeftToRight` starts them in the top left and -//! moves *rightwards*, going to the start of a new row after reaching the -//! final column; +//! moves *rightwards*, going to the start of a new row after reaching the +//! final column; //! - `Direction::TopToBottom` starts them in the top left and moves -//! *downwards*, going to the top of a new column after reaching the final -//! row. +//! *downwards*, going to the top of a new column after reaching the final +//! row. //! //! //! ## Displaying a grid @@ -93,7 +93,7 @@ use std::cmp::max; use std::fmt; -use std::iter::repeat; +use std::iter::repeat_n; use unicode_width::UnicodeWidthStr; fn unicode_width_strip_ansi(astring: &str) -> usize { @@ -290,7 +290,7 @@ impl Grid { } fn column_widths(&self, num_lines: usize, num_columns: usize) -> Dimensions { - let mut widths: Vec = repeat(0).take(num_columns).collect(); + let mut widths: Vec = repeat_n(0, num_columns).collect(); for (index, cell) in self.cells.iter().enumerate() { let index = match self.options.direction { Direction::LeftToRight => index % num_columns, diff --git a/crates/nu_plugin_polars/src/dataframe/values/nu_dataframe/mod.rs b/crates/nu_plugin_polars/src/dataframe/values/nu_dataframe/mod.rs index 55c1f620c9..e4191012c7 100644 --- a/crates/nu_plugin_polars/src/dataframe/values/nu_dataframe/mod.rs +++ b/crates/nu_plugin_polars/src/dataframe/values/nu_dataframe/mod.rs @@ -317,7 +317,7 @@ impl NuDataFrame { let series = self.as_series(span)?; let column = conversion::create_column_from_series(&series, row, row + 1, span)?; - if column.len() == 0 { + if column.is_empty() { Err(ShellError::AccessEmptyContent { span }) } else { let value = column