diff --git a/.azure/azure-pipelines.yml b/.azure/azure-pipelines.yml index 8b23a385e8..b490d597a1 100644 --- a/.azure/azure-pipelines.yml +++ b/.azure/azure-pipelines.yml @@ -37,6 +37,8 @@ steps: fi if [ "$(uname)" == "Darwin" ]; then curl https://sh.rustup.rs -sSf | sh -s -- -y --no-modify-path --default-toolchain "stable" + echo "Installing clippy" + rustup component add clippy --toolchain stable-x86_64-apple-darwin export PATH=$HOME/.cargo/bin:$PATH fi rustup update diff --git a/Cargo.lock b/Cargo.lock index 72843a5a9d..921d2f55e0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3175,9 +3175,9 @@ dependencies = [ [[package]] name = "rustyline" -version = "6.1.1" +version = "6.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a7384a84da856bd163ef2c22982c816b0bcedaf17978ec13d8e0e277ddc332" +checksum = "1cd20b28d972040c627e209eb29f19c24a71a19d661cc5a220089176e20ee202" dependencies = [ "cfg-if", "dirs 2.0.2", @@ -3185,6 +3185,7 @@ dependencies = [ "log", "memchr", "nix 0.17.0", + "scopeguard", "unicode-segmentation", "unicode-width", "utf8parse 0.2.0", diff --git a/crates/nu-cli/Cargo.toml b/crates/nu-cli/Cargo.toml index 9819d80dae..42a85a3086 100644 --- a/crates/nu-cli/Cargo.toml +++ b/crates/nu-cli/Cargo.toml @@ -64,7 +64,7 @@ query_interface = "0.3.5" rand = "0.7" regex = "1" roxmltree = "0.10.1" -rustyline = "6.1.1" +rustyline = "6.1.2" serde = { version = "1.0.106", features = ["derive"] } serde-hjson = "0.9.1" serde_bytes = "0.11.3" diff --git a/crates/nu-cli/src/data/value.rs b/crates/nu-cli/src/data/value.rs index 2001e84433..a0c0d0bec8 100644 --- a/crates/nu-cli/src/data/value.rs +++ b/crates/nu-cli/src/data/value.rs @@ -110,30 +110,24 @@ pub fn compare_values( left: &UntaggedValue, right: &UntaggedValue, ) -> Result { - match operator { - _ => { - let coerced = coerce_compare(left, right)?; - let ordering = coerced.compare(); + let coerced = coerce_compare(left, right)?; + let ordering = coerced.compare(); - use std::cmp::Ordering; + use std::cmp::Ordering; - let result = match (operator, ordering) { - (Operator::Equal, Ordering::Equal) => true, - (Operator::NotEqual, Ordering::Less) | (Operator::NotEqual, Ordering::Greater) => { - true - } - (Operator::LessThan, Ordering::Less) => true, - (Operator::GreaterThan, Ordering::Greater) => true, - (Operator::GreaterThanOrEqual, Ordering::Greater) - | (Operator::GreaterThanOrEqual, Ordering::Equal) => true, - (Operator::LessThanOrEqual, Ordering::Less) - | (Operator::LessThanOrEqual, Ordering::Equal) => true, - _ => false, - }; + let result = match (operator, ordering) { + (Operator::Equal, Ordering::Equal) => true, + (Operator::NotEqual, Ordering::Less) | (Operator::NotEqual, Ordering::Greater) => true, + (Operator::LessThan, Ordering::Less) => true, + (Operator::GreaterThan, Ordering::Greater) => true, + (Operator::GreaterThanOrEqual, Ordering::Greater) + | (Operator::GreaterThanOrEqual, Ordering::Equal) => true, + (Operator::LessThanOrEqual, Ordering::Less) + | (Operator::LessThanOrEqual, Ordering::Equal) => true, + _ => false, + }; - Ok(result) - } - } + Ok(result) } pub fn format_type<'a>(value: impl Into<&'a UntaggedValue>, width: usize) -> String { diff --git a/crates/nu-cli/src/shell/help_shell.rs b/crates/nu-cli/src/shell/help_shell.rs index f6e4a69e8a..fc32adc39f 100644 --- a/crates/nu-cli/src/shell/help_shell.rs +++ b/crates/nu-cli/src/shell/help_shell.rs @@ -204,12 +204,9 @@ impl Shell for HelpShell { let mut possible_completion = vec![]; let commands = self.commands(); for cmd in commands { - match cmd { - Value { value, .. } => { - for desc in value.data_descriptors() { - possible_completion.push(desc); - } - } + let Value { value, .. } = cmd; + for desc in value.data_descriptors() { + possible_completion.push(desc); } } diff --git a/crates/nu-cli/src/shell/value_shell.rs b/crates/nu-cli/src/shell/value_shell.rs index 3927df8bfa..42af8bc08b 100644 --- a/crates/nu-cli/src/shell/value_shell.rs +++ b/crates/nu-cli/src/shell/value_shell.rs @@ -238,12 +238,9 @@ impl Shell for ValueShell { let mut possible_completion = vec![]; let members = self.members(); for member in members { - match member { - Value { value, .. } => { - for desc in value.data_descriptors() { - possible_completion.push(desc); - } - } + let Value { value, .. } = member; + for desc in value.data_descriptors() { + possible_completion.push(desc); } } diff --git a/crates/nu-protocol/src/hir.rs b/crates/nu-protocol/src/hir.rs index 551e5c1b49..435e5b55c4 100644 --- a/crates/nu-protocol/src/hir.rs +++ b/crates/nu-protocol/src/hir.rs @@ -152,15 +152,16 @@ impl ExternalCommand { SpannedExpression { expr: Expression::Path(path), .. - } => match &**path { - Path { head, .. } => match head { + } => { + let Path { head, .. } = &**path; + match head { SpannedExpression { expr: Expression::Variable(Variable::It(_)), .. } => true, _ => false, - }, - }, + } + } _ => false, }) } diff --git a/crates/nu_plugin_fetch/src/fetch.rs b/crates/nu_plugin_fetch/src/fetch.rs index 51d0ac4652..20216cace1 100644 --- a/crates/nu_plugin_fetch/src/fetch.rs +++ b/crates/nu_plugin_fetch/src/fetch.rs @@ -21,17 +21,16 @@ impl Fetch { } pub fn setup(&mut self, call_info: CallInfo) -> ReturnValue { - self.path = Some( - match call_info.args.nth(0).ok_or_else(|| { + self.path = Some({ + let file = call_info.args.nth(0).ok_or_else(|| { ShellError::labeled_error( "No file or directory specified", "for command", &call_info.name_tag, ) - })? { - file => file.clone(), - }, - ); + })?; + file.clone() + }); self.has_raw = call_info.args.has("raw"); diff --git a/crates/nu_plugin_post/src/post.rs b/crates/nu_plugin_post/src/post.rs index 46c60a856d..178eaef16a 100644 --- a/crates/nu_plugin_post/src/post.rs +++ b/crates/nu_plugin_post/src/post.rs @@ -42,24 +42,24 @@ impl Post { } pub fn setup(&mut self, call_info: CallInfo) -> ReturnValue { - self.path = Some( - match call_info.args.nth(0).ok_or_else(|| { + self.path = Some({ + let file = call_info.args.nth(0).ok_or_else(|| { ShellError::labeled_error( "No file or directory specified", "for command", &call_info.name_tag, ) - })? { - file => file.clone(), - }, - ); + })?; + file.clone() + }); self.has_raw = call_info.args.has("raw"); - self.body = match call_info.args.nth(1).ok_or_else(|| { - ShellError::labeled_error("No body specified", "for command", &call_info.name_tag) - })? { - file => Some(file.clone()), + self.body = { + let file = call_info.args.nth(1).ok_or_else(|| { + ShellError::labeled_error("No body specified", "for command", &call_info.name_tag) + })?; + Some(file.clone()) }; self.user = match call_info.args.get("user") { diff --git a/crates/nu_plugin_str/src/strutils.rs b/crates/nu_plugin_str/src/strutils.rs index cf095ef1e2..e4b4437f8d 100644 --- a/crates/nu_plugin_str/src/strutils.rs +++ b/crates/nu_plugin_str/src/strutils.rs @@ -68,12 +68,13 @@ impl Str { } } }, - Some(Action::ToInteger) => match input.trim() { - other => match other.parse::() { + Some(Action::ToInteger) => { + let other = input.trim(); + match other.parse::() { Ok(v) => UntaggedValue::int(v), Err(_) => UntaggedValue::string(input), - }, - }, + } + } Some(Action::ToDateTime(dt)) => match DateTime::parse_from_str(input, dt) { Ok(d) => UntaggedValue::date(d), Err(_) => UntaggedValue::string(input),