From 331aada2bdf4ae85c978c2387db3c91e197d88bc Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Thu, 28 Apr 2022 11:00:36 -0400 Subject: [PATCH] tamer: diagnose::report::MaybeResolvedSpan: Move up in file Just rearranging, since this was awkwardly placed relative to where it's used. DEV-12151 --- tamer/src/diagnose/report.rs | 112 +++++++++++++++++------------------ 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/tamer/src/diagnose/report.rs b/tamer/src/diagnose/report.rs index 3cb6bced..73b69f3b 100644 --- a/tamer/src/diagnose/report.rs +++ b/tamer/src/diagnose/report.rs @@ -107,6 +107,62 @@ impl Reporter for VisualReporter { } } +/// A [`Span`] that may have been resolved. +/// +/// The span will remain unresolved if an error occurred, +/// in which case the error will be provided. +/// The idea is to provide as much fallback information as is useful to the +/// user so that they can still debug the problem without the benefit of +/// the resolved context. +/// +/// Furthermore, +/// it is important that the underlying diagnostic message +/// (e.g. error) +/// never be masked by an error of our own. +#[derive(Debug, PartialEq, Eq)] +enum MaybeResolvedSpan<'d, S: ResolvedSpanData> { + Resolved(S, Option>), + Unresolved(Span, Option>, SpanResolverError), +} + +impl<'d, S: ResolvedSpanData> MaybeResolvedSpan<'d, S> { + /// We should never mask an error with our own; + /// the diagnostic system is supposed to _help_ the user in diagnosing + /// problems, + /// not hinder them by masking it. + fn system_labels(&self) -> Vec> { + match self { + Self::Resolved(rspan, _) if rspan.col_num().is_none() => vec![ + SpanLabel( + Level::Help, + "unable to calculate columns because the line is \ + not a valid UTF-8 string" + .into(), + ), + SpanLabel( + Level::Help, + "you have been provided with 0-indexed \ + line-relative inclusive byte offsets" + .into(), + ), + ], + + Self::Unresolved(_, _, e) => { + vec![SpanLabel( + Level::Help, + format!( + "an error occurred while trying to look up \ + information about this span: {e}" + ) + .into(), + )] + } + + _ => vec![], + } + } +} + #[derive(Debug)] pub struct Report<'d, D: Diagnostic> { msg: Message<'d, D>, @@ -246,62 +302,6 @@ impl<'d> Display for Section<'d> { } } -/// A [`Span`] that may have been resolved. -/// -/// The span will remain unresolved if an error occurred, -/// in which case the error will be provided. -/// The idea is to provide as much fallback information as is useful to the -/// user so that they can still debug the problem without the benefit of -/// the resolved context. -/// -/// Furthermore, -/// it is important that the underlying diagnostic message -/// (e.g. error) -/// never be masked by an error of our own. -#[derive(Debug, PartialEq, Eq)] -enum MaybeResolvedSpan<'d, S: ResolvedSpanData> { - Resolved(S, Option>), - Unresolved(Span, Option>, SpanResolverError), -} - -impl<'d, S: ResolvedSpanData> MaybeResolvedSpan<'d, S> { - /// We should never mask an error with our own; - /// the diagnostic system is supposed to _help_ the user in diagnosing - /// problems, - /// not hinder them by masking it. - fn system_labels(&self) -> Vec> { - match self { - Self::Resolved(rspan, _) if rspan.col_num().is_none() => vec![ - SpanLabel( - Level::Help, - "unable to calculate columns because the line is \ - not a valid UTF-8 string" - .into(), - ), - SpanLabel( - Level::Help, - "you have been provided with 0-indexed \ - line-relative inclusive byte offsets" - .into(), - ), - ], - - Self::Unresolved(_, _, e) => { - vec![SpanLabel( - Level::Help, - format!( - "an error occurred while trying to look up \ - information about this span: {e}" - ) - .into(), - )] - } - - _ => vec![], - } - } -} - /// Heading describing the context of a (hopefully resolved) span. /// /// The ideal header contains the context along with the line, and column