Skip to content

Commit

Permalink
fix(protocol): keep the owned spans
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Aug 18, 2021
1 parent f390520 commit 49151bb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions miette-derive/src/snippets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down Expand Up @@ -288,7 +288,7 @@ impl Snippets {
}
};
let context = quote! {
context: #context,
context: #context.clone(),
};

// Highlights
Expand All @@ -301,7 +301,7 @@ impl Snippets {
}
};
quote! {
#m
#m.clone()
}
});
let highlights = quote! {
Expand Down
4 changes: 2 additions & 2 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<&'a SourceSpan>>,
pub highlights: Option<Vec<SourceSpan>>,
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions tests/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
))
Expand Down

0 comments on commit 49151bb

Please sign in to comment.