Skip to content

Commit 17b4fd8

Browse files
authored
Merge pull request #137 from azriel91/compatibility/rust-1-18
Maintain compatibility with Rust 1.25
2 parents 962a57f + 2f27cff commit 17b4fd8

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

.travis.yml

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ matrix:
4343
- rust: nightly
4444
script: *test_all
4545

46+
# Make sure the default crate builds with 1.25.0
47+
- rust: 1.25.0
48+
script: cargo test
49+
4650
# Upload docs on nightly
4751
- rust: nightly
4852
script:

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ winapi = { version = "0.3.3", features = ["dbghelp", "processthreadsapi", "winnt
4141
[target.'cfg(all(unix, not(target_os = "fuchsia"), not(target_os = "emscripten"), not(target_os = "macos"), not(target_os = "ios")))'.dependencies]
4242
backtrace-sys = { path = "backtrace-sys", version = "0.1.17", optional = true }
4343

44+
[build-dependencies]
45+
autocfg = "0.1"
46+
4447
# Each feature controls the two phases of finding a backtrace: getting a
4548
# backtrace and then resolving instruction pointers to symbols. The default
4649
# feature enables all the necessary features for each platform this library

build.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
extern crate autocfg;
2+
3+
fn main() {
4+
let ac = autocfg::new();
5+
6+
// ffi types moved from `std` to `core` in Rust 1.30, so we need to adjust imports based on
7+
// this.
8+
//
9+
// <https://github.com/rust-lang/rust/pull/53910>
10+
ac.emit_rustc_version(1, 30);
11+
12+
println!("cargo:rerun-if-changed=build.rs");
13+
}

src/symbolize/dbghelp.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@
1010

1111
#![allow(bad_style)]
1212

13+
// This is a hack for compatibility with rustc 1.25.0. The no_std mode of this
14+
// crate is not supported pre-1.30.0, but in std mode the `char` module here
15+
// moved in rustc 1.26.0 (ish). As a result, in std mode we use `std::char` to
16+
// retain compatibility with rustc 1.25.0, but in `no_std` mode (which is
17+
// 1.30.0+ already) we use `core::char`.
18+
#[cfg(feature = "std")]
19+
use std::char;
20+
#[cfg(not(feature = "std"))]
21+
use core::char;
22+
1323
use core::mem;
1424
use core::slice;
15-
use core::char;
1625

1726
use winapi::ctypes::*;
1827
use winapi::shared::basetsd::*;

src/types.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ cfg_if! {
77
use std::fmt;
88
use std::path::PathBuf;
99
use std::prelude::v1::*;
10-
} else {
10+
} else if #[cfg(rustc_1_30)] {
1111
pub use core::ffi::c_void;
12+
} else {
13+
compile_error!("`backtrace` requires Rust >=1.30.0 to support `no_std`.");
1214
}
1315
}
1416

@@ -31,8 +33,8 @@ impl<'a> BytesOrWideString<'a> {
3133
use self::BytesOrWideString::*;
3234

3335
match self {
34-
Bytes(slice) => String::from_utf8_lossy(slice),
35-
Wide(wide) => Cow::Owned(String::from_utf16_lossy(wide)),
36+
&Bytes(slice) => String::from_utf8_lossy(slice),
37+
&Wide(wide) => Cow::Owned(String::from_utf16_lossy(wide)),
3638
}
3739
}
3840

0 commit comments

Comments
 (0)