Skip to content

Commit

Permalink
Adds #![deny(rust_2018_idioms)], applies lifetime elision suggestions (
Browse files Browse the repository at this point in the history
  • Loading branch information
zslayton authored Dec 2, 2024
1 parent 4e7431f commit 137d79e
Show file tree
Hide file tree
Showing 73 changed files with 497 additions and 439 deletions.
18 changes: 6 additions & 12 deletions benches/read_many_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ fn maximally_compact_1_1_data(num_values: usize) -> TestData_1_1 {

let mut binary_1_1_data = vec![0xE0u8, 0x01, 0x01, 0xEA]; // IVM
#[rustfmt::skip]
let mut binary_1_1_data_body: Vec<u8> = vec![
MacroTable::FIRST_USER_MACRO_ID as u8, // Macro ID
let mut binary_1_1_data_body: Vec<u8> = [MacroTable::FIRST_USER_MACRO_ID as u8, // Macro ID
0b10, // [NOTE: `0b`] `parameters*` arg is an arg group
0x66, // 6-byte integer (`timestamp` param)
0x75, 0x5D, 0x63, 0xEE, 0x84, 0x01,
Expand All @@ -73,8 +72,7 @@ fn maximally_compact_1_1_data(num_values: usize) -> TestData_1_1 {
0x32, 0x30, 0x3A, 0x35,
0x39, 0x3A, 0x35, 0x39,
0x2E, 0x37, 0x34, 0x34,
0x30, 0x30, 0x30, 0x5A,
].repeat(num_values);
0x30, 0x30, 0x30, 0x5A].repeat(num_values);
binary_1_1_data.append(&mut binary_1_1_data_body);
TestData_1_1 {
name: "maximally compact".to_owned(),
Expand Down Expand Up @@ -111,8 +109,7 @@ fn moderately_compact_1_1_data(num_values: usize) -> TestData_1_1 {
let text_1_1_data = r#"(:event 1670446800245 418 "scheduler-thread-6" "example-client-1" "aws-us-east-5f-abc123" (: "region 4" "2022-12-07T20:59:59.744000Z"))"#.repeat(num_values);
let mut binary_1_1_data = vec![0xE0u8, 0x01, 0x01, 0xEA]; // IVM
#[rustfmt::skip]
let mut binary_1_1_data_body: Vec<u8> = vec![
MacroTable::FIRST_USER_MACRO_ID as u8, // Macro ID
let mut binary_1_1_data_body: Vec<u8> = [MacroTable::FIRST_USER_MACRO_ID as u8, // Macro ID
0b10, // [NOTE: `0b` prefix] `parameters*` arg is an arg group
0x66, // 6-byte integer (`timestamp` param)
0x75, 0x5D, 0x63, 0xEE, 0x84, 0x01,
Expand Down Expand Up @@ -143,8 +140,7 @@ fn moderately_compact_1_1_data(num_values: usize) -> TestData_1_1 {
0x32, 0x30, 0x3A, 0x35,
0x39, 0x3A, 0x35, 0x39,
0x2E, 0x37, 0x34, 0x34,
0x30, 0x30, 0x30, 0x5A,
].repeat(num_values);
0x30, 0x30, 0x30, 0x5A].repeat(num_values);

binary_1_1_data.append(&mut binary_1_1_data_body);
TestData_1_1 {
Expand Down Expand Up @@ -182,8 +178,7 @@ fn length_prefixed_moderately_compact_1_1_data(num_values: usize) -> TestData_1_
let text_1_1_data = r#"(:event 1670446800245 418 "scheduler-thread-6" "example-client-1" "aws-us-east-5f-abc123" (: "region 4" "2022-12-07T20:59:59.744000Z"))"#.repeat(num_values);
let mut binary_1_1_data = vec![0xE0u8, 0x01, 0x01, 0xEA]; // IVM
#[rustfmt::skip]
let mut binary_1_1_data_body: Vec<u8> = vec![
0xF5, // LP invocation
let mut binary_1_1_data_body: Vec<u8> = [0xF5, // LP invocation
((MacroTable::FIRST_USER_MACRO_ID * 2) + 1) as u8, // Macro ID
0xDF, // Length prefix: FlexUInt 111
0b10, // [NOTE: `0b` prefix] `parameters*` arg is an arg group
Expand Down Expand Up @@ -216,8 +211,7 @@ fn length_prefixed_moderately_compact_1_1_data(num_values: usize) -> TestData_1_
0x32, 0x30, 0x3A, 0x35,
0x39, 0x3A, 0x35, 0x39,
0x2E, 0x37, 0x34, 0x34,
0x30, 0x30, 0x30, 0x5A,
].repeat(num_values);
0x30, 0x30, 0x30, 0x5A].repeat(num_values);

binary_1_1_data.append(&mut binary_1_1_data_body);
TestData_1_1 {
Expand Down
4 changes: 2 additions & 2 deletions benches/write_many_structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ mod benchmark {
// $16 = parameters
.write(
16,
&[
[
black_box("SUCCESS"),
black_box("example-client-1"),
black_box("aws-us-east-5f-abc-123"),
Expand Down Expand Up @@ -68,7 +68,7 @@ mod benchmark {
// $16 = parameters
.write(
16,
&[
[
// $21 = SUCCESS
symbol_id(black_box(21)),
// $22 = example-client-1
Expand Down
2 changes: 1 addition & 1 deletion examples/read_all_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod lazy_reader_example {
pub fn read_all_values() -> IonResult<()> {
let args: Vec<String> = std::env::args().collect();
let path = args.get(1).unwrap_or_else(|| {
eprintln!("USAGE:\n\n {} [Binary Ion file]\n", args.get(0).unwrap());
eprintln!("USAGE:\n\n {} [Binary Ion file]\n", args.first().unwrap());
eprintln!("No mode was specified.");
exit(1);
});
Expand Down
30 changes: 15 additions & 15 deletions examples/write_log_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ mod example {
// By default, this program deletes the encoded output before it ends. To keep the files
// for further review, you can pass a `--keep-files`/`-k` flag.
let args: Vec<String> = args().collect();
let keep_files_flag = match args.get(1).map(|a| a.as_str()) {
Some("--keep-files") | Some("-k") => true,
_ => false,
};
let keep_files_flag = matches!(
args.get(1).map(|a| a.as_str()),
Some("--keep-files") | Some("-k")
);

// Create a set of Log4J-style statements that might appear in a typical program. These statements
// have a fixed combination of (logger name, log level, format string) fields.
Expand Down Expand Up @@ -179,13 +179,13 @@ mod example {
// field name/value pair. In the case of recurring strings, we take the liberty of writing
// out symbol IDs instead of the full text; this silent type coercion from string to symbol
// is technically data loss, but results in a much more compact encoding.
impl<'a, 'b> WriteAsIon for SerializeWithoutMacros<'a, 'b> {
impl WriteAsIon for SerializeWithoutMacros<'_, '_> {
fn write_as_ion<V: ValueWriter>(&self, writer: V) -> IonResult<()> {
let event = self.0;
let mut struct_ = writer.struct_writer()?;
struct_
// v--- Each field name is a symbol ID
.write(10, &event.timestamp)?
.write(10, event.timestamp)?
.write(11, event.thread_id)?
.write(12, &event.thread_name)?
// v--- The fixed strings from the log statement are also SIDs
Expand All @@ -202,7 +202,7 @@ mod example {
// behavior for the thread name.
struct ThreadName<'a>(&'a str);

impl<'a> WriteAsIon for ThreadName<'a> {
impl WriteAsIon for ThreadName<'_> {
fn write_as_ion<V: ValueWriter>(&self, writer: V) -> IonResult<()> {
// ID 12 chosen arbitrarily, but aligns with Ion 1.0 encoding above
let mut eexp = writer.eexp_writer(12)?;
Expand All @@ -213,11 +213,11 @@ mod example {
}
}

impl<'a, 'b> WriteAsIon for SerializeWithMacros<'a, 'b> {
impl WriteAsIon for SerializeWithMacros<'_, '_> {
fn write_as_ion<V: ValueWriter>(&self, writer: V) -> IonResult<()> {
let event = self.0;
let mut eexp = writer.eexp_writer(event.statement.index)?;
eexp.write(&event.timestamp)?
eexp.write(event.timestamp)?
.write(event.thread_id)?
// Wrap the thread name in the `ThreadName` wrapper to change its serialization.
.write(ThreadName(&event.thread_name))?
Expand Down Expand Up @@ -246,28 +246,28 @@ mod example {
"Foo",
"DEBUG",
"Database heartbeat received after {} ms",
&[Int]
[Int]
),
LogStatement::new(
1,
"Bar",
"INFO",
"Retrieved {} results from the '{}' table in {} ms",
&[Int, String, Int],
[Int, String, Int],
),
LogStatement::new(
2,
"Baz",
"WARN",
"Query to the '{}' table took {} ms to execute, which is higher than the configured threshold",
&[String, Int],
[String, Int],
),
LogStatement::new(
3,
"Quux",
"ERROR",
"Connection to database lost",
&[]
[]
),
]
}
Expand All @@ -287,8 +287,8 @@ mod example {
.collect()
}

fn generate_event<'rng, 'statements>(
rng: &'rng mut StdRng,
fn generate_event<'statements>(
rng: &mut StdRng,
log_statements: &'statements [LogStatement],
event_index: usize,
) -> LogEvent<'statements> {
Expand Down
2 changes: 1 addition & 1 deletion src/element/annotations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Annotations {

/// Returns an [`Iterator`] that yields each of the [`Symbol`]s in this annotations
/// sequence in order.
pub fn iter(&self) -> SymbolsIterator {
pub fn iter(&self) -> SymbolsIterator<'_> {
SymbolsIterator::new(self.symbols.as_slice())
}

Expand Down
2 changes: 1 addition & 1 deletion src/element/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct ElementIterator<'a, R: ElementReader + ?Sized> {
reader: &'a mut R,
}

impl<'a, R: ElementReader + ?Sized> Iterator for ElementIterator<'a, R> {
impl<R: ElementReader + ?Sized> Iterator for ElementIterator<'_, R> {
type Item = IonResult<Element>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
28 changes: 14 additions & 14 deletions src/lazy/any_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub enum LazyRawAnyVersionMarkerKind<'top> {
Binary_1_1(LazyRawBinaryVersionMarker_1_1<'top>),
}

impl<'top> LazyRawAnyVersionMarker<'top> {
impl LazyRawAnyVersionMarker<'_> {
pub fn encoding(&self) -> IonEncoding {
use crate::lazy::any_encoding::LazyRawAnyVersionMarkerKind::*;
match self.encoding {
Expand All @@ -127,7 +127,7 @@ impl<'top> HasSpan<'top> for LazyRawAnyVersionMarker<'top> {
}
}

impl<'top> HasRange for LazyRawAnyVersionMarker<'top> {
impl HasRange for LazyRawAnyVersionMarker<'_> {
fn range(&self) -> Range<usize> {
use LazyRawAnyVersionMarkerKind::*;
match self.encoding {
Expand Down Expand Up @@ -240,7 +240,7 @@ impl<'top> HasSpan<'top> for LazyRawAnyEExpression<'top> {
}
}

impl<'top> HasRange for LazyRawAnyEExpression<'top> {
impl HasRange for LazyRawAnyEExpression<'_> {
fn range(&self) -> Range<usize> {
use LazyRawAnyEExpressionKind::*;
match self.encoding {
Expand Down Expand Up @@ -286,7 +286,7 @@ pub enum AnyEExpArgGroupKind<'top> {
Binary_1_1(BinaryEExpArgGroup<'top>),
}

impl<'top> AnyEExpArgGroupKind<'top> {
impl AnyEExpArgGroupKind<'_> {
fn encoding(&self) -> &ParameterEncoding {
match self {
AnyEExpArgGroupKind::Text_1_1(g) => g.encoding(),
Expand All @@ -295,7 +295,7 @@ impl<'top> AnyEExpArgGroupKind<'top> {
}
}

impl<'top> HasRange for AnyEExpArgGroup<'top> {
impl HasRange for AnyEExpArgGroup<'_> {
fn range(&self) -> Range<usize> {
match self.kind {
AnyEExpArgGroupKind::Text_1_1(group) => group.range(),
Expand Down Expand Up @@ -445,7 +445,7 @@ pub struct LazyRawAnyReader<'data> {
encoding_reader: RawReaderKind<'data>,
}

impl<'data> LazyRawAnyReader<'data> {
impl LazyRawAnyReader<'_> {
fn detect_encoding(data: &[u8]) -> IonEncoding {
const BINARY_1_0_IVM: &[u8] = &[0xEA, 0x01, 0x00, 0xE0];

Expand Down Expand Up @@ -478,7 +478,7 @@ impl<'data> RawReaderKind<'data> {
data: &'data [u8],
stream_offset: usize,
encoding_hint: IonEncoding,
) -> RawReaderKind {
) -> RawReaderKind<'data> {
use IonEncoding::*;
match encoding_hint {
Text_1_0 => RawReaderKind::Text_1_0(LazyRawTextReader_1_0::resume_at_offset(
Expand Down Expand Up @@ -659,7 +659,7 @@ impl<'data> LazyRawReader<'data, AnyEncoding> for LazyRawAnyReader<'data> {
}

use RawReaderKind::*;
let item: LazyRawStreamItem<AnyEncoding> = match &mut self.encoding_reader {
let item: LazyRawStreamItem<'_, AnyEncoding> = match &mut self.encoding_reader {
Text_1_0(r) => r.next(context)?.into(),
Binary_1_0(r) => r.next()?.into(),
Text_1_1(r) => r.next(context)?.into(),
Expand Down Expand Up @@ -1008,7 +1008,7 @@ impl<'top> HasSpan<'top> for LazyRawAnyValue<'top> {
}
}

impl<'top> HasRange for LazyRawAnyValue<'top> {
impl HasRange for LazyRawAnyValue<'_> {
fn range(&self) -> Range<usize> {
use LazyRawValueKind::*;
match &self.encoding {
Expand Down Expand Up @@ -1490,7 +1490,7 @@ impl<'top> HasSpan<'top> for LazyRawAnyFieldName<'top> {
}
}

impl<'top> HasRange for LazyRawAnyFieldName<'top> {
impl HasRange for LazyRawAnyFieldName<'_> {
fn range(&self) -> Range<usize> {
use LazyRawFieldNameKind::*;
match self.encoding {
Expand Down Expand Up @@ -1817,8 +1817,8 @@ mod tests {
}

fn expect_version_change(
context_ref: EncodingContextRef,
reader: &mut LazyRawAnyReader,
context_ref: EncodingContextRef<'_>,
reader: &mut LazyRawAnyReader<'_>,
encoding_before: IonEncoding,
encoding_after: IonEncoding,
) -> IonResult<()> {
Expand All @@ -1835,8 +1835,8 @@ mod tests {
}

fn expect_int(
context_ref: EncodingContextRef,
reader: &mut LazyRawAnyReader,
context_ref: EncodingContextRef<'_>,
reader: &mut LazyRawAnyReader<'_>,
expected_encoding: IonEncoding,
expected_int: i64,
) -> IonResult<()> {
Expand Down
6 changes: 3 additions & 3 deletions src/lazy/binary/immutable_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct BinaryBuffer<'a> {
offset: usize,
}

impl<'a> Debug for BinaryBuffer<'a> {
impl Debug for BinaryBuffer<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "BinaryBuffer {{")?;
for byte in self.bytes().iter().take(16) {
Expand All @@ -57,11 +57,11 @@ pub(crate) type ParseResult<'a, T> = IonResult<(T, BinaryBuffer<'a>)>;
impl<'a> BinaryBuffer<'a> {
/// Constructs a new `BinaryBuffer` that wraps `data`.
#[inline]
pub fn new(data: &[u8]) -> BinaryBuffer {
pub fn new(data: &[u8]) -> BinaryBuffer<'_> {
Self::new_with_offset(data, 0)
}

pub fn new_with_offset(data: &[u8], offset: usize) -> BinaryBuffer {
pub fn new_with_offset(data: &[u8], offset: usize) -> BinaryBuffer<'_> {
BinaryBuffer { data, offset }
}

Expand Down
4 changes: 2 additions & 2 deletions src/lazy/binary/raw/sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl<'top> LazyRawBinarySequence_1_0<'top> {
}
}

impl<'a, 'top> IntoIterator for &'a LazyRawBinarySequence_1_0<'top> {
impl<'top> IntoIterator for &LazyRawBinarySequence_1_0<'top> {
type Item = IonResult<LazyRawValueExpr<'top, BinaryEncoding_1_0>>;
type IntoIter = RawBinarySequenceIterator_1_0<'top>;

Expand All @@ -115,7 +115,7 @@ impl<'a, 'top> IntoIterator for &'a LazyRawBinarySequence_1_0<'top> {
}
}

impl<'a> Debug for LazyRawBinarySequence_1_0<'a> {
impl Debug for LazyRawBinarySequence_1_0<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self.value.encoded_value.ion_type() {
IonType::SExp => {
Expand Down
8 changes: 4 additions & 4 deletions src/lazy/binary/raw/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'top> LazyRawBinaryStruct_1_0<'top> {
}
}

impl<'a, 'top> IntoIterator for &'a LazyRawBinaryStruct_1_0<'top> {
impl<'top> IntoIterator for &LazyRawBinaryStruct_1_0<'top> {
type Item = IonResult<LazyRawFieldExpr<'top, BinaryEncoding_1_0>>;
type IntoIter = RawBinaryStructIterator_1_0<'top>;

Expand All @@ -36,7 +36,7 @@ impl<'a, 'top> IntoIterator for &'a LazyRawBinaryStruct_1_0<'top> {
}
}

impl<'top> Debug for LazyRawBinaryStruct_1_0<'top> {
impl Debug for LazyRawBinaryStruct_1_0<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{{")?;
for field in self {
Expand Down Expand Up @@ -129,7 +129,7 @@ impl<'top> HasSpan<'top> for LazyRawBinaryFieldName_1_0<'top> {
}
}

impl<'top> HasRange for LazyRawBinaryFieldName_1_0<'top> {
impl HasRange for LazyRawBinaryFieldName_1_0<'_> {
fn range(&self) -> Range<usize> {
self.matched.range()
}
Expand Down Expand Up @@ -157,7 +157,7 @@ mod tests {
// occupy the specified input ranges.
type FieldNameAndRange<'a> = (RawSymbolRef<'a>, Range<usize>);
type FieldTest<'a> = (&'a [u8], &'a [FieldNameAndRange<'a>]);
let tests: &[FieldTest] = &[
let tests: &[FieldTest<'_>] = &[
// (Ion input, expected ranges of the struct's field names)
(
&[0xD2, 0x84, 0x80], // {name: ""}
Expand Down
Loading

0 comments on commit 137d79e

Please sign in to comment.