diff --git a/tamer/src/diagnose.rs b/tamer/src/diagnose.rs index 6f31ba11..424a8f97 100644 --- a/tamer/src/diagnose.rs +++ b/tamer/src/diagnose.rs @@ -30,7 +30,7 @@ pub use report::{Reporter, VisualReporter}; pub use resolver::*; use core::fmt; -use std::{error::Error, fmt::Display}; +use std::{borrow::Cow, error::Error, fmt::Display}; use crate::span::Span; @@ -92,23 +92,23 @@ impl Display for Level { /// /// See [`AnnotatedSpan`]. #[derive(Debug, PartialEq, Eq, Clone)] -pub struct Label(String); +pub struct Label<'a>(Cow<'a, str>); -impl Display for Label { +impl<'a> Display for Label<'a> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { Display::fmt(&self.0, f) } } -impl From for Label { +impl<'a> From for Label<'a> { fn from(s: String) -> Self { - Self(s) + Self(Cow::Owned(s)) } } -impl From<&str> for Label { - fn from(s: &str) -> Self { - String::from(s).into() +impl<'a> From<&'a str> for Label<'a> { + fn from(s: &'a str) -> Self { + Self(Cow::Borrowed(s)) } } @@ -118,17 +118,20 @@ impl From<&str> for Label { /// diagnostic message by describing important source locations that /// contribute to a given diagnostic event. #[derive(Debug, PartialEq, Eq, Clone)] -pub struct AnnotatedSpan(Span, Level, Option