Skip to content

Commit d915eba

Browse files
committed
Migrate to the 2018 edition
1 parent a062fa3 commit d915eba

21 files changed

+83
-141
lines changed

Cargo.toml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ A library to acquire a stack trace (backtrace) at runtime in a Rust program.
1212
"""
1313
autoexamples = true
1414
autotests = true
15+
edition = "2018"
1516

1617
[dependencies]
1718
cfg-if = "0.1.6"
@@ -22,8 +23,7 @@ core = { version = "1.0.0", optional = true, package = 'rustc-std-workspace-core
2223
compiler_builtins = { version = '0.1.2', optional = true }
2324

2425
# Optionally enable the ability to serialize a `Backtrace`
25-
serde = { version = "1.0", optional = true }
26-
serde_derive = { version = "1.0", optional = true }
26+
serde = { version = "1.0", optional = true, features = ['derive'] }
2727
rustc-serialize = { version = "0.3", optional = true }
2828

2929
# Optionally demangle C++ frames' symbols in backtraces.
@@ -37,9 +37,6 @@ memmap = { version = "0.7.0", optional = true }
3737
[target.'cfg(windows)'.dependencies]
3838
winapi = { version = "0.3.3", optional = true }
3939

40-
[build-dependencies]
41-
autocfg = "0.1"
42-
4340
# Each feature controls the two phases of finding a backtrace: getting a
4441
# backtrace and then resolving instruction pointers to symbols. The default
4542
# feature enables all the necessary features for each platform this library
@@ -102,7 +99,7 @@ gimli-symbolize = ["addr2line", "findshlibs", "memmap" ]
10299
#
103100
# Various features used for enabling rustc-serialize or syntex codegen.
104101
serialize-rustc = ["rustc-serialize"]
105-
serialize-serde = ["serde", "serde_derive"]
102+
serialize-serde = ["serde"]
106103

107104
#=======================================
108105
# Internal features for testing and such.

build.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/backtrace/dbghelp.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@
2121
2222
#![allow(bad_style)]
2323

24+
use core::ffi::c_void;
2425
use core::mem;
25-
use core::prelude::v1::*;
26-
27-
use dbghelp;
28-
use windows::*;
29-
use types::c_void;
26+
use crate::dbghelp;
27+
use crate::windows::*;
3028

3129
#[derive(Clone, Copy)]
3230
pub enum Frame {

src/backtrace/libunwind.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
//!
2626
//! This is the default unwinding API for all non-Windows platforms currently.
2727
28-
use types::c_void;
28+
use core::ffi::c_void;
2929

3030
pub enum Frame {
3131
Raw(*mut uw::_Unwind_Context),
@@ -94,7 +94,7 @@ pub unsafe fn trace(mut cb: &mut FnMut(&super::Frame) -> bool) {
9494
inner: Frame::Raw(ctx),
9595
};
9696

97-
let mut bomb = ::Bomb { enabled: true };
97+
let mut bomb = crate::Bomb { enabled: true };
9898
let keep_going = cb(&cx);
9999
bomb.enabled = false;
100100

@@ -117,8 +117,7 @@ pub unsafe fn trace(mut cb: &mut FnMut(&super::Frame) -> bool) {
117117
mod uw {
118118
pub use self::_Unwind_Reason_Code::*;
119119

120-
use libc;
121-
use types::c_void;
120+
use core::ffi::c_void;
122121

123122
#[repr(C)]
124123
pub enum _Unwind_Reason_Code {

src/backtrace/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use core::fmt;
2-
use types::c_void;
2+
use core::ffi::c_void;
33

44
/// Inspects the current call-stack, passing all active frames into the closure
55
/// provided to calculate a stack trace.
@@ -49,7 +49,7 @@ use types::c_void;
4949
/// ```
5050
#[cfg(feature = "std")]
5151
pub fn trace<F: FnMut(&Frame) -> bool>(cb: F) {
52-
let _guard = ::lock::lock();
52+
let _guard = crate::lock::lock();
5353
unsafe { trace_unsynchronized(cb) }
5454
}
5555

@@ -112,7 +112,7 @@ impl fmt::Debug for Frame {
112112
}
113113
}
114114

115-
cfg_if! {
115+
cfg_if::cfg_if! {
116116
if #[cfg(
117117
any(
118118
all(

src/backtrace/noop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Empty implementation of unwinding used when no other implementation is
22
//! appropriate.
33
4-
use types::c_void;
4+
use core::ffi::c_void;
55

66
#[inline(always)]
77
pub fn trace(_cb: &mut FnMut(&super::Frame) -> bool) {}

src/backtrace/unix_backtrace.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
//! straightforward binding of the `backtrace` API to the `Frame` API that we'd
1717
//! like to have.
1818
19+
use core::ffi::c_void;
1920
use core::mem;
2021
use libc::c_int;
2122

22-
use types::c_void;
23-
2423
#[derive(Clone)]
2524
pub struct Frame {
2625
addr: usize,

src/capture.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
use crate::{resolve, resolve_frame, trace, Symbol, SymbolName};
2+
use std::ffi::c_void;
13
use std::fmt;
24
use std::path::{Path, PathBuf};
35
use std::prelude::v1::*;
46

5-
use types::c_void;
6-
use {resolve, resolve_frame, trace, Symbol, SymbolName};
7+
#[cfg(feature = "serde")]
8+
use serde::{Serialize, Deserialize};
79

810
/// Representation of an owned and self-contained backtrace.
911
///
@@ -19,7 +21,7 @@ use {resolve, resolve_frame, trace, Symbol, SymbolName};
1921
/// enabled, and the `std` feature is enabled by default.
2022
#[derive(Clone)]
2123
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
22-
#[cfg_attr(feature = "serialize-serde", derive(Deserialize, Serialize))]
24+
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
2325
pub struct Backtrace {
2426
// Frames here are listed from top-to-bottom of the stack
2527
frames: Vec<BacktraceFrame>,
@@ -50,7 +52,7 @@ pub struct BacktraceFrame {
5052

5153
#[derive(Clone)]
5254
enum Frame {
53-
Raw(::Frame),
55+
Raw(crate::Frame),
5456
#[allow(dead_code)]
5557
Deserialized {
5658
ip: usize,
@@ -85,7 +87,7 @@ impl Frame {
8587
/// enabled, and the `std` feature is enabled by default.
8688
#[derive(Clone)]
8789
#[cfg_attr(feature = "serialize-rustc", derive(RustcDecodable, RustcEncodable))]
88-
#[cfg_attr(feature = "serialize-serde", derive(Deserialize, Serialize))]
90+
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
8991
pub struct BacktraceSymbol {
9092
name: Option<Vec<u8>>,
9193
addr: Option<usize>,
@@ -505,7 +507,7 @@ mod rustc_serialize_impls {
505507
}
506508
}
507509

508-
#[cfg(feature = "serialize-serde")]
510+
#[cfg(feature = "serde")]
509511
mod serde_impls {
510512
extern crate serde;
511513

src/dbghelp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
use core::mem;
2727
use core::ptr;
28-
use windows::*;
28+
use crate::windows::*;
2929

3030
// Work around `SymGetOptions` and `SymSetOptions` not being present in winapi
3131
// itself. Otherwise this is only used when we're double-checking types against
@@ -36,7 +36,7 @@ mod dbghelp {
3636
StackWalk64, SymCleanup, SymFromAddrW, SymFunctionTableAccess64, SymGetLineFromAddrW64,
3737
SymGetModuleBase64, SymInitializeW,
3838
};
39-
use windows::*;
39+
use crate::windows::*;
4040

4141
extern "system" {
4242
// Not defined in winapi yet

src/lib.rs

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -73,48 +73,21 @@
7373
#[macro_use]
7474
extern crate std;
7575

76-
extern crate libc;
77-
#[cfg(all(windows, feature = "verify-winapi"))]
78-
extern crate winapi;
79-
80-
#[cfg(feature = "serde_derive")]
81-
#[cfg_attr(feature = "serde_derive", macro_use)]
82-
extern crate serde_derive;
83-
84-
#[cfg(feature = "rustc-serialize")]
85-
extern crate rustc_serialize;
86-
87-
#[macro_use]
88-
extern crate cfg_if;
89-
90-
extern crate rustc_demangle;
91-
92-
#[cfg(feature = "cpp_demangle")]
93-
extern crate cpp_demangle;
94-
95-
cfg_if! {
96-
if #[cfg(all(feature = "gimli-symbolize", unix, target_os = "linux"))] {
97-
extern crate addr2line;
98-
extern crate findshlibs;
99-
extern crate memmap;
100-
}
101-
}
102-
103-
pub use backtrace::{trace_unsynchronized, Frame};
76+
pub use crate::backtrace::{trace_unsynchronized, Frame};
10477
mod backtrace;
10578

106-
pub use symbolize::resolve_frame_unsynchronized;
107-
pub use symbolize::{resolve_unsynchronized, Symbol, SymbolName};
79+
pub use crate::symbolize::resolve_frame_unsynchronized;
80+
pub use crate::symbolize::{resolve_unsynchronized, Symbol, SymbolName};
10881
mod symbolize;
10982

110-
pub use types::BytesOrWideString;
83+
pub use crate::types::BytesOrWideString;
11184
mod types;
11285

113-
cfg_if! {
86+
cfg_if::cfg_if! {
11487
if #[cfg(feature = "std")] {
115-
pub use backtrace::trace;
116-
pub use symbolize::{resolve, resolve_frame};
117-
pub use capture::{Backtrace, BacktraceFrame, BacktraceSymbol};
88+
pub use crate::backtrace::trace;
89+
pub use crate::symbolize::{resolve, resolve_frame};
90+
pub use crate::capture::{Backtrace, BacktraceFrame, BacktraceSymbol};
11891
mod capture;
11992
}
12093
}

src/symbolize/coresymbolication.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@
2525
2626
#![allow(bad_style)]
2727

28+
use crate::symbolize::dladdr;
29+
use crate::symbolize::ResolveWhat;
30+
use crate::types::BytesOrWideString;
31+
use crate::SymbolName;
32+
use core::ffi::c_void;
2833
use core::mem;
2934
use core::ptr;
3035
use core::slice;
31-
32-
use libc::{self, c_char, c_int};
33-
34-
use symbolize::ResolveWhat;
35-
use symbolize::dladdr;
36-
use types::{c_void, BytesOrWideString};
37-
use SymbolName;
36+
use libc::{c_char, c_int};
3837

3938
#[repr(C)]
4039
#[derive(Copy, Clone, PartialEq)]

src/symbolize/dbghelp.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,26 +27,17 @@
2727
2828
#![allow(bad_style)]
2929

30-
// This is a hack for compatibility with rustc 1.25.0. The no_std mode of this
31-
// crate is not supported pre-1.30.0, but in std mode the `char` module here
32-
// moved in rustc 1.26.0 (ish). As a result, in std mode we use `std::char` to
33-
// retain compatibility with rustc 1.25.0, but in `no_std` mode (which is
34-
// 1.30.0+ already) we use `core::char`.
35-
#[cfg(not(feature = "std"))]
30+
use crate::backtrace::FrameImp as Frame;
31+
use crate::dbghelp;
32+
use crate::symbolize::ResolveWhat;
33+
use crate::types::BytesOrWideString;
34+
use crate::windows::*;
35+
use crate::SymbolName;
3636
use core::char;
37-
#[cfg(feature = "std")]
38-
use std::char;
39-
37+
use core::ffi::c_void;
4038
use core::mem;
4139
use core::slice;
4240

43-
use backtrace::FrameImp as Frame;
44-
use dbghelp;
45-
use symbolize::ResolveWhat;
46-
use types::{c_void, BytesOrWideString};
47-
use windows::*;
48-
use SymbolName;
49-
5041
// Store an OsString on std so we can provide the symbol name and filename.
5142
pub struct Symbol {
5243
name: *const [u8],

src/symbolize/dladdr.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
1414
#![allow(dead_code)]
1515

16-
cfg_if! {
16+
cfg_if::cfg_if! {
1717
if #[cfg(all(unix, not(target_os = "emscripten"), feature = "dladdr"))] {
1818
use core::{mem, slice};
19-
20-
use types::{BytesOrWideString, c_void};
19+
use crate::types::BytesOrWideString;
20+
use core::ffi::c_void;
2121
use libc::{self, Dl_info};
2222

23-
use SymbolName;
23+
use crate::SymbolName;
2424

2525
pub struct Symbol {
2626
inner: Dl_info,
@@ -66,8 +66,9 @@ cfg_if! {
6666
}
6767
}
6868
} else {
69-
use types::{BytesOrWideString, c_void};
70-
use symbolize::SymbolName;
69+
use core::ffi::c_void;
70+
use crate::types::BytesOrWideString;
71+
use crate::symbolize::SymbolName;
7172

7273
pub enum Symbol {}
7374

src/symbolize/dladdr_resolve.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
//! basic, not handling inline frame information at all. Since it's so prevalent
1515
//! though we have an option to use it!
1616
17-
use types::{BytesOrWideString, c_void};
18-
use symbolize::{dladdr, SymbolName, ResolveWhat};
17+
use core::ffi::c_void;
18+
use crate::types::BytesOrWideString;
19+
use crate::symbolize::{dladdr, SymbolName, ResolveWhat};
1920

2021
pub struct Symbol(dladdr::Symbol);
2122

src/symbolize/gimli.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
//! all platforms, but it's hoped to be developed over time! Long-term this is
55
//! intended to wholesale replace the `libbacktrace.rs` implementation.
66
7+
use crate::symbolize::ResolveWhat;
8+
use crate::types::BytesOrWideString;
9+
use crate::SymbolName;
710
use addr2line;
811
use addr2line::object::{self, Object};
912
use findshlibs::{self, Segment, SharedLibrary};
@@ -17,10 +20,6 @@ use std::path::{Path, PathBuf};
1720
use std::prelude::v1::*;
1821
use std::u32;
1922

20-
use symbolize::ResolveWhat;
21-
use types::BytesOrWideString;
22-
use SymbolName;
23-
2423
const MAPPINGS_CACHE_SIZE: usize = 4;
2524

2625
type Dwarf = addr2line::Context;

0 commit comments

Comments
 (0)