mirror of https://github.com/zkat/miette.git
fix(clippy): fix Rust v1.78.0 clippy warnings (#382)
This commit is contained in:
parent
813232ba79
commit
e1026f75e0
|
|
@ -410,7 +410,7 @@ impl Report {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Provide source code for this error
|
/// Provide source code for this error
|
||||||
pub fn with_source_code(self, source_code: impl SourceCode + Send + Sync + 'static) -> Report {
|
pub fn with_source_code(self, source_code: impl SourceCode + 'static) -> Report {
|
||||||
WithSourceCode {
|
WithSourceCode {
|
||||||
source_code,
|
source_code,
|
||||||
error: self,
|
error: self,
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ pub struct Report {
|
||||||
unsafe impl Sync for Report {}
|
unsafe impl Sync for Report {}
|
||||||
unsafe impl Send for Report {}
|
unsafe impl Send for Report {}
|
||||||
|
|
||||||
///
|
#[allow(missing_docs)]
|
||||||
pub type ErrorHook =
|
pub type ErrorHook =
|
||||||
Box<dyn Fn(&(dyn Diagnostic + 'static)) -> Box<dyn ReportHandler> + Sync + Send + 'static>;
|
Box<dyn Fn(&(dyn Diagnostic + 'static)) -> Box<dyn ReportHandler> + Sync + Send + 'static>;
|
||||||
|
|
||||||
|
|
@ -109,7 +109,7 @@ fn get_default_printer(_err: &(dyn Diagnostic + 'static)) -> Box<dyn ReportHandl
|
||||||
}
|
}
|
||||||
|
|
||||||
impl dyn ReportHandler {
|
impl dyn ReportHandler {
|
||||||
///
|
#[allow(missing_docs)]
|
||||||
pub fn is<T: ReportHandler>(&self) -> bool {
|
pub fn is<T: ReportHandler>(&self) -> bool {
|
||||||
// Get `TypeId` of the type this function is instantiated with.
|
// Get `TypeId` of the type this function is instantiated with.
|
||||||
let t = core::any::TypeId::of::<T>();
|
let t = core::any::TypeId::of::<T>();
|
||||||
|
|
@ -121,7 +121,7 @@ impl dyn ReportHandler {
|
||||||
t == concrete
|
t == concrete
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
#[allow(missing_docs)]
|
||||||
pub fn downcast_ref<T: ReportHandler>(&self) -> Option<&T> {
|
pub fn downcast_ref<T: ReportHandler>(&self) -> Option<&T> {
|
||||||
if self.is::<T>() {
|
if self.is::<T>() {
|
||||||
unsafe { Some(&*(self as *const dyn ReportHandler as *const T)) }
|
unsafe { Some(&*(self as *const dyn ReportHandler as *const T)) }
|
||||||
|
|
@ -130,7 +130,7 @@ impl dyn ReportHandler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
#[allow(missing_docs)]
|
||||||
pub fn downcast_mut<T: ReportHandler>(&mut self) -> Option<&mut T> {
|
pub fn downcast_mut<T: ReportHandler>(&mut self) -> Option<&mut T> {
|
||||||
if self.is::<T>() {
|
if self.is::<T>() {
|
||||||
unsafe { Some(&mut *(self as *mut dyn ReportHandler as *mut T)) }
|
unsafe { Some(&mut *(self as *mut dyn ReportHandler as *mut T)) }
|
||||||
|
|
|
||||||
|
|
@ -215,18 +215,6 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
|
||||||
#[error("outer")]
|
|
||||||
struct Outer {
|
|
||||||
pub(crate) errors: Vec<Inner>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Diagnostic for Outer {
|
|
||||||
fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>> {
|
|
||||||
Some(Box::new(self.errors.iter().map(|e| e as _)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn no_override() {
|
fn no_override() {
|
||||||
let inner_source = "hello world";
|
let inner_source = "hello world";
|
||||||
|
|
@ -254,6 +242,18 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
#[cfg(feature = "fancy")]
|
#[cfg(feature = "fancy")]
|
||||||
fn two_source_codes() {
|
fn two_source_codes() {
|
||||||
|
#[derive(Error, Debug)]
|
||||||
|
#[error("outer")]
|
||||||
|
struct Outer {
|
||||||
|
pub(crate) errors: Vec<Inner>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Diagnostic for Outer {
|
||||||
|
fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>> {
|
||||||
|
Some(Box::new(self.errors.iter().map(|e| e as _)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let inner_source = "hello world";
|
let inner_source = "hello world";
|
||||||
let outer_source = "abc";
|
let outer_source = "abc";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,22 +11,17 @@ use crate::ThemeCharacters;
|
||||||
use crate::ThemeStyles;
|
use crate::ThemeStyles;
|
||||||
|
|
||||||
/// Settings to control the color format used for graphical rendering.
|
/// Settings to control the color format used for graphical rendering.
|
||||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)]
|
||||||
pub enum RgbColors {
|
pub enum RgbColors {
|
||||||
/// Use RGB colors even if the terminal does not support them
|
/// Use RGB colors even if the terminal does not support them
|
||||||
Always,
|
Always,
|
||||||
/// Use RGB colors instead of ANSI if the terminal supports RGB
|
/// Use RGB colors instead of ANSI if the terminal supports RGB
|
||||||
Preferred,
|
Preferred,
|
||||||
/// Always use ANSI, regardless of terminal support for RGB
|
/// Always use ANSI, regardless of terminal support for RGB
|
||||||
|
#[default]
|
||||||
Never,
|
Never,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for RgbColors {
|
|
||||||
fn default() -> RgbColors {
|
|
||||||
RgbColors::Never
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Create a custom [`MietteHandler`] from options.
|
Create a custom [`MietteHandler`] from options.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -359,7 +359,7 @@ impl GraphicalReportHandler {
|
||||||
|
|
||||||
// If there was no header, remove the leading newline
|
// If there was no header, remove the leading newline
|
||||||
let inner = inner.trim_start_matches('\n');
|
let inner = inner.trim_start_matches('\n');
|
||||||
writeln!(f, "{}", self.wrap(&inner, opts))?;
|
writeln!(f, "{}", self.wrap(inner, opts))?;
|
||||||
}
|
}
|
||||||
ErrorKind::StdError(err) => {
|
ErrorKind::StdError(err) => {
|
||||||
writeln!(f, "{}", self.wrap(&err.to_string(), opts))?;
|
writeln!(f, "{}", self.wrap(&err.to_string(), opts))?;
|
||||||
|
|
@ -667,7 +667,7 @@ impl GraphicalReportHandler {
|
||||||
f,
|
f,
|
||||||
max_gutter,
|
max_gutter,
|
||||||
line,
|
line,
|
||||||
&labels,
|
labels,
|
||||||
LabelRenderMode::SingleLine,
|
LabelRenderMode::SingleLine,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
@ -683,7 +683,7 @@ impl GraphicalReportHandler {
|
||||||
f,
|
f,
|
||||||
max_gutter,
|
max_gutter,
|
||||||
line,
|
line,
|
||||||
&labels,
|
labels,
|
||||||
LabelRenderMode::MultiLineFirst,
|
LabelRenderMode::MultiLineFirst,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
@ -701,7 +701,7 @@ impl GraphicalReportHandler {
|
||||||
f,
|
f,
|
||||||
max_gutter,
|
max_gutter,
|
||||||
line,
|
line,
|
||||||
&labels,
|
labels,
|
||||||
LabelRenderMode::MultiLineRest,
|
LabelRenderMode::MultiLineRest,
|
||||||
)?;
|
)?;
|
||||||
self.render_multi_line_end_single(
|
self.render_multi_line_end_single(
|
||||||
|
|
@ -714,13 +714,7 @@ impl GraphicalReportHandler {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// gutter _again_
|
// gutter _again_
|
||||||
self.render_highlight_gutter(
|
self.render_highlight_gutter(f, max_gutter, line, labels, LabelRenderMode::SingleLine)?;
|
||||||
f,
|
|
||||||
max_gutter,
|
|
||||||
line,
|
|
||||||
&labels,
|
|
||||||
LabelRenderMode::SingleLine,
|
|
||||||
)?;
|
|
||||||
// has no label
|
// has no label
|
||||||
writeln!(f, "{}", self.theme.characters.hbar.style(label.style))?;
|
writeln!(f, "{}", self.theme.characters.hbar.style(label.style))?;
|
||||||
}
|
}
|
||||||
|
|
@ -894,12 +888,10 @@ impl GraphicalReportHandler {
|
||||||
} else {
|
} else {
|
||||||
result.push_str(opts.initial_indent);
|
result.push_str(opts.initial_indent);
|
||||||
}
|
}
|
||||||
|
} else if line.trim().is_empty() {
|
||||||
|
result.push_str(trimmed_indent);
|
||||||
} else {
|
} else {
|
||||||
if line.trim().is_empty() {
|
result.push_str(opts.subsequent_indent);
|
||||||
result.push_str(trimmed_indent);
|
|
||||||
} else {
|
|
||||||
result.push_str(opts.subsequent_indent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
result.push_str(line);
|
result.push_str(line);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
// all syntect imports are explicitly qualified, but their paths are shortened for convenience
|
// all syntect imports are explicitly qualified, but their paths are shortened for convenience
|
||||||
|
#[allow(clippy::module_inception)]
|
||||||
mod syntect {
|
mod syntect {
|
||||||
pub(super) use syntect::{
|
pub(super) use syntect::{
|
||||||
highlighting::{
|
highlighting::{
|
||||||
|
|
@ -96,7 +97,7 @@ 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(
|
return 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()?,
|
||||||
|
|
@ -116,13 +117,13 @@ pub(crate) struct SyntectHighlighterState<'h> {
|
||||||
|
|
||||||
impl<'h> HighlighterState for SyntectHighlighterState<'h> {
|
impl<'h> HighlighterState for SyntectHighlighterState<'h> {
|
||||||
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;
|
||||||
syntect::HighlightIterator::new(
|
syntect::HighlightIterator::new(
|
||||||
&mut self.highlight_state,
|
&mut self.highlight_state,
|
||||||
&ops,
|
&ops,
|
||||||
line,
|
line,
|
||||||
&mut self.highlighter,
|
&self.highlighter,
|
||||||
)
|
)
|
||||||
.map(|(style, str)| (convert_style(style, use_bg_color).style(str)))
|
.map(|(style, str)| (convert_style(style, use_bg_color).style(str)))
|
||||||
.collect()
|
.collect()
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#![deny(missing_docs, missing_debug_implementations, nonstandard_style)]
|
#![deny(missing_docs, missing_debug_implementations, nonstandard_style)]
|
||||||
#![warn(unreachable_pub, rust_2018_idioms)]
|
#![warn(unreachable_pub, rust_2018_idioms)]
|
||||||
|
#![allow(unexpected_cfgs)]
|
||||||
//! You run miette? You run her code like the software? Oh. Oh! Error code for
|
//! You run miette? You run her code like the software? Oh. Oh! Error code for
|
||||||
//! coder! Error code for One Thousand Lines!
|
//! coder! Error code for One Thousand Lines!
|
||||||
//!
|
//!
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ pub fn set_panic_hook() {
|
||||||
message = msg.to_string();
|
message = msg.to_string();
|
||||||
}
|
}
|
||||||
if let Some(msg) = payload.downcast_ref::<String>() {
|
if let Some(msg) = payload.downcast_ref::<String>() {
|
||||||
message = msg.clone();
|
message.clone_from(msg);
|
||||||
}
|
}
|
||||||
let mut report: Result<()> = Err(Panic(message).into());
|
let mut report: Result<()> = Err(Panic(message).into());
|
||||||
if let Some(loc) = info.location() {
|
if let Some(loc) = info.location() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue