Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed up clippy warnrings/errors #296

Merged
merged 1 commit into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions fluent-bundle/benches/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn get_strings(tests: &[&'static str]) -> HashMap<&'static str, String> {
let path = format!("./benches/{}.ftl", test);
ftl_strings.insert(*test, read_file(&path).expect("Couldn't load file"));
}
return ftl_strings;
ftl_strings
}

fn get_ids(res: &FluentResource) -> Vec<String> {
Expand Down Expand Up @@ -62,7 +62,7 @@ fn add_functions<R>(name: &'static str, bundle: &mut FluentBundle<R>) {
"preferences" => {
bundle
.add_function("PLATFORM", |_args, _named_args| {
return "linux".into();
"linux".into()
})
.expect("Failed to add a function to the bundle.");
}
Expand Down Expand Up @@ -133,7 +133,7 @@ fn resolver_bench(c: &mut Criterion) {
bundle.write_pattern(&mut s, attr.value(), args.as_ref(), &mut errors);
s.clear();
}
assert!(errors.len() == 0, "Resolver errors: {:#?}", errors);
assert!(errors.is_empty(), "Resolver errors: {:#?}", errors);
}
})
});
Expand All @@ -156,7 +156,7 @@ fn resolver_bench(c: &mut Criterion) {
for attr in msg.attributes() {
let _ = bundle.format_pattern(attr.value(), args.as_ref(), &mut errors);
}
assert!(errors.len() == 0, "Resolver errors: {:#?}", errors);
assert!(errors.is_empty(), "Resolver errors: {:#?}", errors);
}
})
});
Expand Down
4 changes: 2 additions & 2 deletions fluent-bundle/benches/resolver_iai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn add_functions<R>(name: &'static str, bundle: &mut FluentBundle<R>) {
"preferences" => {
bundle
.add_function("PLATFORM", |_args, _named_args| {
return "linux".into();
"linux".into()
})
.expect("Failed to add a function to the bundle.");
}
Expand Down Expand Up @@ -71,7 +71,7 @@ fn iai_resolve_preferences() {
.expect("Failed to write a pattern.");
s.clear();
}
assert!(errors.len() == 0, "Resolver errors: {:#?}", errors);
assert!(errors.is_empty(), "Resolver errors: {:#?}", errors);
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions fluent-bundle/examples/custom_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use fluent_bundle::{FluentArgs, FluentBundle, FluentResource, FluentValue};

fn custom_formatter<M: MemoizerKind>(num: &FluentValue, _intls: &M) -> Option<String> {
match num {
FluentValue::Number(n) => Some(format!("CUSTOM({})", n.value).into()),
FluentValue::Number(n) => Some(format!("CUSTOM({})", n.value)),
_ => None,
}
}
Expand Down Expand Up @@ -59,7 +59,7 @@ key-var-with-arg = Here is a variable formatted with an argument { NUMBER($num,
.get_message("key-implicit")
.expect("Message doesn't exist.");
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, None, &mut errors);
let value = bundle.format_pattern(pattern, None, &mut errors);
assert_eq!(value, "Here is an implicitly encoded number: 5.");
println!("{}", value);

Expand All @@ -72,7 +72,7 @@ key-var-with-arg = Here is a variable formatted with an argument { NUMBER($num,
.get_message("key-implicit")
.expect("Message doesn't exist.");
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, None, &mut errors);
let value = bundle.format_pattern(pattern, None, &mut errors);
assert_eq!(value, "Here is an implicitly encoded number: CUSTOM(5).");
println!("{}", value);

Expand All @@ -82,7 +82,7 @@ key-var-with-arg = Here is a variable formatted with an argument { NUMBER($num,
.get_message("key-explicit")
.expect("Message doesn't exist.");
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, None, &mut errors);
let value = bundle.format_pattern(pattern, None, &mut errors);
assert_eq!(value, "Here is an explicitly encoded number: CUSTOM(5).");
println!("{}", value);

Expand All @@ -92,7 +92,7 @@ key-var-with-arg = Here is a variable formatted with an argument { NUMBER($num,
let pattern = msg.value().expect("Message has no value.");
let mut args = FluentArgs::new();
args.set("num", FluentValue::from(-15));
let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);
let value = bundle.format_pattern(pattern, Some(&args), &mut errors);
assert_eq!(
value,
"Here is an implicitly encoded variable: CUSTOM(-15)."
Expand All @@ -105,7 +105,7 @@ key-var-with-arg = Here is a variable formatted with an argument { NUMBER($num,
let pattern = msg.value().expect("Message has no value.");
let mut args = FluentArgs::new();
args.set("num", FluentValue::from(-15));
let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);
let value = bundle.format_pattern(pattern, Some(&args), &mut errors);
assert_eq!(
value,
"Here is an explicitly encoded variable: CUSTOM(-15)."
Expand All @@ -129,7 +129,7 @@ key-var-with-arg = Here is a variable formatted with an argument { NUMBER($num,
},
);
args.set("num", num);
let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);
let value = bundle.format_pattern(pattern, Some(&args), &mut errors);

// Notice, that since we specificed minimum and maximum fraction digits options
// to be 1 and 8 when construction the argument, and then the minimum fraction
Expand Down
6 changes: 3 additions & 3 deletions fluent-bundle/examples/external_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ unread-emails =
.expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);
let value = bundle.format_pattern(pattern, Some(&args), &mut errors);
println!("{}", value);

let msg = bundle.get_message("ref").expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);
let value = bundle.format_pattern(pattern, Some(&args), &mut errors);
println!("{}", value);

let mut args = FluentArgs::new();
Expand All @@ -45,6 +45,6 @@ unread-emails =
.expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);
let value = bundle.format_pattern(pattern, Some(&args), &mut errors);
println!("{}", value);
}
8 changes: 4 additions & 4 deletions fluent-bundle/examples/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn main() {
// Test for a simple function that returns a string
bundle
.add_function("HELLO", |_args, _named_args| {
return "I'm a function!".into();
"I'm a function!".into()
})
.expect("Failed to add a function to the bundle.");

Expand Down Expand Up @@ -61,22 +61,22 @@ fn main() {
.expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, None, &mut errors);
let value = bundle.format_pattern(pattern, None, &mut errors);
assert_eq!(&value, "Hey there! \u{2068}I'm a function!\u{2069}");

let msg = bundle
.get_message("meaning-of-life")
.expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, None, &mut errors);
let value = bundle.format_pattern(pattern, None, &mut errors);
assert_eq!(&value, "The answer to life, the universe, and everything");

let msg = bundle
.get_message("all-your-base")
.expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, None, &mut errors);
let value = bundle.format_pattern(pattern, None, &mut errors);
assert_eq!(&value, "All your base belong to us");
}
2 changes: 1 addition & 1 deletion fluent-bundle/examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ fn main() {
.expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, None, &mut errors);
let value = bundle.format_pattern(pattern, None, &mut errors);
assert_eq!(&value, "Hello, world!");
}
4 changes: 2 additions & 2 deletions fluent-bundle/examples/message_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ bazbar = { baz } Bar
.expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, None, &mut errors);
let value = bundle.format_pattern(pattern, None, &mut errors);
println!("{}", value);

