Skip to content

Commit 5153a7a

Browse files
authored
Merge pull request #315 from waywardmonkeys/clippy-fixes
2 parents 466e100 + fde63cb commit 5153a7a

21 files changed

+69
-83
lines changed

fluent-bundle/benches/resolver.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,10 @@ fn get_args(name: &str) -> Option<FluentArgs> {
5858
}
5959

6060
fn add_functions<R>(name: &'static str, bundle: &mut FluentBundle<R>) {
61-
match name {
62-
"preferences" => {
63-
bundle
64-
.add_function("PLATFORM", |_args, _named_args| "linux".into())
65-
.expect("Failed to add a function to the bundle.");
66-
}
67-
_ => {}
61+
if name == "preferences" {
62+
bundle
63+
.add_function("PLATFORM", |_args, _named_args| "linux".into())
64+
.expect("Failed to add a function to the bundle.");
6865
}
6966
}
7067

@@ -106,7 +103,7 @@ fn resolver_bench(c: &mut Criterion) {
106103
.add_resource(res.clone())
107104
.expect("Couldn't add FluentResource to the FluentBundle");
108105
add_functions(name, &mut bundle);
109-
})
106+
});
110107
});
111108
}
112109
group.finish();
@@ -133,7 +130,7 @@ fn resolver_bench(c: &mut Criterion) {
133130
}
134131
assert!(errors.is_empty(), "Resolver errors: {:#?}", errors);
135132
}
136-
})
133+
});
137134
});
138135
}
139136
group.finish();
@@ -156,7 +153,7 @@ fn resolver_bench(c: &mut Criterion) {
156153
}
157154
assert!(errors.is_empty(), "Resolver errors: {:#?}", errors);
158155
}
159-
})
156+
});
160157
});
161158
}
162159
group.finish();

fluent-bundle/benches/resolver_iai.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,10 @@ use unic_langid::{langid, LanguageIdentifier};
55
const LANG_EN: LanguageIdentifier = langid!("en");
66

