Skip to content

Commit

Permalink
Run rustfmt-nightly on Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
stasm committed Oct 16, 2017
1 parent 90389cb commit c3bc55b
Show file tree
Hide file tree
Showing 22 changed files with 272 additions and 323 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ addons:
before_script:
- cargo install --force cargo-travis
- export PATH=$HOME/.cargo/bin:$PATH
- which rustfmt || cargo install rustfmt
- which rustfmt || cargo install rustfmt-nightly

script:
- cargo fmt -- --write-mode=diff
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ fn main() {
let mut ctx = MessageContext::new(&["en-US"]);
ctx.add_messages("hello-world = Hello, world!");

let value = ctx.get_message("hello-world").and_then(|message| {
ctx.format(message, None)
});
let value = ctx.get_message("hello-world")
.and_then(|message| ctx.format(message, None));

assert_eq!(value, Some("Hello, world!".to_string()));
}
Expand All @@ -69,7 +68,7 @@ Local Development
cargo bench
cargo run --example hello

When submitting a PR please use [`cargo fmt`][] (stable).
When submitting a PR please use [`cargo fmt`][] (nightly).

[`cargo fmt`]: https://github.com/rust-lang-nursery/rustfmt

Expand Down
2 changes: 1 addition & 1 deletion benches/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![feature(test)]

extern crate test;
extern crate fluent;
extern crate test;

