diff options
| author | Caleb Cartwright <caleb.cartwright@outlook.com> | 2020-03-26 21:25:34 -0500 |
|---|---|---|
| committer | Caleb Cartwright <caleb.cartwright@outlook.com> | 2020-03-26 21:25:34 -0500 |
| commit | bd5dff4012a73ad4c5eb5db1dbb111bd92ed31dd (patch) | |
| tree | b781aa6ed959466d2b6605ab844a2ba7fe56b6a6 /src/source_map.rs | |
| parent | 9699c96cf1e6a13e0cc12e17c55ca11d2f9a6bf2 (diff) | |
| download | rust-bd5dff4012a73ad4c5eb5db1dbb111bd92ed31dd.tar.gz rust-bd5dff4012a73ad4c5eb5db1dbb111bd92ed31dd.zip | |
refactor: backport syntux mod
Diffstat (limited to 'src/source_map.rs')
| -rw-r--r-- | src/source_map.rs | 29 |
1 files changed, 2 insertions, 27 deletions
diff --git a/src/source_map.rs b/src/source_map.rs index c3a549d3b84..76e0d24cf1e 100644 --- a/src/source_map.rs +++ b/src/source_map.rs @@ -1,11 +1,10 @@ //! This module contains utilities that work with the `SourceMap` from `libsyntax`/`syntex_syntax`. //! This includes extension traits and methods for looking up spans and line ranges for AST nodes. -use rustc_span::{source_map::SourceMap, BytePos, Span}; +use rustc_span::{BytePos, Span}; use crate::comment::FindUncommented; use crate::config::file_lines::LineRange; -use crate::utils::starts_with_newline; use crate::visitor::SnippetProvider; pub(crate) trait SpanUtils { @@ -26,7 +25,7 @@ pub(crate) trait LineRangeUtils { fn lookup_line_range(&self, span: Span) -> LineRange; } -impl<'a> SpanUtils for SnippetProvider<'a> { +impl SpanUtils for SnippetProvider { fn span_after(&self, original: Span, needle: &str) -> BytePos { self.opt_span_after(original, needle).unwrap_or_else(|| { panic!( @@ -81,27 +80,3 @@ impl<'a> SpanUtils for SnippetProvider<'a> { Some(original.lo() + BytePos(offset as u32)) } } - -impl LineRangeUtils for SourceMap { - fn lookup_line_range(&self, span: Span) -> LineRange { - let snippet = self.span_to_snippet(span).unwrap_or_default(); - let lo = self.lookup_line(span.lo()).unwrap(); - let hi = self.lookup_line(span.hi()).unwrap(); - - debug_assert_eq!( - lo.sf.name, hi.sf.name, - "span crossed file boundary: lo: {:?}, hi: {:?}", - lo, hi - ); - - // in case the span starts with a newline, the line range is off by 1 without the - // adjustment below - let offset = 1 + if starts_with_newline(&snippet) { 1 } else { 0 }; - // Line numbers start at 1 - LineRange { - file: lo.sf.clone(), - lo: lo.line + offset, - hi: hi.line + offset, - } - } -} |