let msg = bundle
.get_message("bazbar")
.expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, None, &mut errors);
let value = bundle.format_pattern(pattern, None, &mut errors);
println!("{}", value);
}
4 changes: 2 additions & 2 deletions fluent-bundle/examples/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ hello-world2 = Hello { $name ->
.expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, None, &mut errors);
let value = bundle.format_pattern(pattern, None, &mut errors);
println!("{}", value);

let mut args = FluentArgs::new();
Expand All @@ -36,6 +36,6 @@ hello-world2 = Hello { $name ->
.expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);
let value = bundle.format_pattern(pattern, Some(&args), &mut errors);
println!("{}", value);
}
12 changes: 6 additions & 6 deletions fluent-bundle/examples/simple-app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn get_available_locales() -> Result<Vec<LanguageIdentifier>, io::Error> {
}
}
}
return Ok(locales);
Ok(locales)
}

static L10N_RESOURCES: &[&str] = &["simple.ftl"];
Expand All @@ -82,7 +82,7 @@ fn main() {
// take the second argument as a comma-separated
// list of requested locales.
let requested = args.get(2).map_or(vec![], |arg| {
arg.split(",")
arg.split(',')
.map(|s| -> LanguageIdentifier { s.parse().expect("Parsing locale failed.") })
.collect()
});
Expand Down Expand Up @@ -126,7 +126,7 @@ fn main() {
match args.get(1) {
Some(input) => {
// 7.1. Cast it to a number.
match isize::from_str(&input) {
match isize::from_str(input) {
Ok(i) => {
// 7.2. Construct a map of arguments
// to format the message.
Expand All @@ -139,7 +139,7 @@ fn main() {
.get_message("response-msg")
.expect("Message doesn't exist.");
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);
let value = bundle.format_pattern(pattern, Some(&args), &mut errors);
println!("{}", value);
}
Err(err) => {
Expand All @@ -151,7 +151,7 @@ fn main() {
.get_message("input-parse-error")
.expect("Message doesn't exist.");
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);
let value = bundle.format_pattern(pattern, Some(&args), &mut errors);
println!("{}", value);
}
}
Expand All @@ -162,7 +162,7 @@ fn main() {
.get_message("missing-arg-error")
.expect("Message doesn't exist.");
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, None, &mut errors);
let value = bundle.format_pattern(pattern, None, &mut errors);
println!("{}", value);
}
}
Expand Down
2 changes: 1 addition & 1 deletion fluent-bundle/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub trait GetEntry {
fn get_entry_function(&self, id: &str) -> Option<&FluentFunction>;
}

impl<'bundle, R: Borrow<FluentResource>, M> GetEntry for FluentBundle<R, M> {
impl<R: Borrow<FluentResource>, M> GetEntry for FluentBundle<R, M> {
fn get_entry_message(&self, id: &str) -> Option<&ast::Message<&str>> {
self.entries.get(id).and_then(|ref entry| match entry {
Entry::Message((resource_idx, entry_idx)) => {
Expand Down
4 changes: 2 additions & 2 deletions fluent-bundle/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::resolver::ResolverError;
use fluent_syntax::parser::ParserError;
use std::error::Error;

#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum EntryKind {
Message,
Term,
Expand All @@ -23,7 +23,7 @@ impl std::fmt::Display for EntryKind {
///
/// It contains three main types of errors that may come up
/// during runtime use of the fluent-bundle crate.
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum FluentError {
/// An error which occurs when
/// [`FluentBundle::add_resource`](crate::bundle::FluentBundle::add_resource)
Expand Down
4 changes: 2 additions & 2 deletions fluent-bundle/src/resolver/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::error::Error;
/// Maps an [`InlineExpression`] into the kind of reference, with owned strings
/// that identify the expression. This makes it so that the [`InlineExpression`] can
/// be used to generate an error string.
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum ReferenceKind {
Function {
id: String,
Expand Down Expand Up @@ -49,7 +49,7 @@ where

/// Errors generated during the process of resolving a fluent message into a string.
/// This process takes place in the `write` method of the `WriteValue` trait.
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub enum ResolverError {
Reference(ReferenceKind),
NoValue(String),
Expand Down
8 changes: 4 additions & 4 deletions fluent-bundle/tests/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ liked-count2 = { NUMBER($num) ->

let mut errors = vec![];
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);
let value = bundle.format_pattern(pattern, Some(&args), &mut errors);
assert_eq!("\u{2068}1\u{2069} people liked your message", &value);

// 3. Example with passing number, but without NUMBER call
Expand All @@ -75,7 +75,7 @@ liked-count2 = { NUMBER($num) ->
.expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);
let value = bundle.format_pattern(pattern, Some(&args), &mut errors);
assert_eq!("One person liked your message", &value);

// 4. Example with NUMBER call
Expand All @@ -87,7 +87,7 @@ liked-count2 = { NUMBER($num) ->
.expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);
let value = bundle.format_pattern(pattern, Some(&args), &mut errors);
assert_eq!("One person liked your message", &value);

// 5. Example with NUMBER call from number
Expand All @@ -99,6 +99,6 @@ liked-count2 = { NUMBER($num) ->
.expect("Message doesn't exist.");
let mut errors = vec![];
let pattern = msg.value().expect("Message has no value.");
let value = bundle.format_pattern(&pattern, Some(&args), &mut errors);
let value = bundle.format_pattern(pattern, Some(&args), &mut errors);
assert_eq!("One person liked your message", &value);
}
10 changes: 5 additions & 5 deletions fluent-bundle/tests/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn get_defaults(path: &str) -> Result<TestDefaults, io::Error> {
Ok(serde_yaml::from_str(&s).expect("Parsing YAML failed."))
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct TestBundle {
pub name: Option<String>,
Expand All @@ -102,7 +102,7 @@ pub struct TestBundle {
pub errors: Vec<TestError>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct TestResource {
pub name: Option<String>,
Expand All @@ -120,7 +120,7 @@ pub struct TestSetup {
pub resources: Vec<TestResource>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct TestError {
#[serde(rename = "type")]
Expand Down Expand Up @@ -186,7 +186,7 @@ pub struct TestFixture {
pub suites: Vec<TestSuite>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct BundleDefaults {
#[serde(rename = "useIsolating")]
Expand All @@ -195,7 +195,7 @@ pub struct BundleDefaults {
pub locales: Option<Vec<String>>,
}

#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct TestDefaults {
pub bundle: BundleDefaults,
Expand Down
Loading