From a9e9dd452e23fa2e816df926a56c1f743eb32488 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 11 Mar 2025 16:18:01 +1300 Subject: Implement source chains A SourceSpan can now contain a child SourceSpan, ad infinitum, in order to represent a chain of locations. The report_source_issue function has been changed to print the entire chain, instead of just one SourceSpan. The report_source_issue function has also been changed to correctly print SourceSpans that extend across multiple source lines. --- src/locators/source.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/locators/source.rs') diff --git a/src/locators/source.rs b/src/locators/source.rs index 6837133..7e5abd2 100644 --- a/src/locators/source.rs +++ b/src/locators/source.rs @@ -9,12 +9,19 @@ pub struct SourceSpan { pub in_merged: SourceLocation, /// The location of this span in the original source file. pub in_source: Option, + /// Drill down to a more accurate location. + pub child: Option>, } impl SourceSpan { pub fn location(&self) -> &SourceLocation { self.in_source.as_ref().unwrap_or(&self.in_merged) } + + /// Wrap this source span around a child source span. + pub fn wrap(mut self, source: SourceSpan) -> Self { + self.child = Some(Box::new(source)); self + } } -- cgit v1.2.3-70-g09d2