Repository: gimli-rs/addr2line
Pull request #268 (2023-02-17 00:21:39)

Update to Edition 2018
The crate isn't compatible with any 2015-only compiler, so it can use a more recent Rust edition.


Patch:
diff --git a/Cargo.toml b/Cargo.toml
index dad13e9..e6e5bf1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,6 +9,7 @@ categories = ["development-tools::debugging"]
 license = "Apache-2.0 OR MIT"
 readme = "./README.md"
 repository = "https://github.com/gimli-rs/addr2line"
+edition = "2018"
 
 [dependencies]
 gimli = { version = "0.27.2", default-features = false, features = ["read"] }
diff --git a/benches/bench.rs b/benches/bench.rs
index a4080d0..d6ff4a6 100644
--- a/benches/bench.rs
+++ b/benches/bench.rs
@@ -1,8 +1,5 @@
 #![feature(test)]
 
-extern crate addr2line;
-extern crate memmap2;
-extern crate object;
 extern crate test;
 
 use std::borrow::Cow;
@@ -22,7 +19,7 @@ fn release_fixture_path() -> PathBuf {
     path
 }
 
-fn with_file<F: FnOnce(&object::File)>(target: &path::Path, f: F) {
+fn with_file<F: FnOnce(&object::File<'_>)>(target: &path::Path, f: F) {
     let file = File::open(target).unwrap();
     let map = unsafe { memmap2::Mmap::map(&file).unwrap() };
     let file = object::File::parse(&*map).unwrap();
@@ -40,17 +37,17 @@ fn dwarf_load<'a>(object: &object::File<'a>) -> gimli::Dwarf<Cow<'a, [u8]>> {
 }
 
 fn dwarf_borrow<'a>(
-    dwarf: &'a gimli::Dwarf<Cow<[u8]>>,
+    dwarf: &'a gimli::Dwarf<Cow<'_, [u8]>>,
 ) -> gimli::Dwarf<gimli::EndianSlice<'a, gimli::LittleEndian>> {
     let borrow_section: &dyn for<'b> Fn(
-        &'b Cow<[u8]>,
+        &'b Cow<'_, [u8]>,
     ) -> gimli::EndianSlice<'b, gimli::LittleEndian> =
         &|section| gimli::EndianSlice::new(&*section, gimli::LittleEndian);
     dwarf.borrow(&borrow_section)
 }
 
 /// Obtain a list of addresses contained within the text section of the `target` executable.
