Fix clippy warnings (upcoming) (#9282)

# Description

Fixes the clippy warnings we're about to get hit with next time we
upgrade Rust.

The big one was shrinking ShellError and related under 128 bytes.

# User-Facing Changes

Shouldn't notice much difference. In theory, we could see a tiny perf
improvement, but I didn't notice one.

# Tests + Formatting
<!--
Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect -A clippy::result_large_err` to check that
you're using the standard code style
- `cargo test --workspace` to check that all tests pass
- `cargo run -- crates/nu-std/tests/run.nu` to run the tests for the
standard library

> **Note**
> from `nushell` you can also use the `toolkit` as follows
> ```bash
> use toolkit.nu # or use an `env_change` hook to activate it
automatically
> toolkit check pr
> ```
-->

# After Submitting
<!-- If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
-->
This commit is contained in:
JT
2023-05-25 10:58:18 +12:00
committed by GitHub
parent 7ead89844a
commit fa113172da
11 changed files with 124 additions and 137 deletions

View File

@ -2243,7 +2243,7 @@ mod engine_state_tests {
let variables = working_set
.list_variables()
.into_iter()
.map(|v| from_utf8(v))
.map(from_utf8)
.collect::<Result<Vec<&str>, Utf8Error>>()?;
assert_eq!(variables, vec![varname_with_sigil]);
Ok(())

View File

@ -2,7 +2,7 @@ use miette::Diagnostic;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use crate::{ast::Operator, Span, Type, Value};
use crate::{ast::Operator, Span, Value};
/// The fundamental error type for the evaluation engine. These cases represent different kinds of errors
/// the evaluator might face, along with helpful spans to label. An error renderer will take this error value
@ -19,10 +19,10 @@ pub enum ShellError {
OperatorMismatch {
#[label = "type mismatch for operator"]
op_span: Span,
lhs_ty: Type,
lhs_ty: String,
#[label("{lhs_ty}")]
lhs_span: Span,
rhs_ty: Type,
rhs_ty: String,
#[label("{rhs_ty}")]
rhs_span: Span,
},
@ -391,20 +391,13 @@ pub enum ShellError {
help: Option<String>,
},
/// Failed to convert a value of one type into a different type. Includes hint for what the first value is.
///
/// ## Resolution
///
/// Not all values can be coerced this way. Check the supported type(s) and try again.
#[error("Can't convert {from_type} `{details}` to {to_type}.")]
#[error("Can't convert string `{details}` to duration.")]
#[diagnostic(code(nu::shell::cant_convert_with_value))]
CantConvertWithValue {
to_type: String,
from_type: String,
CantConvertToDuration {
details: String,
#[label("can't be converted to {to_type}")]
#[label("can't be converted to duration")]
dst_span: Span,
#[label("this {from_type} value...")]
#[label("this string value...")]
src_span: Span,
#[help]
help: Option<String>,

View File

@ -2174,9 +2174,9 @@ impl Value {
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -2211,9 +2211,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -2292,9 +2292,9 @@ impl Value {
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -2402,9 +2402,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -2539,9 +2539,9 @@ impl Value {
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -2675,9 +2675,9 @@ impl Value {
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -2698,9 +2698,9 @@ impl Value {
{
return Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
});
}
@ -2713,9 +2713,9 @@ impl Value {
} else {
Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
})
}
@ -2741,9 +2741,9 @@ impl Value {
{
return Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
});
}
@ -2755,9 +2755,9 @@ impl Value {
})
.ok_or(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
})
}
@ -2782,9 +2782,9 @@ impl Value {
{
return Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
});
}
@ -2796,9 +2796,9 @@ impl Value {
})
.ok_or(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
})
}
@ -2823,9 +2823,9 @@ impl Value {
{
return Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
});
}
@ -2837,9 +2837,9 @@ impl Value {
}),
None => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -2862,9 +2862,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -2888,9 +2888,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -2946,9 +2946,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -3003,9 +3003,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -3079,9 +3079,9 @@ impl Value {
),
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -3098,9 +3098,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -3117,9 +3117,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -3136,9 +3136,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -3155,9 +3155,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -3174,9 +3174,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -3193,9 +3193,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -3212,9 +3212,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -3268,9 +3268,9 @@ impl Value {
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -3287,9 +3287,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -3306,9 +3306,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -3325,9 +3325,9 @@ impl Value {
}
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}
@ -3360,9 +3360,9 @@ impl Value {
_ => Err(ShellError::OperatorMismatch {
op_span: op,
lhs_ty: self.get_type(),
lhs_ty: self.get_type().to_string(),
lhs_span: self.span()?,
rhs_ty: rhs.get_type(),
rhs_ty: rhs.get_type().to_string(),
rhs_span: rhs.span()?,
}),
}