]> git.lizzy.rs Git - rust.git/blobdiff - src/missed_spans.rs
Merge pull request #3011 from topecongiro/rustc-ap-syntax
[rust.git] / src / missed_spans.rs
index 7e558d308b79a361c67dcffb4644eb3142948ca5..f2f2295a8720b30ea2c203186d9ffa905c9840d9 100644 (file)
 
 use std::borrow::Cow;
 
-use syntax::codemap::{BytePos, Pos, Span};
+use syntax::source_map::{BytePos, Pos, Span};
 
-use codemap::LineRangeUtils;
 use comment::{rewrite_comment, CodeCharKind, CommentCodeSlices};
 use config::{EmitMode, FileName};
 use shape::{Indent, Shape};
+use source_map::LineRangeUtils;
 use utils::{count_newlines, last_line_width, mk_sp};
 use visitor::FmtVisitor;
 
@@ -43,8 +43,6 @@ fn output_at_start(&self) -> bool {
         self.buffer.is_empty()
     }
 
-    // TODO these format_missing methods are ugly. Refactor and add unit tests
-    // for the central whitespace stripping loop.
     pub fn format_missing(&mut self, end: BytePos) {
         // HACK(topecongiro)
         // We use `format_missing()` to extract a missing comment between a macro
@@ -99,8 +97,8 @@ fn format_missing_inner<F: Fn(&mut FmtVisitor, &str, &str)>(
         assert!(
             start < end,
             "Request to format inverted span: {:?} to {:?}",
-            self.codemap.lookup_char_pos(start),
-            self.codemap.lookup_char_pos(end)
+            self.source_map.lookup_char_pos(start),
+            self.source_map.lookup_char_pos(end)
         );
 
         self.last_pos = end;
@@ -161,9 +159,9 @@ fn write_snippet<F>(&mut self, span: Span, process_last_snippet: F)
         // Get a snippet from the file start to the span's hi without allocating.
         // We need it to determine what precedes the current comment. If the comment
         // follows code on the same line, we won't touch it.
-        let big_span_lo = self.codemap.lookup_char_pos(span.lo()).file.start_pos;
-        let local_begin = self.codemap.lookup_byte_offset(big_span_lo);
-        let local_end = self.codemap.lookup_byte_offset(span.hi());
+        let big_span_lo = self.source_map.lookup_char_pos(span.lo()).file.start_pos;
+        let local_begin = self.source_map.lookup_byte_offset(big_span_lo);
+        let local_end = self.source_map.lookup_byte_offset(span.hi());
         let start_index = local_begin.pos.to_usize();
         let end_index = local_end.pos.to_usize();
         let big_snippet = &local_begin.fm.src.as_ref().unwrap()[start_index..end_index];
@@ -189,7 +187,7 @@ fn write_snippet_inner<F>(
         // Trim whitespace from the right hand side of each line.
         // Annoyingly, the library functions for splitting by lines etc. are not
         // quite right, so we must do it ourselves.
-        let char_pos = self.codemap.lookup_char_pos(span.lo());
+        let char_pos = self.source_map.lookup_char_pos(span.lo());
         let file_name = &char_pos.file.name.clone().into();
         let mut status = SnippetStatus::new(char_pos.line);
 
@@ -317,7 +315,7 @@ fn process_missing_code(
                     self.push_str("\n");
                     status.last_wspace = None;
                 } else {
-                    self.push_str(&snippet[status.line_start..i + 1]);
+                    self.push_str(&snippet[status.line_start..=i]);
                 }
 
                 status.cur_line += 1;