Skip to content

Commit f507dbf

Browse files
authored
Merge pull request #388 from brendanzab/enable-clippy
Fix clippy lints
2 parents 53dcccd + 46f19eb commit f507dbf

File tree

17 files changed

+85
-80
lines changed

17 files changed

+85
-80
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ jobs:
4848
# runs-on: ubuntu-latest
4949
# strategy:
5050
# matrix:
51-
# rust-toolchain: ["stable", "minimum"]
52-
# name: Clippy (${{ matrix.rust }})
51+
# rust-toolchain: ["stable"]
52+
# name: Clippy (${{ matrix.rust-toolchain }})
5353
# steps:
5454
# - name: Checkout repository
5555
# uses: actions/checkout@v3
5656
# - name: Install Nix
5757
# uses: cachix/install-nix-action@v17
58-
#
58+
5959
# - name: Run cargo clippy
60-
# run: nix develop .#${{ matrix.rust }} --command cargo clippy --deny warnings
60+
# run: nix develop .#${{ matrix.rust-toolchain }} --command cargo clippy -- --deny warnings
6161

6262
nixpkgs-fmt:
6363
runs-on: ubuntu-latest

fathom/src/alloc.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ impl<'a, Elem> Deref for SliceVec<'a, Elem> {
6969
}
7070
}
7171

72-
impl<'a, Elem> Into<&'a [Elem]> for SliceVec<'a, Elem> {
73-
fn into(self) -> &'a [Elem] {
72+
impl<'a, Elem> From<SliceVec<'a, Elem>> for &'a [Elem] {
73+
fn from(slice: SliceVec<'a, Elem>) -> Self {
7474
// SAFETY: This is safe because we know that `self.elems[..self.next_index]`
7575
// only ever contains elements initialized with `MaybeUninit::new`.
7676
// We know this because:
@@ -79,12 +79,13 @@ impl<'a, Elem> Into<&'a [Elem]> for SliceVec<'a, Elem> {
7979
// - `self.next_index` is only incremented in `SliceBuilder::push`,
8080
// and in that case we make sure `self.elems[self.next_index]`
8181
// has been initialized before hand.
82-
unsafe { slice_assume_init_ref(&self.elems[..self.next_index]) }
82+
unsafe { slice_assume_init_ref(&slice.elems[..slice.next_index]) }
8383
}
8484
}
8585

8686
// NOTE: This is the same implementation as `MaybeUninit::slice_assume_init_ref`,
8787
// which is currently unstable (see https://github.com/rust-lang/rust/issues/63569).
88+
#[allow(clippy::needless_lifetimes)] // These serve as important documentation
8889
pub unsafe fn slice_assume_init_ref<'a, T>(slice: &'a [MaybeUninit<T>]) -> &'a [T] {
8990
// SAFETY: casting slice to a `*const [T]` is safe since the caller guarantees that
9091
// `slice` is initialized, and`MaybeUninit` is guaranteed to have the same layout as `T`.

fathom/src/core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ def_prims! {
552552
}
553553

