Rework for new clippy lints (#12736)

- **Clippy lint `assigning_clones`**
- **Clippy lint `legacy_numeric_constants`**
- **`clippy::float_equality_without_abs`**
- **`nu-table`: clippy::zero_repeat_side_effects**

---------

Co-authored-by: Ian Manske <ian.manske@pm.me>
This commit is contained in:
Stefan Holderbach
2024-05-02 19:29:03 +02:00
committed by GitHub
parent 0805f1fd90
commit b88d8726d0
8 changed files with 31 additions and 57 deletions

View File

@ -55,7 +55,7 @@ pub fn lev_distance(a: &str, b: &str, limit: usize) -> Option<usize> {
/// Finds the Levenshtein distance between two strings.
pub fn levenshtein_distance(a: &str, b: &str) -> usize {
lev_distance(a, b, usize::max_value()).unwrap_or(usize::max_value())
lev_distance(a, b, usize::MAX).unwrap_or(usize::MAX)
}
/// Provides a word similarity score between two words that accounts for substrings being more
/// meaningful than a typical Levenshtein distance. The lower the score, the closer the match.

View File

@ -66,7 +66,7 @@ impl PluginRegistryFile {
error_span: Option<Span>,
) -> Result<(), ShellError> {
// Update the Nushell version before writing
self.nushell_version = env!("CARGO_PKG_VERSION").to_owned();
env!("CARGO_PKG_VERSION").clone_into(&mut self.nushell_version);
// Format is brotli compressed messagepack
let mut brotli_writer =

View File

@ -2893,7 +2893,7 @@ impl Value {
if *rhs != 0 {
Ok(Value::int(
(*lhs as f64 / *rhs as f64)
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
.clamp(i64::MIN as f64, i64::MAX as f64)
.floor() as i64,
span,
))
@ -2905,7 +2905,7 @@ impl Value {
if *rhs != 0.0 {
Ok(Value::int(
(*lhs as f64 / *rhs)
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
.clamp(i64::MIN as f64, i64::MAX as f64)
.floor() as i64,
span,
))
@ -2917,7 +2917,7 @@ impl Value {
if *rhs != 0 {
Ok(Value::int(
(*lhs / *rhs as f64)
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
.clamp(i64::MIN as f64, i64::MAX as f64)
.floor() as i64,
span,
))
@ -2928,9 +2928,7 @@ impl Value {
(Value::Float { val: lhs, .. }, Value::Float { val: rhs, .. }) => {
if *rhs != 0.0 {
Ok(Value::int(
(lhs / rhs)
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
.floor() as i64,
(lhs / rhs).clamp(i64::MIN as f64, i64::MAX as f64).floor() as i64,
span,
))
} else {
@ -2941,7 +2939,7 @@ impl Value {
if *rhs != 0 {
Ok(Value::int(
(*lhs as f64 / *rhs as f64)
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
.clamp(i64::MIN as f64, i64::MAX as f64)
.floor() as i64,
span,
))
@ -2953,7 +2951,7 @@ impl Value {
if *rhs != 0 {
Ok(Value::filesize(
((*lhs as f64) / (*rhs as f64))
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
.clamp(i64::MIN as f64, i64::MAX as f64)
.floor() as i64,
span,
))
@ -2965,7 +2963,7 @@ impl Value {
if *rhs != 0.0 {
Ok(Value::filesize(
(*lhs as f64 / *rhs)
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
.clamp(i64::MIN as f64, i64::MAX as f64)
.floor() as i64,
span,
))
@ -2977,7 +2975,7 @@ impl Value {
if *rhs != 0 {
Ok(Value::int(
(*lhs as f64 / *rhs as f64)
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
.clamp(i64::MIN as f64, i64::MAX as f64)
.floor() as i64,
span,
))
@ -2989,7 +2987,7 @@ impl Value {
if *rhs != 0 {
Ok(Value::duration(
(*lhs as f64 / *rhs as f64)
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
.clamp(i64::MIN as f64, i64::MAX as f64)
.floor() as i64,
span,
))
@ -3001,7 +2999,7 @@ impl Value {
if *rhs != 0.0 {
Ok(Value::duration(
(*lhs as f64 / *rhs)
.clamp(std::i64::MIN as f64, std::i64::MAX as f64)
.clamp(i64::MIN as f64, i64::MAX as f64)
.floor() as i64,
span,
))