Skip to content

Commit

Permalink
lint: deny more things
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed May 8, 2024
1 parent 66a10e8 commit 68a8f24
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 62 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Deny more things ([#78](https://github.com/gadomski/las-rs/pull/78))

## [0.8.6] - 2024-05-06

### Fixed
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ edition = "2021"
[dependencies]
byteorder = "1.4"
chrono = "0.4"
log = "0.4"
num-traits = "0.2"
thiserror = "1.0"
uuid = "1"
Expand Down
32 changes: 16 additions & 16 deletions src/compression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub(crate) struct CompressedPointReader<Decompressor> {
}

#[cfg(not(feature = "laz-parallel"))]
impl<'a, R: Read + Seek + Send> CompressedPointReader<laz::LasZipDecompressor<'a, R>> {
impl<R: Read + Seek + Send> CompressedPointReader<laz::LasZipDecompressor<'_, R>> {
pub(crate) fn new(source: R, header: Header) -> Result<Self> {
let laszip_vlr = match header.vlrs().iter().find(|vlr| is_laszip_vlr(*vlr)) {
None => return Err(Error::LasZipVlrNotFound),
Expand Down Expand Up @@ -75,7 +75,7 @@ impl<R: Read + Seek + Send> CompressedPointReader<laz::ParLasZipDecompressor<R>>
}

impl<Decompressor> Debug for CompressedPointReader<Decompressor> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"CompressedPointReader(num_read: {}, header: {:?})",
Expand Down Expand Up @@ -140,35 +140,35 @@ where
fn laz_vlr_from_point_format(point_format: &crate::point::Format) -> LazVlr {
let mut laz_items = laz::las::laszip::LazItemRecordBuilder::new();
if !point_format.is_extended {
laz_items.add_item(laz::LazItemType::Point10);
let _ = laz_items.add_item(laz::LazItemType::Point10);

if point_format.has_gps_time {
laz_items.add_item(laz::LazItemType::GpsTime);
let _ = laz_items.add_item(laz::LazItemType::GpsTime);
}

if point_format.has_color {
laz_items.add_item(laz::LazItemType::RGB12);
let _ = laz_items.add_item(laz::LazItemType::RGB12);
}

if point_format.extra_bytes > 0 {
laz_items.add_item(laz::LazItemType::Byte(point_format.extra_bytes));
let _ = laz_items.add_item(laz::LazItemType::Byte(point_format.extra_bytes));
}
} else {
laz_items.add_item(laz::LazItemType::Point14);
let _ = laz_items.add_item(laz::LazItemType::Point14);

if point_format.has_color {
// Point format 7 & 8 both have RGB
if point_format.has_nir {
laz_items.add_item(laz::LazItemType::RGBNIR14);
let _ = laz_items.add_item(laz::LazItemType::RGBNIR14);
} else {
laz_items.add_item(laz::LazItemType::RGB14);
let _ = laz_items.add_item(laz::LazItemType::RGB14);
}
}
if point_format.extra_bytes > 0 {
laz_items.add_item(laz::LazItemType::Byte14(point_format.extra_bytes));
let _ = laz_items.add_item(laz::LazItemType::Byte14(point_format.extra_bytes));
}
}
laz::LazVlr::from_laz_items(laz_items.build())
LazVlr::from_laz_items(laz_items.build())
}

/// struct that knows how to write LAZ
Expand All @@ -184,7 +184,7 @@ pub(crate) struct CompressedPointWriter<'a, W: Write + Seek + Send> {
compressor: laz::las::laszip::LasZipCompressor<'a, W>,
}

impl<'a, W: Write + Seek + Send> CompressedPointWriter<'a, W> {
impl<W: Write + Seek + Send> CompressedPointWriter<'_, W> {
pub(crate) fn new(mut dest: W, mut header: Header) -> Result<Self> {
let laz_vlr = laz_vlr_from_point_format(header.point_format());
// Clear any existing laszip vlr as they might not be correct
Expand All @@ -204,10 +204,10 @@ impl<'a, W: Write + Seek + Send> CompressedPointWriter<'a, W> {
}
}

impl<'a, W: Write + Seek + Send> PointWriter<W> for CompressedPointWriter<'a, W> {
impl<W: Write + Seek + Send> PointWriter<W> for CompressedPointWriter<'_, W> {
fn write_next(&mut self, point: Point) -> Result<()> {
self.header.add_point(&point);
self.compressor_input.seek(SeekFrom::Start(0))?;
let _ = self.compressor_input.seek(SeekFrom::Start(0))?;
write_point_to(&mut self.compressor_input, point, &self.header)?;
self.compressor
.compress_one(self.compressor_input.get_ref())?;
Expand All @@ -232,8 +232,8 @@ impl<'a, W: Write + Seek + Send> PointWriter<W> for CompressedPointWriter<'a, W>
}
}

impl<'a, W: Write + Seek + Send> Debug for CompressedPointWriter<'a, W> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
impl<W: Write + Seek + Send> Debug for CompressedPointWriter<'_, W> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "CompressedPointWriter(header: {:?})", self.header)
}
}
8 changes: 4 additions & 4 deletions src/header/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl Header {
/// builder.evlrs.push(Vlr::default());
/// let header = builder.into_header().unwrap();
/// assert_eq!(2, header.all_vlrs().count());
pub fn all_vlrs(&self) -> Vlrs {
pub fn all_vlrs(&self) -> Vlrs<'_> {
Vlrs(self.vlrs.iter().chain(&self.evlrs))
}

Expand Down Expand Up @@ -805,7 +805,7 @@ mod tests {
use std::u32;
let mut header = Header::from((1, 4));
header.number_of_points = u64::from(u32::MAX) + 1;
header.number_of_points_by_return.insert(6, 42);
let _ = header.number_of_points_by_return.insert(6, 42);
let raw_header = header.into_raw().unwrap();
assert_eq!(0, raw_header.number_of_point_records);
assert_eq!(
Expand Down Expand Up @@ -863,13 +863,13 @@ mod tests {
use std::u32;

let mut header = Header::from((1, 2));
header
let _ = header
.number_of_points_by_return
.insert(1, u32::MAX as u64 + 1);
assert!(header.into_raw().is_err());

let mut header = Header::from((1, 4));
header
let _ = header
.number_of_points_by_return
.insert(1, u32::MAX as u64 + 1);
let raw_header = header.into_raw().unwrap();
Expand Down
40 changes: 27 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,28 +135,39 @@
//! writer.write(point).unwrap();
//! ```

#![cfg_attr(docsrs, feature(doc_auto_cfg))]
#![deny(
missing_docs,
elided_lifetimes_in_paths,
explicit_outlives_requirements,
keyword_idents,
macro_use_extern_crate,
meta_variable_misuse,
missing_abi,
missing_debug_implementations,
missing_copy_implementations,
missing_docs,
non_ascii_idents,
noop_method_call,
pointer_structural_match,
rust_2021_incompatible_closure_captures,
rust_2021_incompatible_or_patterns,
rust_2021_prefixes_incompatible_syntax,
rust_2021_prelude_collisions,
single_use_lifetimes,
trivial_casts,
trivial_numeric_casts,
unreachable_pub,
unsafe_code,
unstable_features,
unsafe_op_in_unsafe_fn,
unused_crate_dependencies,
unused_extern_crates,
unused_import_braces,
unused_qualifications
unused_lifetimes,
unused_qualifications,
unused_results,
warnings
)]
#![recursion_limit = "128"]

extern crate byteorder;
extern crate chrono;
extern crate num_traits;
extern crate thiserror;
extern crate uuid;

#[cfg(feature = "laz")]
extern crate laz;

#[cfg(feature = "laz")]
mod compression;

Expand Down Expand Up @@ -193,3 +204,6 @@ pub use crate::writer::{Write, Writer};

/// Crate-specific result type.
pub type Result<T> = std::result::Result<T, Error>;

#[cfg(test)]
use criterion as _;
2 changes: 1 addition & 1 deletion src/point/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl Format {
}

impl fmt::Display for Format {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Ok(n) = self.to_u8() {
write!(f, "point format {}", n)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/raw/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ mod tests {
let mut cursor = Cursor::new(Vec::new());
header.write_to(&mut cursor).unwrap();
cursor.set_position(0);
Header::read_from(cursor)?;
let _ = Header::read_from(cursor)?;
Ok(())
}

Expand Down
8 changes: 4 additions & 4 deletions src/raw/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,10 +909,10 @@ mod tests {

#[test]
fn scan_angle() {
assert_eq!(-90i8, ScanAngle::Scaled(-15_000).into());
assert_eq!(90i8, ScanAngle::Scaled(15_000).into());
assert_eq!(-15_000i16, ScanAngle::Rank(-90).into());
assert_eq!(15_000i16, ScanAngle::Rank(90).into());
assert_eq!(-90i8, i8::from(ScanAngle::Scaled(-15_000)));
assert_eq!(90i8, i8::from(ScanAngle::Scaled(15_000)));
assert_eq!(-15_000i16, i16::from(ScanAngle::Rank(-90)));
assert_eq!(15_000i16, i16::from(ScanAngle::Rank(90)));
}

#[test]
Expand Down
26 changes: 14 additions & 12 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ pub(crate) fn read_point_from<R: std::io::Read>(
point
}

/// Trait to specify behaviour of a PointReader
/// Trait to specify behavior of a PointReader
pub(crate) trait PointReader: Debug + Send {
fn read_next(&mut self) -> Option<Result<Point>>;
fn read_into_vec(&mut self, points: &mut Vec<Point>, n: u64) -> Result<u64>;
fn read_next_points(&mut self, n: u64) -> Result<Vec<Point>> {
let mut points = Vec::with_capacity(n as usize);
self.read_into_vec(&mut points, n)?;
let _ = self.read_into_vec(&mut points, n)?;
Ok(points)
}
fn seek(&mut self, position: u64) -> Result<()>;
Expand All @@ -95,7 +95,7 @@ pub struct PointIterator<'a> {
point_reader: &'a mut dyn PointReader,
}

impl<'a> Iterator for PointIterator<'a> {
impl Iterator for PointIterator<'_> {
type Item = Result<Point>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -136,7 +136,7 @@ impl<R: std::io::Read + Seek + Debug + Send> PointReader for UncompressedPointRe

fn seek(&mut self, position: u64) -> Result<()> {
self.last_point_idx = position;
self.source.seek(SeekFrom::Start(
let _ = self.source.seek(SeekFrom::Start(
self.offset_to_point_data + position * u64::from(self.header.point_format().len()),
))?;
Ok(())
Expand Down Expand Up @@ -206,7 +206,7 @@ pub trait Read {
/// let mut reader = Reader::from_path("tests/data/autzen.las").unwrap();
/// let points = reader.points().collect::<Result<Vec<_>, _>>().unwrap();
/// ```
fn points(&mut self) -> PointIterator;
fn points(&mut self) -> PointIterator<'_>;
}

/// Reads LAS data.
Expand Down Expand Up @@ -253,7 +253,8 @@ impl<'a> Reader<'a> {
}
match position.cmp(&offset_to_point_data) {
Ordering::Less => {
read.by_ref()
let _ = read
.by_ref()
.take(offset_to_point_data - position)
.read_to_end(&mut builder.vlr_padding)?;
}
Expand All @@ -263,7 +264,7 @@ impl<'a> Reader<'a> {
}
}

read.seek(SeekFrom::Start(offset_to_end_of_points))?;
let _ = read.seek(SeekFrom::Start(offset_to_end_of_points))?;
if let Some(evlr) = evlr {
// Account for any padding between the end of the point data and the start of the ELVRs
//
Expand All @@ -285,19 +286,20 @@ impl<'a> Reader<'a> {
Ordering::Equal => {} // pass
Ordering::Greater => {
let n = evlr.start_of_first_evlr - offset_to_end_of_points;
read.by_ref()
let _ = read
.by_ref()
.take(n)
.read_to_end(&mut builder.point_padding)?;
}
}
}
read.seek(SeekFrom::Start(evlr.start_of_first_evlr))?;
let _ = read.seek(SeekFrom::Start(evlr.start_of_first_evlr))?;
builder
.evlrs
.push(raw::Vlr::read_from(&mut read, true).map(Vlr::new)?);
}

read.seek(SeekFrom::Start(offset_to_point_data))?;
let _ = read.seek(SeekFrom::Start(offset_to_point_data))?;

let header = builder.into_header()?;

Expand Down Expand Up @@ -332,7 +334,7 @@ impl<'a> Reader<'a> {
}
}

impl<'a> Read for Reader<'a> {
impl Read for Reader<'_> {
/// Returns a reference to this reader's header.
fn header(&self) -> &Header {
self.point_reader.header()
Expand Down Expand Up @@ -362,7 +364,7 @@ impl<'a> Read for Reader<'a> {
}

/// Returns an iterator over this reader's points.
fn points(&mut self) -> PointIterator {
fn points(&mut self) -> PointIterator<'_> {
PointIterator {
point_reader: &mut *self.point_reader,
}
Expand Down
2 changes: 1 addition & 1 deletion src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Default for Transform {
}

impl fmt::Display for Transform {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "`{} * x + {}`", self.scale, self.offset)
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@ use crate::{Error, Result};
use num_traits::Zero;
use std::str;

pub trait AsLasStr {
pub(crate) trait AsLasStr {
fn as_las_str(&self) -> Result<&str>;
fn as_las_string_lossy(&self) -> String;
}

pub trait FromLasStr {
pub(crate) trait FromLasStr {
fn from_las_str(&mut self, s: &str) -> Result<()>;
}

pub fn some_or_none_if_zero<T: Zero>(n: T) -> Option<T> {
pub(crate) fn some_or_none_if_zero<T: Zero>(n: T) -> Option<T> {
if n.is_zero() {
None
} else {
Some(n)
}
}

impl<'a> AsLasStr for &'a [u8] {
impl AsLasStr for &'_ [u8] {
fn as_las_str(&self) -> Result<&str> {
let s = if let Some(position) = self.iter().position(|c| *c == 0) {
if self[position..].iter().any(|c| *c != 0) {
Expand All @@ -45,7 +45,7 @@ impl<'a> AsLasStr for &'a [u8] {
}
}

impl<'a> FromLasStr for &'a mut [u8] {
impl FromLasStr for &'_ mut [u8] {
fn from_las_str(&mut self, s: &str) -> Result<()> {
if self.len() < s.bytes().count() {
return Err(Error::StringTooLong {
Expand Down
Loading

0 comments on commit 68a8f24

Please sign in to comment.