style(clippy): quickly fix up clippy lints

This commit is contained in:
Brooks J Rady 2025-04-26 15:25:47 +01:00
parent 59c81617de
commit 69c507bfef
3 changed files with 8 additions and 5 deletions

View File

@ -280,7 +280,7 @@ impl Report {
/// The root cause is the last error in the iterator produced by /// The root cause is the last error in the iterator produced by
/// [`chain()`](Report::chain). /// [`chain()`](Report::chain).
pub fn root_cause(&self) -> &(dyn StdError + 'static) { pub fn root_cause(&self) -> &(dyn StdError + 'static) {
self.chain().last().unwrap() self.chain().next_back().unwrap()
} }
/// Returns true if `E` is the type held by this error object. /// Returns true if `E` is the type held by this error object.

View File

@ -424,7 +424,7 @@ impl HighlighterOption {
highlighter: Option<MietteHighlighter>, highlighter: Option<MietteHighlighter>,
supports_color: bool, supports_color: bool,
) -> HighlighterOption { ) -> HighlighterOption {
if color == Some(false) || (color == None && !supports_color) { if color == Some(false) || (color.is_none() && !supports_color) {
return HighlighterOption::Disable; return HighlighterOption::Disable;
} }
highlighter highlighter
@ -433,6 +433,9 @@ impl HighlighterOption {
} }
} }
// NOTE: This is manually implemented so that it's clearer what's going on with
// the conditional compilation — clippy isn't picking up the `cfg` stuff here
#[allow(clippy::derivable_impls)]
impl Default for HighlighterOption { impl Default for HighlighterOption {
fn default() -> Self { fn default() -> Self {
cfg_if! { cfg_if! {

View File

@ -96,12 +96,12 @@ impl SyntectHighlighter {
} }
} }
// finally, attempt to guess syntax based on first line // finally, attempt to guess syntax based on first line
return self.syntax_set.find_syntax_by_first_line( self.syntax_set.find_syntax_by_first_line(
std::str::from_utf8(contents.data()) std::str::from_utf8(contents.data())
.ok()? .ok()?
.split('\n') .split('\n')
.next()?, .next()?,
); )
} }
} }
@ -115,7 +115,7 @@ pub(crate) struct SyntectHighlighterState<'h> {
use_bg_color: bool, use_bg_color: bool,
} }
impl<'h> HighlighterState for SyntectHighlighterState<'h> { impl HighlighterState for SyntectHighlighterState<'_> {
fn highlight_line<'s>(&mut self, line: &'s str) -> Vec<Styled<&'s str>> { fn highlight_line<'s>(&mut self, line: &'s str) -> Vec<Styled<&'s str>> {
if let Ok(ops) = self.parse_state.parse_line(line, self.syntax_set) { if let Ok(ops) = self.parse_state.parse_line(line, self.syntax_set) {
let use_bg_color = self.use_bg_color; let use_bg_color = self.use_bg_color;