diff --git a/codespan-reporting/src/diagnostic.rs b/codespan-reporting/src/diagnostic.rs index 98924d65..f5215a03 100644 --- a/codespan-reporting/src/diagnostic.rs +++ b/codespan-reporting/src/diagnostic.rs @@ -90,6 +90,7 @@ impl Label { } /// Add a message to the diagnostic. + #[must_use] pub fn with_message(mut self, message: impl Display) -> Label { self.message = message.to_string(); self @@ -137,6 +138,7 @@ impl Diagnostic { /// Create a new diagnostic with a severity of [`Severity::Bug`]. /// /// [`Severity::Bug`]: Severity::Bug + #[must_use] pub fn bug() -> Diagnostic { Diagnostic::new(Severity::Bug) } @@ -144,6 +146,7 @@ impl Diagnostic { /// Create a new diagnostic with a severity of [`Severity::Error`]. /// /// [`Severity::Error`]: Severity::Error + #[must_use] pub fn error() -> Diagnostic { Diagnostic::new(Severity::Error) } @@ -151,6 +154,7 @@ impl Diagnostic { /// Create a new diagnostic with a severity of [`Severity::Warning`]. /// /// [`Severity::Warning`]: Severity::Warning + #[must_use] pub fn warning() -> Diagnostic { Diagnostic::new(Severity::Warning) } @@ -158,6 +162,7 @@ impl Diagnostic { /// Create a new diagnostic with a severity of [`Severity::Note`]. /// /// [`Severity::Note`]: Severity::Note + #[must_use] pub fn note() -> Diagnostic { Diagnostic::new(Severity::Note) } @@ -165,35 +170,41 @@ impl Diagnostic { /// Create a new diagnostic with a severity of [`Severity::Help`]. /// /// [`Severity::Help`]: Severity::Help + #[must_use] pub fn help() -> Diagnostic { Diagnostic::new(Severity::Help) } /// Set the error code of the diagnostic. + #[must_use] pub fn with_code(mut self, code: impl Display) -> Diagnostic { self.code = Some(code.to_string()); self } /// Set the message of the diagnostic. + #[must_use] pub fn with_message(mut self, message: impl Display) -> Diagnostic { self.message = message.to_string(); self } /// Add a label to the diagnostic. + #[must_use] pub fn with_label(mut self, label: Label) -> Diagnostic { self.labels.push(label); self } /// Add some labels to the diagnostic. + #[must_use] pub fn with_labels(mut self, mut labels: Vec>) -> Diagnostic { self.labels.append(&mut labels); self } /// Add some labels to the diagnostic. + #[must_use] pub fn with_labels_iter( mut self, labels: impl IntoIterator>, @@ -203,18 +214,22 @@ impl Diagnostic { } /// Add a note to the diagnostic. - pub fn with_note(mut self, note: &impl ToString) -> Diagnostic { + #[allow(clippy::needless_pass_by_value)] + #[must_use] + pub fn with_note(mut self, note: impl ToString) -> Diagnostic { self.notes.push(note.to_string()); self } /// Add some notes to the diagnostic. + #[must_use] pub fn with_notes(mut self, mut notes: Vec) -> Diagnostic { self.notes.append(&mut notes); self } /// Add some notes to the diagnostic. + #[must_use] pub fn with_notes_iter( mut self, notes: impl IntoIterator, diff --git a/codespan-reporting/src/files.rs b/codespan-reporting/src/files.rs index 45391ea7..08e89ec4 100644 --- a/codespan-reporting/src/files.rs +++ b/codespan-reporting/src/files.rs @@ -224,6 +224,7 @@ pub struct Location { /// assert_eq!(files::column_index(source, 2..13, 2 + 11), 3); /// assert_eq!(files::column_index(source, 2..13, 2 + 12), 3); /// ``` +#[must_use] pub fn column_index(source: &str, line_range: Range, byte_index: usize) -> usize { let end_index = core::cmp::min(byte_index, core::cmp::min(line_range.end, source.len())); @@ -383,6 +384,7 @@ where Source: AsRef, { /// Create a new files database. + #[must_use] pub fn new() -> SimpleFiles { SimpleFiles { files: Vec::new() } } diff --git a/codespan-reporting/src/term/config.rs b/codespan-reporting/src/term/config.rs index 764d93f1..de92d662 100644 --- a/codespan-reporting/src/term/config.rs +++ b/codespan-reporting/src/term/config.rs @@ -152,6 +152,7 @@ pub mod styles { impl Styles { /// The style used to mark a header at a given severity. + #[must_use] pub fn header(&self, severity: Severity) -> &ColorSpec { match severity { Severity::Bug => &self.header_bug, @@ -162,23 +163,28 @@ pub mod styles { } } + #[must_use] pub fn header_message(&self) -> &ColorSpec { &self.header_message } + #[must_use] pub fn line_number(&self) -> &ColorSpec { &self.line_number } + #[must_use] pub fn note_bullet(&self) -> &ColorSpec { &self.note_bullet } + #[must_use] pub fn source_border(&self) -> &ColorSpec { &self.source_border } /// The style used to mark a primary or secondary label at a given severity. + #[must_use] pub fn label(&self, severity: Severity, label_style: LabelStyle) -> &ColorSpec { match (label_style, severity) { (LabelStyle::Primary, Severity::Bug) => &self.primary_label_bug, @@ -192,6 +198,7 @@ pub mod styles { } impl Styles { + #[must_use] pub fn no_color() -> Styles { Styles { header_bug: ColorSpec::new(), @@ -416,6 +423,7 @@ impl Default for Chars { impl Chars { /// A character set that uses Unicode box drawing characters. + #[must_use] pub fn box_drawing() -> Chars { Chars { snippet_start: "┌─".into(), @@ -446,6 +454,7 @@ impl Chars { /// This is useful if your terminal's font does not support box drawing /// characters well and results in output that looks similar to rustc's /// diagnostic output. + #[must_use] pub fn ascii() -> Chars { Chars { snippet_start: "-->".into(), diff --git a/codespan-reporting/src/term/renderer.rs b/codespan-reporting/src/term/renderer.rs index b4dd9524..5cb94467 100644 --- a/codespan-reporting/src/term/renderer.rs +++ b/codespan-reporting/src/term/renderer.rs @@ -602,7 +602,7 @@ impl<'writer, 'config> Renderer<'writer, 'config> { let current_label_style = single_labels .iter() .filter(|(_, range, _)| is_overlapping(range, &column_range)) - .map(|(label_style, _, _)| label_style.clone()) + .map(|(label_style, _, _)| *label_style) .max_by_key(label_priority_key); // Update writer style if necessary @@ -925,7 +925,7 @@ impl<'writer, 'config> Renderer<'writer, 'config> { let column_range = metrics.byte_index..(metrics.byte_index + ch.len_utf8()); let label_style = hanging_labels(single_labels, trailing_label) .filter(|(_, range, _)| column_range.contains(&range.start)) - .map(|(label_style, _, _)| label_style.clone()) + .map(|(label_style, _, _)| *label_style) .max_by_key(label_priority_key); let mut spaces = match label_style { @@ -1199,6 +1199,7 @@ fn is_overlapping(range0: &Range, range1: &Range) -> bool { } /// For prioritizing primary labels over secondary labels when rendering carets. +#[allow(clippy::trivially_copy_pass_by_ref)] fn label_priority_key(label_style: &LabelStyle) -> u8 { match label_style { LabelStyle::Secondary => 0, diff --git a/codespan-reporting/src/term/views.rs b/codespan-reporting/src/term/views.rs index caccc3f1..ef2807f0 100644 --- a/codespan-reporting/src/term/views.rs +++ b/codespan-reporting/src/term/views.rs @@ -23,6 +23,7 @@ impl<'diagnostic, 'config, FileId> RichDiagnostic<'diagnostic, 'config, FileId> where FileId: Copy + PartialEq, { + #[must_use] pub fn new( diagnostic: &'diagnostic Diagnostic, config: &'config Config,