Skip to content

Commit bf23573

Browse files
Update Rust to 1.88.0 and use let-chains (nushell#16671)
Co-authored-by: Tim 'Piepmatz' Hesse <[email protected]>
1 parent 089b628 commit bf23573

File tree

85 files changed

+1496
-1534
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+1496
-1534
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ homepage = "https://www.nushell.sh"
1010
license = "MIT"
1111
name = "nu"
1212
repository = "https://github.com/nushell/nushell"
13-
rust-version = "1.87.0"
13+
rust-version = "1.88.0"
1414
version = "0.107.1"
1515

1616
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

crates/nu-cli/src/completions/command_completions.rs

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -31,57 +31,57 @@ impl CommandCompletion {
3131

3232
let paths = working_set.permanent_state.get_env_var_insensitive("path");
3333

34-
if let Some((_, paths)) = paths {
35-
if let Ok(paths) = paths.as_list() {
36-
for path in paths {
37-
let path = path.coerce_str().unwrap_or_default();
34+
if let Some((_, paths)) = paths
35+
&& let Ok(paths) = paths.as_list()
36+
{
37+
for path in paths {
38+
let path = path.coerce_str().unwrap_or_default();
3839

39-
if let Ok(mut contents) = std::fs::read_dir(path.as_ref()) {
40-
while let Some(Ok(item)) = contents.next() {
41-
if working_set
42-
.permanent_state
43-
.config
44-
.completions
45-
.external
46-
.max_results
47-
<= suggs.len() as i64
48-
{
49-
break;
50-
}
51-
let Ok(name) = item.file_name().into_string() else {
52-
continue;
53-
};
54-
let value = if matched_internal(&name) {
55-
format!("^{name}")
56-
} else {
57-
name.clone()
58-
};
59-
if suggs.contains_key(&value) {
60-
continue;
61-
}
62-
// TODO: check name matching before a relative heavy IO involved
63-
// `is_executable` for performance consideration, should avoid
64-
// duplicated `match_aux` call for matched items in the future
65-
if matcher.matches(&name) && is_executable::is_executable(item.path()) {
66-
// If there's an internal command with the same name, adds ^cmd to the
67-
// matcher so that both the internal and external command are included
68-
matcher.add(&name, value.clone());
69-
suggs.insert(
70-
value.clone(),
71-
SemanticSuggestion {
72-
suggestion: Suggestion {
73-
value,
74-
span: sugg_span,
75-
append_whitespace: true,
76-
..Default::default()
77-
},
78-
kind: Some(SuggestionKind::Command(
79-
CommandType::External,
80-
None,
81-
)),
40+
if let Ok(mut contents) = std::fs::read_dir(path.as_ref()) {
41+
while let Some(Ok(item)) = contents.next() {
42+
if working_set
43+
.permanent_state
44+
.config
45+
.completions
46+
.external
47+
.max_results
48+
<= suggs.len() as i64
49+
{
50+
break;
51+
}
52+
let Ok(name) = item.file_name().into_string() else {
53+
continue;
54+
};
55+
let value = if matched_internal(&name) {
56+
format!("^{name}")
57+
} else {
58+
name.clone()
59+
};
60+
if suggs.contains_key(&value) {
61+
continue;
62+
}
63+
// TODO: check name matching before a relative heavy IO involved
64+
// `is_executable` for performance consideration, should avoid
65+
// duplicated `match_aux` call for matched items in the future
66+
if matcher.matches(&name) && is_executable::is_executable(item.path()) {
67+
// If there's an internal command with the same name, adds ^cmd to the
68+
// matcher so that both the internal and external command are included
69+
matcher.add(&name, value.clone());
70+
suggs.insert(
71+
value.clone(),
72+
SemanticSuggestion {
73+
suggestion: Suggestion {
74+
value,
75+
span: sugg_span,
76+
append_whitespace: true,
77+
..Default::default()
8278
},
83-
);
84-
}
79+
kind: Some(SuggestionKind::Command(
80+
CommandType::External,
81+
None,
82+
)),
83+
},
84+
);
8585
}
8686
}
8787
}

crates/nu-cli/src/completions/completer.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,9 @@ impl NuCompleter {
523523
.collect();
524524
let mut new_span = span;
525525
// strip the placeholder
526-
if strip {
527-
if let Some(last) = text_spans.last_mut() {
528-
last.pop();
529-
new_span = Span::new(span.start, span.end.saturating_sub(1));
530-
}
526+
if strip && let Some(last) = text_spans.last_mut() {
527+
last.pop();
528+
new_span = Span::new(span.start, span.end.saturating_sub(1));
531529
}
532530
if let Some(external_result) =
533531
self.external_completion(closure, &text_spans, offset, new_span)
@@ -749,19 +747,19 @@ impl NuCompleter {
749747
.captures_to_stack_preserve_out_dest(closure.captures.clone());
750748

751749
// Line
752-
if let Some(pos_arg) = block.signature.required_positional.first() {
753-
if let Some(var_id) = pos_arg.var_id {
754-
callee_stack.add_var(
755-
var_id,
756-
Value::list(
757-
spans
758-
.iter()
759-
.map(|it| Value::string(it, Span::unknown()))
760-
.collect(),
761-
Span::unknown(),
762-
),
763-
);
764-
}
750+
if let Some(pos_arg) = block.signature.required_positional.first()
751+
&& let Some(var_id) = pos_arg.var_id
752+
{
753+
callee_stack.add_var(
754+
var_id,
755+
Value::list(
756+
spans
757+
.iter()
758+
.map(|it| Value::string(it, Span::unknown()))
759+
.collect(),
760+
Span::unknown(),
761+
),
762+
);
765763
}
766764

767765
let result = eval_block::<WithoutDebug>(

crates/nu-cli/src/completions/completion_common.rs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,27 @@ fn complete_rec(
4141
) -> Vec<PathBuiltFromString> {
4242
let has_more = !partial.is_empty() && (partial.len() > 1 || isdir);
4343

44-
if let Some((&base, rest)) = partial.split_first() {
45-
if base.chars().all(|c| c == '.') && has_more {
46-
let built_paths: Vec<_> = built_paths
47-
.iter()
48-
.map(|built| {
49-
let mut built = built.clone();
50-
built.parts.push(base.to_string());
51-
built.isdir = true;
52-
built
53-
})
54-
.collect();
55-
return complete_rec(
56-
rest,
57-
&built_paths,
58-
options,
59-
want_directory,
60-
isdir,
61-
enable_exact_match,
62-
);
63-
}
44+
if let Some((&base, rest)) = partial.split_first()
45+
&& base.chars().all(|c| c == '.')
46+
&& has_more
47+
{
48+
let built_paths: Vec<_> = built_paths
49+
.iter()
50+
.map(|built| {
51+
let mut built = built.clone();
52+
built.parts.push(base.to_string());
53+
built.isdir = true;
54+
built
55+
})
56+
.collect();
57+
return complete_rec(
58+
rest,
59+
&built_paths,
60+
options,
61+
want_directory,
62+
isdir,
63+
enable_exact_match,
64+
);
6465
}
6566

6667
let prefix = partial.first().unwrap_or(&"");
@@ -109,17 +110,15 @@ fn complete_rec(
109110
}
110111

111112
// Don't show longer completions if we have a single exact match (#13204, #14794)
112-
if !multiple_exact_matches {
113-
if let Some(built) = exact_match {
114-
return complete_rec(
115-
&partial[1..],
116-
&[built],
117-
options,
118-
want_directory,
119-
isdir,
120-
true,
121-
);
122-
}
113+
if !multiple_exact_matches && let Some(built) = exact_match {
114+
return complete_rec(
115+
&partial[1..],
116+
&[built],
117+
options,
118+
want_directory,
119+
isdir,
120+
true,
121+
);
123122
}
124123

125124
if has_more {

crates/nu-cli/src/completions/completion_options.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,8 @@ impl<T> NuMatcher<'_, T> {
129129
Cow::Owned(haystack.to_folded_case())
130130
};
131131
let matches = haystack_folded.starts_with(self.needle.as_str());
132-
if matches {
133-
if let Some(item) = item {
134-
items.push((haystack.to_string(), item));
135-
}
132+
if matches && let Some(item) = item {
133+
items.push((haystack.to_string(), item));
136134
}
137135
matches
138136
}
@@ -143,10 +141,8 @@ impl<T> NuMatcher<'_, T> {
143141
Cow::Owned(haystack.to_folded_case())
144142
};
145143
let matches = haystack_folded.contains(self.needle.as_str());
146-
if matches {
147-
if let Some(item) = item {
148-
items.push((haystack.to_string(), item));
149-
}
144+
if matches && let Some(item) = item {
145+
items.push((haystack.to_string(), item));
150146
}
151147
matches
152148
}

crates/nu-cli/src/completions/custom_completions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ impl<T: Completer> Completer for CustomCompletion<T> {
116116
.and_then(|option| option.try_into().ok())
117117
{
118118
completion_options.match_algorithm = algorithm;
119-
if let Some(false) = positional {
120-
if completion_options.match_algorithm == MatchAlgorithm::Prefix {
121-
completion_options.match_algorithm = MatchAlgorithm::Substring
122-
}
119+
if let Some(false) = positional
120+
&& completion_options.match_algorithm == MatchAlgorithm::Prefix
121+
{
122+
completion_options.match_algorithm = MatchAlgorithm::Substring
123123
}
124124
}
125125
}

crates/nu-cli/src/completions/directory_completions.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ impl Completer for DirectoryCompletion {
5858
for item in items.into_iter() {
5959
let item_path = Path::new(&item.suggestion.value);
6060

61-
if let Some(value) = item_path.file_name() {
62-
if let Some(value) = value.to_str() {
63-
if value.starts_with('.') {
64-
hidden.push(item);
65-
} else {
66-
non_hidden.push(item);
67-
}
61+
if let Some(value) = item_path.file_name()
62+
&& let Some(value) = value.to_str()
63+
{
64+
if value.starts_with('.') {
65+
hidden.push(item);
66+
} else {
67+
non_hidden.push(item);
6868
}
6969
}
7070
}

crates/nu-cli/src/completions/file_completions.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ impl Completer for FileCompletion {
6767
for item in items.into_iter() {
6868
let item_path = Path::new(&item.suggestion.value);
6969

70-
if let Some(value) = item_path.file_name() {
71-
if let Some(value) = value.to_str() {
72-
if value.starts_with('.') {
73-
hidden.push(item);
74-
} else {
75-
non_hidden.push(item);
76-
}
70+
if let Some(value) = item_path.file_name()
71+
&& let Some(value) = value.to_str()
72+
{
73+
if value.starts_with('.') {
74+
hidden.push(item);
75+
} else {
76+
non_hidden.push(item);
7777
}
7878
}
7979
}

crates/nu-cli/src/menus/menu_completions.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ impl Completer for NuMenuCompleter {
4141

4242
let block = self.engine_state.get_block(self.block_id);
4343

44-
if let Some(buffer) = block.signature.get_positional(0) {
45-
if let Some(buffer_id) = &buffer.var_id {
46-
let line_buffer = Value::string(parsed.remainder, self.span);
47-
self.stack.add_var(*buffer_id, line_buffer);
48-
}
44+
if let Some(buffer) = block.signature.get_positional(0)
45+
&& let Some(buffer_id) = &buffer.var_id
46+
{
47+
let line_buffer = Value::string(parsed.remainder, self.span);
48+
self.stack.add_var(*buffer_id, line_buffer);
4949
}
5050

51-
if let Some(position) = block.signature.get_positional(1) {
52-
if let Some(position_id) = &position.var_id {
53-
let line_buffer = Value::int(pos as i64, self.span);
54-
self.stack.add_var(*position_id, line_buffer);
55-
}
51+
if let Some(position) = block.signature.get_positional(1)
52+
&& let Some(position_id) = &position.var_id
53+
{
54+
let line_buffer = Value::int(pos as i64, self.span);
55+
self.stack.add_var(*position_id, line_buffer);
5656
}
5757

5858
let input = Value::nothing(self.span).into_pipeline_data();

crates/nu-cli/src/print.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ Since this command has no output, there is no point in piping it with other comm
8080
}
8181
}
8282
} else if !input.is_nothing() {
83-
if let PipelineData::ByteStream(stream, _) = &mut input {
84-
if let ByteStreamSource::Child(child) = stream.source_mut() {
85-
child.ignore_error(true);
86-
}
83+
if let PipelineData::ByteStream(stream, _) = &mut input
84+
&& let ByteStreamSource::Child(child) = stream.source_mut()
85+
{
86+
child.ignore_error(true);
8787
}
8888
if raw {
8989
input.print_raw(engine_state, no_newline, to_stderr)?;

0 commit comments

Comments
 (0)