From 13e409bcfbc57a062e738fb3fbddb7f4cda9fa10 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Fri, 29 Nov 2024 14:54:11 +0300 Subject: [PATCH 1/2] refactor: Apply clippy fixes with more idiomatic code patterns --- fluent-bundle/examples/functions.rs | 4 ++-- fluent-bundle/src/types/number.rs | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/fluent-bundle/examples/functions.rs b/fluent-bundle/examples/functions.rs index cfa4f46b..092af530 100644 --- a/fluent-bundle/examples/functions.rs +++ b/fluent-bundle/examples/functions.rs @@ -35,12 +35,12 @@ fn main() { // Test for a function that accepts named arguments bundle .add_function("BASE_OWNERSHIP", |_args, named_args| { - return match named_args.get("ownership") { + match named_args.get("ownership") { Some(FluentValue::String(ref string)) => { format!("All your base belong to {}", string).into() } _ => FluentValue::Error, - }; + } }) .expect("Failed to add a function to the bundle."); diff --git a/fluent-bundle/src/types/number.rs b/fluent-bundle/src/types/number.rs index b9c3b2de..0e80dccd 100644 --- a/fluent-bundle/src/types/number.rs +++ b/fluent-bundle/src/types/number.rs @@ -150,11 +150,7 @@ impl FluentNumber { if let Some(minfd) = self.options.minimum_fraction_digits { if let Some(pos) = val.find('.') { let frac_num = val.len() - pos - 1; - let missing = if frac_num > minfd { - 0 - } else { - minfd - frac_num - }; + let missing = minfd.saturating_sub(frac_num); val = format!("{}{}", val, "0".repeat(missing)); } else { val = format!("{}.{}", val, "0".repeat(minfd)); From 4709056985d8df2edc38fa70835cfa32815d2b12 Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Fri, 29 Nov 2024 14:51:16 +0300 Subject: [PATCH 2/2] refactor: Apply clippy fixes for needless_lifetimes lint https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes --- fluent-bundle/examples/custom_type.rs | 4 ++-- fluent-bundle/src/types/mod.rs | 6 +++--- fluent-bundle/src/types/number.rs | 2 +- fluent-bundle/tests/custom_types.rs | 4 ++-- fluent-syntax/src/parser/slice.rs | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fluent-bundle/examples/custom_type.rs b/fluent-bundle/examples/custom_type.rs index a6093732..97bc1f57 100644 --- a/fluent-bundle/examples/custom_type.rs +++ b/fluent-bundle/examples/custom_type.rs @@ -33,7 +33,7 @@ enum DateTimeStyleValue { // This is just a helper to make it easier to convert // a value provided to FluentArgs into an option value. -impl<'l> From<&FluentValue<'l>> for DateTimeStyleValue { +impl From<&FluentValue<'_>> for DateTimeStyleValue { fn from(input: &FluentValue) -> Self { if let FluentValue::String(s) = input { match s.as_ref() { @@ -73,7 +73,7 @@ impl DateTimeOptions { } } -impl<'l> From<&FluentArgs<'l>> for DateTimeOptions { +impl From<&FluentArgs<'_>> for DateTimeOptions { fn from(input: &FluentArgs) -> Self { let mut opts = Self::default(); opts.merge(input); diff --git a/fluent-bundle/src/types/mod.rs b/fluent-bundle/src/types/mod.rs index 585e90b6..418f18db 100644 --- a/fluent-bundle/src/types/mod.rs +++ b/fluent-bundle/src/types/mod.rs @@ -84,7 +84,7 @@ pub enum FluentValue<'source> { Error, } -impl<'s> PartialEq for FluentValue<'s> { +impl PartialEq for FluentValue<'_> { fn eq(&self, other: &Self) -> bool { match (self, other) { (FluentValue::String(s), FluentValue::String(s2)) => s == s2, @@ -95,7 +95,7 @@ impl<'s> PartialEq for FluentValue<'s> { } } -impl<'s> Clone for FluentValue<'s> { +impl Clone for FluentValue<'_> { fn clone(&self) -> Self { match self { FluentValue::String(s) => FluentValue::String(s.clone()), @@ -291,7 +291,7 @@ impl<'source> FluentValue<'source> { } } -impl<'source> From for FluentValue<'source> { +impl From for FluentValue<'_> { fn from(s: String) -> Self { FluentValue::String(s.into()) } diff --git a/fluent-bundle/src/types/number.rs b/fluent-bundle/src/types/number.rs index 0e80dccd..8cdeb26e 100644 --- a/fluent-bundle/src/types/number.rs +++ b/fluent-bundle/src/types/number.rs @@ -175,7 +175,7 @@ impl FromStr for FluentNumber { } } -impl<'l> From for FluentValue<'l> { +impl From for FluentValue<'_> { fn from(input: FluentNumber) -> Self { FluentValue::Number(input) } diff --git a/fluent-bundle/tests/custom_types.rs b/fluent-bundle/tests/custom_types.rs index 082f864a..5b5b66f7 100644 --- a/fluent-bundle/tests/custom_types.rs +++ b/fluent-bundle/tests/custom_types.rs @@ -57,7 +57,7 @@ fn fluent_date_time_builtin() { None, } - impl<'l> From<&FluentValue<'l>> for DateTimeStyleValue { + impl From<&FluentValue<'_>> for DateTimeStyleValue { fn from(input: &FluentValue) -> Self { if let FluentValue::String(s) = input { match s.as_ref() { @@ -91,7 +91,7 @@ fn fluent_date_time_builtin() { } } - impl<'l> From<&FluentArgs<'l>> for DateTimeOptions { + impl From<&FluentArgs<'_>> for DateTimeOptions { fn from(input: &FluentArgs) -> Self { let mut opts = Self::default(); opts.merge(input); diff --git a/fluent-syntax/src/parser/slice.rs b/fluent-syntax/src/parser/slice.rs index 4c640aa8..a04409ef 100644 --- a/fluent-syntax/src/parser/slice.rs +++ b/fluent-syntax/src/parser/slice.rs @@ -9,7 +9,7 @@ pub trait Slice<'s>: AsRef + Clone + PartialEq { fn trim(&mut self); } -impl<'s> Slice<'s> for String { +impl Slice<'_> for String { fn slice(&self, range: Range) -> Self { self[range].to_string() }