|
11 | 11 | use std::cmp::Ordering; |
12 | 12 |
|
13 | 13 | use syntax::ast::{self, Visibility, Attribute, MetaItem, MetaItemKind}; |
14 | | -use syntax::codemap::{CodeMap, Span, BytePos}; |
| 14 | +use syntax::codemap::BytePos; |
15 | 15 | use syntax::abi; |
16 | 16 |
|
17 | 17 | use Indent; |
18 | | -use comment::FindUncommented; |
19 | 18 | use rewrite::{Rewrite, RewriteContext}; |
20 | 19 |
|
21 | 20 | use SKIP_ANNOTATION; |
22 | 21 |
|
23 | | -pub trait CodeMapSpanUtils { |
24 | | - fn span_after(&self, original: Span, needle: &str) -> BytePos; |
25 | | - fn span_after_last(&self, original: Span, needle: &str) -> BytePos; |
26 | | - fn span_before(&self, original: Span, needle: &str) -> BytePos; |
27 | | -} |
28 | | - |
29 | | -impl CodeMapSpanUtils for CodeMap { |
30 | | - #[inline] |
31 | | - fn span_after(&self, original: Span, needle: &str) -> BytePos { |
32 | | - let snippet = self.span_to_snippet(original).unwrap(); |
33 | | - let offset = snippet.find_uncommented(needle).unwrap() + needle.len(); |
34 | | - |
35 | | - original.lo + BytePos(offset as u32) |
36 | | - } |
37 | | - |
38 | | - #[inline] |
39 | | - fn span_after_last(&self, original: Span, needle: &str) -> BytePos { |
40 | | - let snippet = self.span_to_snippet(original).unwrap(); |
41 | | - let mut offset = 0; |
42 | | - |
43 | | - while let Some(additional_offset) = snippet[offset..].find_uncommented(needle) { |
44 | | - offset += additional_offset + needle.len(); |
45 | | - } |
46 | | - |
47 | | - original.lo + BytePos(offset as u32) |
48 | | - } |
49 | | - |
50 | | - #[inline] |
51 | | - fn span_before(&self, original: Span, needle: &str) -> BytePos { |
52 | | - let snippet = self.span_to_snippet(original).unwrap(); |
53 | | - let offset = snippet.find_uncommented(needle).unwrap(); |
54 | | - |
55 | | - original.lo + BytePos(offset as u32) |
56 | | - } |
57 | | -} |
58 | | - |
59 | 22 | // Computes the length of a string's last line, minus offset. |
60 | 23 | #[inline] |
61 | 24 | pub fn extra_offset(text: &str, offset: Indent) -> usize { |
|
0 commit comments