554554
/// Formatting style for integers
555-
#[derive(Debug, Copy, Clone, PartialEq, PartialOrd)]
555+
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd)]
556556
pub enum UIntStyle {
557557
Binary,
558558
Decimal,

fathom/src/core/binary.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl<'data> BufferReader<'data> {
180180
/// Set the offset of the reader relative to the start position.
181181
pub fn set_offset(&mut self, offset: usize) -> Result<(), BufferError> {
182182
usize::checked_sub(offset, self.buffer.start_offset)
183-
.ok_or_else(|| BufferError::SetOffsetBeforeStartOfBuffer { offset })
183+
.ok_or(BufferError::SetOffsetBeforeStartOfBuffer { offset })
184184
.and_then(|relative_offset| self.set_relative_offset(relative_offset))
185185
}
186186

@@ -329,7 +329,7 @@ impl<'arena, 'env, 'data> Context<'arena, 'env, 'data> {
329329
))
330330
}
331331
Value::FormatCond(_label, format, cond) => {
332-
let value = self.read_format(reader, &format)?;
332+
let value = self.read_format(reader, format)?;
333333
let cond_res = self.elim_env().apply_closure(cond, value.clone());
334334

335335
match cond_res.as_ref() {
@@ -392,7 +392,7 @@ impl<'arena, 'env, 'data> Context<'arena, 'env, 'data> {
392392
) -> Result<ArcValue<'arena>, ReadError<'arena>> {
393393
use crate::core::semantics::Elim::FunApp;
394394

395-
match (prim, &slice[..]) {
395+
match (prim, slice) {
396396
(Prim::FormatU8, []) => read_const(reader, span, read_u8, |num| Const::U8(num, UIntStyle::Decimal)),
397397
(Prim::FormatU16Be, []) => read_const(reader, span, read_u16be, |num| Const::U16(num, UIntStyle::Decimal)),
398398
(Prim::FormatU16Le, []) => read_const(reader, span, read_u16le, |num| Const::U16(num, UIntStyle::Decimal)),
@@ -445,7 +445,7 @@ impl<'arena, 'env, 'data> Context<'arena, 'env, 'data> {
445445
Value::ConstLit(Const::U8(len, _)) => u64::from(*len),
446446
Value::ConstLit(Const::U16(len, _)) => u64::from(*len),
447447
Value::ConstLit(Const::U32(len, _)) => u64::from(*len),
448-
Value::ConstLit(Const::U64(len, _)) => u64::from(*len),
448+
Value::ConstLit(Const::U64(len, _)) => *len,
449449
_ => return Err(ReadError::InvalidValue(len.span())),
450450
};
451451

@@ -552,27 +552,27 @@ impl<'arena, 'env, 'data> Context<'arena, 'env, 'data> {
552552
// that parsed reference alongside the position in `Const::Ref`.
553553

554554
(self.cached_refs.get(&pos)?.iter())
555-
.find(|r| self.conversion_env().is_equal(&r.format, &format))
555+
.find(|r| self.conversion_env().is_equal(&r.format, format))
556556
}
557557

558558
fn lookup_or_read_ref(
559559
&mut self,
560560
pos: usize,
561561
format: &ArcValue<'arena>,
562562
) -> Result<ArcValue<'arena>, ReadError<'arena>> {
563-
if let Some(parsed_ref) = self.lookup_ref(pos, &format) {
563+
if let Some(parsed_ref) = self.lookup_ref(pos, format) {
564564
return Ok(parsed_ref.expr.clone());
565565
}
566566

567567
// Read the data at the ref location
568568
let mut reader = self.initial_buffer.reader_with_offset(pos)?;
569-
let expr = self.read_format(&mut reader, &format)?;
569+
let expr = self.read_format(&mut reader, format)?;
570570

571571
// We might have parsed the current reference during the above call to
572572
// `read_format`. It's unclear if this could ever happen in practice,
573573
// especially without succumbing to non-termination, but we'll panic
574574
// here just in case.
575-
if let Some(_) = self.lookup_ref(pos, &format) {
575+
if self.lookup_ref(pos, format).is_some() {
576576
panic!("recursion found when storing cached reference {}", pos);
577577
}
578578

@@ -614,11 +614,11 @@ fn read_const<'arena, 'data, T>(
614614
))
615615
}
616616

617-
fn read_u8<'data>(reader: &mut BufferReader<'data>) -> Result<u8, BufferError> {
617+
fn read_u8(reader: &mut BufferReader<'_>) -> Result<u8, BufferError> {
618618
reader.read_byte()
619619
}
620620

621-
fn read_s8<'data>(reader: &mut BufferReader<'data>) -> Result<i8, BufferError> {
621+
fn read_s8(reader: &mut BufferReader<'_>) -> Result<i8, BufferError> {
622622
reader.read_byte().map(|b| b as i8)
623623
}
624624

fathom/src/core/semantics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'arena> Value<'arena> {
7474

7575
pub fn match_prim_spine(&self) -> Option<(Prim, &[Elim<'arena>])> {
7676
match self {
77-
Value::Stuck(Head::Prim(prim), spine) => Some((*prim, &spine)),
77+
Value::Stuck(Head::Prim(prim), spine) => Some((*prim, spine)),
7878
_ => None,
7979
}
8080
}
@@ -1156,7 +1156,7 @@ impl<'arena, 'env> ConversionEnv<'arena, 'env> {
11561156
(Value::RecordLit(labels0, exprs0), Value::RecordLit(labels1, exprs1)) => {
11571157
labels0 == labels1
11581158
&& Iterator::zip(exprs0.iter(), exprs1.iter())
1159-
.all(|(expr0, expr1)| self.is_equal(&expr0, &expr1))
1159+
.all(|(expr0, expr1)| self.is_equal(expr0, expr1))
11601160
}
11611161
(Value::RecordLit(labels, exprs), _) => {
11621162
self.is_equal_record_lit(labels, exprs, &value1)
@@ -1167,7 +1167,7 @@ impl<'arena, 'env> ConversionEnv<'arena, 'env> {
11671167

11681168
(Value::ArrayLit(elem_exprs0), Value::ArrayLit(elem_exprs1)) => {
11691169
Iterator::zip(elem_exprs0.iter(), elem_exprs1.iter())
1170-
.all(|(elem_expr0, elem_expr1)| self.is_equal(&elem_expr0, &elem_expr1))
1170+
.all(|(elem_expr0, elem_expr1)| self.is_equal(elem_expr0, elem_expr1))
11711171
}
11721172

11731173
(Value::FormatRecord(labels0, formats0), Value::FormatRecord(labels1, formats1))

fathom/src/driver.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'surface, 'core> Driver<'surface, 'core> {
9797
.with_notes(vec![
9898
match location {
9999
Some(location) => format!("panicked at: {}", location),
100-
None => format!("panicked at: unknown location"),
100+
None => "panicked at: unknown location".to_owned(),
101101
},
102102
format!("please file a bug report at: {}", BUG_REPORT_URL),
103103
// TODO: print rust backtrace
@@ -140,7 +140,7 @@ impl<'surface, 'core> Driver<'surface, 'core> {
140140

141141
/// Load a source string into the file database.
142142
pub fn load_source_string(&mut self, name: String, source: String) -> FileId {
143-
self.files.add(name.to_owned(), source)
143+
self.files.add(name, source)
144144
}
145145

146146
/// Load a source file into the file database using a reader.
@@ -272,7 +272,7 @@ impl<'surface, 'core> Driver<'surface, 'core> {
272272
Status::Ok
273273
}
274274

275-
pub fn read_and_emit_format<'data>(
275+
pub fn read_and_emit_format(
276276
&mut self,
277277
module_file_id: Option<FileId>,
278278
format_file_id: FileId,
@@ -380,7 +380,7 @@ impl<'surface, 'core> Driver<'surface, 'core> {
380380
context.space(),
381381
context.sequence(
382382
context.text("["),
383-
exprs.iter().map(|expr| context.term(&expr)),
383+
exprs.iter().map(|expr| context.term(expr)),
384384
context.text(","),
385385
context.text("]"),
386386
),
@@ -455,7 +455,7 @@ impl<'surface, 'core> Driver<'surface, 'core> {
455455
)
456456
.with_notes(vec![
457457
"The predicate on a conditional format did not succeed.".to_string(),
458-
format!("failed value: {}", doc.pretty(self.emit_width).to_string()),
458+
format!("failed value: {}", doc.pretty(self.emit_width)),
459459
])
460460
}
461461
ReadError::UnwrappedNone(_) => Diagnostic::error()

fathom/src/env.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl<Entry> SliceEnv<Entry> {
250250
}
251251

252252
/// Iterate over the elements in the environment.
253-
pub fn iter<'this>(&'this self) -> impl 'this + DoubleEndedIterator<Item = &'this Entry> {
253+
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &Entry> {
254254
self.entries.iter()
255255
}
256256
}
@@ -326,7 +326,7 @@ impl<Entry> SharedEnv<Entry> {
326326
}
327327

328328
/// Iterate over the elements in the environment.
329-
pub fn iter<'this>(&'this self) -> impl 'this + DoubleEndedIterator<Item = &'this Entry> {
329+
pub fn iter(&self) -> impl DoubleEndedIterator<Item = &Entry> {
330330
self.entries.iter()
331331
}
332332
}

fathom/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#![doc = include_str!("../../README.md")]
2+
#![allow(clippy::bool_assert_comparison)]
3+
#![allow(clippy::len_without_is_empty)]
4+
#![allow(clippy::new_without_default)]
25

36
// Supporting modules
47
mod alloc;

fathom/src/source.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ impl ByteRange {
124124
}
125125
}
126126

127-
impl Into<std::ops::Range<usize>> for ByteRange {
128-
fn into(self) -> std::ops::Range<usize> {
129-
self.start..self.end
127+
impl From<ByteRange> for std::ops::Range<usize> {
128+
fn from(range: ByteRange) -> Self {
129+
range.start..range.end
130130
}
131131
}

fathom/src/surface.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ use scoped_arena::Scope;
1010
use crate::source::{ByteRange, FileId};
1111
use crate::{StringId, StringInterner};
1212

13-
lalrpop_mod!(grammar, "/surface/grammar.rs");
13+
lalrpop_mod!(
14+
#[allow(clippy::all)]
15+
grammar,
16+
"/surface/grammar.rs"
17+
);
1418
mod lexer;
1519
pub mod pretty;
1620

0 commit comments

Comments
 (0)