feat(MSRV): Actually bump the MSRV to 1.70.0

This commit is contained in:
Kat Marchán 2024-02-03 19:44:46 -08:00
parent 29d000f201
commit ab59a7bc9b
No known key found for this signature in database
GPG Key ID: AEB529C08A3C7E9E
5 changed files with 47 additions and 11 deletions

View File

@ -9,7 +9,7 @@ documentation = "https://docs.rs/miette"
license = "Apache-2.0" license = "Apache-2.0"
readme = "README.md" readme = "README.md"
edition = "2018" edition = "2018"
rust-version = "1.56.0" rust-version = "1.70.0"
exclude = ["images/", "tests/", "miette-derive/"] exclude = ["images/", "tests/", "miette-derive/"]
[dependencies] [dependencies]

View File

@ -48,6 +48,7 @@ libraries and such might not want.
- [... delayed source code](#-delayed-source-code) - [... delayed source code](#-delayed-source-code)
- [... handler options](#-handler-options) - [... handler options](#-handler-options)
- [... dynamic diagnostics](#-dynamic-diagnostics) - [... dynamic diagnostics](#-dynamic-diagnostics)
- [... syntax highlighting](#-syntax-highlighting)
- [Acknowledgements](#acknowledgements) - [Acknowledgements](#acknowledgements)
- [License](#license) - [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`! `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; use thiserror::Error;
#[derive(Error, Debug, Diagnostic)] #[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 throughout your app (but NOT your libraries! Those should always return
concrete types!). concrete types!).
*/ */
use miette::Result; use miette::{NamedSource, Result};
fn this_fails() -> Result<()> { fn this_fails() -> Result<()> {
// You can use plain strings as a `Source`, or anything that implements // You can use plain strings as a `Source`, or anything that implements
// the one-method `Source` trait. // the one-method `Source` trait.
@ -611,6 +612,7 @@ miette::set_hook(Box::new(|_| {
.unicode(false) .unicode(false)
.context_lines(3) .context_lines(3)
.tab_width(4) .tab_width(4)
.break_words(true)
.build(), .build(),
) )
})) }))
@ -632,7 +634,7 @@ then you may want to use [`miette!`], [`diagnostic!`] macros or
let source = "2 + 2 * 2 = 8".to_string(); let source = "2 + 2 * 2 = 8".to_string();
let report = miette!( let report = miette!(
labels = vec![ labels = vec[
LabeledSpan::at(12..13, "this should be 6"), LabeledSpan::at(12..13, "this should be 6"),
], ],
help = "'*' has greater precedence than '+'", help = "'*' has greater precedence than '+'",
@ -641,6 +643,38 @@ let report = miette!(
println!("{:?}", report) println!("{:?}", report)
``` ```
#### ... syntax highlighting
`miette` can be configured to highlight syntax in source code snippets.
<!-- TODO: screenshot goes here once default Theme is decided -->
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 ### Acknowledgements
`miette` was not developed in a void. It owes enormous credit to various `miette` was not developed in a void. It owes enormous credit to various

View File

@ -1 +1 @@
msrv = "1.56.0" msrv = "1.70.0"

View File

@ -672,6 +672,10 @@
//! [`with_syntax_highlighting`](MietteHandlerOpts::with_syntax_highlighting) //! [`with_syntax_highlighting`](MietteHandlerOpts::with_syntax_highlighting)
//! method. See the [`highlighters`] module docs for more details. //! method. See the [`highlighters`] module docs for more details.
//! //!
//! ## MSRV
//!
//! This crate requires rustc 1.70.0 or later.
//!
//! ## Acknowledgements //! ## Acknowledgements
//! //!
//! `miette` was not developed in a void. It owes enormous credit to various //! `miette` was not developed in a void. It owes enormous credit to various

View File

@ -179,6 +179,7 @@ impl From<Box<dyn std::error::Error + Send + Sync>> for Box<dyn Diagnostic + Sen
*/ */
#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] #[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Default)]
pub enum Severity { pub enum Severity {
/// Just some help. Here's how you could be doing it better. /// Just some help. Here's how you could be doing it better.
Advice, Advice,
@ -186,14 +187,11 @@ pub enum Severity {
Warning, Warning,
/// Critical failure. The program cannot continue. /// Critical failure. The program cannot continue.
/// This is the default severity, if you don't specify another one. /// This is the default severity, if you don't specify another one.
#[default]
Error, Error,
} }
impl Default for Severity {
fn default() -> Self {
Severity::Error
}
}
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
#[test] #[test]