Skip to content

Commit

Permalink
WIP: Make tests and examples compile with Rust 1.10
Browse files Browse the repository at this point in the history
- 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 rust-lang/rust#34436
  (fixed in Rust 1.11).

- Replace a single instance of `?` with `try!`.

This still fails to work with 1.10 due to
rust-lang/rust#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.
  • Loading branch information
joshtriplett committed Dec 25, 2016
1 parent 339af70 commit eb9ba6e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
3 changes: 1 addition & 2 deletions examples/quickstart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
18 changes: 6 additions & 12 deletions examples/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,14 @@ fn main() {
println!(" ErrorKind::Msg: {}", size_of_val(&msg));
println!(" String: {}", size_of::<String>());
println!(" State: {}", size_of::<error_chain::State>());
let state = error_chain::State::default();
println!(" State.next_error: {}", size_of_val(&state.next_error));
#[cfg(feature = "backtrace")]
{
let state = error_chain::State {
next_error: None,
backtrace: None,
};
println!(" State.next_error: {}", size_of_val(&state.next_error));
fn size_of_backtrace() {
let state = error_chain::State::default();
println!(" State.backtrace: {}", size_of_val(&state.backtrace));
}
#[cfg(not(feature = "backtrace"))]
{
let state = error_chain::State {
next_error: None,
};
println!(" State.next_error: {}", size_of_val(&state.next_error));
}
fn size_of_backtrace() {}
size_of_backtrace();
}
14 changes: 11 additions & 3 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(|| "");
}

Expand All @@ -262,6 +262,8 @@ fn links() {
Test(test::Error, test::ErrorKind);
}
}

{}
}

#[cfg(test)]
Expand Down Expand Up @@ -435,6 +437,8 @@ fn documentation() {
Variant
}
}

{}
}

#[cfg(test)]
Expand Down Expand Up @@ -469,6 +473,8 @@ fn rustup_regression() {
}
}
}

{}
}

#[test]
Expand Down Expand Up @@ -503,6 +509,8 @@ fn error_first() {

foreign_links { }
}

{}
}

#[test]
Expand Down

0 comments on commit eb9ba6e

Please sign in to comment.