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

Update proc_macro2, syn, etc #319

Closed
wants to merge 2 commits into from
Closed
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 Cargo.lock.ci

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ homepage = "https://rust-lang-nursery.github.io/failure/"
license = "MIT OR Apache-2.0"
name = "failure"
repository = "https://github.com/rust-lang-nursery/failure"
version = "0.1.5"
version = "0.1.6"

[dependencies.failure_derive]
optional = true
version = "0.1.5"
version = "0.1.6"
path = "./failure_derive"

[dependencies.backtrace]
Expand Down
10 changes: 5 additions & 5 deletions failure_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ name = "failure_derive"
repository = "https://github.com/withoutboats/failure_derive"
homepage = "https://rust-lang-nursery.github.io/failure/"
documentation = "https://docs.rs/failure"
version = "0.1.5"
version = "0.1.6"
build = "build.rs"

[dependencies]
quote = "0.6.3"
syn = "0.15.0"
synstructure = "0.10.0"
proc-macro2 = "0.4.8"
quote = "1"
syn = "1.0.3"
synstructure = "0.12.0"
proc-macro2 = "1"

[dev-dependencies.failure]
version = "0.1.0"
Expand Down
39 changes: 23 additions & 16 deletions failure_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ impl Error {
}
}

impl From<syn::Error> for Error {
fn from(e: syn::Error) -> Error {
Error(e.to_compile_error())
}
}

decl_derive!([Fail, attributes(fail, cause)] => fail_derive);

fn fail_derive(s: synstructure::Structure) -> TokenStream {
Expand Down Expand Up @@ -120,7 +126,7 @@ fn display_body(s: &synstructure::Structure) -> Result<Option<quote::__rt::Token
}

