Skip to content

Commit

Permalink
Merge pull request #315 from waywardmonkeys/clippy-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed May 5, 2024
2 parents 466e100 + fde63cb commit 5153a7a
Show file tree
Hide file tree
Showing 21 changed files with 69 additions and 83 deletions.
17 changes: 7 additions & 10 deletions fluent-bundle/benches/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,10 @@ fn get_args(name: &str) -> Option<FluentArgs> {
}

fn add_functions<R>(name: &'static str, bundle: &mut FluentBundle<R>) {
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.");
}
}

Expand Down Expand Up @@ -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();
Expand All @@ -133,7 +130,7 @@ fn resolver_bench(c: &mut Criterion) {
}
assert!(errors.is_empty(), "Resolver errors: {:#?}", errors);
}
})
});
});
}
group.finish();
Expand All @@ -156,7 +153,7 @@ fn resolver_bench(c: &mut Criterion) {
}
assert!(errors.is_empty(), "Resolver errors: {:#?}", errors);
}
})
});
});
}
group.finish();
Expand Down
11 changes: 4 additions & 7 deletions fluent-bundle/benches/resolver_iai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ use unic_langid::{langid, LanguageIdentifier};
const LANG_EN: LanguageIdentifier = langid!("en");

fn add_functions<R>(name: &'static str, bundle: &mut FluentBundle<R>) {
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.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion fluent-bundle/examples/custom_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fluent-bundle/examples/custom_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion fluent-bundle/examples/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
18 changes: 8 additions & 10 deletions fluent-bundle/examples/simple-app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ fn get_available_locales() -> Result<Vec<LanguageIdentifier>, 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);
}
}
}
Expand Down Expand Up @@ -97,7 +95,7 @@ fn main() {
NegotiationStrategy::Filtering,
);
let current_locale = resolved_locales
.get(0)
.first()
.cloned()
.expect("At least one locale should match.");

Expand Down
6 changes: 3 additions & 3 deletions fluent-bundle/src/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,10 +482,10 @@ impl<R, M> FluentBundle<R, M> {
///
/// 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<FluentError>,
) -> Cow<'bundle, str>
where
Expand Down Expand Up @@ -577,7 +577,7 @@ impl<R> FluentBundle<R, IntlLangMemoizer> {
///
/// This will panic if no formatters can be found for the locales.
pub fn new(locales: Vec<LanguageIdentifier>) -> Self {
let first_locale = locales.get(0).cloned().unwrap_or_default();
let first_locale = locales.first().cloned().unwrap_or_default();
Self {
locales,
resources: vec![],
Expand Down
2 changes: 1 addition & 1 deletion fluent-bundle/src/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<R> FluentBundle<R> {
/// FluentBundle::new_concurrent(vec![langid_en]);
/// ```
pub fn new_concurrent(locales: Vec<LanguageIdentifier>) -> Self {
let first_locale = locales.get(0).cloned().unwrap_or_default();
let first_locale = locales.first().cloned().unwrap_or_default();
Self {
locales,
resources: vec![],
Expand Down
6 changes: 3 additions & 3 deletions fluent-bundle/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 1 addition & 7 deletions fluent-bundle/tests/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 5 additions & 5 deletions fluent-bundle/tests/custom_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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::<DateTime>() {
let mut dt = that.clone();
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions fluent-bundle/tests/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ 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);

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;
Expand Down
6 changes: 3 additions & 3 deletions fluent-bundle/tests/resolver_fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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."),
};
Expand Down Expand Up @@ -242,7 +242,7 @@ fn test_test(test: &Test, defaults: &Option<TestDefaults>, 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!();
Expand Down
30 changes: 15 additions & 15 deletions fluent-bundle/tests/types_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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]
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion fluent-fallback/examples/simple-fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn get_available_locales() -> io::Result<Vec<LanguageIdentifier>> {
Ok(locales)
}

fn resolve_app_locales<'l>(args: &[String]) -> Vec<LanguageIdentifier> {
fn resolve_app_locales(args: &[String]) -> Vec<LanguageIdentifier> {
let default_locale = langid!("en-US");
let available = get_available_locales().expect("Retrieving available locales failed.");

Expand Down
2 changes: 1 addition & 1 deletion fluent-fallback/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
6 changes: 3 additions & 3 deletions fluent-fallback/src/localization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand All @@ -53,7 +53,7 @@ where
generator,
provider,
sync,
res_ids: FxHashSet::from_iter(res_ids.into_iter()),
res_ids: FxHashSet::from_iter(res_ids),
}
}

Expand Down Expand Up @@ -115,7 +115,7 @@ where
{
pub async fn prefetch_async(&mut self) {
let bundles = self.bundles();
bundles.prefetch_async().await
bundles.prefetch_async().await;
}
}

Expand Down
4 changes: 2 additions & 2 deletions fluent-fallback/tests/localization_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion fluent-resmgr/src/resource_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion fluent-syntax/benches/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
})
});
});
}

Expand Down
Loading

0 comments on commit 5153a7a

Please sign in to comment.