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!")]
#[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,
}
```

View File

@ -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 _;

View File

@ -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