diff --git a/tamer/src/diagnose/report.rs b/tamer/src/diagnose/report.rs index fdccf6fe..e249820c 100644 --- a/tamer/src/diagnose/report.rs +++ b/tamer/src/diagnose/report.rs @@ -20,8 +20,8 @@ //! Rendering of diagnostic information. use super::{ - AnnotatedSpan, Diagnostic, Label, Level, ResolvedSpan, - SpanResolver, SpanResolverError, + AnnotatedSpan, Diagnostic, Label, Level, ResolvedSpan, SpanResolver, + SpanResolverError, }; use crate::span::{Context, Span, UNKNOWN_SPAN}; use std::fmt::{self, Display, Write}; diff --git a/tamer/src/diagnose/resolver.rs b/tamer/src/diagnose/resolver.rs index 1e687eab..2e30fd39 100644 --- a/tamer/src/diagnose/resolver.rs +++ b/tamer/src/diagnose/resolver.rs @@ -177,9 +177,6 @@ impl ResolvedSpan { /// with font rather than a byte offset. #[derive(Debug, PartialEq, Eq, Clone, Copy)] pub enum Column { - /// A 1-indexed column number. - At(NonZeroU32), - /// A range of 1-indexed columns, inclusive. Endpoints(NonZeroU32, NonZeroU32), @@ -196,9 +193,7 @@ impl Display for Column { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { // Coerces to a single column number. - Self::At(at) | Self::Endpoints(at, _) | Self::Before(at) => { - Display::fmt(at, f) - } + Self::Endpoints(at, _) | Self::Before(at) => Display::fmt(at, f), } } } @@ -631,10 +626,8 @@ impl Line { // Start will only be > end (by 1) if the span begins on a newline. if span.len() == 0 { Column::Before(col_start) - } else if col_start >= col_end { - Column::At(col_start) } else { - Column::Endpoints(col_start, col_end) + Column::Endpoints(col_start, col_end.max(col_start)) } } diff --git a/tamer/src/diagnose/resolver/test.rs b/tamer/src/diagnose/resolver/test.rs index 0d7d7b11..9b950bea 100644 --- a/tamer/src/diagnose/resolver/test.rs +++ b/tamer/src/diagnose/resolver/test.rs @@ -119,7 +119,10 @@ fn last_byte_of_line() { span, lines: NonEmptyVec::new(vec![SourceLine { num: 3.unwrap_into(), - column: Some(Column::At(6.unwrap_into(),)), + column: Some(Column::Endpoints( + 6.unwrap_into(), + 6.unwrap_into() + )), span: ctx.span(14, 6), text: "line 3".into(), }]) @@ -322,7 +325,10 @@ fn newline_between_lines() { span, lines: NonEmptyVec::new(vec![SourceLine { num: 2.unwrap_into(), - column: Some(Column::At(7.unwrap_into())), + column: Some(Column::Endpoints( + 7.unwrap_into(), + 7.unwrap_into() + )), // Trailing newline _is not_ stripped since it was // explicitly referenced; // we don't want our line span to not contain the @@ -744,7 +750,10 @@ fn at_invalid_char_boundary() { // Intuitively this really should be [2,4], // but the implementation shouldn't change to // accommodate this very unlikely case. - column: Some(Column::At(4.unwrap_into(),)), + column: Some(Column::Endpoints( + 4.unwrap_into(), + 4.unwrap_into() + )), span: line_span, text: buf.clone().into(), }]) @@ -760,7 +769,10 @@ fn at_invalid_char_boundary() { num: 1.unwrap_into(), // Also unideal, // but see comment for previous assertion. - column: Some(Column::At(4.unwrap_into(),)), + column: Some(Column::Endpoints( + 4.unwrap_into(), + 4.unwrap_into() + )), span: line_span, text: buf.clone().into(), }])