Skip to content

Commit f7cc1be

Browse files
author
Brandon Williams
committed
refactor: replace allow(...) with expect(...) or drop when unused
The `expect` attribute, stabilized in Rust 1.81, is stricter than `allow`: it verifies that the suppressed lint actually fires. This surfaces stale suppressions and prevents silently hiding new issues. Convert remaining `allow(...)` attributes to `expect(...)` across the codebase where the suppression is genuinely load-bearing. For items that are dead in non-test builds but used by tests, use `#[cfg_attr(not(test), expect(dead_code))]` so the expectation holds under every configuration. Several `allow(...)` attributes turned out to be suppressing nothing at all — drop them. Examples: - `Range::range` and `Range::empty` are called from the merge path. - `ParseOpts::no_skip_preamble` is called from the patch set parser. - `Text::ends_with` and `Text::lines` are called through the trait. - The `Diff` enum and `DiffOptions::diff` are reachable through the free `diff` fn, which is the only real anchor in that chain. - A number of `needless_lifetimes` annotations as the lint was relaxed upstream. These were all silently wrong under `allow`; `expect` caught them.
1 parent afd2faa commit f7cc1be

8 files changed

Lines changed: 9 additions & 19 deletions

File tree

‎src/binary/base85.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ pub fn decode_into(input: &[u8], output: &mut impl Extend<u8>) -> Result<(), Bas
9090
/// Callers encoding data where the byte count isn't a multiple of 4
9191
/// must handle padding at a higher level.
9292
/// For example, via a length indicator in Git binary patch format.
93-
#[allow(dead_code)] // will be used for patch formatting
93+
// will be used for patch formatting
94+
#[cfg_attr(not(test), expect(dead_code))]
9495
pub fn encode_into(input: &[u8], output: &mut impl Extend<char>) -> Result<(), Base85Error> {
9596
if input.len() % 4 != 0 {
9697
return Err(Base85Error::InvalidLength);

‎src/diff/cleanup.rs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use alloc::vec::Vec;
44

55
// Walks through all edits and shifts them up and then down, trying to see if they run into similar
66
// edits which can be merged
7-
#[allow(clippy::needless_lifetimes)]
87
pub fn compact<'a, 'b, T: ?Sized + SliceLike>(diffs: &mut Vec<DiffRange<'a, 'b, T>>) {
98
// First attempt to compact all Deletions
109
let mut pointer = 0;
@@ -29,7 +28,6 @@ pub fn compact<'a, 'b, T: ?Sized + SliceLike>(diffs: &mut Vec<DiffRange<'a, 'b,
2928
}
3029

3130
// Attempts to shift the Insertion or Deletion at location `pointer` as far upwards as possible.
32-
#[allow(clippy::needless_lifetimes)]
3331
fn shift_diff_up<'a, 'b, T: ?Sized + SliceLike>(
3432
diffs: &mut Vec<DiffRange<'a, 'b, T>>,
3533
mut pointer: usize,
@@ -131,7 +129,6 @@ fn shift_diff_up<'a, 'b, T: ?Sized + SliceLike>(
131129
}
132130

133131
// Attempts to shift the Insertion or Deletion at location `pointer` as far downwards as possible.
134-
#[allow(clippy::needless_lifetimes)]
135132
fn shift_diff_down<'a, 'b, T: ?Sized + SliceLike>(
136133
diffs: &mut Vec<DiffRange<'a, 'b, T>>,
137134
mut pointer: usize,

‎src/diff/mod.rs‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ mod myers;
1717
mod tests;
1818

1919
// TODO determine if this should be exposed in the public API
20-
#[allow(dead_code)]
2120
#[derive(Debug, PartialEq, Eq)]
2221
enum Diff<'a, T: ?Sized> {
2322
Equal(&'a T),
@@ -117,7 +116,7 @@ impl DiffOptions {
117116
/// produce a prettier diff by reducing the number of edited blocks by shifting and merging
118117
/// edit blocks.
119118
// TODO determine if this should be exposed in the public API
120-
#[allow(dead_code)]
119+
#[expect(dead_code)]
121120
fn set_compact(&mut self, compact: bool) -> &mut Self {
122121
self.compact = compact;
123122
self
@@ -146,7 +145,6 @@ impl DiffOptions {
146145
}
147146

148147
// TODO determine if this should be exposed in the public API
149-
#[allow(dead_code)]
150148
fn diff<'a>(&self, original: &'a str, modified: &'a str) -> Vec<Diff<'a, str>> {
151149
let solution = myers::diff(original.as_bytes(), modified.as_bytes());
152150

@@ -229,7 +227,7 @@ impl Default for DiffOptions {
229227
}
230228

231229
// TODO determine if this should be exposed in the public API
232-
#[allow(dead_code)]
230+
#[cfg_attr(not(test), expect(dead_code))]
233231
fn diff<'a>(original: &'a str, modified: &'a str) -> Vec<Diff<'a, str>> {
234232
DiffOptions::default().diff(original, modified)
235233
}

‎src/merge/mod.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,6 @@ fn create_merge_range<'ancestor, 'ours, 'theirs, T: ?Sized + SliceLike>(
524524
}
525525
}
526526

527-
#[allow(clippy::needless_lifetimes)]
528527
fn cleanup_conflicts<'ancestor, 'ours, 'theirs, T: ?Sized + SliceLike + PartialEq>(
529528
solution: &mut [MergeRange<'ancestor, 'ours, 'theirs, T>],
530529
) {

‎src/patch/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'a> Patch<'a, str> {
146146
///
147147
/// let patch = Patch::from_str(s).unwrap();
148148
/// ```
149-
#[allow(clippy::should_implement_trait)]
149+
#[expect(clippy::should_implement_trait)]
150150
pub fn from_str(s: &'a str) -> Result<Patch<'a, str>, ParsePatchError> {
151151
parse::parse(s)
152152
}

‎src/patch/parse.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ impl ParseOpts {
3838
///
3939
/// Useful when the caller has already positioned the input
4040
/// at the start of the patch content.
41-
#[allow(dead_code)] // will be used by patch_set parser
4241
pub(crate) fn no_skip_preamble(mut self) -> Self {
4342
self.skip_preamble = false;
4443
self
@@ -145,7 +144,7 @@ pub(crate) fn parse_one<T: Text + ?Sized>(
145144
(Ok(Patch::new(header.0, header.1, hunks)), parser.offset())
146145
}
147146

148-
#[allow(clippy::type_complexity)]
147+
#[expect(clippy::type_complexity)]
149148
fn patch_header<'a, T: Text + ?Sized>(
150149
parser: &mut Parser<'a, T>,
151150
opts: &ParseOpts,

‎src/range.rs‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ impl<'a, T: ?Sized> Range<'a, T> {
3535
self.offset
3636
}
3737

38-
#[allow(dead_code)]
3938
pub fn range(&self) -> ops::Range<usize> {
4039
self.offset..self.offset + self.len
4140
}
@@ -98,7 +97,6 @@ where
9897
Range { inner, offset, len }
9998
}
10099

101-
#[allow(dead_code)]
102100
pub fn empty() -> Range<'a, T> {
103101
Range {
104102
inner: T::empty(),
@@ -119,17 +117,17 @@ where
119117
self.as_slice().common_suffix_len(other.as_slice())
120118
}
121119

122-
#[allow(dead_code)]
120+
#[cfg_attr(not(test), expect(dead_code))]
123121
pub fn common_overlap_len(&self, other: Range<'_, T>) -> usize {
124122
self.as_slice().common_overlap_len(other.as_slice())
125123
}
126124

127-
#[allow(dead_code)]
125+
#[expect(dead_code)]
128126
pub fn starts_with(&self, prefix: Range<'_, T>) -> bool {
129127
self.as_slice().starts_with(prefix.as_slice())
130128
}
131129

132-
#[allow(dead_code)]
130+
#[expect(dead_code)]
133131
pub fn ends_with(&self, suffix: Range<'_, T>) -> bool {
134132
self.as_slice().ends_with(suffix.as_slice())
135133
}

‎src/utils.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ pub trait Text: Eq + Hash + ToOwned {
140140
fn is_empty(&self) -> bool;
141141
fn len(&self) -> usize;
142142
fn starts_with(&self, prefix: &str) -> bool;
143-
#[allow(unused)]
144143
fn ends_with(&self, suffix: &str) -> bool;
145144
fn strip_prefix(&self, prefix: &str) -> Option<&Self>;
146145
fn strip_suffix(&self, suffix: &str) -> Option<&Self>;
@@ -149,7 +148,6 @@ pub trait Text: Eq + Hash + ToOwned {
149148
fn split_at(&self, mid: usize) -> (&Self, &Self);
150149
fn as_str(&self) -> Option<&str>;
151150
fn as_bytes(&self) -> &[u8];
152-
#[allow(unused)]
153151
fn lines(&self) -> LineIter<'_, Self>;
154152

155153
/// Converts raw bytes into `Self::Owned`.

0 commit comments

Comments
 (0)