Skip to content

Commit

Permalink
feat(MSRV): Actually bump the MSRV to 1.70.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Feb 4, 2024
1 parent 29d000f commit ab59a7b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
42 changes: 38 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)]
Expand All @@ -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.
Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -611,6 +612,7 @@ miette::set_hook(Box::new(|_| {
.unicode(false)
.context_lines(3)
.tab_width(4)
.break_words(true)
.build(),
)
}))
Expand All @@ -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 '+'",
Expand All @@ -641,6 +643,38 @@ let report = miette!(
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

`miette` was not developed in a void. It owes enormous credit to various
Expand Down
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.56.0"
msrv = "1.70.0"
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,19 @@ impl From<Box<dyn std::error::Error + Send + Sync>> for Box<dyn Diagnostic + Sen
*/
#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Default)]
pub enum Severity {
/// Just some help. Here's how you could be doing it better.
Advice,
/// Warning. Please take note.
Warning,
/// Critical failure. The program cannot continue.
/// This is the default severity, if you don't specify another one.
#[default]
Error,
}

impl Default for Severity {
fn default() -> Self {
Severity::Error
}
}


#[cfg(feature = "serde")]
#[test]
Expand Down

0 comments on commit ab59a7b

Please sign in to comment.