|
11 | 11 | // Formatting top-level items - functions, structs, enums, traits, impls.
|
12 | 12 |
|
13 | 13 | use {ReturnIndent, BraceStyle};
|
14 |
| -use utils::{format_visibility, make_indent}; |
| 14 | +use utils::{format_visibility, make_indent, FindUncommented}; |
15 | 15 | use lists::{write_list, ListFormatting, SeparatorTactic, ListTactic};
|
16 | 16 | use visitor::FmtVisitor;
|
17 | 17 | use syntax::{ast, abi};
|
@@ -336,12 +336,11 @@ impl<'a> FmtVisitor<'a> {
|
336 | 336 | // FIXME If you thought the crap with the commas was ugly, just wait.
|
337 | 337 | // This is awful. We're going to look from the last item span to the
|
338 | 338 | // start of the return type span, then we drop everything after the
|
339 |
| - // first closing paren. Obviously, this will break if there is a |
340 |
| - // closing paren in the comment. |
| 339 | + // first closing paren. |
341 | 340 | // The fix is comments in the AST or a span for the closing paren.
|
342 | 341 | let snippet = self.snippet(codemap::mk_sp(prev_end, next_span_start));
|
343 | 342 | let snippet = snippet.trim();
|
344 |
| - let snippet = &snippet[..snippet.find(terminator).unwrap_or(snippet.len())]; |
| 343 | + let snippet = &snippet[..snippet.find_uncommented(terminator).unwrap_or(snippet.len())]; |
345 | 344 | let snippet = snippet.trim();
|
346 | 345 | result.push(snippet.to_owned());
|
347 | 346 |
|
@@ -417,8 +416,7 @@ impl<'a> FmtVisitor<'a> {
|
417 | 416 | self.changes.push_str_span(span, &header_str);
|
418 | 417 |
|
419 | 418 | let enum_snippet = self.snippet(span);
|
420 |
| - // FIXME this will give incorrect results if there is a { in a comment. |
421 |
| - let body_start = span.lo + BytePos(enum_snippet.find('{').unwrap() as u32 + 1); |
| 419 | + let body_start = span.lo + BytePos(enum_snippet.find_uncommented("{").unwrap() as u32 + 1); |
422 | 420 | let generics_str = self.format_generics(generics, body_start);
|
423 | 421 | self.changes.push_str_span(span, &generics_str);
|
424 | 422 |
|
@@ -542,8 +540,8 @@ impl<'a> FmtVisitor<'a> {
|
542 | 540 | self.changes.push_str_span(span, &generics_str);
|
543 | 541 |
|
544 | 542 | let struct_snippet = self.snippet(span);
|
545 |
| - // FIXME this will give incorrect results if there is a { in a comment. |
546 |
| - self.last_pos = span.lo + BytePos(struct_snippet.find('{').unwrap() as u32 + 1); |
| 543 | + // This will drop the comment in between the header and body. |
| 544 | + self.last_pos = span.lo + BytePos(struct_snippet.find_uncommented("{").unwrap() as u32 + 1); |
547 | 545 |
|
548 | 546 | self.block_indent += config!(tab_spaces);
|
549 | 547 | for (i, f) in struct_def.fields.iter().enumerate() {
|
@@ -632,8 +630,7 @@ impl<'a> FmtVisitor<'a> {
|
632 | 630 | // This hack makes sure we only add comments etc. after the comma, and
|
633 | 631 | // makes sure we don't repeat any commas.
|
634 | 632 | let hi = field.span.hi;
|
635 |
| - // FIXME a comma in a comment will break this hack. |
636 |
| - let comma_pos = match struct_snippet[(hi.0 - struct_start.0) as usize..].find(',') { |
| 633 | + let comma_pos = match struct_snippet[(hi.0 - struct_start.0) as usize..].find_uncommented(",") { |
637 | 634 | Some(i) => i,
|
638 | 635 | None => 0,
|
639 | 636 | };
|
|
0 commit comments