]> git.lizzy.rs Git - rust.git/commitdiff
Remove count_missing_closing_parens()
authortopecongiro <seuchida@gmail.com>
Sun, 20 Aug 2017 14:23:13 +0000 (23:23 +0900)
committertopecongiro <seuchida@gmail.com>
Sun, 20 Aug 2017 14:23:13 +0000 (23:23 +0900)
src/visitor.rs

index c5d91fee5b3b65c821f0f5a1ab7d61e70ecd9f68..309148d7c7bf3bb59b0ed0b06229531df0565e3c 100644 (file)
@@ -837,52 +837,6 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
     }
 }
 
-fn count_missing_closing_parens(s: &str) -> u32 {
-    let mut op_parens: u32 = 0;
-    let mut cl_parens: u32 = 0;
-
-    #[derive(Eq, PartialEq)]
-    pub enum SnippetState {
-        Normal,
-        InsideStr,
-        InsideBulletComment,
-        InsideSingleLineComment,
-    }
-
-    let mut state = SnippetState::Normal;
-    let mut iter = s.chars().peekable();
-    let mut prev_char: Option<char> = None;
-    while let Some(c) = iter.next() {
-        let next_char = iter.peek();
-        match c {
-            '/' if state == SnippetState::Normal => match next_char {
-                Some(&'*') => state = SnippetState::InsideBulletComment,
-                Some(&'/') if prev_char.map_or(true, |c| c != '*') => {
-                    state = SnippetState::InsideSingleLineComment;
-                }
-                _ => (),
-            },
-            '*' if state == SnippetState::InsideBulletComment &&
-                next_char.map_or(false, |c| *c == '/') =>
-            {
-                state = SnippetState::Normal;
-            }
-            '\n' if state == SnippetState::InsideSingleLineComment => state = SnippetState::Normal,
-            '"' if state == SnippetState::InsideStr && prev_char.map_or(false, |c| c != '\\') => {
-                state = SnippetState::Normal;
-            }
-            '"' if state == SnippetState::Normal && prev_char.map_or(false, |c| c != '\\') => {
-                state = SnippetState::InsideStr
-            }
-            '(' if state == SnippetState::Normal => op_parens += 1,
-            ')' if state == SnippetState::Normal => cl_parens += 1,
-            _ => (),
-        }
-        prev_char = Some(c);
-    }
-    op_parens.checked_sub(cl_parens).unwrap_or(0)
-}
-
 impl Rewrite for ast::MetaItem {
     fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
         Some(match self.node {
@@ -895,21 +849,15 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
                         .shrink_left(name.len() + 3)
                         .and_then(|s| s.sub_width(2))
                 );
-                let hi = self.span.hi +
-                    BytePos(count_missing_closing_parens(&context.snippet(self.span)));
                 let items = itemize_list(
                     context.codemap,
                     list.iter(),
                     ")",
                     |nested_meta_item| nested_meta_item.span.lo,
-                    // FIXME: Span from MetaItem is missing closing parens.
-                    |nested_meta_item| {
-                        let snippet = context.snippet(nested_meta_item.span);
-                        nested_meta_item.span.hi + BytePos(count_missing_closing_parens(&snippet))
-                    },
+                    |nested_meta_item| nested_meta_item.span.hi,
                     |nested_meta_item| nested_meta_item.rewrite(context, item_shape),
                     self.span.lo,
-                    hi,
+                    self.span.hi,
                     false,
                 );
                 let item_vec = items.collect::<Vec<_>>();