77
fn add_functions<R>(name: &'static str, bundle: &mut FluentBundle<R>) {
8-
match name {
9-
"preferences" => {
10-
bundle
11-
.add_function("PLATFORM", |_args, _named_args| "linux".into())
12-
.expect("Failed to add a function to the bundle.");
13-
}
14-
_ => {}
8+
if name == "preferences" {
9+
bundle
10+
.add_function("PLATFORM", |_args, _named_args| "linux".into())
11+
.expect("Failed to add a function to the bundle.");
1512
}
1613
}
1714

fluent-bundle/examples/custom_formatter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ key-var-with-arg = Here is a variable formatted with an argument { NUMBER($num,
3636
.expect("Failed to add FTL resources to the bundle.");
3737
bundle
3838
.add_function("NUMBER", |positional, named| {
39-
match positional.get(0) {
39+
match positional.first() {
4040
Some(FluentValue::Number(n)) => {
4141
let mut num = n.clone();
4242
// This allows us to merge the arguments provided

fluent-bundle/examples/custom_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ key-date = Today is { DATETIME($epoch, dateStyle: "long", timeStyle: "short") }
165165
.expect("Failed to add FTL resources to the bundle.");
166166

167167
bundle
168-
.add_function("DATETIME", |positional, named| match positional.get(0) {
168+
.add_function("DATETIME", |positional, named| match positional.first() {
169169
Some(FluentValue::Number(n)) => {
170170
let epoch = n.value as usize;
171171
let options = named.into();

fluent-bundle/examples/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn main() {
2222
// Test for a function that accepts unnamed positional arguments
2323
bundle
2424
.add_function("MEANING_OF_LIFE", |args, _named_args| {
25-
if let Some(arg0) = args.get(0) {
25+
if let Some(arg0) = args.first() {
2626
if *arg0 == 42.into() {
2727
return "The answer to life, the universe, and everything".into();
2828
}

fluent-bundle/examples/simple-app.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,13 @@ fn get_available_locales() -> Result<Vec<LanguageIdentifier>, io::Error> {
5656
dir.push("examples");
5757
dir.push("resources");
5858
let res_dir = fs::read_dir(dir)?;
59-
for entry in res_dir {
60-
if let Ok(entry) = entry {
61-
let path = entry.path();
62-
if path.is_dir() {
63-
if let Some(name) = path.file_name() {
64-
if let Some(name) = name.to_str() {
65-
let langid = name.parse().expect("Parsing failed.");
66-
locales.push(langid);
67-
}
59+
for entry in res_dir.flatten() {
60+
let path = entry.path();
61+
if path.is_dir() {
62+
if let Some(name) = path.file_name() {
63+
if let Some(name) = name.to_str() {
64+
let langid = name.parse().expect("Parsing failed.");
65+
locales.push(langid);
6866
}
6967
}
7068
}
@@ -97,7 +95,7 @@ fn main() {
9795
NegotiationStrategy::Filtering,
9896
);
9997
let current_locale = resolved_locales
100-
.get(0)
98+
.first()
10199
.cloned()
102100
.expect("At least one locale should match.");
103101

fluent-bundle/src/bundle.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,10 @@ impl<R, M> FluentBundle<R, M> {
482482
///
483483
/// assert_eq!(result, "Hello World!");
484484
/// ```
485-
pub fn format_pattern<'bundle, 'args>(
485+
pub fn format_pattern<'bundle>(
486486
&'bundle self,
487487
pattern: &'bundle ast::Pattern<&'bundle str>,
488-
args: Option<&'args FluentArgs>,
488+
args: Option<&FluentArgs>,
489489
errors: &mut Vec<FluentError>,
490490
) -> Cow<'bundle, str>
491491
where
@@ -577,7 +577,7 @@ impl<R> FluentBundle<R, IntlLangMemoizer> {
577577
///
578578
/// This will panic if no formatters can be found for the locales.
579579
pub fn new(locales: Vec<LanguageIdentifier>) -> Self {
580-
let first_locale = locales.get(0).cloned().unwrap_or_default();
580+
let first_locale = locales.first().cloned().unwrap_or_default();
581581
Self {
582582
locales,
583583
resources: vec![],

fluent-bundle/src/concurrent.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<R> FluentBundle<R> {
3030
/// FluentBundle::new_concurrent(vec![langid_en]);
3131
/// ```
3232
pub fn new_concurrent(locales: Vec<LanguageIdentifier>) -> Self {
33-
let first_locale = locales.get(0).cloned().unwrap_or_default();
33+
let first_locale = locales.first().cloned().unwrap_or_default();
3434
Self {
3535
locales,
3636
resources: vec![],

fluent-bundle/src/types/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ impl<'source> FluentValue<'source> {
185185
M: MemoizerKind,
186186
{
187187
match (self, other) {
188-
(&FluentValue::String(ref a), &FluentValue::String(ref b)) => a == b,
189-
(&FluentValue::Number(ref a), &FluentValue::Number(ref b)) => a == b,
190-
(&FluentValue::String(ref a), &FluentValue::Number(ref b)) => {
188+
(FluentValue::String(a), FluentValue::String(b)) => a == b,
189+
(FluentValue::Number(a), FluentValue::Number(b)) => a == b,
190+
(FluentValue::String(a), FluentValue::Number(b)) => {
191191
let cat = match a.as_ref() {
192192
"zero" => PluralCategory::ZERO,
193193
"one" => PluralCategory::ONE,

fluent-bundle/tests/bundle.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,8 @@ fn borrowed_plain_message() {
5555
bundle.format_pattern(value, None, &mut errors)
5656
};
5757

58-
fn is_borrowed(cow: Cow<'_, str>) -> bool {
59-
match cow {
60-
Cow::Borrowed(_) => true,
61-
_ => false,
62-
}
63-
}
6458
assert_eq!(formatted_pattern, "Value");
65-
assert!(is_borrowed(formatted_pattern));
59+
assert!(matches!(formatted_pattern, Cow::Borrowed(_)));
6660
}
6761

6862
#[test]

fluent-bundle/tests/custom_types.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ fn fluent_custom_type() {
4040

4141
let sv = FluentValue::from("foo");
4242

43-
assert_eq!(dt == dt2, true);
44-
assert_eq!(dt == dt3, false);
45-
assert_eq!(dt == sv, false);
43+
assert!(dt == dt2);
44+
assert!(dt != dt3);
45+
assert!(dt != sv);
4646
}
4747

4848
#[test]
@@ -146,7 +146,7 @@ key-ref = Hello { DATETIME($date, dateStyle: "full") } World
146146
bundle.set_use_isolating(false);
147147

148148
bundle
149-
.add_function("DATETIME", |positional, named| match positional.get(0) {
149+
.add_function("DATETIME", |positional, named| match positional.first() {
150150
Some(FluentValue::Custom(custom)) => {
151151
if let Some(that) = custom.as_ref().as_any().downcast_ref::<DateTime>() {
152152
let mut dt = that.clone();
@@ -202,7 +202,7 @@ key-num-explicit = Hello { NUMBER(5, minimumFractionDigits: 2) } World
202202
bundle.set_use_isolating(false);
203203

204204
bundle
205-
.add_function("NUMBER", |positional, named| match positional.get(0) {
205+
.add_function("NUMBER", |positional, named| match positional.first() {
206206
Some(FluentValue::Number(n)) => {
207207
let mut num = n.clone();
208208
num.options.merge(named);

fluent-bundle/tests/function.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ liked-count2 = { NUMBER($num) ->
2424
let mut bundle = FluentBundle::default();
2525

2626
bundle
27-
.add_function("NUMBER", |positional, named| match positional.get(0) {
27+
.add_function("NUMBER", |positional, named| match positional.first() {
2828
Some(FluentValue::Number(n)) => {
2929
let mut num = n.clone();
3030
num.options.merge(named);
3131

3232
FluentValue::Number(num)
3333
}
3434
Some(FluentValue::String(s)) => {
35-
let num: f64 = if let Ok(n) = s.to_owned().parse() {
35+
let num: f64 = if let Ok(n) = s.clone().parse() {
3636
n
3737
} else {
3838
return FluentValue::Error;

fluent-bundle/tests/resolver_fixtures.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ fn create_bundle(
155155
.into()
156156
}),
157157
"IDENTITY" => bundle.add_function(f.as_str(), |args, _name_args| {
158-
args.get(0).cloned().unwrap_or(FluentValue::Error)
158+
args.first().cloned().unwrap_or(FluentValue::Error)
159159
}),
160160
"NUMBER" => bundle.add_function(f.as_str(), |args, _name_args| {
161-
args.get(0).expect("Argument must be passed").clone()
161+
args.first().expect("Argument must be passed").clone()
162162
}),
163163
_ => unimplemented!("No such function."),
164164
};
@@ -242,7 +242,7 @@ fn test_test(test: &Test, defaults: &Option<TestDefaults>, mut scope: Scope) {
242242
.get(bundle_name)
243243
.expect("Failed to retrieve bundle.")
244244
} else if bundles.len() == 1 {
245-
let name = bundles.keys().into_iter().last().unwrap();
245+
let name = bundles.keys().last().unwrap();
246246
bundles.get(name).expect("Failed to retrieve bundle.")
247247
} else {
248248
panic!();

fluent-bundle/tests/types_test.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ fn fluent_value_matches() {
3131
let number_val_copy = FluentValue::from(-23.5);
3232
let number_val2 = FluentValue::from(23.5);
3333

34-
assert_eq!(string_val.matches(&string_val_copy, &scope), true);
35-
assert_eq!(string_val.matches(&string_val2, &scope), false);
34+
assert!(string_val.matches(&string_val_copy, &scope));
35+
assert!(!string_val.matches(&string_val2, &scope));
3636

37-
assert_eq!(number_val.matches(&number_val_copy, &scope), true);
38-
assert_eq!(number_val.matches(&number_val2, &scope), false);
37+
assert!(number_val.matches(&number_val_copy, &scope));
38+
assert!(!number_val.matches(&number_val2, &scope));
3939

40-
assert_eq!(string_val2.matches(&number_val2, &scope), false);
40+
assert!(!string_val2.matches(&number_val2, &scope));
4141

42-
assert_eq!(string_val2.matches(&number_val2, &scope), false);
42+
assert!(!string_val2.matches(&number_val2, &scope));
4343

4444
let string_cat_zero = FluentValue::from("zero");
4545
let string_cat_one = FluentValue::from("one");
@@ -55,15 +55,15 @@ fn fluent_value_matches() {
5555
let number_cat_many = 11.into();
5656
let number_cat_other = 101.into();
5757

58-
assert_eq!(string_cat_zero.matches(&number_cat_zero, &scope), true);
59-
assert_eq!(string_cat_one.matches(&number_cat_one, &scope), true);
60-
assert_eq!(string_cat_two.matches(&number_cat_two, &scope), true);
61-
assert_eq!(string_cat_few.matches(&number_cat_few, &scope), true);
62-
assert_eq!(string_cat_many.matches(&number_cat_many, &scope), true);
63-
assert_eq!(string_cat_other.matches(&number_cat_other, &scope), true);
64-
assert_eq!(string_cat_other.matches(&number_cat_one, &scope), false);
58+
assert!(string_cat_zero.matches(&number_cat_zero, &scope));
59+
assert!(string_cat_one.matches(&number_cat_one, &scope));
60+
assert!(string_cat_two.matches(&number_cat_two, &scope));
61+
assert!(string_cat_few.matches(&number_cat_few, &scope));
62+
assert!(string_cat_many.matches(&number_cat_many, &scope));
63+
assert!(string_cat_other.matches(&number_cat_other, &scope));
64+
assert!(!string_cat_other.matches(&number_cat_one, &scope));
6565

66-
assert_eq!(string_val2.matches(&number_cat_one, &scope), false);
66+
assert!(!string_val2.matches(&number_cat_one, &scope));
6767
}
6868

6969
#[test]
@@ -120,7 +120,7 @@ fn fluent_number_style() {
120120
assert_eq!(fno.style, FluentNumberStyle::Currency);
121121
assert_eq!(fno.currency, Some("EUR".to_string()));
122122
assert_eq!(fno.currency_display, FluentNumberCurrencyDisplayStyle::Code);
123-
assert_eq!(fno.use_grouping, false);
123+
assert!(!fno.use_grouping);
124124

125125
let num = FluentNumber::new(0.2, FluentNumberOptions::default());
126126
assert_eq!(num.as_string(), "0.2");

fluent-fallback/examples/simple-fallback.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn get_available_locales() -> io::Result<Vec<LanguageIdentifier>> {
6666
Ok(locales)
6767
}
6868

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

fluent-fallback/src/cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ where
185185
let pin = unsafe { Pin::new_unchecked(&self.stream) };
186186
unsafe { PinMut::as_mut(&mut pin.borrow_mut()).get_unchecked_mut() }
187187
.prefetch_async()
188-
.await
188+
.await;
189189
}
190190
}
191191

fluent-fallback/src/localization.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ where
3434
generator: G::default(),
3535
provider: P::default(),
3636
sync,
37-
res_ids: FxHashSet::from_iter(res_ids.into_iter()),
37+
res_ids: FxHashSet::from_iter(res_ids),
3838
}
3939
}
4040
}
@@ -53,7 +53,7 @@ where
5353
generator,
5454
provider,
5555
sync,
56-
res_ids: FxHashSet::from_iter(res_ids.into_iter()),
56+
res_ids: FxHashSet::from_iter(res_ids),
5757
}
5858
}
5959

@@ -115,7 +115,7 @@ where
115115
{
116116
pub async fn prefetch_async(&mut self) {
117117
let bundles = self.bundles();
118-
bundles.prefetch_async().await
118+
bundles.prefetch_async().await;
119119
}
120120
}
121121

fluent-fallback/tests/localization_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ fn localization_format_missing_argument_error() {
454454

455455
let msgs = bundles.format_messages_sync(&keys, &mut errors).unwrap();
456456
assert_eq!(
457-
msgs.get(0).unwrap().as_ref().unwrap().value,
457+
msgs.first().unwrap().as_ref().unwrap().value,
458458
Some(Cow::Borrowed("Hello, John. [en]"))
459459
);
460460
assert_eq!(errors.len(), 0);
@@ -465,7 +465,7 @@ fn localization_format_missing_argument_error() {
465465
}];
466466
let msgs = bundles.format_messages_sync(&keys, &mut errors).unwrap();
467467
assert_eq!(
468-
msgs.get(0).unwrap().as_ref().unwrap().value,
468+
msgs.first().unwrap().as_ref().unwrap().value,
469469
Some(Cow::Borrowed("Hello, {$userName}. [en]"))
470470
);
471471
assert_eq!(

fluent-resmgr/src/resource_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl ResourceManager {
125125
Ok(resource) => {
126126
if let Err(errs) = bundle.add_resource(resource) {
127127
for error in errs {
128-
errors.push(ResourceManagerError::Fluent(error))
128+
errors.push(ResourceManagerError::Fluent(error));
129129
}
130130
}
131131
}

fluent-syntax/benches/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn parse_bench(c: &mut Criterion) {
8484
for source in ctx {
8585
parse_runtime(source.as_str()).expect("Parsing of the FTL failed.");
8686
}
87-
})
87+
});
8888
});
8989
}
9090

0 commit comments

Comments
 (0)