Skip to content

Commit 1ca764e

Browse files
authored
Warn about 2018 idioms (#331)
Make sure we keep the code up-to-date!
1 parent 108472f commit 1ca764e

File tree

13 files changed

+29
-38
lines changed

13 files changed

+29
-38
lines changed

benches/benchmarks.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
extern crate test;
44

5-
extern crate backtrace;
6-
75
#[cfg(feature = "std")]
86
use backtrace::Backtrace;
97

examples/backtrace.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate backtrace;
2-
31
use backtrace::Backtrace;
42

53
fn main() {

examples/raw.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate backtrace;
2-
31
fn main() {
42
foo();
53
}

src/backtrace/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl Frame {
104104
}
105105

106106
impl fmt::Debug for Frame {
107-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
107+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108108
f.debug_struct("Frame")
109109
.field("ip", &self.ip())
110110
.field("symbol_address", &self.symbol_address())

src/capture.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ impl BacktraceSymbol {
289289
///
290290
/// This function requires the `std` feature of the `backtrace` crate to be
291291
/// enabled, and the `std` feature is enabled by default.
292-
pub fn name(&self) -> Option<SymbolName> {
292+
pub fn name(&self) -> Option<SymbolName<'_>> {
293293
self.name.as_ref().map(|s| SymbolName::new(s))
294294
}
295295

@@ -325,7 +325,7 @@ impl BacktraceSymbol {
325325
}
326326

327327
impl fmt::Debug for Backtrace {
328-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
328+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
329329
let full = fmt.alternate();
330330
let (frames, style) = if full {
331331
(&self.frames[..], PrintFmt::Full)
@@ -338,7 +338,7 @@ impl fmt::Debug for Backtrace {
338338
// short format, because if it's full we presumably want to print
339339
// everything.
340340
let cwd = std::env::current_dir();
341-
let mut print_path = move |fmt: &mut fmt::Formatter, path: crate::BytesOrWideString| {
341+
let mut print_path = move |fmt: &mut fmt::Formatter<'_>, path: crate::BytesOrWideString<'_>| {
342342
let path = path.into_path_buf();
343343
if !full {
344344
if let Ok(cwd) = &cwd {
@@ -367,7 +367,7 @@ impl Default for Backtrace {
367367
}
368368

369369
impl fmt::Debug for BacktraceFrame {
370-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
370+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
371371
fmt.debug_struct("BacktraceFrame")
372372
.field("ip", &self.ip())
373373
.field("symbol_address", &self.symbol_address())
@@ -376,7 +376,7 @@ impl fmt::Debug for BacktraceFrame {
376376
}
377377

378378
impl fmt::Debug for BacktraceSymbol {
379-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
379+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
380380
fmt.debug_struct("BacktraceSymbol")
381381
.field("name", &self.name())
382382
.field("addr", &self.addr())

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
all(feature = "std", target_env = "sgx", target_vendor = "fortanix"),
4949
feature(sgx_platform)
5050
)]
51+
#![warn(rust_2018_idioms)]
5152

5253
#[cfg(feature = "std")]
5354
#[macro_use]

src/print.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ pub struct BacktraceFmt<'a, 'b> {
1616
fmt: &'a mut fmt::Formatter<'b>,
1717
frame_index: usize,
1818
format: PrintFmt,
19-
print_path: &'a mut (dyn FnMut(&mut fmt::Formatter, BytesOrWideString) -> fmt::Result + 'b),
19+
print_path:
20+
&'a mut (dyn FnMut(&mut fmt::Formatter<'_>, BytesOrWideString<'_>) -> fmt::Result + 'b),
2021
}
2122

2223
/// The styles of printing that we can print
@@ -41,7 +42,8 @@ impl<'a, 'b> BacktraceFmt<'a, 'b> {
4142
pub fn new(
4243
fmt: &'a mut fmt::Formatter<'b>,
4344
format: PrintFmt,
44-
print_path: &'a mut (dyn FnMut(&mut fmt::Formatter, BytesOrWideString) -> fmt::Result + 'b),
45+
print_path: &'a mut (dyn FnMut(&mut fmt::Formatter<'_>, BytesOrWideString<'_>) -> fmt::Result
46+
+ 'b),
4547
) -> Self {
4648
BacktraceFmt {
4749
fmt,
@@ -160,8 +162,8 @@ impl BacktraceFrameFmt<'_, '_, '_> {
160162
pub fn print_raw(
161163
&mut self,
162164
frame_ip: *mut c_void,
163-
symbol_name: Option<crate::SymbolName>,
164-
filename: Option<BytesOrWideString>,
165+
symbol_name: Option<crate::SymbolName<'_>>,
166+
filename: Option<BytesOrWideString<'_>>,
165167
lineno: Option<u32>,
166168
) -> fmt::Result {
167169
// Fuchsia is unable to symbolize within a process so it has a special
@@ -180,8 +182,8 @@ impl BacktraceFrameFmt<'_, '_, '_> {
180182
fn print_raw_generic(
181183
&mut self,
182184
mut frame_ip: *mut c_void,
183-
symbol_name: Option<crate::SymbolName>,
184-
filename: Option<BytesOrWideString>,
185+
symbol_name: Option<crate::SymbolName<'_>>,
186+
filename: Option<BytesOrWideString<'_>>,
185187
lineno: Option<u32>,
186188
) -> fmt::Result {
187189
// No need to print "null" frames, it basically just means that the
@@ -234,7 +236,7 @@ impl BacktraceFrameFmt<'_, '_, '_> {
234236
Ok(())
235237
}
236238

237-
fn print_fileline(&mut self, file: BytesOrWideString, line: u32) -> fmt::Result {
239+
fn print_fileline(&mut self, file: BytesOrWideString<'_>, line: u32) -> fmt::Result {
238240
// Filename/line are printed on lines under the symbol name, so print
239241
// some appropriate whitespace to sort of right-align ourselves.
240242
if let PrintFmt::Full = self.fmt.format {

src/symbolize/gimli.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,13 @@ impl Cache {
467467
}
468468
}
469469

470-
pub unsafe fn resolve(what: ResolveWhat, cb: &mut dyn FnMut(&super::Symbol)) {
470+
pub unsafe fn resolve(what: ResolveWhat<'_>, cb: &mut dyn FnMut(&super::Symbol)) {
471471
let addr = what.address_or_ip();
472-
let mut call = |sym: Symbol| {
472+
let mut call = |sym: Symbol<'_>| {
473473
// Extend the lifetime of `sym` to `'static` since we are unfortunately
474474
// required to here, but it's ony ever going out as a reference so no
475475
// reference to it should be persisted beyond this frame anyway.
476-
let sym = mem::transmute::<Symbol, Symbol<'static>>(sym);
476+
let sym = mem::transmute::<Symbol<'_>, Symbol<'static>>(sym);
477477
(cb)(&super::Symbol { inner: sym });
478478
};
479479

@@ -526,7 +526,7 @@ pub enum Symbol<'a> {
526526
}
527527

528528
impl Symbol<'_> {
529-
pub fn name(&self) -> Option<SymbolName> {
529+
pub fn name(&self) -> Option<SymbolName<'_>> {
530530
match self {
531531
Symbol::Frame { name, .. } => {
532532
let name = name.as_ref()?;
@@ -543,7 +543,7 @@ impl Symbol<'_> {
543543
}
544544
}
545545

546-
pub fn filename_raw(&self) -> Option<BytesOrWideString> {
546+
pub fn filename_raw(&self) -> Option<BytesOrWideString<'_>> {
547547
match self {
548548
Symbol::Frame { location, .. } => {
549549
let file = location.as_ref()?.file?;

src/symbolize/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl Symbol {
204204
/// * The raw `str` value of the symbol can be accessed (if it's valid
205205
/// utf-8).
206206
/// * The raw bytes for the symbol name can be accessed.
207-
pub fn name(&self) -> Option<SymbolName> {
207+
pub fn name(&self) -> Option<SymbolName<'_>> {
208208
self.inner.name()
209209
}
210210

@@ -215,7 +215,7 @@ impl Symbol {
215215

216216
/// Returns the raw filename as a slice. This is mainly useful for `no_std`
217217
/// environments.
218-
pub fn filename_raw(&self) -> Option<BytesOrWideString> {
218+
pub fn filename_raw(&self) -> Option<BytesOrWideString<'_>> {
219219
self.inner.filename_raw()
220220
}
221221

@@ -246,7 +246,7 @@ impl Symbol {
246246
}
247247

248248
impl fmt::Debug for Symbol {
249-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
249+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
250250
let mut d = f.debug_struct("Symbol");
251251
if let Some(name) = self.name() {
252252
d.field("name", &name);
@@ -349,9 +349,9 @@ impl<'a> SymbolName<'a> {
349349
}
350350

351351
fn format_symbol_name(
352-
fmt: fn(&str, &mut fmt::Formatter) -> fmt::Result,
352+
fmt: fn(&str, &mut fmt::Formatter<'_>) -> fmt::Result,
353353
mut bytes: &[u8],
354-
f: &mut fmt::Formatter,
354+
f: &mut fmt::Formatter<'_>,
355355
) -> fmt::Result {
356356
while bytes.len() > 0 {
357357
match str::from_utf8(bytes) {
@@ -387,7 +387,7 @@ cfg_if::cfg_if! {
387387
}
388388
} else {
389389
impl<'a> fmt::Display for SymbolName<'a> {
390-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
390+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
391391
if let Some(ref s) = self.demangled {
392392
s.fmt(f)
393393
} else {
@@ -423,7 +423,7 @@ cfg_if::cfg_if! {
423423
}
424424
} else {
425425
impl<'a> fmt::Debug for SymbolName<'a> {
426-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
426+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
427427
if let Some(ref s) = self.demangled {
428428
s.fmt(f)
429429
} else {

src/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<'a> BytesOrWideString<'a> {
7777

7878
#[cfg(feature = "std")]
7979
impl<'a> fmt::Display for BytesOrWideString<'a> {
80-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
80+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8181
self.to_str_lossy().fmt(f)
8282
}
8383
}

tests/long_fn_name.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate backtrace;
2-
31
use backtrace::Backtrace;
42

53
// 50-character module name

tests/skip_inner_frames.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate backtrace;
2-
31
use backtrace::Backtrace;
42

53
// This test only works on platforms which have a working `symbol_address`

tests/smoke.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
extern crate backtrace;
2-
31
use backtrace::Frame;
42
use std::thread;
53

0 commit comments

Comments
 (0)