Skip to content

Commit 02f0b19

Browse files
chore: clippy
1 parent cf75d6b commit 02f0b19

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

src/draw.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ pub struct Characters {
55
pub hbar: char,
66
pub vbar: char,
77
pub xbar: char,
8+
#[allow(unused)]
89
pub vbar_break: char,
910
pub vbar_gap: char,
1011

1112
pub uarrow: char,
1213
pub rarrow: char,
1314

1415
pub ltop: char,
16+
#[allow(unused)]
1517
pub mtop: char,
1618
pub rtop: char,
1719
pub lbot: char,
@@ -22,6 +24,7 @@ pub struct Characters {
2224
pub rbox: char,
2325

2426
pub lcross: char,
27+
#[allow(unused)]
2528
pub rcross: char,
2629

2730
pub underbar: char,
@@ -234,7 +237,7 @@ impl ColorGenerator {
234237
pub fn from_state(state: [u16; 3], min_brightness: f32) -> Self {
235238
Self {
236239
state,
237-
min_brightness: min_brightness.max(0.0).min(1.0),
240+
min_brightness: min_brightness.clamp(0.0, 1.0),
238241
}
239242
}
240243

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl<S: Span> Report<'_, S> {
257257
}
258258
}
259259

260-
impl<'a, S: Span> fmt::Debug for Report<'a, S> {
260+
impl<S: Span> fmt::Debug for Report<'_, S> {
261261
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
262262
f.debug_struct("Report")
263263
.field("kind", &self.kind)
@@ -406,7 +406,7 @@ impl<'a, S: Span> ReportBuilder<'a, S> {
406406
}
407407
}
408408

409-
impl<'a, S: Span> fmt::Debug for ReportBuilder<'a, S> {
409+
impl<S: Span> fmt::Debug for ReportBuilder<'_, S> {
410410
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
411411
f.debug_struct("ReportBuilder")
412412
.field("kind", &self.kind)

src/source.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub trait Cache<Id: ?Sized> {
2525
fn display<'a>(&self, id: &'a Id) -> Option<impl fmt::Display + 'a>;
2626
}
2727

28-
impl<'b, C: Cache<Id>, Id: ?Sized> Cache<Id> for &'b mut C {
28+
impl<C: Cache<Id>, Id: ?Sized> Cache<Id> for &mut C {
2929
type Storage = C::Storage;
3030

3131
fn fetch(&mut self, id: &Id) -> Result<&Source<Self::Storage>, impl fmt::Debug> {
@@ -275,7 +275,7 @@ impl<I: AsRef<str>> Source<I> {
275275
impl<I: AsRef<str>> Cache<()> for Source<I> {
276276
type Storage = I;
277277

278-
fn fetch(&mut self, _: &()) -> Result<&Source<I>, impl fmt::Debug + '_> {
278+
fn fetch(&mut self, _: &()) -> Result<&Source<I>, impl fmt::Debug> {
279279
Ok::<_, ()>(self)
280280
}
281281
fn display<'a>(&self, _: &'a ()) -> Option<impl fmt::Display + 'a> {
@@ -286,18 +286,18 @@ impl<I: AsRef<str>> Cache<()> for Source<I> {
286286
impl<I: AsRef<str>> Cache<()> for &'_ Source<I> {
287287
type Storage = I;
288288

289-
fn fetch(&mut self, _: &()) -> Result<&Source<I>, Box<dyn fmt::Debug + '_>> {
290-
Ok(*self)
289+
fn fetch(&mut self, _: &()) -> Result<&Source<I>, impl fmt::Debug> {
290+
Ok::<_, ()>(*self)
291291
}
292-
fn display(&self, _: &()) -> Option<Box<dyn fmt::Display>> {
293-
None
292+
fn display<'a>(&self, _: &'a ()) -> std::option::Option<impl std::fmt::Display + 'a> {
293+
None::<&str>
294294
}
295295
}
296296

297297
impl<I: AsRef<str>, Id: fmt::Display + Eq> Cache<Id> for (Id, Source<I>) {
298298
type Storage = I;
299299

300-
fn fetch(&mut self, id: &Id) -> Result<&Source<I>, impl fmt::Debug + '_> {
300+
fn fetch(&mut self, id: &Id) -> Result<&Source<I>, impl fmt::Debug> {
301301
if id == &self.0 {
302302
Ok(&self.1)
303303
} else {
@@ -312,14 +312,14 @@ impl<I: AsRef<str>, Id: fmt::Display + Eq> Cache<Id> for (Id, Source<I>) {
312312
impl<I: AsRef<str>, Id: fmt::Display + Eq> Cache<Id> for (Id, &'_ Source<I>) {
313313
type Storage = I;
314314

315-
fn fetch(&mut self, id: &Id) -> Result<&Source<I>, Box<dyn fmt::Debug + '_>> {
315+
fn fetch(&mut self, id: &Id) -> Result<&Source<I>, impl fmt::Debug> {
316316
if id == &self.0 {
317317
Ok(self.1)
318318
} else {
319319
Err(Box::new(format!("Failed to fetch source '{}'", id)))
320320
}
321321
}
322-
fn display<'a>(&self, id: &'a Id) -> Option<Box<dyn fmt::Display + 'a>> {
322+
fn display<'a>(&self, id: &'a Id) -> Option<impl fmt::Display + 'a> {
323323
Some(Box::new(id))
324324
}
325325
}
@@ -333,7 +333,7 @@ pub struct FileCache {
333333
impl Cache<Path> for FileCache {
334334
type Storage = String;
335335

336-
fn fetch(&mut self, path: &Path) -> Result<&Source, impl fmt::Debug + '_> {
336+
fn fetch(&mut self, path: &Path) -> Result<&Source, impl fmt::Debug> {
337337
Ok::<_, Error>(match self.files.entry(path.to_path_buf()) {
338338
// TODO: Don't allocate here
339339
Entry::Occupied(entry) => entry.into_mut(),

src/write.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ struct LabelInfo<'a> {
2626
display_info: &'a LabelDisplay,
2727
}
2828

29-
impl<'a> LabelInfo<'a> {
29+
impl LabelInfo<'_> {
3030
fn last_offset(&self) -> usize {
3131
self.char_span
3232
.end
@@ -73,7 +73,7 @@ impl<S: Span> Report<'_, S> {
7373
.take(col)
7474
.map(|ch| ch.len_utf8())
7575
.sum();
76-
byte_offset.end = byte_offset.start as usize
76+
byte_offset.end = byte_offset.start
7777
+ src
7878
.chars()
7979
.skip(line_obj.offset() + col)
@@ -451,7 +451,7 @@ impl<S: Span> Report<'_, S> {
451451

452452
if let (Some((margin, _is_start)), true) = (margin_ptr, is_line) {
453453
let is_col =
454-
multi_label.map_or(false, |ml| std::ptr::eq(*ml, margin.label));
454+
multi_label.is_some_and(|ml| std::ptr::eq(*ml, margin.label));
455455
let is_limit = col + 1 == multi_labels_with_message.len();
456456
if !is_col && !is_limit {
457457
hbar = hbar.or(Some(margin.label));
@@ -495,7 +495,7 @@ impl<S: Span> Report<'_, S> {
495495
)
496496
} else if let (Some((margin, is_start)), true) = (margin_ptr, is_line) {
497497
let is_col =
498-
multi_label.map_or(false, |ml| std::ptr::eq(*ml, margin.label));
498+
multi_label.is_some_and(|ml| std::ptr::eq(*ml, margin.label));
499499
let is_limit = col == multi_labels_with_message.len();
500500
(
501501
if is_limit {
@@ -536,8 +536,7 @@ impl<S: Span> Report<'_, S> {
536536

537537
let margin_label = multi_labels_with_message
538538
.iter()
539-
.enumerate()
540-
.filter_map(|(_i, label)| {
539+
.filter_map(|label| {
541540
let is_start = line.span().contains(&label.char_span.start);
542541
let is_end = line.span().contains(&label.last_offset());
543542
if is_start {
@@ -564,8 +563,7 @@ impl<S: Span> Report<'_, S> {
564563
// Generate a list of labels for this line, along with their label columns
565564
let mut line_labels = multi_labels_with_message
566565
.iter()
567-
.enumerate()
568-
.filter_map(|(_i, label)| {
566+
.filter_map(|label| {
569567
let is_start = line.span().contains(&label.char_span.start);
570568
let is_end = line.span().contains(&label.last_offset());
571569
if is_start
@@ -1561,7 +1559,7 @@ mod tests {
15611559
fn ascii() {
15621560
let source = "'🤨🤨🤨🤨' + import('missing');";
15631561

1564-
let label = Label::new(28..37).with_message(format!("This is of type "));
1562+
let label = Label::new(28..37).with_message("This is of type ");
15651563
let msg = remove_trailing(
15661564
Report::build(ReportKind::Error, 0..0)
15671565
.with_config(no_color_and_ascii().with_index_type(IndexType::Byte))

0 commit comments

Comments
 (0)