From b10693a91c287b59a00f0087588dd73ad499e0a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Wed, 22 Sep 2021 13:20:30 -0700 Subject: [PATCH] tests: fix doctests and such --- README.md | 28 +++++++++------------------- src/eyreish/mod.rs | 2 +- tests/test_location.rs | 6 +----- 3 files changed, 11 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index cd09dab..fba4447 100644 --- a/README.md +++ b/README.md @@ -87,16 +87,16 @@ use thiserror::Error; #[error("oops!")] #[diagnostic( code(oops::my::bad), + url(docsrs), help("try doing it better next time?"), )] struct MyBad { // The Source that we're gonna be printing snippets out of. // This can be a String if you don't have or care about file names. + #[source_code] src: NamedSource, // Snippets and highlights can be included in the diagnostic! - #[snippet(src, message("This is the part that broke"))] - snip: SourceSpan, - #[highlight(snip, label("This bit here"))] + #[label("This bit here")] bad_bit: SourceSpan, } @@ -116,7 +116,6 @@ fn this_fails() -> Result<()> { Err(MyBad { src: NamedSource::new("bad_file.rs", src), - snip: (0, len).into(), bad_bit: (9, 4).into(), })?; @@ -329,26 +328,17 @@ use thiserror::Error; #[diagnostic(code(my_lib::random_error))] pub struct MyErrorType { // The `Source` that miette will use. + #[source_code] src: String, - // A snippet that points to `src`, our `Source`. - #[snippet( - src, - message("This is the snippet") - )] - snip: SourceSpan, - - // A highlight for the `snip` snippet we defined above. This will - // underline/mark the specific code inside the larger snippet context. - #[highlight(snip, label("This is the highlight"))] + // This will underline/mark the specific code inside the larger + // snippet context. + #[label = "This is the highlight"] err_span: SourceSpan, - // You can add as many snippets as you want against the same Source. + // You can add as many labels as you want. // They'll be rendered sequentially. - #[snippet( - src, - message("This is a warning") - )] + #[label("This is bad")] snip2: SourceSpan, } ``` diff --git a/src/eyreish/mod.rs b/src/eyreish/mod.rs index f051dd4..26776c5 100644 --- a/src/eyreish/mod.rs +++ b/src/eyreish/mod.rs @@ -148,7 +148,7 @@ pub trait ReportHandler: core::any::Any + Send + Sync { /// impl ReportHandler for Handler { /// fn debug( /// &self, - /// error: &(dyn Diagnostic + 'static), + /// error: &dyn Diagnostic, /// f: &mut core::fmt::Formatter<'_>, /// ) -> core::fmt::Result { /// use core::fmt::Write as _; diff --git a/tests/test_location.rs b/tests/test_location.rs index 07cd754..9f86e12 100644 --- a/tests/test_location.rs +++ b/tests/test_location.rs @@ -17,11 +17,7 @@ impl LocationHandler { } impl miette::ReportHandler for LocationHandler { - fn debug( - &self, - _error: &(dyn Diagnostic + 'static), - _f: &mut std::fmt::Formatter<'_>, - ) -> std::fmt::Result { + fn debug(&self, _error: &dyn Diagnostic, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { // we assume that if the compiler is new enough to support // `track_caller` that we will always have `actual` be `Some`, so we can // safely skip the assertion if the location is `None` which should only