From c52440b3533d3a4a608b58deb732b1fa13f9f851 Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Sat, 24 Dec 2016 20:28:42 -0800 Subject: [PATCH] WIP: Make tests and examples compile with Rust 1.10 - Avoid using attributes on statements; use them on items instead. - Change a test to use std::env::VarError instead of std::fmt::Error, because the latter didn't impl Error until Rust 1.11. - Add an empty block after invocations of `error_chain!` inside functions, to work around https://github.com/rust-lang/rust/pull/34436 (fixed in Rust 1.11). - Replace a single instance of `?` with `try!`. This still fails to work with 1.10 due to https://github.com/rust-lang/rust/issues/22250 . Because of that issue, an invocation of `#[derive(Debug)]` inside a macro doesn't take cfg(...) attributes into account, and fails to compile due to referencing enum variants that don't exist. Posted for reference only. --- examples/quickstart.rs | 3 +-- examples/size.rs | 5 +++-- tests/tests.rs | 14 +++++++++++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/examples/quickstart.rs b/examples/quickstart.rs index 7c53ad3eb..0b0a20749 100644 --- a/examples/quickstart.rs +++ b/examples/quickstart.rs @@ -53,8 +53,7 @@ fn run() -> Result<()> { use std::fs::File; // This operation will fail - File::open("tretrete") - .chain_err(|| "unable to open tretrete file")?; + try!(File::open("tretrete").chain_err(|| "unable to open tretrete file")); Ok(()) } diff --git a/examples/size.rs b/examples/size.rs index 01f677b49..337ca32a1 100644 --- a/examples/size.rs +++ b/examples/size.rs @@ -22,7 +22,7 @@ fn main() { println!(" String: {}", size_of::()); println!(" State: {}", size_of::()); #[cfg(feature = "backtrace")] - { + fn size_of_state() { let state = error_chain::State { next_error: None, backtrace: None, @@ -31,10 +31,11 @@ fn main() { println!(" State.backtrace: {}", size_of_val(&state.backtrace)); } #[cfg(not(feature = "backtrace"))] - { + fn size_of_state() { let state = error_chain::State { next_error: None, }; println!(" State.next_error: {}", size_of_val(&state.next_error)); } + size_of_state(); } diff --git a/tests/tests.rs b/tests/tests.rs index 1d7544c33..cc61d1eb2 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -236,18 +236,18 @@ fn has_backtrace_depending_on_env() { #[test] fn chain_err() { - use std::fmt; + use std::env; error_chain! { foreign_links { - Fmt(fmt::Error); + Var(env::VarError); } errors { Test } } - let _: Result<()> = Err(fmt::Error).chain_err(|| ""); + let _: Result<()> = Err(env::VarError::NotPresent).chain_err(|| ""); let _: Result<()> = Err(Error::from_kind(ErrorKind::Test)).chain_err(|| ""); } @@ -262,6 +262,8 @@ fn links() { Test(test::Error, test::ErrorKind); } } + + {} } #[cfg(test)] @@ -435,6 +437,8 @@ fn documentation() { Variant } } + + {} } #[cfg(test)] @@ -469,6 +473,8 @@ fn rustup_regression() { } } } + + {} } #[test] @@ -503,6 +509,8 @@ fn error_first() { foreign_links { } } + + {} } #[test]