Skip to content

Commit eb9ba6e

Browse files
committed
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 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.
1 parent 339af70 commit eb9ba6e

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

examples/quickstart.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ fn run() -> Result<()> {
5353
use std::fs::File;
5454

5555
// This operation will fail
56-
File::open("tretrete")
57-
.chain_err(|| "unable to open tretrete file")?;
56+
try!(File::open("tretrete").chain_err(|| "unable to open tretrete file"));
5857

5958
Ok(())
6059
}

examples/size.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,14 @@ fn main() {
2121
println!(" ErrorKind::Msg: {}", size_of_val(&msg));
2222
println!(" String: {}", size_of::<String>());
2323
println!(" State: {}", size_of::<error_chain::State>());
24+
let state = error_chain::State::default();
25+
println!(" State.next_error: {}", size_of_val(&state.next_error));
2426
#[cfg(feature = "backtrace")]
25-
{
26-
let state = error_chain::State {
27-
next_error: None,
28-
backtrace: None,
29-
};
30-
println!(" State.next_error: {}", size_of_val(&state.next_error));
27+
fn size_of_backtrace() {
28+
let state = error_chain::State::default();
3129
println!(" State.backtrace: {}", size_of_val(&state.backtrace));
3230
}
3331
#[cfg(not(feature = "backtrace"))]
34-
{
35-
let state = error_chain::State {
36-
next_error: None,
37-
};
38-
println!(" State.next_error: {}", size_of_val(&state.next_error));
39-
}
32+
fn size_of_backtrace() {}
33+
size_of_backtrace();
4034
}

tests/tests.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,18 @@ fn has_backtrace_depending_on_env() {
236236

237237
#[test]
238238
fn chain_err() {
239-
use std::fmt;
239+
use std::env;
240240

241241
error_chain! {
242242
foreign_links {
243-
Fmt(fmt::Error);
243+
Var(env::VarError);
244244
}
245245
errors {
246246
Test
247247
}
248248
}
249249

250-
let _: Result<()> = Err(fmt::Error).chain_err(|| "");
250+
let _: Result<()> = Err(env::VarError::NotPresent).chain_err(|| "");
251251
let _: Result<()> = Err(Error::from_kind(ErrorKind::Test)).chain_err(|| "");
252252
}
253253

@@ -262,6 +262,8 @@ fn links() {
262262
Test(test::Error, test::ErrorKind);
263263
}
264264
}
265+
266+
{}
265267
}
266268

267269
#[cfg(test)]
@@ -435,6 +437,8 @@ fn documentation() {
435437
Variant
436438
}
437439
}
440+
441+
{}
438442
}
439443

440444
#[cfg(test)]
@@ -469,6 +473,8 @@ fn rustup_regression() {
469473
}
470474
}
471475
}
476+
477+
{}
472478
}
473479

474480
#[test]
@@ -503,6 +509,8 @@ fn error_first() {
503509

504510
foreign_links { }
505511
}
512+
513+
{}
506514
}
507515

508516
#[test]

0 commit comments

Comments
 (0)