-fn get_test_addresses(target: &object::File) -> Vec<u64> {
+fn get_test_addresses(target: &object::File<'_>) -> Vec<u64> {
     let addresses: Vec<_> = target
         .symbols()
         .filter(|s| s.kind() == object::SymbolKind::Text && s.address() != 0 && s.size() != 0)
diff --git a/examples/addr2line.rs b/examples/addr2line.rs
index 134d605..fbc683c 100644
--- a/examples/addr2line.rs
+++ b/examples/addr2line.rs
@@ -1,11 +1,3 @@
-extern crate addr2line;
-extern crate clap;
-extern crate fallible_iterator;
-extern crate gimli;
-extern crate memmap2;
-extern crate object;
-extern crate typed_arena;
-
 use std::borrow::Cow;
 use std::fs::File;
 use std::io::{BufRead, Lines, StdinLock, Write};
@@ -45,8 +37,8 @@ impl<'a> Iterator for Addrs<'a> {
     }
 }
 
-fn print_loc(loc: Option<&Location>, basenames: bool, llvm: bool) {
-    if let Some(ref loc) = loc {
+fn print_loc(loc: Option<&Location<'_>>, basenames: bool, llvm: bool) {
+    if let Some(loc) = loc {
         if let Some(ref file) = loc.file.as_ref() {
             let path = if basenames {
                 Path::new(Path::new(file).file_name().unwrap())
@@ -102,7 +94,7 @@ fn load_file_section<'input, 'arena, Endian: gimli::Endianity>(
 }
 
 fn find_name_from_symbols<'a>(
-    symbols: &'a SymbolMap<SymbolMapName>,
+    symbols: &'a SymbolMap<SymbolMapName<'_>>,
     probe: u64,
 ) -> Option<&'a str> {
     symbols.get(probe).map(|x| x.name())
diff --git a/src/builtin_split_dwarf_loader.rs b/src/builtin_split_dwarf_loader.rs
index c0393c4..b108a71 100644
--- a/src/builtin_split_dwarf_loader.rs
+++ b/src/builtin_split_dwarf_loader.rs
@@ -14,7 +14,7 @@ fn convert_path<R: gimli::Reader<Endian = gimli::RunTimeEndian>>(
     use std::ffi::OsStr;
     use std::os::unix::ffi::OsStrExt;
     let bytes = r.to_slice()?;
-    let s = OsStr::from_bytes(&*bytes);
+    let s = OsStr::from_bytes(&bytes);
     Ok(PathBuf::from(s))
 }
 
@@ -45,7 +45,7 @@ where
 pub struct SplitDwarfLoader<R, F>
 where
     R: gimli::Reader<Endian = gimli::RunTimeEndian>,
-    F: FnMut(Cow<[u8]>, R::Endian) -> R,
+    F: FnMut(Cow<'_, [u8]>, R::Endian) -> R,
 {
     loader: F,
     dwarf_package: Option<gimli::DwarfPackage<R>>,
@@ -54,7 +54,7 @@ where
 impl<R, F> SplitDwarfLoader<R, F>
 where
     R: gimli::Reader<Endian = gimli::RunTimeEndian>,
-    F: FnMut(Cow<[u8]>, R::Endian) -> R,
+    F: FnMut(Cow<'_, [u8]>, R::Endian) -> R,
 {
     fn load_dwarf_package(loader: &mut F, path: Option<PathBuf>) -> Option<gimli::DwarfPackage<R>> {
         let mut path = path.map(Ok).unwrap_or_else(std::env::current_exe).ok()?;
diff --git a/src/function.rs b/src/function.rs
index b7a97c9..09c19e0 100644
--- a/src/function.rs
+++ b/src/function.rs
@@ -253,7 +253,7 @@ impl<R: gimli::Reader> Function<R> {
     }
 
     fn parse_children(
-        entries: &mut gimli::EntriesRaw<R>,
+        entries: &mut gimli::EntriesRaw<'_, '_, R>,
         depth: isize,
         file: DebugFile,
         unit: &gimli::Unit<R>,
@@ -298,7 +298,7 @@ impl<R: gimli::Reader> Function<R> {
     }
 
     fn skip(
-        entries: &mut gimli::EntriesRaw<R>,
+        entries: &mut gimli::EntriesRaw<'_, '_, R>,
         abbrev: &gimli::Abbreviation,
         depth: isize,
     ) -> Result<(), Error> {
@@ -354,7 +354,7 @@ impl<R: gimli::Reader> Function<R> {
 impl<R: gimli::Reader> InlinedFunction<R> {
     fn parse(
         dw_die_offset: gimli::UnitOffset<R::Offset>,
-        entries: &mut gimli::EntriesRaw<R>,
+        entries: &mut gimli::EntriesRaw<'_, '_, R>,
         abbrev: &gimli::Abbreviation,
         depth: isize,
         file: DebugFile,
diff --git a/src/lib.rs b/src/lib.rs
index e41b88b..2829fa9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -36,7 +36,6 @@ extern crate alloc;
 extern crate cpp_demangle;
 #[cfg(feature = "fallible-iterator")]
 pub extern crate fallible_iterator;
-pub extern crate gimli;
 #[cfg(feature = "object")]
 pub extern crate object;
 #[cfg(feature = "rustc-demangle")]
@@ -288,7 +287,7 @@ impl<R: gimli::Reader> Context<R> {
             debug_types: default_section.clone().into(),
             locations: gimli::LocationLists::new(
                 default_section.clone().into(),
-                default_section.clone().into(),
+                default_section.into(),
             ),
             ranges: gimli::RangeLists::new(debug_ranges, debug_rnglists),
             file_type: gimli::DwarfFileType::Main,
@@ -451,7 +450,8 @@ impl<R: gimli::Reader> Context<R> {
     pub fn find_frames(
         &self,
         probe: u64,
-    ) -> LookupResult<impl LookupContinuation<Output = Result<FrameIter<R>, Error>, Buf = R>> {
+    ) -> LookupResult<impl LookupContinuation<Output = Result<FrameIter<'_, R>, Error>, Buf = R>>
+    {
         let mut units_iter = self.find_units(probe);
         if let Some(unit) = units_iter.next() {
             LoopingLookup::new_lookup(unit.find_function_or_location(probe, self), move |r| {
@@ -1536,11 +1536,11 @@ impl<R: gimli::Reader> RangeAttributes<R> {
 /// An iterator over function frames.
 pub struct FrameIter<'ctx, R>(FrameIterState<'ctx, R>)
 where
-    R: gimli::Reader + 'ctx;
+    R: gimli::Reader;
 
 enum FrameIterState<'ctx, R>
 where
-    R: gimli::Reader + 'ctx,
+    R: gimli::Reader,
 {
     Empty,
     Location(Option<Location<'ctx>>),
@@ -1549,7 +1549,7 @@ where
 
 struct FrameIterFrames<'ctx, R>
 where
-    R: gimli::Reader + 'ctx,
+    R: gimli::Reader,
 {
     unit: &'ctx ResUnit<R>,
     sections: &'ctx gimli::Dwarf<R>,
@@ -1661,12 +1661,12 @@ pub struct FunctionName<R: gimli::Reader> {
 
 impl<R: gimli::Reader> FunctionName<R> {
     /// The raw name of this function before demangling.
-    pub fn raw_name(&self) -> Result<Cow<str>, Error> {
+    pub fn raw_name(&self) -> Result<Cow<'_, str>, Error> {
         self.name.to_string_lossy()
     }
 
     /// The name of this function after demangling (if applicable).
-    pub fn demangle(&self) -> Result<Cow<str>, Error> {
+    pub fn demangle(&self) -> Result<Cow<'_, str>, Error> {
         self.raw_name().map(|x| demangle_auto(x, self.language))
     }
 }
@@ -1702,7 +1702,7 @@ pub fn demangle(name: &str, language: gimli::DwLang) -> Option<String> {
 /// demangle the name. Currently, these heuristics are very basic.
 ///
 /// If demangling fails or is not required, then `name` is returned unchanged.
-pub fn demangle_auto(name: Cow<str>, language: Option<gimli::DwLang>) -> Cow<str> {
+pub fn demangle_auto(name: Cow<'_, str>, language: Option<gimli::DwLang>) -> Cow<'_, str> {
     match language {
         Some(language) => demangle(name.as_ref(), language),
         None => demangle(name.as_ref(), gimli::DW_LANG_Rust)
@@ -1727,6 +1727,6 @@ mod tests {
     #[test]
     fn context_is_send() {
         fn assert_is_send<T: Send>() {}
-        assert_is_send::<crate::Context<gimli::read::EndianSlice<gimli::LittleEndian>>>();
+        assert_is_send::<crate::Context<gimli::read::EndianSlice<'_, gimli::LittleEndian>>>();
     }
 }


Test patch:
diff --git a/tests/correctness.rs b/tests/correctness.rs
index 9b53cd5..e469aa0 100644
--- a/tests/correctness.rs
+++ b/tests/correctness.rs
@@ -1,10 +1,3 @@
-extern crate addr2line;
-extern crate fallible_iterator;
-extern crate findshlibs;
-extern crate gimli;
-extern crate memmap2;
-extern crate object;
-
 use addr2line::Context;
 use fallible_iterator::FallibleIterator;
 use findshlibs::{IterationControl, SharedLibrary, TargetSharedLibrary};
diff --git a/tests/output_equivalence.rs b/tests/output_equivalence.rs
index c0e1f83..cfd1620 100644
--- a/tests/output_equivalence.rs
+++ b/tests/output_equivalence.rs
@@ -1,5 +1,3 @@
-extern crate backtrace;
-extern crate findshlibs;
 extern crate rustc_test as test;
 
 use std::env;
@@ -7,9 +5,9 @@ use std::ffi::OsStr;
 use std::path::Path;
 use std::process::Command;
 
+use crate::test::{ShouldPanic, TestDesc, TestDescAndFn, TestFn, TestName};
 use backtrace::Backtrace;
 use findshlibs::{IterationControl, SharedLibrary, TargetSharedLibrary};
-use test::{ShouldPanic, TestDesc, TestDescAndFn, TestFn, TestName};
 
 #[inline(never)]
 fn make_trace() -> Vec<String> {
@@ -102,7 +100,7 @@ $ {3} {0} --exe {1} {2}
     }
 }
 
-static FLAGS: &'static str = "aipsf";
+static FLAGS: &str = "aipsf";
 
 fn make_tests() -> Vec<TestDescAndFn> {
     (0..(1 << FLAGS.len()))
diff --git a/tests/parse.rs b/tests/parse.rs
index 60b2300..4dafe38 100644
--- a/tests/parse.rs
+++ b/tests/parse.rs
@@ -1,7 +1,3 @@
-extern crate addr2line;
-extern crate memmap2;
-extern crate object;
-
 use std::borrow::Cow;
 use std::env;
 use std::fs::File;
@@ -23,7 +19,7 @@ fn release_fixture_path() -> PathBuf {
     path
 }
 
-fn with_file<F: FnOnce(&object::File)>(target: &path::Path, f: F) {
+fn with_file<F: FnOnce(&object::File<'_>)>(target: &path::Path, f: F) {
     let file = File::open(target).unwrap();
     let map = unsafe { memmap2::Mmap::map(&file).unwrap() };
     let file = object::File::parse(&*map).unwrap();
@@ -44,12 +40,12 @@ fn dwarf_load<'a>(object: &object::File<'a>) -> gimli::Dwarf<Cow<'a, [u8]>> {
 }
 
 fn dwarf_borrow<'a>(
-    dwarf: &'a gimli::Dwarf<Cow<[u8]>>,
+    dwarf: &'a gimli::Dwarf<Cow<'_, [u8]>>,
 ) -> gimli::Dwarf<gimli::EndianSlice<'a, gimli::LittleEndian>> {
     let borrow_section: &dyn for<'b> Fn(
-        &'b Cow<[u8]>,
+        &'b Cow<'_, [u8]>,
     ) -> gimli::EndianSlice<'b, gimli::LittleEndian> =
-        &|section| gimli::EndianSlice::new(&*section, gimli::LittleEndian);
+        &|section| gimli::EndianSlice::new(section, gimli::LittleEndian);
     dwarf.borrow(&borrow_section)
 }