let format_string = match msg.nested[0] {
syn::NestedMeta::Meta(syn::Meta::NameValue(ref nv)) if nv.ident == "display" => {
syn::NestedMeta::Meta(syn::Meta::NameValue(ref nv)) if nv.path.is_ident("display") => {
nv.lit.clone()
}
_ => {
Expand All @@ -131,12 +137,12 @@ fn display_body(s: &synstructure::Structure) -> Result<Option<quote::__rt::Token
}
};
let args = msg.nested.iter().skip(1).map(|arg| match *arg {
syn::NestedMeta::Literal(syn::Lit::Int(ref i)) => {
let bi = &v.bindings()[i.value() as usize];
syn::NestedMeta::Lit(syn::Lit::Int(ref i)) => {
let bi = &v.bindings()[i.base10_parse::<usize>()?];
Ok(quote!(#bi))
}
syn::NestedMeta::Meta(syn::Meta::Word(ref id)) => {
let id_s = id.to_string();
syn::NestedMeta::Meta(syn::Meta::Path(ref path)) => {
let id_s = path.get_ident().map(syn::Ident::to_string).unwrap_or("".to_string());
if id_s.starts_with("_") {
if let Ok(idx) = id_s[1..].parse::<usize>() {
let bi = match v.bindings().get(idx) {
Expand All @@ -160,15 +166,16 @@ fn display_body(s: &synstructure::Structure) -> Result<Option<quote::__rt::Token
}
}
for bi in v.bindings() {
if bi.ast().ident.as_ref() == Some(id) {
let id = bi.ast().ident.as_ref();
if id.is_some() && path.is_ident(id.unwrap()) {
return Ok(quote!(#bi));
}
}
return Err(Error::new(
arg.span(),
&format!(
"Couldn't find field `{}` in `{}::{}`",
id,
"Couldn't find field `{:?}` in `{}::{}`",
path,
s.ast().ident,
v.ast().ident
)
Expand All @@ -192,8 +199,8 @@ fn display_body(s: &synstructure::Structure) -> Result<Option<quote::__rt::Token
fn find_error_msg(attrs: &[syn::Attribute]) -> Result<Option<syn::MetaList>, Error> {
let mut error_msg = None;
for attr in attrs {
if let Some(meta) = attr.interpret_meta() {
if meta.name() == "fail" {
if let Ok(meta) = attr.parse_meta() {
if meta.path().is_ident("fail") {
if error_msg.is_some() {
return Err(Error::new(
meta.span(),
Expand Down Expand Up @@ -223,7 +230,7 @@ fn is_backtrace(bi: &&synstructure::BindingInfo) -> bool {
segments: ref path, ..
},
}) => path.last().map_or(false, |s| {
s.value().ident == "Backtrace" && s.value().arguments.is_empty()
s.ident == "Backtrace" && s.arguments.is_empty()
}),
_ => false,
}
Expand All @@ -232,18 +239,18 @@ fn is_backtrace(bi: &&synstructure::BindingInfo) -> bool {
fn is_cause(bi: &&synstructure::BindingInfo) -> bool {
let mut found_cause = false;
for attr in &bi.ast().attrs {
if let Some(meta) = attr.interpret_meta() {
if meta.name() == "cause" {
if let Ok(meta) = attr.parse_meta() {
if meta.path().is_ident("cause") {
if found_cause {
panic!("Cannot have two `cause` attributes");
}
found_cause = true;
}
if meta.name() == "fail" {
if meta.path().is_ident("fail") {
if let syn::Meta::List(ref list) = meta {
if let Some(ref pair) = list.nested.first() {
if let &&syn::NestedMeta::Meta(syn::Meta::Word(ref word)) = pair.value() {
if word == "cause" {
if let &&syn::NestedMeta::Meta(syn::Meta::Path(ref path)) = pair {
if path.is_ident("cause") {
if found_cause {
panic!("Cannot have two `cause` attributes");
}
Expand Down
8 changes: 4 additions & 4 deletions failure_derive/tests/wraps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ fn wrap_backtrace_error() {
.and_then(|err| err.downcast_ref::<io::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!(err.backtrace().unwrap().is_empty());
assert!(err.backtrace().unwrap().to_string().trim().is_empty());
}

#[derive(Fail, Debug)]
Expand Down Expand Up @@ -93,6 +93,6 @@ fn wrap_enum_error() {
.and_then(|err| err.downcast_ref::<fmt::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!(err.backtrace().unwrap().is_empty());
assert!(err.backtrace().unwrap().to_string().trim().is_empty());
}
10 changes: 5 additions & 5 deletions src/as_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ use Fail;
/// custom cause.
pub trait AsFail {
/// Converts a reference to `Self` into a dynamic trait object of `Fail`.
fn as_fail(&self) -> &Fail;
fn as_fail(&self) -> &dyn Fail;
}

impl<T> AsFail for T
where
T: Fail,
{
fn as_fail(&self) -> &Fail {
fn as_fail(&self) -> &dyn Fail {
self
}
}

impl AsFail for Fail {
fn as_fail(&self) -> &Fail {
impl AsFail for dyn Fail {
fn as_fail(&self) -> &dyn Fail {
self
}
}
Expand All @@ -30,7 +30,7 @@ with_std! {
use error::Error;

impl AsFail for Error {
fn as_fail(&self) -> &Fail {
fn as_fail(&self) -> &dyn Fail {
self.as_fail()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/box_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::error::Error;
use std::fmt;
use Fail;

pub struct BoxStd(pub Box<Error + Send + Sync + 'static>);
pub struct BoxStd(pub Box<dyn Error + Send + Sync + 'static>);

impl fmt::Display for BoxStd {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Expand Down
8 changes: 4 additions & 4 deletions src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ with_std! {
}
}

impl From<Error> for Box<StdError> {
fn from(error: Error) -> Box<StdError> {
impl From<Error> for Box<dyn StdError> {
fn from(error: Error) -> Box<dyn StdError> {
Box::new(Compat { error })
}
}

impl From<Error> for Box<StdError + Send + Sync> {
fn from(error: Error) -> Box<StdError + Send + Sync> {
impl From<Error> for Box<dyn StdError + Send + Sync> {
fn from(error: Error) -> Box<dyn StdError + Send + Sync> {
Box::new(Compat { error })
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ with_std! {
self.failure.as_cause().and_then(|x| x.name())
}

fn cause(&self) -> Option<&Fail> {
fn cause(&self) -> Option<&dyn Fail> {
self.failure.as_cause()
}

Expand Down Expand Up @@ -146,7 +146,7 @@ with_std! {
}
}

fn as_cause(&self) -> Option<&Fail> {
fn as_cause(&self) -> Option<&dyn Fail> {
match *self {
Either::This(_) => None,
Either::That(ref error) => Some(error.as_fail())
Expand Down
6 changes: 3 additions & 3 deletions src/error/error_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Fail;
use backtrace::Backtrace;

pub(crate) struct ErrorImpl {
inner: Box<Inner<Fail>>,
inner: Box<Inner<dyn Fail>>,
}

struct Inner<F: ?Sized + Fail> {
Expand All @@ -25,11 +25,11 @@ impl<F: Fail> From<F> for ErrorImpl {
}

impl ErrorImpl {
pub(crate) fn failure(&self) -> &Fail {
pub(crate) fn failure(&self) -> &dyn Fail {
&self.inner.failure
}

pub(crate) fn failure_mut(&mut self) -> &mut Fail {
pub(crate) fn failure_mut(&mut self) -> &mut dyn Fail {
&mut self.inner.failure
}

Expand Down
14 changes: 7 additions & 7 deletions src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ impl Error {
/// }
/// ```
#[cfg(feature = "std")]
pub fn from_boxed_compat(err: Box<StdError + Sync + Send + 'static>) -> Error {
pub fn from_boxed_compat(err: Box<dyn StdError + Sync + Send + 'static>) -> Error {
Error::from(BoxStd(err))
}

/// Return a reference to the underlying failure that this `Error`
/// contains.
pub fn as_fail(&self) -> &Fail {
pub fn as_fail(&self) -> &dyn Fail {
self.imp.failure()
}

Expand All @@ -82,7 +82,7 @@ impl Error {
/// This method has been deprecated in favor of the [Error::as_fail] method,
/// which does the same thing.
#[deprecated(since = "0.1.2", note = "please use 'as_fail()' method instead")]
pub fn cause(&self) -> &Fail {
pub fn cause(&self) -> &dyn Fail {
self.as_fail()
}

Expand Down Expand Up @@ -133,7 +133,7 @@ impl Error {

/// Returns the "root cause" of this error - the last value in the
/// cause chain which does not return an underlying `cause`.
pub fn find_root_cause(&self) -> &Fail {
pub fn find_root_cause(&self) -> &dyn Fail {
self.as_fail().find_root_cause()
}

Expand Down Expand Up @@ -173,7 +173,7 @@ impl Error {

/// Deprecated alias to `find_root_cause`.
#[deprecated(since = "0.1.2", note = "please use the 'find_root_cause()' method instead")]
pub fn root_cause(&self) -> &Fail {
pub fn root_cause(&self) -> &dyn Fail {
::find_root_cause(self.as_fail())
}

Expand Down Expand Up @@ -201,8 +201,8 @@ impl Debug for Error {
}
}

impl AsRef<Fail> for Error {
fn as_ref(&self) -> &Fail {
impl AsRef<dyn Fail> for Error {
fn as_ref(&self) -> &dyn Fail {
self.as_fail()
}
}
Expand Down
Loading