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

Commit 996f919

Browse files
djcdavidbarsky
authored andcommitted
Bump MSRV to 1.31.0 + commits from #319 (#329)
* Update proc_macro2, syn, quote * Update MSRV to 1.31.0 as discussed in #319
1 parent 7b7d03c commit 996f919

15 files changed

+79
-72
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
language: rust
22
rust:
3-
- 1.18.0
3+
- 1.31.0
44
- stable
55
- beta
66
- nightly
77
cache: cargo
88
script:
9-
- if [ "$TRAVIS_RUST_VERSION" == "1.18.0" ]; then cp Cargo.lock.ci Cargo.lock; fi
9+
- if [ "$TRAVIS_RUST_VERSION" == "1.31.0" ]; then cp Cargo.lock.ci Cargo.lock; fi
1010
- cargo test
1111
- cargo test --features backtrace
1212
- cargo check --no-default-features

Cargo.lock.ci

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ homepage = "https://rust-lang-nursery.github.io/failure/"
66
license = "MIT OR Apache-2.0"
77
name = "failure"
88
repository = "https://github.com/rust-lang-nursery/failure"
9-
version = "0.1.5"
9+
version = "0.1.6"
1010

1111
[dependencies.failure_derive]
1212
optional = true
13-
version = "0.1.5"
13+
version = "0.1.6"
1414
path = "./failure_derive"
1515

1616
[dependencies.backtrace]

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ pub fn read_toolchains(path: PathBuf) -> Result<Toolchains, Error>
100100
## Requirements
101101

102102
Both failure and failure_derive are intended to compile on all stable versions
103-
of Rust newer than 1.18.0, as well as the latest beta and the latest nightly.
104-
If either crate fails to compile on any version newer than 1.18.0, please open
103+
of Rust newer than 1.31.0, as well as the latest beta and the latest nightly.
104+
If either crate fails to compile on any version newer than 1.31.0, please open
105105
an issue.
106106

107107
failure is **no_std** compatible, though some aspects of it (primarily the

failure_derive/Cargo.toml

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ name = "failure_derive"
66
repository = "https://github.com/withoutboats/failure_derive"
77
homepage = "https://rust-lang-nursery.github.io/failure/"
88
documentation = "https://docs.rs/failure"
9-
version = "0.1.5"
9+
version = "0.1.6"
1010
build = "build.rs"
1111

1212
[dependencies]
13-
quote = "0.6.3"
14-
syn = "0.15.0"
15-
synstructure = "0.10.0"
16-
proc-macro2 = "0.4.8"
13+
quote = "1"
14+
syn = "1.0.3"
15+
synstructure = "0.12.0"
16+
proc-macro2 = "1"
1717

1818
[dev-dependencies.failure]
1919
version = "0.1.0"

failure_derive/src/lib.rs

+23-16
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ impl Error {
2525
}
2626
}
2727

28+
impl From<syn::Error> for Error {
29+
fn from(e: syn::Error) -> Error {
30+
Error(e.to_compile_error())
31+
}
32+
}
33+
2834
decl_derive!([Fail, attributes(fail, cause)] => fail_derive);
2935

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

