From ab59a7bc9bceace5761a862ee2ebff3e5943b12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Sat, 3 Feb 2024 19:44:46 -0800 Subject: [PATCH] feat(MSRV): Actually bump the MSRV to 1.70.0 --- Cargo.toml | 2 +- README.md | 42 ++++++++++++++++++++++++++++++++++++++---- clippy.toml | 2 +- src/lib.rs | 4 ++++ src/protocol.rs | 8 +++----- 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index cbf357a..15c83e7 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.56.0" +rust-version = "1.70.0" exclude = ["images/", "tests/", "miette-derive/"] [dependencies] diff --git a/README.md b/README.md index 8af2845..0e936b3 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ libraries and such might not want. - [... delayed source code](#-delayed-source-code) - [... handler options](#-handler-options) - [... dynamic diagnostics](#-dynamic-diagnostics) + - [... syntax highlighting](#-syntax-highlighting) - [Acknowledgements](#acknowledgements) - [License](#license) @@ -96,7 +97,7 @@ You can derive a `Diagnostic` from any `std::error::Error` type. `thiserror` is a great way to define them, and plays nicely with `miette`! */ -use miette::{Diagnostic, NamedSource, SourceSpan}; +use miette::{Diagnostic, SourceSpan}; use thiserror::Error; #[derive(Error, Debug, Diagnostic)] @@ -123,7 +124,7 @@ Use this `Result` type (or its expanded version) as the return type throughout your app (but NOT your libraries! Those should always return concrete types!). */ -use miette::Result; +use miette::{NamedSource, Result}; fn this_fails() -> Result<()> { // You can use plain strings as a `Source`, or anything that implements // the one-method `Source` trait. @@ -305,7 +306,7 @@ enabled: miette = { version = "X.Y.Z", features = ["fancy"] } ``` -Another way to display a diagnostic is by printing them using the debug formatter. +Another way to display a diagnostic is by printing them using the debug formatter. This is, in fact, what returning diagnostics from main ends up doing. To do it yourself, you can write the following: @@ -611,6 +612,7 @@ miette::set_hook(Box::new(|_| { .unicode(false) .context_lines(3) .tab_width(4) + .break_words(true) .build(), ) })) @@ -632,7 +634,7 @@ then you may want to use [`miette!`], [`diagnostic!`] macros or let source = "2 + 2 * 2 = 8".to_string(); let report = miette!( - labels = vec![ + labels = vec[ LabeledSpan::at(12..13, "this should be 6"), ], help = "'*' has greater precedence than '+'", @@ -641,6 +643,38 @@ let report = miette!( println!("{:?}", report) ``` +#### ... syntax highlighting + +`miette` can be configured to highlight syntax in source code snippets. + + + +To use the built-in highlighting functionality, you must enable the +`syntect-highlighter` crate feature. When this feature is enabled, `miette` will +automatically use the [`syntect`] crate to highlight the `#[source_code]` +field of your [`Diagnostic`]. + +Syntax detection with [`syntect`] is handled by checking 2 methods on the [`SpanContents`] trait, in order: +* [language()](SpanContents::language) - Provides the name of the language + as a string. For example `"Rust"` will indicate Rust syntax highlighting. + You can set the language of the [`SpanContents`] produced by a + [`NamedSource`] via the [`with_language`](NamedSource::with_language) + method. +* [name()](SpanContents::name) - In the absence of an explicitly set + language, the name is assumed to contain a file name or file path. + The highlighter will check for a file extension at the end of the name and + try to guess the syntax from that. + +If you want to use a custom highlighter, you can provide a custom +implementation of the [`Highlighter`](highlighters::Highlighter) +trait to [`MietteHandlerOpts`] by calling the +[`with_syntax_highlighting`](MietteHandlerOpts::with_syntax_highlighting) +method. See the [`highlighters`] module docs for more details. + +### MSRV + +This crate requires rustc 1.70.0 or later. + ### Acknowledgements `miette` was not developed in a void. It owes enormous credit to various diff --git a/clippy.toml b/clippy.toml index 0d369b5..1645c19 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -msrv = "1.56.0" +msrv = "1.70.0" diff --git a/src/lib.rs b/src/lib.rs index f8d92f4..7674f2b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -672,6 +672,10 @@ //! [`with_syntax_highlighting`](MietteHandlerOpts::with_syntax_highlighting) //! method. See the [`highlighters`] module docs for more details. //! +//! ## MSRV +//! +//! This crate requires rustc 1.70.0 or later. +//! //! ## Acknowledgements //! //! `miette` was not developed in a void. It owes enormous credit to various diff --git a/src/protocol.rs b/src/protocol.rs index 8ca719d..4c0101f 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -179,6 +179,7 @@ impl From> for Box Self { - Severity::Error - } -} + #[cfg(feature = "serde")] #[test]