From 49151bb0950c0db9d2743c8fb78dcacfc27bc750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Tue, 17 Aug 2021 17:15:05 -0700 Subject: [PATCH] fix(protocol): keep the owned spans --- miette-derive/src/snippets.rs | 8 ++++---- src/protocol.rs | 4 ++-- src/reporter.rs | 2 +- tests/reporter.rs | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/miette-derive/src/snippets.rs b/miette-derive/src/snippets.rs index 1d97da7..5e73ba3 100644 --- a/miette-derive/src/snippets.rs +++ b/miette-derive/src/snippets.rs @@ -200,14 +200,14 @@ impl Snippets { // Context let context = &snippet.snippet; let context = quote! { - context: &self.#context, + context: self.#context.clone(), }; // Highlights let highlights = snippet.highlights.iter().map(|highlight| { let Highlight { highlight } = highlight; quote! { - &self.#highlight + self.#highlight.clone() } }); let highlights = quote! { @@ -288,7 +288,7 @@ impl Snippets { } }; let context = quote! { - context: #context, + context: #context.clone(), }; // Highlights @@ -301,7 +301,7 @@ impl Snippets { } }; quote! { - #m + #m.clone() } }); let highlights = quote! { diff --git a/src/protocol.rs b/src/protocol.rs index 6428a4d..d1d728c 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -177,11 +177,11 @@ pub struct DiagnosticSnippet<'a> { /// A [Source] that can be used to read the actual text of a source. pub source: &'a (dyn Source), /// The primary [SourceSpan] where this diagnostic is located. - pub context: &'a SourceSpan, + pub context: SourceSpan, /// Additional [SourceSpan]s that mark specific sections of the span, for /// example, to underline specific text within the larger span. They're /// paired with labels that should be applied to those sections. - pub highlights: Option>, + pub highlights: Option>, } /** diff --git a/src/reporter.rs b/src/reporter.rs index f0206cf..1c51a72 100644 --- a/src/reporter.rs +++ b/src/reporter.rs @@ -33,7 +33,7 @@ impl MietteReporter { writeln!(f)?; let context_data = snippet .source - .read_span(snippet.context) + .read_span(&snippet.context) .map_err(|_| fmt::Error)?; let context = std::str::from_utf8(context_data.data()).expect("Bad utf8 detected"); let mut line = context_data.line(); diff --git a/tests/reporter.rs b/tests/reporter.rs index e8cf333..beecd5a 100644 --- a/tests/reporter.rs +++ b/tests/reporter.rs @@ -34,8 +34,8 @@ impl Diagnostic for MyBad { vec![DiagnosticSnippet { message: Some(self.message.as_ref()), source: &self.src, - context: &self.ctx, - highlights: Some(vec![&self.highlight]), + context: self.ctx.clone(), + highlights: Some(vec![self.highlight.clone()]), }] .into_iter(), ))