use std::io;
use std::io::Read;
Expand Down
18 changes: 9 additions & 9 deletions examples/external_arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ fn main() {
let mut args = HashMap::new();
args.insert("name", FluentValue::from("John"));

match ctx.get_message("hello-world").and_then(|msg| {
ctx.format(msg, Some(&args))
}) {
match ctx.get_message("hello-world")
.and_then(|msg| ctx.format(msg, Some(&args)))
{
Some(value) => println!("{}", value),
None => println!("None"),
}

match ctx.get_message("ref").and_then(
|msg| ctx.format(msg, Some(&args)),
) {
match ctx.get_message("ref")
.and_then(|msg| ctx.format(msg, Some(&args)))
{
Some(value) => println!("{}", value),
None => println!("None"),
}

let mut args = HashMap::new();
args.insert("emailCount", FluentValue::from(5));

match ctx.get_message("unread-emails").and_then(|msg| {
ctx.format(msg, Some(&args))
}) {
match ctx.get_message("unread-emails")
.and_then(|msg| ctx.format(msg, Some(&args)))
{
Some(value) => println!("{}", value),
None => println!("None"),
}
Expand Down
5 changes: 2 additions & 3 deletions examples/hello.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ fn main() {
let mut ctx = MessageContext::new(&["en-US"]);
ctx.add_messages("hello-world = Hello, world!");

let value = ctx.get_message("hello-world").and_then(|message| {
ctx.format(message, None)
});
let value = ctx.get_message("hello-world")
.and_then(|message| ctx.format(message, None));

assert_eq!(value, Some("Hello, world!".to_string()));
}
12 changes: 6 additions & 6 deletions examples/message_reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ fn main() {
ctx.add_messages("foobar = { foo } Bar");
ctx.add_messages("bazbar = { baz } Bar");

match ctx.get_message("foobar").and_then(
|msg| ctx.format(msg, None),
) {
match ctx.get_message("foobar")
.and_then(|msg| ctx.format(msg, None))
{
Some(value) => println!("{}", value),
None => println!("None"),
}

match ctx.get_message("bazbar").and_then(
|msg| ctx.format(msg, None),
) {
match ctx.get_message("bazbar")
.and_then(|msg| ctx.format(msg, None))
{
Some(value) => println!("{}", value),
None => println!("None"),
}
Expand Down
12 changes: 6 additions & 6 deletions examples/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ hello-world2 = Hello { $name ->
",
);

match ctx.get_message("hello-world").and_then(
|msg| ctx.format(msg, None),
) {
match ctx.get_message("hello-world")
.and_then(|msg| ctx.format(msg, None))
{
Some(value) => println!("{}", value),
None => println!("None"),
}

let mut args = HashMap::new();
args.insert("name", FluentValue::from("moon"));

match ctx.get_message("hello-world2").and_then(|msg| {
ctx.format(msg, Some(&args))
}) {
match ctx.get_message("hello-world2")
.and_then(|msg| ctx.format(msg, Some(&args)))
{
Some(value) => println!("{}", value),
None => println!("None"),
}
Expand Down
12 changes: 6 additions & 6 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ fn main() {
ctx.add_messages("key1 = Value 1");
ctx.add_messages("key2 = Value 2");

match ctx.get_message("key1").and_then(
|msg| ctx.format(msg, None),
) {
match ctx.get_message("key1")
.and_then(|msg| ctx.format(msg, None))
{
Some(value) => println!("{}", value),
None => println!("None"),
}

match ctx.get_message("key2").and_then(
|msg| ctx.format(msg, None),
) {
match ctx.get_message("key2")
.and_then(|msg| ctx.format(msg, None))
{
Some(value) => println!("{}", value),
None => println!("None"),
}
Expand Down
14 changes: 6 additions & 8 deletions src/intl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ static PLURAL_RULES: &[fn(f32) -> &'static str] = &[
if is_between(n % 10.0, 2.0, 4.0) && !is_between(n % 100.0, 12.0, 14.0) {
return "few";
}
if n != 1.0 && is_between(n % 10.0, 0.0, 1.0) || is_between(n % 10.0, 5.0, 9.0) ||
is_between(n % 100.0, 12.0, 14.0)
if n != 1.0 && is_between(n % 10.0, 0.0, 1.0) || is_between(n % 10.0, 5.0, 9.0)
|| is_between(n % 100.0, 12.0, 14.0)
{
return "many";
}
Expand Down Expand Up @@ -403,9 +403,9 @@ static PLURAL_RULES: &[fn(f32) -> &'static str] = &[
},
/* 20 */
|n| {
if (is_between(n % 10.0, 3.0, 4.0) || n % 10.0 == 9.0) &&
!(is_between(n % 100.0, 10.0, 19.0) || is_between(n % 100.0, 70.0, 79.0) ||
is_between(n % 100.0, 90.0, 99.0))
if (is_between(n % 10.0, 3.0, 4.0) || n % 10.0 == 9.0)
&& !(is_between(n % 100.0, 10.0, 19.0) || is_between(n % 100.0, 70.0, 79.0)
|| is_between(n % 100.0, 90.0, 99.0))
{
return "few";
}
Expand Down Expand Up @@ -438,9 +438,7 @@ static PLURAL_RULES: &[fn(f32) -> &'static str] = &[
"other"
},
/* 23 */
|n| if is_between(n, 0.0, 1.0) ||
is_between(n, 11.0, 99.0)
{
|n| if is_between(n, 0.0, 1.0) || is_between(n, 11.0, 99.0) {
"one"
} else {
"other"
Expand Down
57 changes: 28 additions & 29 deletions src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ pub trait ResolveValue {

impl ResolveValue for ast::Message {
fn to_value(&self, env: &Env) -> Option<FluentValue> {
self.value.as_ref().and_then(
|pattern| pattern.to_value(env),
)
self.value
.as_ref()
.and_then(|pattern| pattern.to_value(env))
}
}

Expand All @@ -45,9 +45,8 @@ impl ResolveValue for ast::Pattern {
let string = self.elements
.iter()
.map(|elem| {
elem.to_value(env).map_or(String::from("___"), |elem| {
elem.format(env.ctx)
})
elem.to_value(env)
.map_or(String::from("___"), |elem| elem.format(env.ctx))
})
.collect::<String>();
Some(FluentValue::from(string))
Expand Down Expand Up @@ -88,17 +87,13 @@ impl ResolveValue for ast::Expression {
Some(FluentValue::from(value.clone()))
}
ast::Expression::NumberExpression { ref value } => value.to_value(env),
ast::Expression::MessageReference { ref id } => {
env.ctx
.get_message(&id.name)
.and_then(|message| message.value.as_ref())
.and_then(|pattern| pattern.to_value(env))
}
ast::Expression::ExternalArgument { ref id } => {
env.args
.and_then(|args| args.get(&id.name.as_ref()))
.cloned()
}
ast::Expression::MessageReference { ref id } => env.ctx
.get_message(&id.name)
.and_then(|message| message.value.as_ref())
.and_then(|pattern| pattern.to_value(env)),
ast::Expression::ExternalArgument { ref id } => env.args
.and_then(|args| args.get(&id.name.as_ref()))
.cloned(),
ast::Expression::SelectExpression {
expression: None,
ref variants,
Expand All @@ -107,9 +102,9 @@ impl ResolveValue for ast::Expression {
expression: Some(box ast::Expression::MessageReference { ref id }),
ref variants,
} => {
let tags = env.ctx.get_message(&id.name).and_then(
|message| message.tags.as_ref(),
);
let tags = env.ctx
.get_message(&id.name)
.and_then(|message| message.tags.as_ref());

if let Some(tags) = tags {
for variant in variants {
Expand Down Expand Up @@ -154,9 +149,10 @@ impl ResolveValue for ast::Expression {
select_default(variants).and_then(|variant| variant.value.to_value(env))
}
ast::Expression::AttributeExpression { ref id, ref name } => {
let attributes = env.ctx.get_message(&id.name).as_ref().and_then(|message| {
message.attributes.as_ref()
});
let attributes = env.ctx
.get_message(&id.name)
.as_ref()
.and_then(|message| message.attributes.as_ref());
if let Some(attributes) = attributes {
for attribute in attributes {
if attribute.id.name == name.name {
Expand All @@ -177,11 +173,15 @@ impl ResolveValue for ast::Expression {
}

match pattern.elements.first() {
Some(&ast::PatternElement::Placeable(ast::Placeable {
expression: ast::Expression::SelectExpression {
expression: None, ref variants
}
})) => Some(variants),
Some(
&ast::PatternElement::Placeable(ast::Placeable {
expression:
ast::Expression::SelectExpression {
expression: None,
ref variants,
},
}),
) => Some(variants),
_ => None,
}
});
Expand All @@ -200,7 +200,6 @@ impl ResolveValue for ast::Expression {
.as_ref()
.and_then(|message| message.value.as_ref())
.and_then(|pattern| pattern.to_value(env))

}
_ => unimplemented!(),
}
Expand Down
25 changes: 9 additions & 16 deletions src/syntax/errors/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,8 @@ fn format_slice(
pos += line.chars().count() + 1;
let prev_line_end = pos;

if let Some(label_line) = format_labels(
prev_line_start,
prev_line_end,
max_ln_width,
item,
labels,
)
if let Some(label_line) =
format_labels(prev_line_start, prev_line_end, max_ln_width, item, labels)
{
result += &label_line;
} else if i == lines_num - 1 {
Expand Down Expand Up @@ -150,12 +145,10 @@ fn format_labels(
for label in labels {
if label.start_pos >= start_pos && label.start_pos <= end_pos {
let color = match label.kind {
LabelKind::Primary => {
match *item {
Item::Error(_) => Fixed(9).bold(),
Item::Warning => Fixed(11).bold(),
}
}
LabelKind::Primary => match *item {
Item::Error(_) => Fixed(9).bold(),
Item::Warning => Fixed(11).bold(),
},
LabelKind::Secondary => Fixed(12).bold(),
};

Expand All @@ -173,9 +166,9 @@ fn format_labels(
};
result += &format!(
"{} {}\n",
Fixed(12).bold().paint(
format!("{} |", " ".repeat(max_ln_width)),
),
Fixed(12)
.bold()
.paint(format!("{} |", " ".repeat(max_ln_width)),),
format!("{}{} {}", pad, color.paint(mark), color.paint(label.text))
);
return Some(result);
Expand Down
Loading

0 comments on commit c3bc55b

Please sign in to comment.