Skip to content

Commit c52440b

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 c52440b

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
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

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn main() {
2222
println!(" String: {}", size_of::<String>());
2323
println!(" State: {}", size_of::<error_chain::State>());
2424
#[cfg(feature = "backtrace")]
25-
{
25+
fn size_of_state() {
2626
let state = error_chain::State {
2727
next_error: None,
2828
backtrace: None,
@@ -31,10 +31,11 @@ fn main() {
3131
println!(" State.backtrace: {}", size_of_val(&state.backtrace));
3232
}
3333
#[cfg(not(feature = "backtrace"))]
34-
{
34+
fn size_of_state() {
3535
let state = error_chain::State {
3636
next_error: None,
3737
};
3838
println!(" State.next_error: {}", size_of_val(&state.next_error));
3939
}
40+
size_of_state();
4041
}

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)