Skip to content

Commit

Permalink
clippy: Apply fix for get_first lint
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Mar 9, 2024
1 parent 22c91e9 commit 9440d91
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion fluent-bundle/examples/custom_formatter.rs
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
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
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
3 changes: 1 addition & 2 deletions fluent-bundle/examples/simple-app.rs
Expand Up @@ -94,8 +94,7 @@ fn main() {
Some(&default_locale),
NegotiationStrategy::Filtering,
);
let current_locale = resolved_locales
.get(0)
let current_locale = resolved_locales.first()
.cloned()
.expect("At least one locale should match.");

Expand Down
2 changes: 1 addition & 1 deletion fluent-bundle/src/bundle.rs
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
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
4 changes: 2 additions & 2 deletions fluent-bundle/tests/custom_types.rs
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
2 changes: 1 addition & 1 deletion fluent-bundle/tests/function.rs
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions fluent-bundle/tests/resolver_fixtures.rs
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
4 changes: 2 additions & 2 deletions fluent-fallback/tests/localization_test.rs
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-syntax/src/serializer.rs
Expand Up @@ -371,7 +371,7 @@ impl<'s, S: Slice<'s>> Pattern<S> {
}

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
Expand Down

0 comments on commit 9440d91

Please sign in to comment.