Skip to content

Commit

Permalink
Warn about 2018 idioms (rust-lang#331)
Browse files Browse the repository at this point in the history
Make sure we keep the code up-to-date!
  • Loading branch information
alexcrichton authored May 13, 2020
1 parent 108472f commit 1ca764e
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 38 deletions.
2 changes: 0 additions & 2 deletions benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

extern crate test;

extern crate backtrace;

#[cfg(feature = "std")]
use backtrace::Backtrace;

Expand Down
2 changes: 0 additions & 2 deletions examples/backtrace.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate backtrace;

use backtrace::Backtrace;

fn main() {
Expand Down
2 changes: 0 additions & 2 deletions examples/raw.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate backtrace;

fn main() {
foo();
}
Expand Down
2 changes: 1 addition & 1 deletion src/backtrace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl Frame {
}

impl fmt::Debug for Frame {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Frame")
.field("ip", &self.ip())
.field("symbol_address", &self.symbol_address())
Expand Down
10 changes: 5 additions & 5 deletions src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl BacktraceSymbol {
///
/// This function requires the `std` feature of the `backtrace` crate to be
/// enabled, and the `std` feature is enabled by default.
pub fn name(&self) -> Option<SymbolName> {
pub fn name(&self) -> Option<SymbolName<'_>> {
self.name.as_ref().map(|s| SymbolName::new(s))
}

Expand Down Expand Up @@ -325,7 +325,7 @@ impl BacktraceSymbol {
}

impl fmt::Debug for Backtrace {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
let full = fmt.alternate();
let (frames, style) = if full {
(&self.frames[..], PrintFmt::Full)
Expand All @@ -338,7 +338,7 @@ impl fmt::Debug for Backtrace {
// short format, because if it's full we presumably want to print
// everything.
let cwd = std::env::current_dir();
let mut print_path = move |fmt: &mut fmt::Formatter, path: crate::BytesOrWideString| {
let mut print_path = move |fmt: &mut fmt::Formatter<'_>, path: crate::BytesOrWideString<'_>| {
let path = path.into_path_buf();
if !full {
if let Ok(cwd) = &cwd {
Expand Down Expand Up @@ -367,7 +367,7 @@ impl Default for Backtrace {
}

impl fmt::Debug for BacktraceFrame {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("BacktraceFrame")
.field("ip", &self.ip())
.field("symbol_address", &self.symbol_address())
Expand All @@ -376,7 +376,7 @@ impl fmt::Debug for BacktraceFrame {
}

impl fmt::Debug for BacktraceSymbol {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("BacktraceSymbol")
.field("name", &self.name())
.field("addr", &self.addr())
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
all(feature = "std", target_env = "sgx", target_vendor = "fortanix"),
feature(sgx_platform)
)]
#![warn(rust_2018_idioms)]

#[cfg(feature = "std")]
#[macro_use]
Expand Down
16 changes: 9 additions & 7 deletions src/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ pub struct BacktraceFmt<'a, 'b> {
fmt: &'a mut fmt::Formatter<'b>,
frame_index: usize,
format: PrintFmt,
print_path: &'a mut (dyn FnMut(&mut fmt::Formatter, BytesOrWideString) -> fmt::Result + 'b),
print_path:
&'a mut (dyn FnMut(&mut fmt::Formatter<'_>, BytesOrWideString<'_>) -> fmt::Result + 'b),
}

/// The styles of printing that we can print
Expand All @@ -41,7 +42,8 @@ impl<'a, 'b> BacktraceFmt<'a, 'b> {
pub fn new(
fmt: &'a mut fmt::Formatter<'b>,
format: PrintFmt,
print_path: &'a mut (dyn FnMut(&mut fmt::Formatter, BytesOrWideString) -> fmt::Result + 'b),
print_path: &'a mut (dyn FnMut(&mut fmt::Formatter<'_>, BytesOrWideString<'_>) -> fmt::Result
+ 'b),
) -> Self {
BacktraceFmt {
fmt,
Expand Down Expand Up @@ -160,8 +162,8 @@ impl BacktraceFrameFmt<'_, '_, '_> {
pub fn print_raw(
&mut self,
frame_ip: *mut c_void,
symbol_name: Option<crate::SymbolName>,
filename: Option<BytesOrWideString>,
symbol_name: Option<crate::SymbolName<'_>>,
filename: Option<BytesOrWideString<'_>>,
lineno: Option<u32>,
) -> fmt::Result {
// Fuchsia is unable to symbolize within a process so it has a special
Expand All @@ -180,8 +182,8 @@ impl BacktraceFrameFmt<'_, '_, '_> {
fn print_raw_generic(
&mut self,
mut frame_ip: *mut c_void,
symbol_name: Option<crate::SymbolName>,
filename: Option<BytesOrWideString>,
symbol_name: Option<crate::SymbolName<'_>>,
filename: Option<BytesOrWideString<'_>>,
lineno: Option<u32>,
) -> fmt::Result {
// No need to print "null" frames, it basically just means that the
Expand Down Expand Up @@ -234,7 +236,7 @@ impl BacktraceFrameFmt<'_, '_, '_> {
Ok(())
}

fn print_fileline(&mut self, file: BytesOrWideString, line: u32) -> fmt::Result {
fn print_fileline(&mut self, file: BytesOrWideString<'_>, line: u32) -> fmt::Result {
// Filename/line are printed on lines under the symbol name, so print
// some appropriate whitespace to sort of right-align ourselves.
if let PrintFmt::Full = self.fmt.format {
Expand Down
10 changes: 5 additions & 5 deletions src/symbolize/gimli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,13 @@ impl Cache {
}
}

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

Expand Down Expand Up @@ -526,7 +526,7 @@ pub enum Symbol<'a> {
}

impl Symbol<'_> {
pub fn name(&self) -> Option<SymbolName> {
pub fn name(&self) -> Option<SymbolName<'_>> {
match self {
Symbol::Frame { name, .. } => {
let name = name.as_ref()?;
Expand All @@ -543,7 +543,7 @@ impl Symbol<'_> {
}
}

pub fn filename_raw(&self) -> Option<BytesOrWideString> {
pub fn filename_raw(&self) -> Option<BytesOrWideString<'_>> {
match self {
Symbol::Frame { location, .. } => {
let file = location.as_ref()?.file?;
Expand Down
14 changes: 7 additions & 7 deletions src/symbolize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl Symbol {
/// * The raw `str` value of the symbol can be accessed (if it's valid
/// utf-8).
/// * The raw bytes for the symbol name can be accessed.
pub fn name(&self) -> Option<SymbolName> {
pub fn name(&self) -> Option<SymbolName<'_>> {
self.inner.name()
}

Expand All @@ -215,7 +215,7 @@ impl Symbol {

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

Expand Down Expand Up @@ -246,7 +246,7 @@ impl Symbol {
}

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

fn format_symbol_name(
fmt: fn(&str, &mut fmt::Formatter) -> fmt::Result,
fmt: fn(&str, &mut fmt::Formatter<'_>) -> fmt::Result,
mut bytes: &[u8],
f: &mut fmt::Formatter,
f: &mut fmt::Formatter<'_>,
) -> fmt::Result {
while bytes.len() > 0 {
match str::from_utf8(bytes) {
Expand Down Expand Up @@ -387,7 +387,7 @@ cfg_if::cfg_if! {
}
} else {
impl<'a> fmt::Display for SymbolName<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(ref s) = self.demangled {
s.fmt(f)
} else {
Expand Down Expand Up @@ -423,7 +423,7 @@ cfg_if::cfg_if! {
}
} else {
impl<'a> fmt::Debug for SymbolName<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(ref s) = self.demangled {
s.fmt(f)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'a> BytesOrWideString<'a> {

#[cfg(feature = "std")]
impl<'a> fmt::Display for BytesOrWideString<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.to_str_lossy().fmt(f)
}
}
2 changes: 0 additions & 2 deletions tests/long_fn_name.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate backtrace;

use backtrace::Backtrace;

// 50-character module name
Expand Down
2 changes: 0 additions & 2 deletions tests/skip_inner_frames.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate backtrace;

use backtrace::Backtrace;

// This test only works on platforms which have a working `symbol_address`
Expand Down
2 changes: 0 additions & 2 deletions tests/smoke.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate backtrace;

use backtrace::Frame;
use std::thread;

Expand Down

0 comments on commit 1ca764e

Please sign in to comment.