diff --git a/fluent-bundle/benches/resolver.rs b/fluent-bundle/benches/resolver.rs index b27c365e..a024da05 100644 --- a/fluent-bundle/benches/resolver.rs +++ b/fluent-bundle/benches/resolver.rs @@ -58,13 +58,10 @@ fn get_args(name: &str) -> Option { } fn add_functions(name: &'static str, bundle: &mut FluentBundle) { - match name { - "preferences" => { - bundle - .add_function("PLATFORM", |_args, _named_args| "linux".into()) - .expect("Failed to add a function to the bundle."); - } - _ => {} + if name == "preferences" { + bundle + .add_function("PLATFORM", |_args, _named_args| "linux".into()) + .expect("Failed to add a function to the bundle."); } } @@ -106,7 +103,7 @@ fn resolver_bench(c: &mut Criterion) { .add_resource(res.clone()) .expect("Couldn't add FluentResource to the FluentBundle"); add_functions(name, &mut bundle); - }) + }); }); } group.finish(); @@ -133,7 +130,7 @@ fn resolver_bench(c: &mut Criterion) { } assert!(errors.is_empty(), "Resolver errors: {:#?}", errors); } - }) + }); }); } group.finish(); @@ -156,7 +153,7 @@ fn resolver_bench(c: &mut Criterion) { } assert!(errors.is_empty(), "Resolver errors: {:#?}", errors); } - }) + }); }); } group.finish(); diff --git a/fluent-bundle/benches/resolver_iai.rs b/fluent-bundle/benches/resolver_iai.rs index dd7892c5..05df9bee 100644 --- a/fluent-bundle/benches/resolver_iai.rs +++ b/fluent-bundle/benches/resolver_iai.rs @@ -5,13 +5,10 @@ use unic_langid::{langid, LanguageIdentifier}; const LANG_EN: LanguageIdentifier = langid!("en"); fn add_functions(name: &'static str, bundle: &mut FluentBundle) { - match name { - "preferences" => { - bundle - .add_function("PLATFORM", |_args, _named_args| "linux".into()) - .expect("Failed to add a function to the bundle."); - } - _ => {} + if name == "preferences" { + bundle + .add_function("PLATFORM", |_args, _named_args| "linux".into()) + .expect("Failed to add a function to the bundle."); } } diff --git a/fluent-bundle/examples/custom_formatter.rs b/fluent-bundle/examples/custom_formatter.rs index b3ef36b1..8fc59f1f 100644 --- a/fluent-bundle/examples/custom_formatter.rs +++ b/fluent-bundle/examples/custom_formatter.rs @@ -36,7 +36,7 @@ key-var-with-arg = Here is a variable formatted with an argument { NUMBER($num, .expect("Failed to add FTL resources to the bundle."); bundle .add_function("NUMBER", |positional, named| { - match positional.get(0) { + match positional.first() { Some(FluentValue::Number(n)) => { let mut num = n.clone(); // This allows us to merge the arguments provided diff --git a/fluent-bundle/examples/custom_type.rs b/fluent-bundle/examples/custom_type.rs index 8feeed11..f3e3c3dc 100644 --- a/fluent-bundle/examples/custom_type.rs +++ b/fluent-bundle/examples/custom_type.rs @@ -165,7 +165,7 @@ key-date = Today is { DATETIME($epoch, dateStyle: "long", timeStyle: "short") } .expect("Failed to add FTL resources to the bundle."); bundle - .add_function("DATETIME", |positional, named| match positional.get(0) { + .add_function("DATETIME", |positional, named| match positional.first() { Some(FluentValue::Number(n)) => { let epoch = n.value as usize; let options = named.into(); diff --git a/fluent-bundle/examples/functions.rs b/fluent-bundle/examples/functions.rs index 4e1c5892..cfa4f46b 100644 --- a/fluent-bundle/examples/functions.rs +++ b/fluent-bundle/examples/functions.rs @@ -22,7 +22,7 @@ fn main() { // Test for a function that accepts unnamed positional arguments bundle .add_function("MEANING_OF_LIFE", |args, _named_args| { - if let Some(arg0) = args.get(0) { + if let Some(arg0) = args.first() { if *arg0 == 42.into() { return "The answer to life, the universe, and everything".into(); } diff --git a/fluent-bundle/examples/simple-app.rs b/fluent-bundle/examples/simple-app.rs index 7ea3917d..8844832c 100644 --- a/fluent-bundle/examples/simple-app.rs +++ b/fluent-bundle/examples/simple-app.rs @@ -56,15 +56,13 @@ fn get_available_locales() -> Result, io::Error> { dir.push("examples"); dir.push("resources"); let res_dir = fs::read_dir(dir)?; - for entry in res_dir { - if let Ok(entry) = entry { - let path = entry.path(); - if path.is_dir() { - if let Some(name) = path.file_name() { - if let Some(name) = name.to_str() { - let langid = name.parse().expect("Parsing failed."); - locales.push(langid); - } + for entry in res_dir.flatten() { + let path = entry.path(); + if path.is_dir() { + if let Some(name) = path.file_name() { + if let Some(name) = name.to_str() { + let langid = name.parse().expect("Parsing failed."); + locales.push(langid); } } } @@ -97,7 +95,7 @@ fn main() { NegotiationStrategy::Filtering, ); let current_locale = resolved_locales - .get(0) + .first() .cloned() .expect("At least one locale should match."); diff --git a/fluent-bundle/src/bundle.rs b/fluent-bundle/src/bundle.rs index 75ec6a9f..1e2a8bd7 100644 --- a/fluent-bundle/src/bundle.rs +++ b/fluent-bundle/src/bundle.rs @@ -482,10 +482,10 @@ impl FluentBundle { /// /// assert_eq!(result, "Hello World!"); /// ``` - pub fn format_pattern<'bundle, 'args>( + pub fn format_pattern<'bundle>( &'bundle self, pattern: &'bundle ast::Pattern<&'bundle str>, - args: Option<&'args FluentArgs>, + args: Option<&FluentArgs>, errors: &mut Vec, ) -> Cow<'bundle, str> where @@ -577,7 +577,7 @@ impl FluentBundle { /// /// This will panic if no formatters can be found for the locales. pub fn new(locales: Vec) -> Self { - let first_locale = locales.get(0).cloned().unwrap_or_default(); + let first_locale = locales.first().cloned().unwrap_or_default(); Self { locales, resources: vec![], diff --git a/fluent-bundle/src/concurrent.rs b/fluent-bundle/src/concurrent.rs index 76e0de44..de55f0a3 100644 --- a/fluent-bundle/src/concurrent.rs +++ b/fluent-bundle/src/concurrent.rs @@ -30,7 +30,7 @@ impl FluentBundle { /// FluentBundle::new_concurrent(vec![langid_en]); /// ``` pub fn new_concurrent(locales: Vec) -> Self { - let first_locale = locales.get(0).cloned().unwrap_or_default(); + let first_locale = locales.first().cloned().unwrap_or_default(); Self { locales, resources: vec![], diff --git a/fluent-bundle/src/types/mod.rs b/fluent-bundle/src/types/mod.rs index eb6c8eeb..a789f385 100644 --- a/fluent-bundle/src/types/mod.rs +++ b/fluent-bundle/src/types/mod.rs @@ -185,9 +185,9 @@ impl<'source> FluentValue<'source> { M: MemoizerKind, { match (self, other) { - (&FluentValue::String(ref a), &FluentValue::String(ref b)) => a == b, - (&FluentValue::Number(ref a), &FluentValue::Number(ref b)) => a == b, - (&FluentValue::String(ref a), &FluentValue::Number(ref b)) => { + (FluentValue::String(a), FluentValue::String(b)) => a == b, + (FluentValue::Number(a), FluentValue::Number(b)) => a == b, + (FluentValue::String(a), FluentValue::Number(b)) => { let cat = match a.as_ref() { "zero" => PluralCategory::ZERO, "one" => PluralCategory::ONE, diff --git a/fluent-bundle/tests/bundle.rs b/fluent-bundle/tests/bundle.rs index c23866ea..7d3e6206 100644 --- a/fluent-bundle/tests/bundle.rs +++ b/fluent-bundle/tests/bundle.rs @@ -55,14 +55,8 @@ fn borrowed_plain_message() { bundle.format_pattern(value, None, &mut errors) }; - fn is_borrowed(cow: Cow<'_, str>) -> bool { - match cow { - Cow::Borrowed(_) => true, - _ => false, - } - } assert_eq!(formatted_pattern, "Value"); - assert!(is_borrowed(formatted_pattern)); + assert!(matches!(formatted_pattern, Cow::Borrowed(_))); } #[test] diff --git a/fluent-bundle/tests/custom_types.rs b/fluent-bundle/tests/custom_types.rs index be534700..8c6f9169 100644 --- a/fluent-bundle/tests/custom_types.rs +++ b/fluent-bundle/tests/custom_types.rs @@ -40,9 +40,9 @@ fn fluent_custom_type() { let sv = FluentValue::from("foo"); - assert_eq!(dt == dt2, true); - assert_eq!(dt == dt3, false); - assert_eq!(dt == sv, false); + assert!(dt == dt2); + assert!(dt != dt3); + assert!(dt != sv); } #[test] @@ -146,7 +146,7 @@ key-ref = Hello { DATETIME($date, dateStyle: "full") } World bundle.set_use_isolating(false); bundle - .add_function("DATETIME", |positional, named| match positional.get(0) { + .add_function("DATETIME", |positional, named| match positional.first() { Some(FluentValue::Custom(custom)) => { if let Some(that) = custom.as_ref().as_any().downcast_ref::() { let mut dt = that.clone(); @@ -202,7 +202,7 @@ key-num-explicit = Hello { NUMBER(5, minimumFractionDigits: 2) } World bundle.set_use_isolating(false); bundle - .add_function("NUMBER", |positional, named| match positional.get(0) { + .add_function("NUMBER", |positional, named| match positional.first() { Some(FluentValue::Number(n)) => { let mut num = n.clone(); num.options.merge(named); diff --git a/fluent-bundle/tests/function.rs b/fluent-bundle/tests/function.rs index 04cf3f3d..1d403e2f 100644 --- a/fluent-bundle/tests/function.rs +++ b/fluent-bundle/tests/function.rs @@ -24,7 +24,7 @@ liked-count2 = { NUMBER($num) -> let mut bundle = FluentBundle::default(); bundle - .add_function("NUMBER", |positional, named| match positional.get(0) { + .add_function("NUMBER", |positional, named| match positional.first() { Some(FluentValue::Number(n)) => { let mut num = n.clone(); num.options.merge(named); @@ -32,7 +32,7 @@ liked-count2 = { NUMBER($num) -> FluentValue::Number(num) } Some(FluentValue::String(s)) => { - let num: f64 = if let Ok(n) = s.to_owned().parse() { + let num: f64 = if let Ok(n) = s.clone().parse() { n } else { return FluentValue::Error; diff --git a/fluent-bundle/tests/resolver_fixtures.rs b/fluent-bundle/tests/resolver_fixtures.rs index 81e0e6eb..e242a390 100644 --- a/fluent-bundle/tests/resolver_fixtures.rs +++ b/fluent-bundle/tests/resolver_fixtures.rs @@ -155,10 +155,10 @@ fn create_bundle( .into() }), "IDENTITY" => bundle.add_function(f.as_str(), |args, _name_args| { - args.get(0).cloned().unwrap_or(FluentValue::Error) + args.first().cloned().unwrap_or(FluentValue::Error) }), "NUMBER" => bundle.add_function(f.as_str(), |args, _name_args| { - args.get(0).expect("Argument must be passed").clone() + args.first().expect("Argument must be passed").clone() }), _ => unimplemented!("No such function."), }; @@ -242,7 +242,7 @@ fn test_test(test: &Test, defaults: &Option, mut scope: Scope) { .get(bundle_name) .expect("Failed to retrieve bundle.") } else if bundles.len() == 1 { - let name = bundles.keys().into_iter().last().unwrap(); + let name = bundles.keys().last().unwrap(); bundles.get(name).expect("Failed to retrieve bundle.") } else { panic!(); diff --git a/fluent-bundle/tests/types_test.rs b/fluent-bundle/tests/types_test.rs index 57a4d6de..08d4d9be 100644 --- a/fluent-bundle/tests/types_test.rs +++ b/fluent-bundle/tests/types_test.rs @@ -31,15 +31,15 @@ fn fluent_value_matches() { let number_val_copy = FluentValue::from(-23.5); let number_val2 = FluentValue::from(23.5); - assert_eq!(string_val.matches(&string_val_copy, &scope), true); - assert_eq!(string_val.matches(&string_val2, &scope), false); + assert!(string_val.matches(&string_val_copy, &scope)); + assert!(!string_val.matches(&string_val2, &scope)); - assert_eq!(number_val.matches(&number_val_copy, &scope), true); - assert_eq!(number_val.matches(&number_val2, &scope), false); + assert!(number_val.matches(&number_val_copy, &scope)); + assert!(!number_val.matches(&number_val2, &scope)); - assert_eq!(string_val2.matches(&number_val2, &scope), false); + assert!(!string_val2.matches(&number_val2, &scope)); - assert_eq!(string_val2.matches(&number_val2, &scope), false); + assert!(!string_val2.matches(&number_val2, &scope)); let string_cat_zero = FluentValue::from("zero"); let string_cat_one = FluentValue::from("one"); @@ -55,15 +55,15 @@ fn fluent_value_matches() { let number_cat_many = 11.into(); let number_cat_other = 101.into(); - assert_eq!(string_cat_zero.matches(&number_cat_zero, &scope), true); - assert_eq!(string_cat_one.matches(&number_cat_one, &scope), true); - assert_eq!(string_cat_two.matches(&number_cat_two, &scope), true); - assert_eq!(string_cat_few.matches(&number_cat_few, &scope), true); - assert_eq!(string_cat_many.matches(&number_cat_many, &scope), true); - assert_eq!(string_cat_other.matches(&number_cat_other, &scope), true); - assert_eq!(string_cat_other.matches(&number_cat_one, &scope), false); + assert!(string_cat_zero.matches(&number_cat_zero, &scope)); + assert!(string_cat_one.matches(&number_cat_one, &scope)); + assert!(string_cat_two.matches(&number_cat_two, &scope)); + assert!(string_cat_few.matches(&number_cat_few, &scope)); + assert!(string_cat_many.matches(&number_cat_many, &scope)); + assert!(string_cat_other.matches(&number_cat_other, &scope)); + assert!(!string_cat_other.matches(&number_cat_one, &scope)); - assert_eq!(string_val2.matches(&number_cat_one, &scope), false); + assert!(!string_val2.matches(&number_cat_one, &scope)); } #[test] @@ -120,7 +120,7 @@ fn fluent_number_style() { assert_eq!(fno.style, FluentNumberStyle::Currency); assert_eq!(fno.currency, Some("EUR".to_string())); assert_eq!(fno.currency_display, FluentNumberCurrencyDisplayStyle::Code); - assert_eq!(fno.use_grouping, false); + assert!(!fno.use_grouping); let num = FluentNumber::new(0.2, FluentNumberOptions::default()); assert_eq!(num.as_string(), "0.2"); diff --git a/fluent-fallback/examples/simple-fallback.rs b/fluent-fallback/examples/simple-fallback.rs index 7585a5d0..523013b6 100644 --- a/fluent-fallback/examples/simple-fallback.rs +++ b/fluent-fallback/examples/simple-fallback.rs @@ -66,7 +66,7 @@ fn get_available_locales() -> io::Result> { Ok(locales) } -fn resolve_app_locales<'l>(args: &[String]) -> Vec { +fn resolve_app_locales(args: &[String]) -> Vec { let default_locale = langid!("en-US"); let available = get_available_locales().expect("Retrieving available locales failed."); diff --git a/fluent-fallback/src/cache.rs b/fluent-fallback/src/cache.rs index 2e80fbb1..a8b6ff52 100644 --- a/fluent-fallback/src/cache.rs +++ b/fluent-fallback/src/cache.rs @@ -185,7 +185,7 @@ where let pin = unsafe { Pin::new_unchecked(&self.stream) }; unsafe { PinMut::as_mut(&mut pin.borrow_mut()).get_unchecked_mut() } .prefetch_async() - .await + .await; } } diff --git a/fluent-fallback/src/localization.rs b/fluent-fallback/src/localization.rs index 5424bcf3..a7054329 100644 --- a/fluent-fallback/src/localization.rs +++ b/fluent-fallback/src/localization.rs @@ -34,7 +34,7 @@ where generator: G::default(), provider: P::default(), sync, - res_ids: FxHashSet::from_iter(res_ids.into_iter()), + res_ids: FxHashSet::from_iter(res_ids), } } } @@ -53,7 +53,7 @@ where generator, provider, sync, - res_ids: FxHashSet::from_iter(res_ids.into_iter()), + res_ids: FxHashSet::from_iter(res_ids), } } @@ -115,7 +115,7 @@ where { pub async fn prefetch_async(&mut self) { let bundles = self.bundles(); - bundles.prefetch_async().await + bundles.prefetch_async().await; } } diff --git a/fluent-fallback/tests/localization_test.rs b/fluent-fallback/tests/localization_test.rs index 616440e1..ebe57314 100644 --- a/fluent-fallback/tests/localization_test.rs +++ b/fluent-fallback/tests/localization_test.rs @@ -454,7 +454,7 @@ fn localization_format_missing_argument_error() { let msgs = bundles.format_messages_sync(&keys, &mut errors).unwrap(); assert_eq!( - msgs.get(0).unwrap().as_ref().unwrap().value, + msgs.first().unwrap().as_ref().unwrap().value, Some(Cow::Borrowed("Hello, John. [en]")) ); assert_eq!(errors.len(), 0); @@ -465,7 +465,7 @@ fn localization_format_missing_argument_error() { }]; let msgs = bundles.format_messages_sync(&keys, &mut errors).unwrap(); assert_eq!( - msgs.get(0).unwrap().as_ref().unwrap().value, + msgs.first().unwrap().as_ref().unwrap().value, Some(Cow::Borrowed("Hello, {$userName}. [en]")) ); assert_eq!( diff --git a/fluent-resmgr/src/resource_manager.rs b/fluent-resmgr/src/resource_manager.rs index 166feed2..1de04eda 100644 --- a/fluent-resmgr/src/resource_manager.rs +++ b/fluent-resmgr/src/resource_manager.rs @@ -125,7 +125,7 @@ impl ResourceManager { Ok(resource) => { if let Err(errs) = bundle.add_resource(resource) { for error in errs { - errors.push(ResourceManagerError::Fluent(error)) + errors.push(ResourceManagerError::Fluent(error)); } } } diff --git a/fluent-syntax/benches/parser.rs b/fluent-syntax/benches/parser.rs index 9a174dec..2397044d 100644 --- a/fluent-syntax/benches/parser.rs +++ b/fluent-syntax/benches/parser.rs @@ -84,7 +84,7 @@ fn parse_bench(c: &mut Criterion) { for source in ctx { parse_runtime(source.as_str()).expect("Parsing of the FTL failed."); } - }) + }); }); } diff --git a/fluent-syntax/src/serializer.rs b/fluent-syntax/src/serializer.rs index 628018f2..a3442429 100644 --- a/fluent-syntax/src/serializer.rs +++ b/fluent-syntax/src/serializer.rs @@ -89,7 +89,7 @@ impl Serializer { Entry::ResourceComment(comment) => self.serialize_free_comment(comment, "###"), Entry::Junk { content } => { if self.options.with_junk { - self.serialize_junk(content.as_ref()) + self.serialize_junk(content.as_ref()); } } }; @@ -103,7 +103,7 @@ impl Serializer { } fn serialize_junk(&mut self, junk: &str) { - self.writer.write_literal(junk) + self.writer.write_literal(junk); } fn serialize_free_comment<'s, S: Slice<'s>>(&mut self, comment: &Comment, prefix: &str) { @@ -232,7 +232,7 @@ impl Serializer { match expr { Expression::Inline(inline) => self.serialize_inline_expression(inline), Expression::Select { selector, variants } => { - self.serialize_select_expression(selector, variants) + self.serialize_select_expression(selector, variants); } } } @@ -320,7 +320,7 @@ impl Serializer { fn serialize_variant_key<'s, S: Slice<'s>>(&mut self, key: &VariantKey) { match key { VariantKey::NumberLiteral { value } | VariantKey::Identifier { name: value } => { - self.writer.write_literal(value.as_ref()) + self.writer.write_literal(value.as_ref()); } } } @@ -367,7 +367,7 @@ impl<'s, S: Slice<'s>> Pattern { } fn has_leading_text_dot(&self) -> bool { - if let Some(PatternElement::TextElement { value }) = self.elements.get(0) { + if let Some(PatternElement::TextElement { value }) = self.elements.first() { value.as_ref().starts_with('.') } else { false