]> git.lizzy.rs Git - rust.git/blobdiff - src/source_map.rs
Remove unnecessary sigils around `Ident::as_str()` calls.
[rust.git] / src / source_map.rs
index db4796eb08e413a4ec94a3fb664f0be6432ffb69..76e0d24cf1eb6d325cb2201e7f179888f25fbace 100644 (file)
@@ -1,13 +1,13 @@
 //! 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 syntax::source_map::{BytePos, SourceMap, Span};
+use rustc_span::{BytePos, Span};
 
 use crate::comment::FindUncommented;
 use crate::config::file_lines::LineRange;
 use crate::visitor::SnippetProvider;
 
-pub trait SpanUtils {
+pub(crate) trait SpanUtils {
     fn span_after(&self, original: Span, needle: &str) -> BytePos;
     fn span_after_last(&self, original: Span, needle: &str) -> BytePos;
     fn span_before(&self, original: Span, needle: &str) -> BytePos;
@@ -16,7 +16,7 @@ pub trait SpanUtils {
     fn opt_span_before(&self, original: Span, needle: &str) -> Option<BytePos>;
 }
 
-pub trait LineRangeUtils {
+pub(crate) trait LineRangeUtils {
     /// Returns the `LineRange` that corresponds to `span` in `self`.
     ///
     /// # Panics
@@ -25,7 +25,7 @@ pub 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!(
@@ -80,27 +80,3 @@ fn opt_span_before(&self, original: Span, needle: &str) -> Option<BytePos> {
         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 snippet.starts_with('\n') { 1 } else { 0 };
-        // Line numbers start at 1
-        LineRange {
-            file: lo.sf.clone(),
-            lo: lo.line + offset,
-            hi: hi.line + offset,
-        }
-    }
-}