122128
let format_string = match msg.nested[0] {
123-
syn::NestedMeta::Meta(syn::Meta::NameValue(ref nv)) if nv.ident == "display" => {
129+
syn::NestedMeta::Meta(syn::Meta::NameValue(ref nv)) if nv.path.is_ident("display") => {
124130
nv.lit.clone()
125131
}
126132
_ => {
@@ -131,12 +137,12 @@ fn display_body(s: &synstructure::Structure) -> Result<Option<quote::__rt::Token
131137
}
132138
};
133139
let args = msg.nested.iter().skip(1).map(|arg| match *arg {
134-
syn::NestedMeta::Literal(syn::Lit::Int(ref i)) => {
135-
let bi = &v.bindings()[i.value() as usize];
140+
syn::NestedMeta::Lit(syn::Lit::Int(ref i)) => {
141+
let bi = &v.bindings()[i.base10_parse::<usize>()?];
136142
Ok(quote!(#bi))
137143
}
138-
syn::NestedMeta::Meta(syn::Meta::Word(ref id)) => {
139-
let id_s = id.to_string();
144+
syn::NestedMeta::Meta(syn::Meta::Path(ref path)) => {
145+
let id_s = path.get_ident().map(syn::Ident::to_string).unwrap_or("".to_string());
140146
if id_s.starts_with("_") {
141147
if let Ok(idx) = id_s[1..].parse::<usize>() {
142148
let bi = match v.bindings().get(idx) {
@@ -160,15 +166,16 @@ fn display_body(s: &synstructure::Structure) -> Result<Option<quote::__rt::Token
160166
}
161167
}
162168
for bi in v.bindings() {
163-
if bi.ast().ident.as_ref() == Some(id) {
169+
let id = bi.ast().ident.as_ref();
170+
if id.is_some() && path.is_ident(id.unwrap()) {
164171
return Ok(quote!(#bi));
165172
}
166173
}
167174
return Err(Error::new(
168175
arg.span(),
169176
&format!(
170-
"Couldn't find field `{}` in `{}::{}`",
171-
id,
177+
"Couldn't find field `{:?}` in `{}::{}`",
178+
path,
172179
s.ast().ident,
173180
v.ast().ident
174181
)
@@ -192,8 +199,8 @@ fn display_body(s: &synstructure::Structure) -> Result<Option<quote::__rt::Token
192199
fn find_error_msg(attrs: &[syn::Attribute]) -> Result<Option<syn::MetaList>, Error> {
193200
let mut error_msg = None;
194201
for attr in attrs {
195-
if let Some(meta) = attr.interpret_meta() {
196-
if meta.name() == "fail" {
202+
if let Ok(meta) = attr.parse_meta() {
203+
if meta.path().is_ident("fail") {
197204
if error_msg.is_some() {
198205
return Err(Error::new(
199206
meta.span(),
@@ -223,7 +230,7 @@ fn is_backtrace(bi: &&synstructure::BindingInfo) -> bool {
223230
segments: ref path, ..
224231
},
225232
}) => path.last().map_or(false, |s| {
226-
s.value().ident == "Backtrace" && s.value().arguments.is_empty()
233+
s.ident == "Backtrace" && s.arguments.is_empty()
227234
}),
228235
_ => false,
229236
}
@@ -232,18 +239,18 @@ fn is_backtrace(bi: &&synstructure::BindingInfo) -> bool {
232239
fn is_cause(bi: &&synstructure::BindingInfo) -> bool {
233240
let mut found_cause = false;
234241
for attr in &bi.ast().attrs {
235-
if let Some(meta) = attr.interpret_meta() {
236-
if meta.name() == "cause" {
242+
if let Ok(meta) = attr.parse_meta() {
243+
if meta.path().is_ident("cause") {
237244
if found_cause {
238245
panic!("Cannot have two `cause` attributes");
239246
}
240247
found_cause = true;
241248
}
242-
if meta.name() == "fail" {
249+
if meta.path().is_ident("fail") {
243250
if let syn::Meta::List(ref list) = meta {
244251
if let Some(ref pair) = list.nested.first() {
245-
if let &&syn::NestedMeta::Meta(syn::Meta::Word(ref word)) = pair.value() {
246-
if word == "cause" {
252+
if let &&syn::NestedMeta::Meta(syn::Meta::Path(ref path)) = pair {
253+
if path.is_ident("cause") {
247254
if found_cause {
248255
panic!("Cannot have two `cause` attributes");
249256
}

failure_derive/tests/wraps.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ fn wrap_backtrace_error() {
5858
.and_then(|err| err.downcast_ref::<io::Error>())
5959
.is_some());
6060
assert!(err.backtrace().is_some());
61-
assert!(err.backtrace().is_empty());
62-
assert_eq!(err.backtrace().is_empty(), err.backtrace().to_string().trim().is_empty());
61+
assert!(err.backtrace().unwrap().is_empty());
62+
assert!(err.backtrace().unwrap().to_string().trim().is_empty());
6363
}
6464

6565
#[derive(Fail, Debug)]
@@ -93,6 +93,6 @@ fn wrap_enum_error() {
9393
.and_then(|err| err.downcast_ref::<fmt::Error>())
9494
.is_some());
9595
assert!(err.backtrace().is_some());
96-
assert!(err.backtrace().is_empty());
97-
assert_eq!(err.backtrace().is_empty(), err.backtrace().to_string().trim().is_empty());
96+
assert!(err.backtrace().unwrap().is_empty());
97+
assert!(err.backtrace().unwrap().to_string().trim().is_empty());
9898
}

src/as_fail.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ use Fail;
88
/// custom cause.
99
pub trait AsFail {
1010
/// Converts a reference to `Self` into a dynamic trait object of `Fail`.
11-
fn as_fail(&self) -> &Fail;
11+
fn as_fail(&self) -> &dyn Fail;
1212
}
1313

1414
impl<T> AsFail for T
1515
where
1616
T: Fail,
1717
{
18-
fn as_fail(&self) -> &Fail {
18+
fn as_fail(&self) -> &dyn Fail {
1919
self
2020
}
2121
}
2222

23-
impl AsFail for Fail {
24-
fn as_fail(&self) -> &Fail {
23+
impl AsFail for dyn Fail {
24+
fn as_fail(&self) -> &dyn Fail {
2525
self
2626
}
2727
}
@@ -30,7 +30,7 @@ with_std! {
3030
use error::Error;
3131

3232
impl AsFail for Error {
33-
fn as_fail(&self) -> &Fail {
33+
fn as_fail(&self) -> &dyn Fail {
3434
self.as_fail()
3535
}
3636
}

src/box_std.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::error::Error;
22
use std::fmt;
33
use Fail;
44

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

77
impl fmt::Display for BoxStd {
88
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {

src/compat.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ with_std! {
3939
}
4040
}
4141

42-
impl From<Error> for Box<StdError> {
43-
fn from(error: Error) -> Box<StdError> {
42+
impl From<Error> for Box<dyn StdError> {
43+
fn from(error: Error) -> Box<dyn StdError> {
4444
Box::new(Compat { error })
4545
}
4646
}
4747

48-
impl From<Error> for Box<StdError + Send + Sync> {
49-
fn from(error: Error) -> Box<StdError + Send + Sync> {
48+
impl From<Error> for Box<dyn StdError + Send + Sync> {
49+
fn from(error: Error) -> Box<dyn StdError + Send + Sync> {
5050
Box::new(Compat { error })
5151
}
5252
}

src/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ with_std! {
112112
self.failure.as_cause().and_then(|x| x.name())
113113
}
114114

115-
fn cause(&self) -> Option<&Fail> {
115+
fn cause(&self) -> Option<&dyn Fail> {
116116
self.failure.as_cause()
117117
}
118118

@@ -146,7 +146,7 @@ with_std! {
146146
}
147147
}
148148

149-
fn as_cause(&self) -> Option<&Fail> {
149+
fn as_cause(&self) -> Option<&dyn Fail> {
150150
match *self {
151151
Either::This(_) => None,
152152
Either::That(ref error) => Some(error.as_fail())

src/error/error_impl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use Fail;
44
use backtrace::Backtrace;
55

66
pub(crate) struct ErrorImpl {
7-
inner: Box<Inner<Fail>>,
7+
inner: Box<Inner<dyn Fail>>,
88
}
99

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

2727
impl ErrorImpl {
28-
pub(crate) fn failure(&self) -> &Fail {
28+
pub(crate) fn failure(&self) -> &dyn Fail {
2929
&self.inner.failure
3030
}
3131

32-
pub(crate) fn failure_mut(&mut self) -> &mut Fail {
32+
pub(crate) fn failure_mut(&mut self) -> &mut dyn Fail {
3333
&mut self.inner.failure
3434
}
3535

src/error/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ impl Error {
6060
/// }
6161
/// ```
6262
#[cfg(feature = "std")]
63-
pub fn from_boxed_compat(err: Box<StdError + Sync + Send + 'static>) -> Error {
63+
pub fn from_boxed_compat(err: Box<dyn StdError + Sync + Send + 'static>) -> Error {
6464
Error::from(BoxStd(err))
6565
}
6666

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

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

@@ -133,7 +133,7 @@ impl Error {
133133

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

@@ -173,7 +173,7 @@ impl Error {
173173

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

@@ -201,8 +201,8 @@ impl Debug for Error {
201201
}
202202
}
203203

204-
impl AsRef<Fail> for Error {
205-
fn as_ref(&self) -> &Fail {
204+
impl AsRef<dyn Fail> for Error {
205+
fn as_ref(&self) -> &dyn Fail {
206206
self.as_fail()
207207
}
208208
}

0 commit comments

Comments
 (0)