X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fvisitor.rs;h=8f6cab0e2dfe9d1ca172566c94abfe450a62dd95;hb=516f15aba154e2cc66b999d0c9613479f4d53275;hp=a7c33d2697c823959d757e38dce4c34b1ebf3685;hpb=fc52a4d33f0880edaae416f3db08ecc9ed5acd2a;p=rust.git diff --git a/src/visitor.rs b/src/visitor.rs index a7c33d2697c..8f6cab0e2df 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -166,7 +166,7 @@ pub fn visit_block( self.last_pos, attr_lo.unwrap_or(first_stmt.span.lo()), )); - let len = CommentCodeSlices::new(&snippet) + let len = CommentCodeSlices::new(snippet) .nth(0) .and_then(|(kind, _, s)| { if kind == CodeCharKind::Normal { @@ -212,7 +212,7 @@ pub fn visit_block( stmt.span.hi(), source!(self, b.span).hi() - brace_compensation, )); - let len = CommentCodeSlices::new(&snippet) + let len = CommentCodeSlices::new(snippet) .last() .and_then(|(kind, _, s)| { if kind == CodeCharKind::Normal && s.trim().is_empty() { @@ -430,7 +430,7 @@ pub fn visit_item(&mut self, item: &ast::Item) { } ast::ItemKind::MacroDef(..) => { // FIXME(#1539): macros 2.0 - let mac_snippet = Some(remove_trailing_white_spaces(&self.snippet(item.span))); + let mac_snippet = Some(remove_trailing_white_spaces(self.snippet(item.span))); self.push_rewrite(item.span, mac_snippet); } } @@ -684,9 +684,8 @@ fn to_stmt_item(stmt: &ast::Stmt) -> Option<&ast::Item> { // Extract leading `use ...;`. let items: Vec<_> = stmts .iter() - .take_while(|stmt| to_stmt_item(stmt).is_some()) + .take_while(|stmt| to_stmt_item(stmt).map_or(false, is_use_item)) .filter_map(|stmt| to_stmt_item(stmt)) - .take_while(|item| is_use_item(item)) .collect(); if items.is_empty() { @@ -779,7 +778,7 @@ pub fn get_context(&self) -> RewriteContext { use_block: false, is_if_else_block: false, force_one_line_chain: false, - snippet_provider: &self.snippet_provider, + snippet_provider: self.snippet_provider, } } } @@ -888,7 +887,7 @@ fn take_while_with_pred<'a, P>( // Extract comments between two attributes. let span_between_attr = mk_sp(attr.span.hi(), next_attr.span.lo()); let snippet = context.snippet(span_between_attr); - if count_newlines(&snippet) >= 2 || snippet.contains('/') { + if count_newlines(snippet) >= 2 || snippet.contains('/') { break; } } @@ -974,7 +973,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { // Preserve an empty line before/after doc comments. if self[0].is_sugared_doc || self[first_group_len].is_sugared_doc { let snippet = context.snippet(missing_span); - let (mla, mlb) = has_newlines_before_after_comment(&snippet); + let (mla, mlb) = has_newlines_before_after_comment(snippet); let comment = ::comment::recover_missing_comment_in_span( missing_span, shape.with_max_width(context.config), @@ -1068,7 +1067,7 @@ fn get_derive_args<'a>(context: &'a RewriteContext, attr: &ast::Attribute) -> Op pub fn rewrite_extern_crate(context: &RewriteContext, item: &ast::Item) -> Option { assert!(is_extern_crate(item)); let new_str = context.snippet(item.span); - Some(if contains_comment(&new_str) { + Some(if contains_comment(new_str) { new_str.to_owned() } else { let no_whitespace = &new_str.split_whitespace().collect::>().join(" ");