From 2b79495c792ff7b4e025b9ad299cf1e9c250a809 Mon Sep 17 00:00:00 2001 From: cgettys-microsoft <67080058+cgettys-microsoft@users.noreply.github.com> Date: Mon, 29 Sep 2025 09:43:02 -0700 Subject: [PATCH] fix(ci, clippy): raise MSRV to 1.82, fix rust 1.90 warnings (#451) * fix: remove unused code * fix: 1.90 errors * MSRV: 1.82.0 * fix: warnings exposed by increasing MSRV --- .github/workflows/ci.yml | 6 ++--- Cargo.toml | 2 +- README.md | 2 +- clippy.toml | 2 +- miette-derive/src/forward.rs | 2 +- miette-derive/src/utils.rs | 38 ++------------------------- src/eyreish/mod.rs | 6 +---- src/handler.rs | 2 +- src/handlers/debug.rs | 4 +-- src/handlers/graphical.rs | 16 +++++------ src/handlers/json.rs | 8 +++--- src/handlers/narratable.rs | 14 +++++----- src/highlighters/syntect.rs | 2 +- src/lib.rs | 2 +- tests/color_format.rs | 1 - tests/test_diagnostic_source_macro.rs | 1 + 16 files changed, 35 insertions(+), 73 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 233b6b4..7d10924 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -33,11 +33,11 @@ jobs: strategy: matrix: features: [fancy, syntect-highlighter] - rust: [1.70.0, stable] + rust: [1.82.0, stable] os: [ubuntu-latest, macOS-latest, windows-latest] exclude: - features: syntect-highlighter - rust: 1.70.0 + rust: 1.82.0 steps: - uses: actions/checkout@v4 @@ -52,7 +52,7 @@ jobs: if: matrix.rust == 'stable' run: cargo test --all --verbose --features ${{matrix.features}} - name: Run tests - if: matrix.rust == '1.70.0' + if: matrix.rust == '1.82.0' run: cargo test --all --verbose --features ${{matrix.features}} no-format-args-capture wasm: diff --git a/Cargo.toml b/Cargo.toml index 3274274..f89f14b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ documentation = "https://docs.rs/miette" license = "Apache-2.0" readme = "README.md" edition = "2018" -rust-version = "1.70.0" +rust-version = "1.82.0" exclude = ["images/", "tests/", "miette-derive/"] [dependencies] diff --git a/README.md b/README.md index d77bda1..8ecc16d 100644 --- a/README.md +++ b/README.md @@ -785,7 +785,7 @@ println!("{:?}", report.with_source_code("About something or another or yet anot ### MSRV -This crate requires rustc 1.70.0 or later. +This crate requires rustc 1.82.0 or later. ### Acknowledgements diff --git a/clippy.toml b/clippy.toml index 1645c19..c3aa642 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -msrv = "1.70.0" +msrv = "1.82.0" diff --git a/miette-derive/src/forward.rs b/miette-derive/src/forward.rs index 171019a..d170366 100644 --- a/miette-derive/src/forward.rs +++ b/miette-derive/src/forward.rs @@ -150,7 +150,7 @@ impl Forward { Self::#variant { #field_name, .. } => #field_name.#method_call, }, Forward::Unnamed(index) => { - let underscores: Vec<_> = core::iter::repeat(quote! { _, }).take(*index).collect(); + let underscores: Vec<_> = std::iter::repeat_n(quote! { _, }, *index).collect(); let unnamed = format_ident!("unnamed"); quote! { Self::#variant ( #(#underscores)* #unnamed, .. ) => #unnamed.#method_call, diff --git a/miette-derive/src/utils.rs b/miette-derive/src/utils.rs index b867849..2d58444 100644 --- a/miette-derive/src/utils.rs +++ b/miette-derive/src/utils.rs @@ -1,40 +1,6 @@ use proc_macro2::TokenStream; -use quote::{format_ident, quote, ToTokens}; -use syn::{ - parse::{Parse, ParseStream}, - spanned::Spanned, -}; - -pub(crate) enum MemberOrString { - Member(syn::Member), - String(syn::LitStr), -} - -impl ToTokens for MemberOrString { - fn to_tokens(&self, tokens: &mut TokenStream) { - use MemberOrString::*; - match self { - Member(member) => member.to_tokens(tokens), - String(string) => string.to_tokens(tokens), - } - } -} - -impl Parse for MemberOrString { - fn parse(input: ParseStream) -> syn::Result { - let lookahead = input.lookahead1(); - if lookahead.peek(syn::Ident) || lookahead.peek(syn::LitInt) { - Ok(MemberOrString::Member(input.parse()?)) - } else if lookahead.peek(syn::LitStr) { - Ok(MemberOrString::String(input.parse()?)) - } else { - Err(syn::Error::new( - input.span(), - "Expected a string or a field reference.", - )) - } - } -} +use quote::{format_ident, quote}; +use syn::spanned::Spanned; use crate::{ diagnostic::{DiagnosticConcreteArgs, DiagnosticDef}, diff --git a/src/eyreish/mod.rs b/src/eyreish/mod.rs index 2dfbf71..3f35103 100644 --- a/src/eyreish/mod.rs +++ b/src/eyreish/mod.rs @@ -172,11 +172,7 @@ pub trait ReportHandler: core::any::Any + Send + Sync { /// } /// } /// ``` - fn debug( - &self, - error: &(dyn Diagnostic), - f: &mut core::fmt::Formatter<'_>, - ) -> core::fmt::Result; + fn debug(&self, error: &dyn Diagnostic, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result; /// Override for the `Display` format fn display( diff --git a/src/handler.rs b/src/handler.rs index c993c43..5cd5a53 100644 --- a/src/handler.rs +++ b/src/handler.rs @@ -402,7 +402,7 @@ impl Default for MietteHandler { } impl ReportHandler for MietteHandler { - fn debug(&self, diagnostic: &(dyn Diagnostic), f: &mut fmt::Formatter<'_>) -> fmt::Result { + fn debug(&self, diagnostic: &dyn Diagnostic, f: &mut fmt::Formatter<'_>) -> fmt::Result { if f.alternate() { return fmt::Debug::fmt(diagnostic, f); } diff --git a/src/handlers/debug.rs b/src/handlers/debug.rs index 50450a4..629908b 100644 --- a/src/handlers/debug.rs +++ b/src/handlers/debug.rs @@ -31,7 +31,7 @@ impl DebugReportHandler { pub fn render_report( &self, f: &mut fmt::Formatter<'_>, - diagnostic: &(dyn Diagnostic), + diagnostic: &dyn Diagnostic, ) -> fmt::Result { let mut diag = f.debug_struct("Diagnostic"); diag.field("message", &format!("{}", diagnostic)); @@ -61,7 +61,7 @@ impl DebugReportHandler { } impl ReportHandler for DebugReportHandler { - fn debug(&self, diagnostic: &(dyn Diagnostic), f: &mut fmt::Formatter<'_>) -> fmt::Result { + fn debug(&self, diagnostic: &dyn Diagnostic, f: &mut fmt::Formatter<'_>) -> fmt::Result { if f.alternate() { return fmt::Debug::fmt(diagnostic, f); } diff --git a/src/handlers/graphical.rs b/src/handlers/graphical.rs index faac695..37b6bf8 100644 --- a/src/handlers/graphical.rs +++ b/src/handlers/graphical.rs @@ -242,7 +242,7 @@ impl GraphicalReportHandler { pub fn render_report( &self, f: &mut impl fmt::Write, - diagnostic: &(dyn Diagnostic), + diagnostic: &dyn Diagnostic, ) -> fmt::Result { self.render_report_inner(f, diagnostic, diagnostic.source_code()) } @@ -250,7 +250,7 @@ impl GraphicalReportHandler { fn render_report_inner( &self, f: &mut impl fmt::Write, - diagnostic: &(dyn Diagnostic), + diagnostic: &dyn Diagnostic, parent_src: Option<&dyn SourceCode>, ) -> fmt::Result { let src = diagnostic.source_code().or(parent_src); @@ -281,7 +281,7 @@ impl GraphicalReportHandler { fn render_header( &self, f: &mut impl fmt::Write, - diagnostic: &(dyn Diagnostic), + diagnostic: &dyn Diagnostic, is_nested: bool, ) -> fmt::Result { let severity_style = match diagnostic.severity() { @@ -326,7 +326,7 @@ impl GraphicalReportHandler { fn render_causes( &self, f: &mut impl fmt::Write, - diagnostic: &(dyn Diagnostic), + diagnostic: &dyn Diagnostic, parent_src: Option<&dyn SourceCode>, ) -> fmt::Result { let src = diagnostic.source_code().or(parent_src); @@ -424,7 +424,7 @@ impl GraphicalReportHandler { Ok(()) } - fn render_footer(&self, f: &mut impl fmt::Write, diagnostic: &(dyn Diagnostic)) -> fmt::Result { + fn render_footer(&self, f: &mut impl fmt::Write, diagnostic: &dyn Diagnostic) -> fmt::Result { if let Some(help) = diagnostic.help() { let width = self.termwidth.saturating_sub(2); let initial_indent = " help: ".style(self.theme.styles.help).to_string(); @@ -447,7 +447,7 @@ impl GraphicalReportHandler { fn render_related( &self, f: &mut impl fmt::Write, - diagnostic: &(dyn Diagnostic), + diagnostic: &dyn Diagnostic, parent_src: Option<&dyn SourceCode>, ) -> fmt::Result { let src = diagnostic.source_code().or(parent_src); @@ -535,7 +535,7 @@ impl GraphicalReportHandler { fn render_snippets( &self, f: &mut impl fmt::Write, - diagnostic: &(dyn Diagnostic), + diagnostic: &dyn Diagnostic, opt_source: Option<&dyn SourceCode>, ) -> fmt::Result { let source = match opt_source { @@ -1361,7 +1361,7 @@ impl GraphicalReportHandler { } impl ReportHandler for GraphicalReportHandler { - fn debug(&self, diagnostic: &(dyn Diagnostic), f: &mut fmt::Formatter<'_>) -> fmt::Result { + fn debug(&self, diagnostic: &dyn Diagnostic, f: &mut fmt::Formatter<'_>) -> fmt::Result { if f.alternate() { return fmt::Debug::fmt(diagnostic, f); } diff --git a/src/handlers/json.rs b/src/handlers/json.rs index 0b4a405..e37064c 100644 --- a/src/handlers/json.rs +++ b/src/handlers/json.rs @@ -60,7 +60,7 @@ impl JSONReportHandler { pub fn render_report( &self, f: &mut impl fmt::Write, - diagnostic: &(dyn Diagnostic), + diagnostic: &dyn Diagnostic, ) -> fmt::Result { self._render_report(f, diagnostic, None) } @@ -68,7 +68,7 @@ impl JSONReportHandler { fn _render_report( &self, f: &mut impl fmt::Write, - diagnostic: &(dyn Diagnostic), + diagnostic: &dyn Diagnostic, parent_src: Option<&dyn SourceCode>, ) -> fmt::Result { write!(f, r#"{{"message": "{}","#, escape(&diagnostic.to_string()))?; @@ -154,7 +154,7 @@ impl JSONReportHandler { fn render_snippets( &self, f: &mut impl fmt::Write, - diagnostic: &(dyn Diagnostic), + diagnostic: &dyn Diagnostic, source: &dyn SourceCode, ) -> fmt::Result { if let Some(mut labels) = diagnostic.labels() { @@ -170,7 +170,7 @@ impl JSONReportHandler { } impl ReportHandler for JSONReportHandler { - fn debug(&self, diagnostic: &(dyn Diagnostic), f: &mut fmt::Formatter<'_>) -> fmt::Result { + fn debug(&self, diagnostic: &dyn Diagnostic, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.render_report(f, diagnostic) } } diff --git a/src/handlers/narratable.rs b/src/handlers/narratable.rs index f8d36ae..8dead98 100644 --- a/src/handlers/narratable.rs +++ b/src/handlers/narratable.rs @@ -69,7 +69,7 @@ impl NarratableReportHandler { pub fn render_report( &self, f: &mut impl fmt::Write, - diagnostic: &(dyn Diagnostic), + diagnostic: &dyn Diagnostic, ) -> fmt::Result { self.render_header(f, diagnostic)?; if self.with_cause_chain { @@ -85,7 +85,7 @@ impl NarratableReportHandler { Ok(()) } - fn render_header(&self, f: &mut impl fmt::Write, diagnostic: &(dyn Diagnostic)) -> fmt::Result { + fn render_header(&self, f: &mut impl fmt::Write, diagnostic: &dyn Diagnostic) -> fmt::Result { writeln!(f, "{}", diagnostic)?; let severity = match diagnostic.severity() { Some(Severity::Error) | None => "error", @@ -96,7 +96,7 @@ impl NarratableReportHandler { Ok(()) } - fn render_causes(&self, f: &mut impl fmt::Write, diagnostic: &(dyn Diagnostic)) -> fmt::Result { + fn render_causes(&self, f: &mut impl fmt::Write, diagnostic: &dyn Diagnostic) -> fmt::Result { if let Some(cause_iter) = diagnostic .diagnostic_source() .map(DiagnosticChain::from_diagnostic) @@ -110,7 +110,7 @@ impl NarratableReportHandler { Ok(()) } - fn render_footer(&self, f: &mut impl fmt::Write, diagnostic: &(dyn Diagnostic)) -> fmt::Result { + fn render_footer(&self, f: &mut impl fmt::Write, diagnostic: &dyn Diagnostic) -> fmt::Result { if let Some(help) = diagnostic.help() { writeln!(f, "diagnostic help: {}", help)?; } @@ -126,7 +126,7 @@ impl NarratableReportHandler { fn render_related( &self, f: &mut impl fmt::Write, - diagnostic: &(dyn Diagnostic), + diagnostic: &dyn Diagnostic, parent_src: Option<&dyn SourceCode>, ) -> fmt::Result { if let Some(related) = diagnostic.related() { @@ -152,7 +152,7 @@ impl NarratableReportHandler { fn render_snippets( &self, f: &mut impl fmt::Write, - diagnostic: &(dyn Diagnostic), + diagnostic: &dyn Diagnostic, source_code: Option<&dyn SourceCode>, ) -> fmt::Result { if let Some(source) = source_code { @@ -344,7 +344,7 @@ impl NarratableReportHandler { } impl ReportHandler for NarratableReportHandler { - fn debug(&self, diagnostic: &(dyn Diagnostic), f: &mut fmt::Formatter<'_>) -> fmt::Result { + fn debug(&self, diagnostic: &dyn Diagnostic, f: &mut fmt::Formatter<'_>) -> fmt::Result { if f.alternate() { return fmt::Debug::fmt(diagnostic, f); } diff --git a/src/highlighters/syntect.rs b/src/highlighters/syntect.rs index 55aa8b6..75759fc 100644 --- a/src/highlighters/syntect.rs +++ b/src/highlighters/syntect.rs @@ -125,7 +125,7 @@ impl HighlighterState for SyntectHighlighterState<'_> { line, &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() } else { vec![Style::default().style(line)] diff --git a/src/lib.rs b/src/lib.rs index 3d9f327..21ad61d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -786,7 +786,7 @@ //! //! ## MSRV //! -//! This crate requires rustc 1.70.0 or later. +//! This crate requires rustc 1.82.0 or later. //! //! ## Acknowledgements //! diff --git a/tests/color_format.rs b/tests/color_format.rs index e5418ec..4e95856 100644 --- a/tests/color_format.rs +++ b/tests/color_format.rs @@ -70,7 +70,6 @@ impl Drop for EnvVarGuard<'_> { static COLOR_ENV_VARS: Mutex<()> = Mutex::new(()); - /// Assert the color format used by a handler with different levels of terminal /// support. fn check_colors MietteHandlerOpts>( diff --git a/tests/test_diagnostic_source_macro.rs b/tests/test_diagnostic_source_macro.rs index e038830..1349303 100644 --- a/tests/test_diagnostic_source_macro.rs +++ b/tests/test_diagnostic_source_macro.rs @@ -376,6 +376,7 @@ enum NestedEnumError { }, } +#[cfg(feature = "fancy-no-backtrace")] #[derive(Debug, miette::Diagnostic, thiserror::Error)] #[error("I am the inner error")] struct Case1Inner {