tests: fix doctests and such

This commit is contained in:
Kat Marchán 2021-09-22 13:20:30 -07:00
parent eb9f6986e9
commit b10693a91c
3 changed files with 11 additions and 25 deletions

View File

@ -87,16 +87,16 @@ use thiserror::Error;
#[error("oops!")] #[error("oops!")]
#[diagnostic( #[diagnostic(
code(oops::my::bad), code(oops::my::bad),
url(docsrs),
help("try doing it better next time?"), help("try doing it better next time?"),
)] )]
struct MyBad { struct MyBad {
// The Source that we're gonna be printing snippets out of. // 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. // This can be a String if you don't have or care about file names.
#[source_code]
src: NamedSource, src: NamedSource,
// Snippets and highlights can be included in the diagnostic! // Snippets and highlights can be included in the diagnostic!
#[snippet(src, message("This is the part that broke"))] #[label("This bit here")]
snip: SourceSpan,
#[highlight(snip, label("This bit here"))]
bad_bit: SourceSpan, bad_bit: SourceSpan,
} }
@ -116,7 +116,6 @@ fn this_fails() -> Result<()> {
Err(MyBad { Err(MyBad {
src: NamedSource::new("bad_file.rs", src), src: NamedSource::new("bad_file.rs", src),
snip: (0, len).into(),
bad_bit: (9, 4).into(), bad_bit: (9, 4).into(),
})?; })?;
@ -329,26 +328,17 @@ use thiserror::Error;
#[diagnostic(code(my_lib::random_error))] #[diagnostic(code(my_lib::random_error))]
pub struct MyErrorType { pub struct MyErrorType {
// The `Source` that miette will use. // The `Source` that miette will use.
#[source_code]
src: String, src: String,
// A snippet that points to `src`, our `Source`. // This will underline/mark the specific code inside the larger
#[snippet( // snippet context.
src, #[label = "This is the highlight"]
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"))]
err_span: SourceSpan, 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. // They'll be rendered sequentially.
#[snippet( #[label("This is bad")]
src,
message("This is a warning")
)]
snip2: SourceSpan, snip2: SourceSpan,
} }
``` ```

View File

@ -148,7 +148,7 @@ pub trait ReportHandler: core::any::Any + Send + Sync {
/// impl ReportHandler for Handler { /// impl ReportHandler for Handler {
/// fn debug( /// fn debug(
/// &self, /// &self,
/// error: &(dyn Diagnostic + 'static), /// error: &dyn Diagnostic,
/// f: &mut core::fmt::Formatter<'_>, /// f: &mut core::fmt::Formatter<'_>,
/// ) -> core::fmt::Result { /// ) -> core::fmt::Result {
/// use core::fmt::Write as _; /// use core::fmt::Write as _;

View File

@ -17,11 +17,7 @@ impl LocationHandler {
} }
impl miette::ReportHandler for LocationHandler { impl miette::ReportHandler for LocationHandler {
fn debug( fn debug(&self, _error: &dyn Diagnostic, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
&self,
_error: &(dyn Diagnostic + 'static),
_f: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
// we assume that if the compiler is new enough to support // we assume that if the compiler is new enough to support
// `track_caller` that we will always have `actual` be `Some`, so we can // `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 // safely skip the assertion if the location is `None` which should only