Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Format code with 'cargo fmt' #307

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 17 additions & 17 deletions failure_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ extern crate synstructure;
#[macro_use]
extern crate quote;

use proc_macro2::{TokenStream, Span};
use syn::LitStr;
use proc_macro2::{Span, TokenStream};
use syn::spanned::Spanned;
use syn::LitStr;

#[derive(Debug)]
struct Error(TokenStream);
Expand Down Expand Up @@ -106,16 +106,16 @@ fn display_body(s: &synstructure::Structure) -> Result<Option<quote::__rt::Token

let mut tokens = TokenStream::new();
for v in s.variants() {
let msg =
find_error_msg(&v.ast().attrs)?
.ok_or_else(|| Error::new(
v.ast().ident.span(),
"All variants must have display attribute."
))?;
let msg = find_error_msg(&v.ast().attrs)?.ok_or_else(|| {
Error::new(
v.ast().ident.span(),
"All variants must have display attribute.",
)
})?;
if msg.nested.is_empty() {
return Err(Error::new(
msg.span(),
"Expected at least one argument to fail attribute"
"Expected at least one argument to fail attribute",
));
}

Expand All @@ -126,7 +126,7 @@ fn display_body(s: &synstructure::Structure) -> Result<Option<quote::__rt::Token
_ => {
return Err(Error::new(
msg.span(),
"Fail attribute must begin `display = \"\"` to control the Display message."
"Fail attribute must begin `display = \"\"` to control the Display message.",
));
}
};
Expand All @@ -146,13 +146,13 @@ fn display_body(s: &synstructure::Structure) -> Result<Option<quote::__rt::Token
arg.span(),
&format!(
"display attempted to access field `{}` in `{}::{}` which \
does not exist (there are {} field{})",
does not exist (there are {} field{})",
idx,
s.ast().ident,
v.ast().ident,
v.bindings().len(),
if v.bindings().len() != 1 { "s" } else { "" }
)
),
));
}
};
Expand All @@ -171,15 +171,15 @@ fn display_body(s: &synstructure::Structure) -> Result<Option<quote::__rt::Token
id,
s.ast().ident,
v.ast().ident
)
),
));
}
ref arg => {
return Err(Error::new(
arg.span(),
"Invalid argument to fail attribute!"
"Invalid argument to fail attribute!",
));
},
}
});
let args = args.collect::<Result<Vec<_>, _>>()?;

Expand All @@ -197,15 +197,15 @@ fn find_error_msg(attrs: &[syn::Attribute]) -> Result<Option<syn::MetaList>, Err
if error_msg.is_some() {
return Err(Error::new(
meta.span(),
"Cannot have two display attributes"
"Cannot have two display attributes",
));
} else {
if let syn::Meta::List(list) = meta {
error_msg = Some(list);
} else {
return Err(Error::new(
meta.span(),
"fail attribute must take a list in parentheses"
"fail attribute must take a list in parentheses",
));
}
}
Expand Down
10 changes: 8 additions & 2 deletions failure_derive/tests/wraps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ fn wrap_backtrace_error() {
.is_some());
assert!(err.backtrace().is_some());
assert!(err.backtrace().is_empty());
assert_eq!(err.backtrace().is_empty(), err.backtrace().to_string().trim().is_empty());
assert_eq!(
err.backtrace().is_empty(),
err.backtrace().to_string().trim().is_empty()
);
}

#[derive(Fail, Debug)]
Expand Down Expand Up @@ -94,5 +97,8 @@ fn wrap_enum_error() {
.is_some());
assert!(err.backtrace().is_some());
assert!(err.backtrace().is_empty());
assert_eq!(err.backtrace().is_empty(), err.backtrace().to_string().trim().is_empty());
assert_eq!(
err.backtrace().is_empty(),
err.backtrace().to_string().trim().is_empty()
);
}
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ with_std! {
/// `Fail` by a blanket impl.
pub trait Fail: Display + Debug + Send + Sync + 'static {
/// Returns the "name" of the error.
///
///
/// This is typically the type name. Not all errors will implement
/// this. This method is expected to be most useful in situations
/// where errors need to be reported to external instrumentation systems
/// where errors need to be reported to external instrumentation systems
/// such as crash reporters.
fn name(&self) -> Option<&str> {
None
Expand Down
2 changes: 1 addition & 1 deletion tests/basic_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ fn test_name() {

assert_eq!(ctx.to_string(), "whatever");
assert_eq!(ctx.name(), Some("basic_fail::MyError"));
}
}
28 changes: 17 additions & 11 deletions tests/macro_trailing_comma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,41 +27,47 @@ macro_rules! wrap_early_return {
fn bail() {
assert_eq!(
wrap_early_return!(bail!("test")),
wrap_early_return!(bail!("test",)));
wrap_early_return!(bail!("test",))
);
assert_eq!(
wrap_early_return!(bail!("test {}", 4)),
wrap_early_return!(bail!("test {}", 4,)));
wrap_early_return!(bail!("test {}", 4,))
);
}

#[test]
fn ensure() {
assert_eq!(
wrap_early_return!(ensure!(false, "test")),
wrap_early_return!(ensure!(false, "test",)));
wrap_early_return!(ensure!(false, "test",))
);
assert_eq!(
wrap_early_return!(ensure!(false, "test {}", 4)),
wrap_early_return!(ensure!(false, "test {}", 4,)));
wrap_early_return!(ensure!(false, "test {}", 4,))
);
}

#[test]
fn single_arg_ensure() {
assert_eq!(
wrap_early_return!(ensure!(false)),
Err("false".to_string()));
assert_eq!(wrap_early_return!(ensure!(false)), Err("false".to_string()));
assert_eq!(
wrap_early_return!(ensure!(true == false)),
Err("true == false".to_string()));
Err("true == false".to_string())
);
assert_eq!(
wrap_early_return!(ensure!(4 == 5)),
Err("4 == 5".to_string()));
Err("4 == 5".to_string())
);
}

#[test]
fn format_err() {
assert_eq!(
format_err!("test").to_string(),
format_err!("test",).to_string());
format_err!("test",).to_string()
);
assert_eq!(
format_err!("test {}", 4).to_string(),
format_err!("test {}", 4,).to_string());
format_err!("test {}", 4,).to_string()
);
}