Skip to content

Commit 5153a7a

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

File tree

21 files changed

+69
-83
lines changed

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]

0 commit comments

Comments
 (0)