]> git.lizzy.rs Git - rust.git/blobdiff - src/missed_spans.rs
Use the last line's width for indent width in rewriting missed span
[rust.git] / src / missed_spans.rs
index fb0e298bbbf42a60c0963f0e963a9b4e9f9a6f4c..5e350cf41b40b05e6186f564ad3c04ffe47b7f63 100644 (file)
@@ -8,12 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
+use {Indent, Shape};
+use comment::{rewrite_comment, CodeCharKind, CommentCodeSlices};
 use config::WriteMode;
-use visitor::FmtVisitor;
-use syntax::codemap::{BytePos, Span, Pos};
-use comment::{CodeCharKind, CommentCodeSlices, rewrite_comment};
-use Shape;
+use syntax::codemap::{BytePos, Pos, Span};
 use utils::mk_sp;
+use visitor::FmtVisitor;
 
 impl<'a> FmtVisitor<'a> {
     fn output_at_start(&self) -> bool {
@@ -82,15 +82,15 @@ 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 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 local_end = self.codemap.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];
 
-        let big_diff = (span.lo - big_span_lo).to_usize();
-        let snippet = self.snippet(span.clone());
+        let big_diff = (span.lo() - big_span_lo).to_usize();
+        let snippet = self.snippet(span);
 
         debug!("write_snippet `{}`", snippet);
 
@@ -114,7 +114,7 @@ fn write_snippet_inner<F>(
         let mut last_wspace = None;
         let mut rewrite_next_comment = true;
 
-        let char_pos = self.codemap.lookup_char_pos(span.lo);
+        let char_pos = self.codemap.lookup_char_pos(span.lo());
         let file_name = &char_pos.file.name;
         let mut cur_line = char_pos.line;
 
@@ -146,10 +146,11 @@ fn replace_chars(string: &str) -> String {
                 let subslice_num_lines = subslice.chars().filter(|c| *c == '\n').count();
 
                 if rewrite_next_comment &&
-                    !self.config
-                        .file_lines()
-                        .intersects_range(file_name, cur_line, cur_line + subslice_num_lines)
-                {
+                    !self.config.file_lines().intersects_range(
+                        file_name,
+                        cur_line,
+                        cur_line + subslice_num_lines,
+                    ) {
                     rewrite_next_comment = false;
                 }
 
@@ -168,18 +169,19 @@ fn replace_chars(string: &str) -> String {
                         self.config.comment_width(),
                         self.config.max_width() - self.block_indent.width(),
                     );
+                    let comment_indent = Indent::from_width(self.config, self.buffer.cur_offset());
 
                     self.buffer.push_str(&rewrite_comment(
                         subslice,
                         false,
-                        Shape::legacy(comment_width, self.block_indent),
+                        Shape::legacy(comment_width, comment_indent),
                         self.config,
                     ).unwrap());
 
                     last_wspace = None;
                     line_start = offset + subslice.len();
 
-                    if let Some('/') = subslice.chars().skip(1).next() {
+                    if let Some('/') = subslice.chars().nth(1) {
                         // check that there are no contained block comments
                         if !subslice
                             .split('\n')