From c0f93a6ea35c41859c21da7d90fb142fa34a2df4 Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Sat, 9 Feb 2019 15:53:12 +0900 Subject: [PATCH 1/4] cargo +nightly fix --edition-idioms --- src/bin/main.rs | 8 ++++---- src/cargo-fmt/main.rs | 6 +++--- src/format-diff/main.rs | 8 ++++---- src/git-rustfmt/main.rs | 6 +++--- src/lib.rs | 16 ---------------- 5 files changed, 14 insertions(+), 30 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 53e95e8b5b608..b357eed34cf3d 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern crate env_logger; +use env_logger; #[macro_use] extern crate failure; -extern crate getopts; -extern crate rustfmt_nightly as rustfmt; + +use rustfmt_nightly as rustfmt; use std::env; use std::fs::File; @@ -296,7 +296,7 @@ fn format( Ok(exit_code) } -fn format_and_emit_report(session: &mut Session, input: Input) { +fn format_and_emit_report(session: &mut Session<'_, T>, input: Input) { match session.format(input) { Ok(report) => { if report.has_warnings() { diff --git a/src/cargo-fmt/main.rs b/src/cargo-fmt/main.rs index 83a93240ff2cc..058617439634d 100644 --- a/src/cargo-fmt/main.rs +++ b/src/cargo-fmt/main.rs @@ -13,9 +13,9 @@ #![cfg(not(test))] #![deny(warnings)] -extern crate cargo_metadata; -extern crate getopts; -extern crate serde_json as json; +use cargo_metadata; +use getopts; + use std::collections::{HashMap, HashSet}; use std::env; diff --git a/src/format-diff/main.rs b/src/format-diff/main.rs index aacfa12d437ea..5ffff79811c01 100644 --- a/src/format-diff/main.rs +++ b/src/format-diff/main.rs @@ -14,16 +14,16 @@ #![deny(warnings)] -extern crate env_logger; +use env_logger; #[macro_use] extern crate failure; -extern crate getopts; +use getopts; #[macro_use] extern crate log; -extern crate regex; +use regex; #[macro_use] extern crate serde_derive; -extern crate serde_json as json; +use serde_json as json; use std::collections::HashSet; use std::io::{self, BufRead}; diff --git a/src/git-rustfmt/main.rs b/src/git-rustfmt/main.rs index f7a181c4b6c66..aae81ba3270ec 100644 --- a/src/git-rustfmt/main.rs +++ b/src/git-rustfmt/main.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -extern crate env_logger; -extern crate getopts; +use env_logger; + #[macro_use] extern crate log; -extern crate rustfmt_nightly as rustfmt; +use rustfmt_nightly as rustfmt; use std::env; use std::io::stdout; diff --git a/src/lib.rs b/src/lib.rs index 6fc3dc859455d..799aad90b7b0f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,29 +10,13 @@ #[macro_use] extern crate derive_new; -extern crate atty; -extern crate bytecount; -extern crate diff; -extern crate dirs; -extern crate failure; -extern crate itertools; #[cfg(test)] #[macro_use] extern crate lazy_static; #[macro_use] extern crate log; -extern crate regex; -extern crate rustc_target; -extern crate serde; #[macro_use] extern crate serde_derive; -extern crate serde_json; -extern crate syntax; -extern crate syntax_pos; -extern crate toml; -extern crate unicode_categories; -extern crate unicode_segmentation; -extern crate unicode_width; use std::cell::RefCell; use std::collections::HashMap; From e70e6eb273d449e78349dde9a0980414df102c06 Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Sat, 9 Feb 2019 15:55:17 +0900 Subject: [PATCH 2/4] deny rust_2018_idioms --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 799aad90b7b0f..fdc8d851d406e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![deny(rust_2018_idioms)] + #[macro_use] extern crate derive_new; #[cfg(test)] From 4bb90f5cc8e0347534436612f45a3c22c7e265bb Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Sat, 9 Feb 2019 16:14:30 +0900 Subject: [PATCH 3/4] Fix rust_2018_idioms warnings --- src/attr.rs | 18 +++---- src/chains.rs | 60 +++++++++++----------- src/closures.rs | 22 ++++---- src/comment.rs | 20 ++++---- src/config/config_type.rs | 6 +-- src/config/file_lines.rs | 4 +- src/config/license.rs | 2 +- src/config/mod.rs | 2 +- src/config/options.rs | 4 +- src/expr.rs | 92 ++++++++++++++++----------------- src/formatting.rs | 2 +- src/imports.rs | 22 ++++---- src/issues.rs | 2 +- src/items.rs | 104 +++++++++++++++++++------------------- src/lib.rs | 6 +-- src/lists.rs | 10 ++-- src/macros.rs | 38 +++++++------- src/matches.rs | 20 ++++---- src/missed_spans.rs | 6 +-- src/overflow.rs | 24 ++++----- src/pairs.rs | 20 ++++---- src/patterns.rs | 16 +++--- src/reorder.rs | 6 +-- src/rewrite.rs | 4 +- src/rustfmt_diff.rs | 2 +- src/test/mod.rs | 2 +- src/types.rs | 42 +++++++-------- src/utils.rs | 10 ++-- src/vertical.rs | 20 ++++---- src/visitor.rs | 12 ++--- 30 files changed, 299 insertions(+), 299 deletions(-) diff --git a/src/attr.rs b/src/attr.rs index 52b55a9a17521..89b0367c48461 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -75,7 +75,7 @@ fn argument_shape( right: usize, combine: bool, shape: Shape, - context: &RewriteContext, + context: &RewriteContext<'_>, ) -> Option { match context.config.indent_style() { IndentStyle::Block => { @@ -100,7 +100,7 @@ fn format_derive( derive_args: &[Span], prefix: &str, shape: Shape, - context: &RewriteContext, + context: &RewriteContext<'_>, ) -> Option { let mut result = String::with_capacity(128); result.push_str(prefix); @@ -133,7 +133,7 @@ fn format_derive( /// Returns the first group of attributes that fills the given predicate. /// We consider two doc comments are in different group if they are separated by normal comments. fn take_while_with_pred<'a, P>( - context: &RewriteContext, + context: &RewriteContext<'_>, attrs: &'a [ast::Attribute], pred: P, ) -> &'a [ast::Attribute] @@ -164,7 +164,7 @@ where /// Rewrite the any doc comments which come before any other attributes. fn rewrite_initial_doc_comments( - context: &RewriteContext, + context: &RewriteContext<'_>, attrs: &[ast::Attribute], shape: Shape, ) -> Option<(usize, Option)> { @@ -193,7 +193,7 @@ fn rewrite_initial_doc_comments( } impl Rewrite for ast::NestedMetaItem { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match self.node { ast::NestedMetaItemKind::MetaItem(ref meta_item) => meta_item.rewrite(context, shape), ast::NestedMetaItemKind::Literal(ref l) => rewrite_literal(context, l, shape), @@ -221,7 +221,7 @@ fn has_newlines_before_after_comment(comment: &str) -> (&str, &str) { } impl Rewrite for ast::MetaItem { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { Some(match self.node { ast::MetaItemKind::Word => { rewrite_path(context, PathContext::Type, None, &self.ident, shape)? @@ -268,7 +268,7 @@ fn format_arg_list( get_hi: F2, get_item_string: F3, span: Span, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, one_line_shape: Shape, one_line_limit: Option, @@ -318,7 +318,7 @@ where } impl Rewrite for ast::Attribute { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { let snippet = context.snippet(self.span); if self.is_sugared_doc { rewrite_doc_comment(snippet, shape.comment(context.config), context.config) @@ -365,7 +365,7 @@ impl Rewrite for ast::Attribute { } impl<'a> Rewrite for [ast::Attribute] { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { if self.is_empty() { return Some(String::new()); } diff --git a/src/chains.rs b/src/chains.rs index 9ea37a3684f14..37bbde1f4ee4c 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -84,7 +84,7 @@ use crate::utils::{ trimmed_last_line_width, wrap_str, }; -pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -> Option { +pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext<'_>, shape: Shape) -> Option { let chain = Chain::from_ast(expr, context); debug!("rewrite_chain {:?} {:?}", chain, shape); @@ -128,7 +128,7 @@ enum ChainItemKind { } impl ChainItemKind { - fn is_block_like(&self, context: &RewriteContext, reps: &str) -> bool { + fn is_block_like(&self, context: &RewriteContext<'_>, reps: &str) -> bool { match self { ChainItemKind::Parent(ref expr) => utils::is_block_expr(context, expr, reps), ChainItemKind::MethodCall(..) @@ -147,7 +147,7 @@ impl ChainItemKind { } } - fn from_ast(context: &RewriteContext, expr: &ast::Expr) -> (ChainItemKind, Span) { + fn from_ast(context: &RewriteContext<'_>, expr: &ast::Expr) -> (ChainItemKind, Span) { let (kind, span) = match expr.node { ast::ExprKind::MethodCall(ref segment, ref expressions) => { let types = if let Some(ref generic_args) = segment.args { @@ -182,7 +182,7 @@ impl ChainItemKind { } impl Rewrite for ChainItem { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { let shape = shape.sub_width(self.tries)?; let rewrite = match self.kind { ChainItemKind::Parent(ref expr) => expr.rewrite(context, shape)?, @@ -204,7 +204,7 @@ impl Rewrite for ChainItem { } impl ChainItem { - fn new(context: &RewriteContext, expr: &ast::Expr, tries: usize) -> ChainItem { + fn new(context: &RewriteContext<'_>, expr: &ast::Expr, tries: usize) -> ChainItem { let (kind, span) = ChainItemKind::from_ast(context, expr); ChainItem { kind, tries, span } } @@ -229,7 +229,7 @@ impl ChainItem { types: &[ast::GenericArg], args: &[ptr::P], span: Span, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option { let type_str = if types.is_empty() { @@ -254,7 +254,7 @@ struct Chain { } impl Chain { - fn from_ast(expr: &ast::Expr, context: &RewriteContext) -> Chain { + fn from_ast(expr: &ast::Expr, context: &RewriteContext<'_>) -> Chain { let subexpr_list = Self::make_subexpr_list(expr, context); // Un-parse the expression tree into ChainItems @@ -376,7 +376,7 @@ impl Chain { // Returns a Vec of the prefixes of the chain. // E.g., for input `a.b.c` we return [`a.b.c`, `a.b`, 'a'] - fn make_subexpr_list(expr: &ast::Expr, context: &RewriteContext) -> Vec { + fn make_subexpr_list(expr: &ast::Expr, context: &RewriteContext<'_>) -> Vec { let mut subexpr_list = vec![expr.clone()]; while let Some(subexpr) = Self::pop_expr_chain(subexpr_list.last().unwrap(), context) { @@ -388,7 +388,7 @@ impl Chain { // Returns the expression's subexpression, if it exists. When the subexpr // is a try! macro, we'll convert it to shorthand when the option is set. - fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext) -> Option { + fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext<'_>) -> Option { match expr.node { ast::ExprKind::MethodCall(_, ref expressions) => { Some(Self::convert_try(&expressions[0], context)) @@ -400,7 +400,7 @@ impl Chain { } } - fn convert_try(expr: &ast::Expr, context: &RewriteContext) -> ast::Expr { + fn convert_try(expr: &ast::Expr, context: &RewriteContext<'_>) -> ast::Expr { match expr.node { ast::ExprKind::Mac(ref mac) if context.config.use_try_shorthand() => { if let Some(subexpr) = convert_try_mac(mac, context) { @@ -415,12 +415,12 @@ impl Chain { } impl Rewrite for Chain { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { debug!("rewrite chain {:?} {:?}", self, shape); let mut formatter = match context.config.indent_style() { - IndentStyle::Block => Box::new(ChainFormatterBlock::new(self)) as Box, - IndentStyle::Visual => Box::new(ChainFormatterVisual::new(self)) as Box, + IndentStyle::Block => Box::new(ChainFormatterBlock::new(self)) as Box, + IndentStyle::Visual => Box::new(ChainFormatterVisual::new(self)) as Box, }; formatter.format_root(&self.parent, context, shape)?; @@ -455,18 +455,18 @@ trait ChainFormatter { fn format_root( &mut self, parent: &ChainItem, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option<()>; - fn child_shape(&self, context: &RewriteContext, shape: Shape) -> Option; - fn format_children(&mut self, context: &RewriteContext, child_shape: Shape) -> Option<()>; + fn child_shape(&self, context: &RewriteContext<'_>, shape: Shape) -> Option; + fn format_children(&mut self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<()>; fn format_last_child( &mut self, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, child_shape: Shape, ) -> Option<()>; - fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option; + fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option; // Returns `Some` if the chain is only a root, None otherwise. fn pure_root(&mut self) -> Option; } @@ -540,7 +540,7 @@ impl<'a> ChainFormatterShared<'a> { fn format_last_child( &mut self, may_extend: bool, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, child_shape: Shape, ) -> Option<()> { @@ -633,7 +633,7 @@ impl<'a> ChainFormatterShared<'a> { Some(()) } - fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option { + fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option { let connector = if self.fits_single_line { // Yay, we can put everything on one line. Cow::from("") @@ -682,7 +682,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> { fn format_root( &mut self, parent: &ChainItem, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option<()> { let mut root_rewrite: String = parent.rewrite(context, shape)?; @@ -713,7 +713,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> { Some(()) } - fn child_shape(&self, context: &RewriteContext, shape: Shape) -> Option { + fn child_shape(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { Some( if self.root_ends_with_block { shape.block_indent(0) @@ -724,7 +724,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> { ) } - fn format_children(&mut self, context: &RewriteContext, child_shape: Shape) -> Option<()> { + fn format_children(&mut self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<()> { for item in &self.shared.children[..self.shared.children.len() - 1] { let rewrite = item.rewrite(context, child_shape)?; self.shared.rewrites.push(rewrite); @@ -734,7 +734,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> { fn format_last_child( &mut self, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, child_shape: Shape, ) -> Option<()> { @@ -742,7 +742,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> { .format_last_child(true, context, shape, child_shape) } - fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option { + fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option { self.shared.join_rewrites(context, child_shape) } @@ -771,7 +771,7 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> { fn format_root( &mut self, parent: &ChainItem, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option<()> { let parent_shape = shape.visual_indent(0); @@ -811,14 +811,14 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> { Some(()) } - fn child_shape(&self, context: &RewriteContext, shape: Shape) -> Option { + fn child_shape(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { shape .with_max_width(context.config) .offset_left(self.offset) .map(|s| s.visual_indent(0)) } - fn format_children(&mut self, context: &RewriteContext, child_shape: Shape) -> Option<()> { + fn format_children(&mut self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<()> { for item in &self.shared.children[..self.shared.children.len() - 1] { let rewrite = item.rewrite(context, child_shape)?; self.shared.rewrites.push(rewrite); @@ -828,7 +828,7 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> { fn format_last_child( &mut self, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, child_shape: Shape, ) -> Option<()> { @@ -836,7 +836,7 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> { .format_last_child(false, context, shape, child_shape) } - fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option { + fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option { self.shared.join_rewrites(context, child_shape) } diff --git a/src/closures.rs b/src/closures.rs index a048971874015..4924c8628f556 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -39,7 +39,7 @@ pub fn rewrite_closure( fn_decl: &ast::FnDecl, body: &ast::Expr, span: Span, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option { debug!("rewrite_closure {:?}", body); @@ -81,7 +81,7 @@ pub fn rewrite_closure( fn try_rewrite_without_block( expr: &ast::Expr, prefix: &str, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, body_shape: Shape, ) -> Option { @@ -97,7 +97,7 @@ fn try_rewrite_without_block( fn get_inner_expr<'a>( expr: &'a ast::Expr, prefix: &str, - context: &RewriteContext, + context: &RewriteContext<'_>, ) -> &'a ast::Expr { if let ast::ExprKind::Block(ref block, _) = expr.node { if !needs_block(block, prefix, context) { @@ -112,7 +112,7 @@ fn get_inner_expr<'a>( } // Figure out if a block is necessary. -fn needs_block(block: &ast::Block, prefix: &str, context: &RewriteContext) -> bool { +fn needs_block(block: &ast::Block, prefix: &str, context: &RewriteContext<'_>) -> bool { is_unsafe_block(block) || block.stmts.len() > 1 || block_contains_comment(block, context.source_map) @@ -139,7 +139,7 @@ fn veto_block(e: &ast::Expr) -> bool { fn rewrite_closure_with_block( body: &ast::Expr, prefix: &str, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option { let left_most = left_most_sub_expr(body); @@ -167,7 +167,7 @@ fn rewrite_closure_with_block( fn rewrite_closure_expr( expr: &ast::Expr, prefix: &str, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option { fn allow_multi_line(expr: &ast::Expr) -> bool { @@ -207,7 +207,7 @@ fn rewrite_closure_expr( fn rewrite_closure_block( block: &ast::Block, prefix: &str, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option { Some(format!("{} {}", prefix, block.rewrite(context, shape)?)) @@ -221,7 +221,7 @@ fn rewrite_closure_fn_decl( fn_decl: &ast::FnDecl, body: &ast::Expr, span: Span, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option<(String, usize)> { let is_async = if asyncness.is_async() { "async " } else { "" }; @@ -296,7 +296,7 @@ fn rewrite_closure_fn_decl( // Rewriting closure which is placed at the end of the function call's arg. // Returns `None` if the reformatted closure 'looks bad'. pub fn rewrite_last_closure( - context: &RewriteContext, + context: &RewriteContext<'_>, expr: &ast::Expr, shape: Shape, ) -> Option { @@ -360,7 +360,7 @@ pub fn rewrite_last_closure( } /// Returns true if the given vector of arguments has more than one `ast::ExprKind::Closure`. -pub fn args_have_many_closure(args: &[OverflowableItem]) -> bool { +pub fn args_have_many_closure(args: &[OverflowableItem<'_>]) -> bool { args.iter() .filter_map(|arg| arg.to_expr()) .filter(|expr| match expr.node { @@ -371,7 +371,7 @@ pub fn args_have_many_closure(args: &[OverflowableItem]) -> bool { > 1 } -fn is_block_closure_forced(context: &RewriteContext, expr: &ast::Expr) -> bool { +fn is_block_closure_forced(context: &RewriteContext<'_>, expr: &ast::Expr) -> bool { // If we are inside macro, we do not want to add or remove block from closure body. if context.inside_macro() { false diff --git a/src/comment.rs b/src/comment.rs index 5845fc6922704..d9d367fa3530c 100644 --- a/src/comment.rs +++ b/src/comment.rs @@ -122,7 +122,7 @@ impl<'a> CommentStyle<'a> { } } -fn comment_style(orig: &str, normalize_comments: bool) -> CommentStyle { +fn comment_style(orig: &str, normalize_comments: bool) -> CommentStyle<'_> { if !normalize_comments { if orig.starts_with("/**") && !orig.starts_with("/**/") { CommentStyle::DoubleBullet @@ -158,7 +158,7 @@ fn comment_style(orig: &str, normalize_comments: bool) -> CommentStyle { /// strings, then they will be put on a single line as long as doing so does not /// exceed max width. pub fn combine_strs_with_missing_comments( - context: &RewriteContext, + context: &RewriteContext<'_>, prev_str: &str, next_str: &str, span: Span, @@ -286,7 +286,7 @@ fn identify_comment( // - a boolean indicating if there is a blank line // - a number indicating the size of the first group of comments fn consume_same_line_comments( - style: CommentStyle, + style: CommentStyle<'_>, orig: &str, line_start: &str, ) -> (bool, usize) { @@ -459,7 +459,7 @@ impl ItemizedBlock { } /// Returns a `StringFormat` used for formatting the content of an item - fn create_string_format<'a>(&'a self, fmt: &'a StringFormat) -> StringFormat<'a> { + fn create_string_format<'a>(&'a self, fmt: &'a StringFormat<'_>) -> StringFormat<'a> { StringFormat { opener: "", closer: "", @@ -777,7 +777,7 @@ impl<'a> CommentRewrite<'a> { fn rewrite_comment_inner( orig: &str, block_style: bool, - style: CommentStyle, + style: CommentStyle<'_>, shape: Shape, config: &Config, is_doc_comment: bool, @@ -820,7 +820,7 @@ fn rewrite_comment_inner( const RUSTFMT_CUSTOM_COMMENT_PREFIX: &str = "//#### "; -fn hide_sharp_behind_comment(s: &str) -> Cow { +fn hide_sharp_behind_comment(s: &str) -> Cow<'_, str> { if s.trim_start().starts_with("# ") { Cow::from(format!("{}{}", RUSTFMT_CUSTOM_COMMENT_PREFIX, s)) } else { @@ -853,7 +853,7 @@ fn has_url(s: &str) -> bool { pub fn rewrite_missing_comment( span: Span, shape: Shape, - context: &RewriteContext, + context: &RewriteContext<'_>, ) -> Option { let missing_snippet = context.snippet(span); let trimmed_snippet = missing_snippet.trim(); @@ -870,7 +870,7 @@ pub fn rewrite_missing_comment( pub fn recover_missing_comment_in_span( span: Span, shape: Shape, - context: &RewriteContext, + context: &RewriteContext<'_>, used_width: usize, ) -> Option { let missing_comment = rewrite_missing_comment(span, shape, context)?; @@ -934,7 +934,7 @@ fn light_rewrite_comment( /// Trims comment characters and possibly a single space from the left of a string. /// Does not trim all whitespace. If a single space is trimmed from the left of the string, /// this function returns true. -fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle) -> (&'a str, bool) { +fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle<'_>) -> (&'a str, bool) { if line.starts_with("//! ") || line.starts_with("/// ") || line.starts_with("/*! ") @@ -1544,7 +1544,7 @@ impl<'a> Iterator for CommentCodeSlices<'a> { pub fn recover_comment_removed( new: String, span: Span, - context: &RewriteContext, + context: &RewriteContext<'_>, ) -> Option { let snippet = context.snippet(span); if snippet != new && changed_comment_content(snippet, &new) { diff --git a/src/config/config_type.rs b/src/config/config_type.rs index 09c41f8bb1dd3..08d086c668e18 100644 --- a/src/config/config_type.rs +++ b/src/config/config_type.rs @@ -173,11 +173,11 @@ macro_rules! create_config { } )+ - pub fn set(&mut self) -> ConfigSetter { + pub fn set(&mut self) -> ConfigSetter<'_> { ConfigSetter(self) } - pub fn was_set(&self) -> ConfigWasSet { + pub fn was_set(&self) -> ConfigWasSet<'_> { ConfigWasSet(self) } @@ -379,7 +379,7 @@ macro_rules! create_config { HIDE_OPTIONS.contains(&name) } - pub fn print_docs(out: &mut Write, include_unstable: bool) { + pub fn print_docs(out: &mut dyn Write, include_unstable: bool) { use std::cmp; let max = 0; $( let max = cmp::max(max, stringify!($i).len()+1); )+ diff --git a/src/config/file_lines.rs b/src/config/file_lines.rs index 07df0e32d9c7d..a7371a3da90ee 100644 --- a/src/config/file_lines.rs +++ b/src/config/file_lines.rs @@ -46,7 +46,7 @@ impl From for FileName { } impl fmt::Display for FileName { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { FileName::Real(p) => write!(f, "{}", p.to_str().unwrap()), FileName::Stdin => write!(f, "stdin"), @@ -202,7 +202,7 @@ impl FileLines { } /// Returns an iterator over the files contained in `self`. - pub fn files(&self) -> Files { + pub fn files(&self) -> Files<'_> { Files(self.0.as_ref().map(|m| m.keys())) } diff --git a/src/config/license.rs b/src/config/license.rs index b732482939364..38e3750845052 100644 --- a/src/config/license.rs +++ b/src/config/license.rs @@ -14,7 +14,7 @@ pub enum LicenseError { } impl fmt::Display for LicenseError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { LicenseError::IO(ref err) => err.fmt(f), LicenseError::Regex(ref err) => err.fmt(f), diff --git a/src/config/mod.rs b/src/config/mod.rs index 3685db306c85e..e51279018e21a 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -208,7 +208,7 @@ fn get_toml_path(dir: &Path) -> Result, Error> { Ok(None) } -fn config_path(options: &CliOptions) -> Result, Error> { +fn config_path(options: &dyn CliOptions) -> Result, Error> { let config_path_not_found = |path: &str| -> Result, Error> { Err(Error::new( ErrorKind::NotFound, diff --git a/src/config/options.rs b/src/config/options.rs index 7734cfbd50691..f167c34aedf2b 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -64,7 +64,7 @@ macro_rules! impl_enum_serialize_and_deserialize { impl<'de, T> Visitor<'de> for StringOnly where T: ::serde::Deserializer<'de> { type Value = String; - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { + fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { formatter.write_str("string") } fn visit_str(self, value: &str) -> Result { @@ -120,7 +120,7 @@ macro_rules! configuration_option_enum { } impl ::std::fmt::Debug for $e { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { f.write_str(match self { $( $e::$name => configuration_option_enum_stringify!($name $(: $value)*), diff --git a/src/expr.rs b/src/expr.rs index 744bc00d0def3..14a5ebd28ee53 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -47,7 +47,7 @@ use crate::vertical::rewrite_with_alignment; use crate::visitor::FmtVisitor; impl Rewrite for ast::Expr { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { format_expr(self, ExprType::SubExpression, context, shape) } } @@ -61,7 +61,7 @@ pub enum ExprType { pub fn format_expr( expr: &ast::Expr, expr_type: ExprType, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option { skip_out_of_file_lines_range!(context, expr.span); @@ -249,7 +249,7 @@ pub fn format_expr( ast::RangeLimits::Closed => "..=", }; - fn needs_space_before_range(context: &RewriteContext, lhs: &ast::Expr) -> bool { + fn needs_space_before_range(context: &RewriteContext<'_>, lhs: &ast::Expr) -> bool { match lhs.node { ast::ExprKind::Lit(ref lit) => match lit.node { ast::LitKind::FloatUnsuffixed(..) => { @@ -399,7 +399,7 @@ pub fn rewrite_array<'a, T: 'a + IntoOverflowableItem<'a>>( name: &'a str, exprs: impl Iterator, span: Span, - context: &'a RewriteContext, + context: &'a RewriteContext<'_>, shape: Shape, force_separator_tactic: Option, delim_token: Option, @@ -416,7 +416,7 @@ pub fn rewrite_array<'a, T: 'a + IntoOverflowableItem<'a>>( } fn rewrite_empty_block( - context: &RewriteContext, + context: &RewriteContext<'_>, block: &ast::Block, attrs: Option<&[ast::Attribute]>, label: Option, @@ -453,7 +453,7 @@ fn rewrite_empty_block( None } -fn block_prefix(context: &RewriteContext, block: &ast::Block, shape: Shape) -> Option { +fn block_prefix(context: &RewriteContext<'_>, block: &ast::Block, shape: Shape) -> Option { Some(match block.rules { ast::BlockCheckMode::Unsafe(..) => { let snippet = context.snippet(block.span); @@ -482,7 +482,7 @@ fn block_prefix(context: &RewriteContext, block: &ast::Block, shape: Shape) -> O } fn rewrite_single_line_block( - context: &RewriteContext, + context: &RewriteContext<'_>, prefix: &str, block: &ast::Block, attrs: Option<&[ast::Attribute]>, @@ -502,7 +502,7 @@ fn rewrite_single_line_block( } pub fn rewrite_block_with_visitor( - context: &RewriteContext, + context: &RewriteContext<'_>, prefix: &str, block: &ast::Block, attrs: Option<&[ast::Attribute]>, @@ -533,7 +533,7 @@ pub fn rewrite_block_with_visitor( } impl Rewrite for ast::Block { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { rewrite_block(self, None, None, context, shape) } } @@ -542,7 +542,7 @@ fn rewrite_block( block: &ast::Block, attrs: Option<&[ast::Attribute]>, label: Option, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option { let prefix = block_prefix(context, block, shape)?; @@ -568,7 +568,7 @@ fn rewrite_block( } impl Rewrite for ast::Stmt { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { skip_out_of_file_lines_range!(context, self.span()); let result = match self.node { @@ -590,7 +590,7 @@ impl Rewrite for ast::Stmt { } // Rewrite condition if the given expression has one. -pub fn rewrite_cond(context: &RewriteContext, expr: &ast::Expr, shape: Shape) -> Option { +pub fn rewrite_cond(context: &RewriteContext<'_>, expr: &ast::Expr, shape: Shape) -> Option { match expr.node { ast::ExprKind::Match(ref cond, _) => { // `match `cond` {` @@ -627,7 +627,7 @@ struct ControlFlow<'a> { span: Span, } -fn to_control_flow(expr: &ast::Expr, expr_type: ExprType) -> Option { +fn to_control_flow(expr: &ast::Expr, expr_type: ExprType) -> Option> { match expr.node { ast::ExprKind::If(ref cond, ref if_block, ref else_block) => Some(ControlFlow::new_if( cond, @@ -767,7 +767,7 @@ impl<'a> ControlFlow<'a> { fn rewrite_single_line( &self, pat_expr_str: &str, - context: &RewriteContext, + context: &RewriteContext<'_>, width: usize, ) -> Option { assert!(self.allow_single_line); @@ -825,7 +825,7 @@ fn last_line_offsetted(start_column: usize, pat_str: &str) -> bool { impl<'a> ControlFlow<'a> { fn rewrite_pat_expr( &self, - context: &RewriteContext, + context: &RewriteContext<'_>, expr: &ast::Expr, shape: Shape, offset: usize, @@ -865,7 +865,7 @@ impl<'a> ControlFlow<'a> { fn rewrite_cond( &self, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, alt_block_sep: &str, ) -> Option<(String, usize)> { @@ -1001,7 +1001,7 @@ impl<'a> ControlFlow<'a> { } impl<'a> Rewrite for ControlFlow<'a> { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { debug!("ControlFlow::rewrite {:?} {:?}", self, shape); let alt_block_sep = &shape.indent.to_string_with_newline(context.config); @@ -1126,7 +1126,7 @@ fn rewrite_label(opt_label: Option) -> Cow<'static, str> { } } -fn extract_comment(span: Span, context: &RewriteContext, shape: Shape) -> Option { +fn extract_comment(span: Span, context: &RewriteContext<'_>, shape: Shape) -> Option { match rewrite_missing_comment(span, shape, context) { Some(ref comment) if !comment.is_empty() => Some(format!( "{indent}{}{indent}", @@ -1197,7 +1197,7 @@ pub fn is_unsafe_block(block: &ast::Block) -> bool { } pub fn rewrite_multiple_patterns( - context: &RewriteContext, + context: &RewriteContext<'_>, pats: &[&ast::Pat], shape: Shape, ) -> Option { @@ -1229,7 +1229,7 @@ pub fn rewrite_multiple_patterns( write_list(&items, &fmt) } -pub fn rewrite_literal(context: &RewriteContext, l: &ast::Lit, shape: Shape) -> Option { +pub fn rewrite_literal(context: &RewriteContext<'_>, l: &ast::Lit, shape: Shape) -> Option { match l.node { ast::LitKind::Str(_, ast::StrStyle::Cooked) => rewrite_string_lit(context, l.span, shape), _ => wrap_str( @@ -1240,7 +1240,7 @@ pub fn rewrite_literal(context: &RewriteContext, l: &ast::Lit, shape: Shape) -> } } -fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Option { +fn rewrite_string_lit(context: &RewriteContext<'_>, span: Span, shape: Shape) -> Option { let string_lit = context.snippet(span); if !context.config.format_strings() { @@ -1285,7 +1285,7 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt ) } -fn choose_separator_tactic(context: &RewriteContext, span: Span) -> Option { +fn choose_separator_tactic(context: &RewriteContext<'_>, span: Span) -> Option { if context.inside_macro() { if span_ends_with_comma(context, span) { Some(SeparatorTactic::Always) @@ -1298,7 +1298,7 @@ fn choose_separator_tactic(context: &RewriteContext, span: Span) -> Option, callee: &str, args: &[ptr::P], span: Span, @@ -1333,11 +1333,11 @@ pub fn is_simple_expr(expr: &ast::Expr) -> bool { } } -pub fn is_every_expr_simple(lists: &[OverflowableItem]) -> bool { +pub fn is_every_expr_simple(lists: &[OverflowableItem<'_>]) -> bool { lists.iter().all(OverflowableItem::is_simple) } -pub fn can_be_overflowed_expr(context: &RewriteContext, expr: &ast::Expr, args_len: usize) -> bool { +pub fn can_be_overflowed_expr(context: &RewriteContext<'_>, expr: &ast::Expr, args_len: usize) -> bool { match expr.node { ast::ExprKind::Match(..) => { (context.use_block_indent() && args_len == 1) @@ -1397,7 +1397,7 @@ pub fn is_nested_call(expr: &ast::Expr) -> bool { /// Return true if a function call or a method call represented by the given span ends with a /// trailing comma. This function is used when rewriting macro, as adding or removing a trailing /// comma from macro can potentially break the code. -pub fn span_ends_with_comma(context: &RewriteContext, span: Span) -> bool { +pub fn span_ends_with_comma(context: &RewriteContext<'_>, span: Span) -> bool { let mut result: bool = Default::default(); let mut prev_char: char = Default::default(); let closing_delimiters = &[')', '}', ']']; @@ -1418,7 +1418,7 @@ pub fn span_ends_with_comma(context: &RewriteContext, span: Span) -> bool { } fn rewrite_paren( - context: &RewriteContext, + context: &RewriteContext<'_>, mut subexpr: &ast::Expr, shape: Shape, mut span: Span, @@ -1462,7 +1462,7 @@ fn rewrite_paren( } fn rewrite_paren_in_multi_line( - context: &RewriteContext, + context: &RewriteContext<'_>, subexpr: &ast::Expr, shape: Shape, pre_span: Span, @@ -1495,7 +1495,7 @@ fn rewrite_paren_in_multi_line( fn rewrite_index( expr: &ast::Expr, index: &ast::Expr, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option { let expr_str = expr.rewrite(context, shape)?; @@ -1556,7 +1556,7 @@ fn struct_lit_can_be_aligned(fields: &[ast::Field], base: Option<&ast::Expr>) -> } fn rewrite_struct_lit<'a>( - context: &RewriteContext, + context: &RewriteContext<'_>, path: &ast::Path, fields: &'a [ast::Field], base: Option<&'a ast::Expr>, @@ -1599,7 +1599,7 @@ fn rewrite_struct_lit<'a>( .map(StructLitField::Regular) .chain(base.into_iter().map(StructLitField::Base)); - let span_lo = |item: &StructLitField| match *item { + let span_lo = |item: &StructLitField<'_>| match *item { StructLitField::Regular(field) => field.span().lo(), StructLitField::Base(expr) => { let last_field_hi = fields.last().map_or(span.lo(), |field| field.span.hi()); @@ -1608,11 +1608,11 @@ fn rewrite_struct_lit<'a>( last_field_hi + BytePos(pos as u32) } }; - let span_hi = |item: &StructLitField| match *item { + let span_hi = |item: &StructLitField<'_>| match *item { StructLitField::Regular(field) => field.span().hi(), StructLitField::Base(expr) => expr.span.hi(), }; - let rewrite = |item: &StructLitField| match *item { + let rewrite = |item: &StructLitField<'_>| match *item { StructLitField::Regular(field) => { // The 1 taken from the v_budget is for the comma. rewrite_field(context, field, v_shape.sub_width(1)?, 0) @@ -1662,7 +1662,7 @@ fn rewrite_struct_lit<'a>( } pub fn wrap_struct_field( - context: &RewriteContext, + context: &RewriteContext<'_>, fields_str: &str, shape: Shape, nested_shape: Shape, @@ -1690,7 +1690,7 @@ pub fn struct_lit_field_separator(config: &Config) -> &str { } pub fn rewrite_field( - context: &RewriteContext, + context: &RewriteContext<'_>, field: &ast::Field, shape: Shape, prefix_max_width: usize, @@ -1739,7 +1739,7 @@ pub fn rewrite_field( } fn rewrite_tuple_in_visual_indent_style<'a, T: 'a + IntoOverflowableItem<'a>>( - context: &RewriteContext, + context: &RewriteContext<'_>, mut items: impl Iterator, span: Span, shape: Shape, @@ -1787,7 +1787,7 @@ fn rewrite_tuple_in_visual_indent_style<'a, T: 'a + IntoOverflowableItem<'a>>( } pub fn rewrite_tuple<'a, T: 'a + IntoOverflowableItem<'a>>( - context: &'a RewriteContext, + context: &'a RewriteContext<'_>, items: impl Iterator, span: Span, shape: Shape, @@ -1822,7 +1822,7 @@ pub fn rewrite_tuple<'a, T: 'a + IntoOverflowableItem<'a>>( } pub fn rewrite_unary_prefix( - context: &RewriteContext, + context: &RewriteContext<'_>, prefix: &str, rewrite: &R, shape: Shape, @@ -1835,7 +1835,7 @@ pub fn rewrite_unary_prefix( // FIXME: this is probably not correct for multi-line Rewrites. we should // subtract suffix.len() from the last line budget, not the first! pub fn rewrite_unary_suffix( - context: &RewriteContext, + context: &RewriteContext<'_>, suffix: &str, rewrite: &R, shape: Shape, @@ -1849,7 +1849,7 @@ pub fn rewrite_unary_suffix( } fn rewrite_unary_op( - context: &RewriteContext, + context: &RewriteContext<'_>, op: ast::UnOp, expr: &ast::Expr, shape: Shape, @@ -1859,7 +1859,7 @@ fn rewrite_unary_op( } fn rewrite_assignment( - context: &RewriteContext, + context: &RewriteContext<'_>, lhs: &ast::Expr, rhs: &ast::Expr, op: Option<&ast::BinOp>, @@ -1889,7 +1889,7 @@ pub enum RhsTactics { // The left hand side must contain everything up to, and including, the // assignment operator. pub fn rewrite_assign_rhs, R: Rewrite>( - context: &RewriteContext, + context: &RewriteContext<'_>, lhs: S, ex: &R, shape: Shape, @@ -1898,7 +1898,7 @@ pub fn rewrite_assign_rhs, R: Rewrite>( } pub fn rewrite_assign_rhs_with, R: Rewrite>( - context: &RewriteContext, + context: &RewriteContext<'_>, lhs: S, ex: &R, shape: Shape, @@ -1927,7 +1927,7 @@ pub fn rewrite_assign_rhs_with, R: Rewrite>( } fn choose_rhs( - context: &RewriteContext, + context: &RewriteContext<'_>, expr: &R, shape: Shape, orig_rhs: Option, @@ -1968,7 +1968,7 @@ fn choose_rhs( } fn shape_from_rhs_tactic( - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, rhs_tactic: RhsTactics, ) -> Option { @@ -1993,7 +1993,7 @@ pub fn prefer_next_line(orig_rhs: &str, next_line_rhs: &str, rhs_tactics: RhsTac } fn rewrite_expr_addrof( - context: &RewriteContext, + context: &RewriteContext<'_>, mutability: ast::Mutability, expr: &ast::Expr, shape: Shape, diff --git a/src/formatting.rs b/src/formatting.rs index 9ffa0308297af..91930bad00a6e 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -111,7 +111,7 @@ fn format_project( // Used for formatting files. #[derive(new)] -struct FormatContext<'a, T: FormatHandler + 'a> { +struct FormatContext<'a, T: FormatHandler> { krate: &'a ast::Crate, report: FormatReport, parse_session: ParseSess, diff --git a/src/imports.rs b/src/imports.rs index ad102a64c6bdd..6ca29cfeaedfd 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -146,7 +146,7 @@ impl UseSegment { } fn from_path_segment( - context: &RewriteContext, + context: &RewriteContext<'_>, path_seg: &ast::PathSegment, modsep: bool, ) -> Option { @@ -193,19 +193,19 @@ fn merge_use_trees_inner(trees: &mut Vec, use_tree: UseTree) { } impl fmt::Debug for UseTree { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, f) } } impl fmt::Debug for UseSegment { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self, f) } } impl fmt::Display for UseSegment { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { UseSegment::Glob => write!(f, "*"), UseSegment::Ident(ref s, _) => write!(f, "{}", s), @@ -227,7 +227,7 @@ impl fmt::Display for UseSegment { } } impl fmt::Display for UseTree { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { for (i, segment) in self.path.iter().enumerate() { let is_last = i == self.path.len() - 1; write!(f, "{}", segment)?; @@ -241,7 +241,7 @@ impl fmt::Display for UseTree { impl UseTree { // Rewrite use tree with `use ` and a trailing `;`. - pub fn rewrite_top_level(&self, context: &RewriteContext, shape: Shape) -> Option { + pub fn rewrite_top_level(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { let vis = self.visibility.as_ref().map_or(Cow::from(""), |vis| { crate::utils::format_visibility(context, &vis) }); @@ -281,7 +281,7 @@ impl UseTree { } pub fn from_ast_with_normalization( - context: &RewriteContext, + context: &RewriteContext<'_>, item: &ast::Item, ) -> Option { match item.node { @@ -305,7 +305,7 @@ impl UseTree { } fn from_ast( - context: &RewriteContext, + context: &RewriteContext<'_>, a: &ast::UseTree, list_item: Option, visibility: Option, @@ -710,7 +710,7 @@ impl Ord for UseTree { } fn rewrite_nested_use_tree( - context: &RewriteContext, + context: &RewriteContext<'_>, use_tree_list: &[UseTree], shape: Shape, ) -> Option { @@ -786,7 +786,7 @@ fn rewrite_nested_use_tree( } impl Rewrite for UseSegment { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { Some(match self { UseSegment::Ident(ref ident, Some(ref rename)) => format!("{} as {}", ident, rename), UseSegment::Ident(ref ident, None) => ident.clone(), @@ -809,7 +809,7 @@ impl Rewrite for UseSegment { impl Rewrite for UseTree { // This does NOT format attributes and visibility or add a trailing `;`. - fn rewrite(&self, context: &RewriteContext, mut shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, mut shape: Shape) -> Option { let mut result = String::with_capacity(256); let mut iter = self.path.iter().peekable(); while let Some(ref segment) = iter.next() { diff --git a/src/issues.rs b/src/issues.rs index 3104f72043663..3716110465ea0 100644 --- a/src/issues.rs +++ b/src/issues.rs @@ -48,7 +48,7 @@ pub struct Issue { } impl fmt::Display for Issue { - fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { let msg = match self.issue_type { IssueType::Todo => "TODO", IssueType::Fixme => "FIXME", diff --git a/src/items.rs b/src/items.rs index 3bef81c7d9acd..b272a42ba18b7 100644 --- a/src/items.rs +++ b/src/items.rs @@ -54,7 +54,7 @@ fn type_annotation_separator(config: &Config) -> &str { // Statements of the form // let pat: ty = init; impl Rewrite for ast::Local { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { debug!( "Local::rewrite {:?} {} {:?}", self, shape.width, shape.indent @@ -214,7 +214,7 @@ impl<'a> FnSig<'a> { } pub fn from_fn_kind( - fn_kind: &'a visit::FnKind, + fn_kind: &'a visit::FnKind<'_>, generics: &'a ast::Generics, decl: &'a ast::FnDecl, defaultness: ast::Defaultness, @@ -242,7 +242,7 @@ impl<'a> FnSig<'a> { } } - fn to_str(&self, context: &RewriteContext) -> String { + fn to_str(&self, context: &RewriteContext<'_>) -> String { let mut result = String::with_capacity(128); // Vis defaultness constness unsafety abi. result.push_str(&*format_visibility(context, &self.visibility)); @@ -260,7 +260,7 @@ impl<'a> FnSig<'a> { } impl<'a> FmtVisitor<'a> { - fn format_item(&mut self, item: &Item) { + fn format_item(&mut self, item: &Item<'_>) { self.buffer.push_str(&item.abi); let snippet = self.snippet(item.span); @@ -292,7 +292,7 @@ impl<'a> FmtVisitor<'a> { self.last_pos = item.span.hi(); } - fn format_body_element(&mut self, element: &BodyElement) { + fn format_body_element(&mut self, element: &BodyElement<'_>) { match *element { BodyElement::ForeignItem(item) => self.format_foreign_item(item), } @@ -313,7 +313,7 @@ impl<'a> FmtVisitor<'a> { &mut self, indent: Indent, ident: ast::Ident, - fn_sig: &FnSig, + fn_sig: &FnSig<'_>, span: Span, block: &ast::Block, inner_attrs: Option<&[ast::Attribute]>, @@ -427,12 +427,12 @@ impl<'a> FmtVisitor<'a> { } } - pub fn visit_static(&mut self, static_parts: &StaticParts) { + pub fn visit_static(&mut self, static_parts: &StaticParts<'_>) { let rewrite = rewrite_static(&self.get_context(), static_parts, self.block_indent); self.push_rewrite(static_parts.span, rewrite); } - pub fn visit_struct(&mut self, struct_parts: &StructParts) { + pub fn visit_struct(&mut self, struct_parts: &StructParts<'_>) { let is_tuple = struct_parts.def.is_tuple(); let rewrite = format_struct(&self.get_context(), struct_parts, self.block_indent, None) .map(|s| if is_tuple { s + ";" } else { s }); @@ -672,7 +672,7 @@ impl<'a> FmtVisitor<'a> { } pub fn format_impl( - context: &RewriteContext, + context: &RewriteContext<'_>, item: &ast::Item, offset: Indent, where_span_end: Option, @@ -800,7 +800,7 @@ pub fn format_impl( } fn is_impl_single_line( - context: &RewriteContext, + context: &RewriteContext<'_>, items: &[ast::ImplItem], result: &str, where_clause_str: &str, @@ -819,7 +819,7 @@ fn is_impl_single_line( } fn format_impl_ref_and_type( - context: &RewriteContext, + context: &RewriteContext<'_>, item: &ast::Item, offset: Indent, ) -> Option { @@ -913,7 +913,7 @@ fn format_impl_ref_and_type( } fn rewrite_trait_ref( - context: &RewriteContext, + context: &RewriteContext<'_>, trait_ref: &ast::TraitRef, offset: Indent, polarity_str: &str, @@ -949,7 +949,7 @@ pub struct StructParts<'a> { } impl<'a> StructParts<'a> { - fn format_header(&self, context: &RewriteContext) -> String { + fn format_header(&self, context: &RewriteContext<'_>) -> String { format_header(context, self.prefix, self.ident, self.vis) } @@ -982,8 +982,8 @@ impl<'a> StructParts<'a> { } fn format_struct( - context: &RewriteContext, - struct_parts: &StructParts, + context: &RewriteContext<'_>, + struct_parts: &StructParts<'_>, offset: Indent, one_line_width: Option, ) -> Option { @@ -998,7 +998,7 @@ fn format_struct( } } -pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent) -> Option { +pub fn format_trait(context: &RewriteContext<'_>, item: &ast::Item, offset: Indent) -> Option { if let ast::ItemKind::Trait( is_auto, unsafety, @@ -1157,7 +1157,7 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent) } pub fn format_trait_alias( - context: &RewriteContext, + context: &RewriteContext<'_>, ident: ast::Ident, generics: &ast::Generics, generic_bounds: &ast::GenericBounds, @@ -1172,7 +1172,7 @@ pub fn format_trait_alias( rewrite_assign_rhs(context, lhs, generic_bounds, shape.sub_width(1)?).map(|s| s + ";") } -fn format_unit_struct(context: &RewriteContext, p: &StructParts, offset: Indent) -> Option { +fn format_unit_struct(context: &RewriteContext<'_>, p: &StructParts<'_>, offset: Indent) -> Option { let header_str = format_header(context, p.prefix, p.ident, p.vis); let generics_str = if let Some(generics) = p.generics { let hi = if generics.where_clause.predicates.is_empty() { @@ -1197,8 +1197,8 @@ fn format_unit_struct(context: &RewriteContext, p: &StructParts, offset: Indent) } pub fn format_struct_struct( - context: &RewriteContext, - struct_parts: &StructParts, + context: &RewriteContext<'_>, + struct_parts: &StructParts<'_>, fields: &[ast::StructField], offset: Indent, one_line_width: Option, @@ -1301,7 +1301,7 @@ fn get_bytepos_after_visibility(vis: &ast::Visibility, default_span: Span) -> By // Format tuple or struct without any fields. We need to make sure that the comments // inside the delimiters are preserved. fn format_empty_struct_or_tuple( - context: &RewriteContext, + context: &RewriteContext<'_>, span: Span, offset: Indent, result: &mut String, @@ -1334,8 +1334,8 @@ fn format_empty_struct_or_tuple( } fn format_tuple_struct( - context: &RewriteContext, - struct_parts: &StructParts, + context: &RewriteContext<'_>, + struct_parts: &StructParts<'_>, fields: &[ast::StructField], offset: Indent, ) -> Option { @@ -1429,7 +1429,7 @@ fn format_tuple_struct( } fn rewrite_type_prefix( - context: &RewriteContext, + context: &RewriteContext<'_>, indent: Indent, prefix: &str, ident: ast::Ident, @@ -1470,7 +1470,7 @@ fn rewrite_type_prefix( } fn rewrite_type_item( - context: &RewriteContext, + context: &RewriteContext<'_>, indent: Indent, prefix: &str, suffix: &str, @@ -1501,7 +1501,7 @@ fn rewrite_type_item( } pub fn rewrite_type_alias( - context: &RewriteContext, + context: &RewriteContext<'_>, indent: Indent, ident: ast::Ident, ty: &ast::Ty, @@ -1512,7 +1512,7 @@ pub fn rewrite_type_alias( } pub fn rewrite_existential_type( - context: &RewriteContext, + context: &RewriteContext<'_>, indent: Indent, ident: ast::Ident, generic_bounds: &ast::GenericBounds, @@ -1539,7 +1539,7 @@ fn type_annotation_spacing(config: &Config) -> (&str, &str) { } pub fn rewrite_struct_field_prefix( - context: &RewriteContext, + context: &RewriteContext<'_>, field: &ast::StructField, ) -> Option { let vis = format_visibility(context, &field.vis); @@ -1556,13 +1556,13 @@ pub fn rewrite_struct_field_prefix( } impl Rewrite for ast::StructField { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { rewrite_struct_field(context, self, shape, 0) } } pub fn rewrite_struct_field( - context: &RewriteContext, + context: &RewriteContext<'_>, field: &ast::StructField, shape: Shape, lhs_max_width: usize, @@ -1693,8 +1693,8 @@ impl<'a> StaticParts<'a> { } fn rewrite_static( - context: &RewriteContext, - static_parts: &StaticParts, + context: &RewriteContext<'_>, + static_parts: &StaticParts<'_>, offset: Indent, ) -> Option { let colon = colon_spaces( @@ -1752,7 +1752,7 @@ pub fn rewrite_associated_type( ty_opt: Option<&ptr::P>, generics: &ast::Generics, generic_bounds_opt: Option<&ast::GenericBounds>, - context: &RewriteContext, + context: &RewriteContext<'_>, indent: Indent, ) -> Option { let ident_str = rewrite_ident(context, ident); @@ -1784,7 +1784,7 @@ pub fn rewrite_associated_type( } pub fn rewrite_existential_impl_type( - context: &RewriteContext, + context: &RewriteContext<'_>, ident: ast::Ident, generics: &ast::Generics, generic_bounds: &ast::GenericBounds, @@ -1799,7 +1799,7 @@ pub fn rewrite_associated_impl_type( defaultness: ast::Defaultness, ty_opt: Option<&ptr::P>, generics: &ast::Generics, - context: &RewriteContext, + context: &RewriteContext<'_>, indent: Indent, ) -> Option { let result = rewrite_associated_type(ident, ty_opt, generics, None, context, indent)?; @@ -1811,7 +1811,7 @@ pub fn rewrite_associated_impl_type( } impl Rewrite for ast::FunctionRetTy { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match *self { ast::FunctionRetTy::Default(_) => Some(String::new()), ast::FunctionRetTy::Ty(ref ty) => { @@ -1831,7 +1831,7 @@ fn is_empty_infer(ty: &ast::Ty, pat_span: Span) -> bool { } impl Rewrite for ast::Arg { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { if is_named_arg(self) { let mut result = self .pat @@ -1863,7 +1863,7 @@ impl Rewrite for ast::Arg { fn rewrite_explicit_self( explicit_self: &ast::ExplicitSelf, args: &[ast::Arg], - context: &RewriteContext, + context: &RewriteContext<'_>, ) -> Option { match explicit_self.node { ast::SelfKind::Region(lt, m) => { @@ -1922,7 +1922,7 @@ pub fn span_lo_for_arg(arg: &ast::Arg) -> BytePos { } } -pub fn span_hi_for_arg(context: &RewriteContext, arg: &ast::Arg) -> BytePos { +pub fn span_hi_for_arg(context: &RewriteContext<'_>, arg: &ast::Arg) -> BytePos { match arg.ty.node { ast::TyKind::Infer if context.snippet(arg.ty.span) == "_" => arg.ty.span.hi(), ast::TyKind::Infer if is_named_arg(arg) => arg.pat.span.hi(), @@ -1940,10 +1940,10 @@ pub fn is_named_arg(arg: &ast::Arg) -> bool { // Return type is (result, force_new_line_for_brace) fn rewrite_fn_base( - context: &RewriteContext, + context: &RewriteContext<'_>, indent: Indent, ident: ast::Ident, - fn_sig: &FnSig, + fn_sig: &FnSig<'_>, span: Span, newline_brace: bool, has_body: bool, @@ -2269,7 +2269,7 @@ impl WhereClauseOption { } fn rewrite_args( - context: &RewriteContext, + context: &RewriteContext<'_>, args: &[ast::Arg], explicit_self: Option<&ast::ExplicitSelf>, one_line_budget: usize, @@ -2427,7 +2427,7 @@ fn arg_has_pattern(arg: &ast::Arg) -> bool { } fn compute_budgets_for_args( - context: &RewriteContext, + context: &RewriteContext<'_>, result: &str, indent: Indent, ret_str_len: usize, @@ -2500,7 +2500,7 @@ fn newline_for_brace(config: &Config, where_clause: &ast::WhereClause) -> bool { } fn rewrite_generics( - context: &RewriteContext, + context: &RewriteContext<'_>, ident: &str, generics: &ast::Generics, shape: Shape, @@ -2531,7 +2531,7 @@ pub fn generics_shape_from_config(config: &Config, shape: Shape, offset: usize) } fn rewrite_where_clause_rfc_style( - context: &RewriteContext, + context: &RewriteContext<'_>, where_clause: &ast::WhereClause, shape: Shape, terminator: &str, @@ -2631,7 +2631,7 @@ fn rewrite_where_clause_rfc_style( } fn rewrite_where_clause( - context: &RewriteContext, + context: &RewriteContext<'_>, where_clause: &ast::WhereClause, brace_style: BraceStyle, shape: Shape, @@ -2743,7 +2743,7 @@ fn missing_span_before_after_where( } fn rewrite_comments_before_after_where( - context: &RewriteContext, + context: &RewriteContext<'_>, span_before_where: Span, span_after_where: Span, shape: Shape, @@ -2758,7 +2758,7 @@ fn rewrite_comments_before_after_where( } fn format_header( - context: &RewriteContext, + context: &RewriteContext<'_>, item_name: &str, ident: ast::Ident, vis: &ast::Visibility, @@ -2779,7 +2779,7 @@ enum BracePos { } fn format_generics( - context: &RewriteContext, + context: &RewriteContext<'_>, generics: &ast::Generics, brace_style: BraceStyle, brace_pos: BracePos, @@ -2853,7 +2853,7 @@ fn format_generics( } impl Rewrite for ast::ForeignItem { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { let attrs_str = self.attrs.rewrite(context, shape)?; // Drop semicolon or it will be interpreted as comment. // FIXME: this may be a faulty span from libsyntax. @@ -2914,7 +2914,7 @@ impl Rewrite for ast::ForeignItem { } /// Rewrite an inline mod. -pub fn rewrite_mod(context: &RewriteContext, item: &ast::Item) -> String { +pub fn rewrite_mod(context: &RewriteContext<'_>, item: &ast::Item) -> String { let mut result = String::with_capacity(32); result.push_str(&*format_visibility(context, &item.vis)); result.push_str("mod "); @@ -2924,7 +2924,7 @@ pub fn rewrite_mod(context: &RewriteContext, item: &ast::Item) -> String { } /// Rewrite `extern crate foo;` WITHOUT attributes. -pub fn rewrite_extern_crate(context: &RewriteContext, item: &ast::Item) -> Option { +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) { diff --git a/src/lib.rs b/src/lib.rs index fdc8d851d406e..49652436493d5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -249,7 +249,7 @@ impl FormatReport { /// fancy output. pub fn fancy_print( &self, - mut t: Box>, + mut t: Box>, ) -> Result<(), term::Error> { for (file, errors) in &self.internal.borrow().0 { for error in errors { @@ -320,7 +320,7 @@ impl FormatReport { impl fmt::Display for FormatReport { // Prints all the formatting errors. - fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { for (file, errors) in &self.internal.borrow().0 { for error in errors { let prefix_space_len = error.line.to_string().len(); @@ -494,7 +494,7 @@ fn format_code_block(code_snippet: &str, config: &Config) -> Option { +pub struct Session<'b, T: Write> { pub config: Config, pub out: Option<&'b mut T>, pub(crate) errors: ReportedErrors, diff --git a/src/lists.rs b/src/lists.rs index 3575b207dbaf8..0fb1eec68d0f2 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -270,7 +270,7 @@ where } // Format a list of commented items into a string. -pub fn write_list(items: I, formatting: &ListFormatting) -> Option +pub fn write_list(items: I, formatting: &ListFormatting<'_>) -> Option where I: IntoIterator + Clone, T: AsRef, @@ -771,7 +771,7 @@ where #[allow(clippy::too_many_arguments)] // Creates an iterator over a list's items with associated comments. pub fn itemize_list<'a, T, I, F1, F2, F3>( - snippet_provider: &'a SnippetProvider, + snippet_provider: &'a SnippetProvider<'_>, inner: I, terminator: &'a str, separator: &'a str, @@ -838,7 +838,7 @@ fn comment_len(comment: Option<&str>) -> usize { // Compute horizontal and vertical shapes for a struct-lit-like thing. pub fn struct_lit_shape( shape: Shape, - context: &RewriteContext, + context: &RewriteContext<'_>, prefix_width: usize, suffix_width: usize, ) -> Option<(Option, Shape)> { @@ -867,7 +867,7 @@ pub fn struct_lit_shape( // Compute the tactic for the internals of a struct-lit-like thing. pub fn struct_lit_tactic( h_shape: Option, - context: &RewriteContext, + context: &RewriteContext<'_>, items: &[ListItem], ) -> DefinitiveListTactic { if let Some(h_shape) = h_shape { @@ -900,7 +900,7 @@ pub fn shape_for_tactic( pub fn struct_lit_formatting<'a>( shape: Shape, tactic: DefinitiveListTactic, - context: &'a RewriteContext, + context: &'a RewriteContext<'_>, force_no_trailing_comma: bool, ) -> ListFormatting<'a> { let ends_with_newline = context.config.indent_style() != IndentStyle::Visual diff --git a/src/macros.rs b/src/macros.rs index a1b571ba0add5..8243b6a9734ba 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -76,7 +76,7 @@ impl MacroArg { } impl Rewrite for ast::Item { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { let mut visitor = crate::visitor::FmtVisitor::from_context(context); visitor.block_indent = shape.indent; visitor.last_pos = self.span().lo(); @@ -86,7 +86,7 @@ impl Rewrite for ast::Item { } impl Rewrite for MacroArg { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match *self { MacroArg::Expr(ref expr) => expr.rewrite(context, shape), MacroArg::Ty(ref ty) => ty.rewrite(context, shape), @@ -145,7 +145,7 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option { /// Rewrite macro name without using pretty-printer if possible. fn rewrite_macro_name( - context: &RewriteContext, + context: &RewriteContext<'_>, path: &ast::Path, extra_ident: Option, ) -> String { @@ -163,7 +163,7 @@ fn rewrite_macro_name( // Use this on failing to format the macro call. fn return_macro_parse_failure_fallback( - context: &RewriteContext, + context: &RewriteContext<'_>, indent: Indent, span: Span, ) -> Option { @@ -197,7 +197,7 @@ struct InsideMacroGuard<'a> { } impl<'a> InsideMacroGuard<'a> { - fn inside_macro_context(context: &'a RewriteContext) -> InsideMacroGuard<'a> { + fn inside_macro_context(context: &'a RewriteContext<'_>) -> InsideMacroGuard<'a> { let is_nested = context.inside_macro.replace(true); InsideMacroGuard { context, is_nested } } @@ -212,7 +212,7 @@ impl<'a> Drop for InsideMacroGuard<'a> { pub fn rewrite_macro( mac: &ast::Mac, extra_ident: Option, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, position: MacroPosition, ) -> Option { @@ -227,7 +227,7 @@ pub fn rewrite_macro( pub fn rewrite_macro_inner( mac: &ast::Mac, extra_ident: Option, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, position: MacroPosition, is_nested_macro: bool, @@ -433,7 +433,7 @@ pub fn rewrite_macro_inner( } pub fn rewrite_macro_def( - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, indent: Indent, def: &ast::MacroDef, @@ -604,7 +604,7 @@ enum MacroArgKind { } fn delim_token_to_str( - context: &RewriteContext, + context: &RewriteContext<'_>, delim_token: DelimToken, shape: Shape, use_multiple_lines: bool, @@ -670,7 +670,7 @@ impl MacroArgKind { fn rewrite( &self, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, use_multiple_lines: bool, ) -> Option { @@ -722,7 +722,7 @@ struct ParsedMacroArg { impl ParsedMacroArg { pub fn rewrite( &self, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, use_multiple_lines: bool, ) -> Option { @@ -975,7 +975,7 @@ impl MacroArgParser { } fn wrap_macro_args( - context: &RewriteContext, + context: &RewriteContext<'_>, args: &[ParsedMacroArg], shape: Shape, ) -> Option { @@ -984,7 +984,7 @@ fn wrap_macro_args( } fn wrap_macro_args_inner( - context: &RewriteContext, + context: &RewriteContext<'_>, args: &[ParsedMacroArg], shape: Shape, use_multiple_lines: bool, @@ -1027,7 +1027,7 @@ fn wrap_macro_args_inner( // // We always try and format on one line. // FIXME: Use multi-line when every thing does not fit on one line. -fn format_macro_args(context: &RewriteContext, toks: TokenStream, shape: Shape) -> Option { +fn format_macro_args(context: &RewriteContext<'_>, toks: TokenStream, shape: Shape) -> Option { if !context.config.format_macro_matchers() { let token_stream: TokenStream = toks.into(); let span = span_for_token_stream(&token_stream); @@ -1118,7 +1118,7 @@ fn next_space(tok: &Token) -> SpaceState { /// Tries to convert a macro use into a short hand try expression. Returns None /// when the macro is not an instance of try! (or parsing the inner expression /// failed). -pub fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext) -> Option { +pub fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext<'_>) -> Option { if &mac.node.path.to_string() == "try" { let ts: TokenStream = mac.node.tts.clone().into(); let mut parser = new_parser_from_tts(context.parse_session, ts.trees().collect()); @@ -1134,7 +1134,7 @@ pub fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext) -> Option DelimToken { +fn macro_style(mac: &ast::Mac, context: &RewriteContext<'_>) -> DelimToken { let snippet = context.snippet(mac.span); let paren_pos = snippet.find_uncommented("(").unwrap_or(usize::max_value()); let bracket_pos = snippet.find_uncommented("[").unwrap_or(usize::max_value()); @@ -1222,7 +1222,7 @@ struct MacroBranch { impl MacroBranch { fn rewrite( &self, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, multi_branch_style: bool, ) -> Option { @@ -1340,7 +1340,7 @@ impl MacroBranch { /// [pub] static ref NAME_N: TYPE_N = EXPR_N; /// } /// ``` -fn format_lazy_static(context: &RewriteContext, shape: Shape, ts: &TokenStream) -> Option { +fn format_lazy_static(context: &RewriteContext<'_>, shape: Shape, ts: &TokenStream) -> Option { let mut result = String::with_capacity(1024); let mut parser = new_parser_from_tts(context.parse_session, ts.trees().collect()); let nested_shape = shape @@ -1409,7 +1409,7 @@ fn format_lazy_static(context: &RewriteContext, shape: Shape, ts: &TokenStream) } fn rewrite_macro_with_items( - context: &RewriteContext, + context: &RewriteContext<'_>, items: &[MacroArg], macro_name: &str, shape: Shape, diff --git a/src/matches.rs b/src/matches.rs index febab4da178ad..15ff7dbb8fe72 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -67,13 +67,13 @@ impl<'a> Spanned for ArmWrapper<'a> { } impl<'a> Rewrite for ArmWrapper<'a> { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { rewrite_match_arm(context, self.arm, shape, self.is_last) } } pub fn rewrite_match( - context: &RewriteContext, + context: &RewriteContext<'_>, cond: &ast::Expr, arms: &[ast::Arm], shape: Shape, @@ -168,7 +168,7 @@ fn arm_comma(config: &Config, body: &ast::Expr, is_last: bool) -> &'static str { /// Collect a byte position of the beginning `|` for each arm, if available. fn collect_beginning_verts( - context: &RewriteContext, + context: &RewriteContext<'_>, arms: &[ast::Arm], span: Span, ) -> Vec> { @@ -184,7 +184,7 @@ fn collect_beginning_verts( } fn rewrite_match_arms( - context: &RewriteContext, + context: &RewriteContext<'_>, arms: &[ast::Arm], shape: Shape, span: Span, @@ -224,7 +224,7 @@ fn rewrite_match_arms( } fn rewrite_match_arm( - context: &RewriteContext, + context: &RewriteContext<'_>, arm: &ast::Arm, shape: Shape, is_last: bool, @@ -286,7 +286,7 @@ fn rewrite_match_arm( } fn block_can_be_flattened<'a>( - context: &RewriteContext, + context: &RewriteContext<'_>, expr: &'a ast::Expr, ) -> Option<&'a ast::Block> { match expr.node { @@ -304,7 +304,7 @@ fn block_can_be_flattened<'a>( // @extend: true if the arm body can be put next to `=>` // @body: flattened body, if the body is block with a single expression fn flatten_arm_body<'a>( - context: &'a RewriteContext, + context: &'a RewriteContext<'_>, body: &'a ast::Expr, opt_shape: Option, ) -> (bool, &'a ast::Expr) { @@ -334,7 +334,7 @@ fn flatten_arm_body<'a>( } fn rewrite_match_body( - context: &RewriteContext, + context: &RewriteContext<'_>, body: &ptr::P, pats_str: &str, shape: Shape, @@ -499,7 +499,7 @@ fn rewrite_match_body( } impl Rewrite for ast::Guard { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match self { ast::Guard::If(ref expr) => expr.rewrite(context, shape), } @@ -508,7 +508,7 @@ impl Rewrite for ast::Guard { // The `if ...` guard on a match arm. fn rewrite_guard( - context: &RewriteContext, + context: &RewriteContext<'_>, guard: &Option, shape: Shape, // The amount of space used up on this line for the pattern in diff --git a/src/missed_spans.rs b/src/missed_spans.rs index 2b409ab7b8711..740378fbc2a5d 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -79,7 +79,7 @@ impl<'a> FmtVisitor<'a> { }) } - fn format_missing_inner( + fn format_missing_inner, &str, &str)>( &mut self, end: BytePos, process_last_snippet: F, @@ -144,7 +144,7 @@ impl<'a> FmtVisitor<'a> { fn write_snippet(&mut self, span: Span, process_last_snippet: F) where - F: Fn(&mut FmtVisitor, &str, &str), + F: Fn(&mut FmtVisitor<'_>, &str, &str), { // 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 @@ -172,7 +172,7 @@ impl<'a> FmtVisitor<'a> { span: Span, process_last_snippet: F, ) where - F: Fn(&mut FmtVisitor, &str, &str), + F: Fn(&mut FmtVisitor<'_>, &str, &str), { // Trim whitespace from the right hand side of each line. // Annoyingly, the library functions for splitting by lines etc. are not diff --git a/src/overflow.rs b/src/overflow.rs index 04456aea106c4..8f50f08ed2ab0 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -89,7 +89,7 @@ pub enum OverflowableItem<'a> { } impl<'a> Rewrite for OverflowableItem<'a> { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { self.map(|item| item.rewrite(context, shape)) } } @@ -103,7 +103,7 @@ impl<'a> Spanned for OverflowableItem<'a> { impl<'a> OverflowableItem<'a> { pub fn map(&self, f: F) -> T where - F: Fn(&IntoOverflowableItem<'a>) -> T, + F: Fn(&dyn IntoOverflowableItem<'a>) -> T, { match self { OverflowableItem::Expr(expr) => f(*expr), @@ -159,7 +159,7 @@ impl<'a> OverflowableItem<'a> { } } - pub fn can_be_overflowed(&self, context: &RewriteContext, len: usize) -> bool { + pub fn can_be_overflowed(&self, context: &RewriteContext<'_>, len: usize) -> bool { match self { OverflowableItem::Expr(expr) => can_be_overflowed_expr(context, expr, len), OverflowableItem::MacroArg(macro_arg) => match macro_arg { @@ -247,7 +247,7 @@ where } pub fn rewrite_with_parens<'a, T: 'a + IntoOverflowableItem<'a>>( - context: &'a RewriteContext, + context: &'a RewriteContext<'_>, ident: &'a str, items: impl Iterator, shape: Shape, @@ -271,7 +271,7 @@ pub fn rewrite_with_parens<'a, T: 'a + IntoOverflowableItem<'a>>( } pub fn rewrite_with_angle_brackets<'a, T: 'a + IntoOverflowableItem<'a>>( - context: &'a RewriteContext, + context: &'a RewriteContext<'_>, ident: &'a str, items: impl Iterator, shape: Shape, @@ -293,7 +293,7 @@ pub fn rewrite_with_angle_brackets<'a, T: 'a + IntoOverflowableItem<'a>>( } pub fn rewrite_with_square_brackets<'a, T: 'a + IntoOverflowableItem<'a>>( - context: &'a RewriteContext, + context: &'a RewriteContext<'_>, name: &'a str, items: impl Iterator, shape: Shape, @@ -338,7 +338,7 @@ struct Context<'a> { impl<'a> Context<'a> { pub fn new>( - context: &'a RewriteContext, + context: &'a RewriteContext<'_>, items: impl Iterator, ident: &'a str, shape: Shape, @@ -375,7 +375,7 @@ impl<'a> Context<'a> { } } - fn last_item(&self) -> Option<&OverflowableItem> { + fn last_item(&self) -> Option<&OverflowableItem<'_>> { self.items.last() } @@ -704,7 +704,7 @@ fn need_block_indent(s: &str, shape: Shape) -> bool { }) } -fn can_be_overflowed(context: &RewriteContext, items: &[OverflowableItem]) -> bool { +fn can_be_overflowed(context: &RewriteContext<'_>, items: &[OverflowableItem<'_>]) -> bool { items .last() .map_or(false, |x| x.can_be_overflowed(context, items.len())) @@ -712,7 +712,7 @@ fn can_be_overflowed(context: &RewriteContext, items: &[OverflowableItem]) -> bo /// Returns a shape for the last argument which is going to be overflowed. fn last_item_shape( - lists: &[OverflowableItem], + lists: &[OverflowableItem<'_>], items: &[ListItem], shape: Shape, args_max_width: usize, @@ -732,7 +732,7 @@ fn last_item_shape( } fn shape_from_indent_style( - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, overhead: usize, offset: usize, @@ -758,7 +758,7 @@ fn no_long_items(list: &[ListItem]) -> bool { } /// In case special-case style is required, returns an offset from which we start horizontal layout. -pub fn maybe_get_args_offset(callee_str: &str, args: &[OverflowableItem]) -> Option<(bool, usize)> { +pub fn maybe_get_args_offset(callee_str: &str, args: &[OverflowableItem<'_>]) -> Option<(bool, usize)> { if let Some(&(_, num_args_before)) = args .get(0)? .whitelist() diff --git a/src/pairs.rs b/src/pairs.rs index 05a0911c388af..8429d33114f06 100644 --- a/src/pairs.rs +++ b/src/pairs.rs @@ -42,7 +42,7 @@ impl<'a> PairParts<'a> { pub(crate) fn rewrite_all_pairs( expr: &ast::Expr, shape: Shape, - context: &RewriteContext, + context: &RewriteContext<'_>, ) -> Option { // First we try formatting on one line. if let Some(list) = expr.flatten(false) { @@ -62,9 +62,9 @@ pub(crate) fn rewrite_all_pairs( // This may return a multi-line result since we allow the last expression to go // multiline in a 'single line' formatting. fn rewrite_pairs_one_line( - list: &PairList, + list: &PairList<'_, '_, T>, shape: Shape, - context: &RewriteContext, + context: &RewriteContext<'_>, ) -> Option { assert!(list.list.len() >= 2, "Not a pair?"); @@ -107,9 +107,9 @@ fn rewrite_pairs_one_line( } fn rewrite_pairs_multiline( - list: &PairList, + list: &PairList<'_, '_, T>, shape: Shape, - context: &RewriteContext, + context: &RewriteContext<'_>, ) -> Option { let rhs_offset = shape.rhs_overhead(&context.config); let nested_shape = (match context.config.indent_style() { @@ -175,8 +175,8 @@ fn rewrite_pairs_multiline( pub(crate) fn rewrite_pair( lhs: &LHS, rhs: &RHS, - pp: PairParts, - context: &RewriteContext, + pp: PairParts<'_>, + context: &RewriteContext<'_>, shape: Shape, separator_place: SeparatorPlace, ) -> Option @@ -264,18 +264,18 @@ trait FlattenPair: Rewrite + Sized { // operator into the list. E.g,, if the source is `a * b + c`, if `_same_op` // is true, we make `[(a * b), c]` if `_same_op` is false, we make // `[a, b, c]` - fn flatten(&self, _same_op: bool) -> Option> { + fn flatten(&self, _same_op: bool) -> Option> { None } } -struct PairList<'a, 'b, T: Rewrite + 'b> { +struct PairList<'a, 'b, T: Rewrite> { list: Vec<&'b T>, separators: Vec<&'a str>, } impl FlattenPair for ast::Expr { - fn flatten(&self, same_op: bool) -> Option> { + fn flatten(&self, same_op: bool) -> Option> { let top_op = match self.node { ast::ExprKind::Binary(op, _, _) => op.node, _ => return None, diff --git a/src/patterns.rs b/src/patterns.rs index acfb6ee193361..6114362e76f77 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -64,7 +64,7 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool { } impl Rewrite for Pat { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match self.node { PatKind::Box(ref pat) => rewrite_unary_prefix(context, "box ", &**pat, shape), PatKind::Ident(binding_mode, ident, ref sub_pat) => { @@ -174,7 +174,7 @@ fn rewrite_struct_pat( fields: &[source_map::Spanned], ellipsis: bool, span: Span, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option { // 2 = ` {` @@ -240,7 +240,7 @@ fn rewrite_struct_pat( } impl Rewrite for FieldPat { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { let pat = self.pat.rewrite(context, shape); if self.is_shorthand { pat @@ -271,7 +271,7 @@ pub enum TuplePatField<'a> { } impl<'a> Rewrite for TuplePatField<'a> { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match *self { TuplePatField::Pat(p) => p.rewrite(context, shape), TuplePatField::Dotdot(_) => Some("..".to_string()), @@ -288,7 +288,7 @@ impl<'a> Spanned for TuplePatField<'a> { } } -pub fn can_be_overflowed_pat(context: &RewriteContext, pat: &TuplePatField, len: usize) -> bool { +pub fn can_be_overflowed_pat(context: &RewriteContext<'_>, pat: &TuplePatField<'_>, len: usize) -> bool { match *pat { TuplePatField::Pat(pat) => match pat.node { ast::PatKind::Path(..) @@ -310,7 +310,7 @@ fn rewrite_tuple_pat( dotdot_pos: Option, path_str: Option, span: Span, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option { let mut pat_vec: Vec<_> = pats.iter().map(|x| TuplePatField::Pat(x)).collect(); @@ -379,8 +379,8 @@ fn rewrite_tuple_pat( } fn count_wildcard_suffix_len( - context: &RewriteContext, - patterns: &[TuplePatField], + context: &RewriteContext<'_>, + patterns: &[TuplePatField<'_>], span: Span, shape: Shape, ) -> usize { diff --git a/src/reorder.rs b/src/reorder.rs index 5891cde75941b..e078cc3279bbf 100644 --- a/src/reorder.rs +++ b/src/reorder.rs @@ -63,7 +63,7 @@ fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering { } fn wrap_reorderable_items( - context: &RewriteContext, + context: &RewriteContext<'_>, list_items: &[ListItem], shape: Shape, ) -> Option { @@ -74,7 +74,7 @@ fn wrap_reorderable_items( } fn rewrite_reorderable_item( - context: &RewriteContext, + context: &RewriteContext<'_>, item: &ast::Item, shape: Shape, ) -> Option { @@ -99,7 +99,7 @@ fn rewrite_reorderable_item( /// Rewrite a list of items with reordering. Every item in `items` must have /// the same `ast::ItemKind`. fn rewrite_reorderable_items( - context: &RewriteContext, + context: &RewriteContext<'_>, reorderable_items: &[&ast::Item], shape: Shape, span: Span, diff --git a/src/rewrite.rs b/src/rewrite.rs index 9d3733a279ce3..5c5ed438f5e2b 100644 --- a/src/rewrite.rs +++ b/src/rewrite.rs @@ -23,11 +23,11 @@ use crate::FormatReport; pub trait Rewrite { /// Rewrite self into shape. - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option; + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option; } impl Rewrite for ptr::P { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { (**self).rewrite(context, shape) } } diff --git a/src/rustfmt_diff.rs b/src/rustfmt_diff.rs index 8a74aa47c0cd9..81778c33ecf97 100644 --- a/src/rustfmt_diff.rs +++ b/src/rustfmt_diff.rs @@ -46,7 +46,7 @@ impl Mismatch { // This struct handles writing output to stdout and abstracts away the logic // of printing in color, if it's possible in the executing environment. pub struct OutputWriter { - terminal: Option>>, + terminal: Option>>, } impl OutputWriter { diff --git a/src/test/mod.rs b/src/test/mod.rs index 7e0be85f5abc9..ac2a1a3ba227f 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -785,7 +785,7 @@ impl ConfigCodeBlock { true } - fn has_parsing_errors(&self, session: &Session) -> bool { + fn has_parsing_errors(&self, session: &Session<'_, T>) -> bool { if session.has_parsing_errors() { write_message(&format!( "\u{261d}\u{1f3fd} Cannot format {}:{}", diff --git a/src/types.rs b/src/types.rs index 2bbf1ba9f22d2..340f15ead481f 100644 --- a/src/types.rs +++ b/src/types.rs @@ -40,7 +40,7 @@ pub enum PathContext { // Does not wrap on simple segments. pub fn rewrite_path( - context: &RewriteContext, + context: &RewriteContext<'_>, path_context: PathContext, qself: Option<&ast::QSelf>, path: &ast::Path, @@ -103,7 +103,7 @@ fn rewrite_path_segments<'a, I>( iter: I, mut span_lo: BytePos, span_hi: BytePos, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option where @@ -148,7 +148,7 @@ pub enum SegmentParam<'a> { } impl<'a> SegmentParam<'a> { - fn from_generic_arg(arg: &ast::GenericArg) -> SegmentParam { + fn from_generic_arg(arg: &ast::GenericArg) -> SegmentParam<'_> { match arg { ast::GenericArg::Lifetime(ref lt) => SegmentParam::LifeTime(lt), ast::GenericArg::Type(ref ty) => SegmentParam::Type(ty), @@ -167,7 +167,7 @@ impl<'a> Spanned for SegmentParam<'a> { } impl<'a> Rewrite for SegmentParam<'a> { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match *self { SegmentParam::LifeTime(lt) => lt.rewrite(context, shape), SegmentParam::Type(ty) => ty.rewrite(context, shape), @@ -204,7 +204,7 @@ fn rewrite_segment( segment: &ast::PathSegment, span_lo: &mut BytePos, span_hi: BytePos, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option { let mut result = String::with_capacity(128); @@ -285,7 +285,7 @@ fn format_function_type<'a, I>( output: &FunctionRetTy, variadic: bool, span: Span, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option where @@ -410,7 +410,7 @@ where } } -fn type_bound_colon(context: &RewriteContext) -> &'static str { +fn type_bound_colon(context: &RewriteContext<'_>) -> &'static str { colon_spaces( context.config.space_before_colon(), context.config.space_after_colon(), @@ -418,7 +418,7 @@ fn type_bound_colon(context: &RewriteContext) -> &'static str { } impl Rewrite for ast::WherePredicate { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { // FIXME: dead spans? let result = match *self { ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate { @@ -459,7 +459,7 @@ impl Rewrite for ast::WherePredicate { } impl Rewrite for ast::GenericArg { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match *self { ast::GenericArg::Lifetime(ref lt) => lt.rewrite(context, shape), ast::GenericArg::Type(ref ty) => ty.rewrite(context, shape), @@ -470,7 +470,7 @@ impl Rewrite for ast::GenericArg { fn rewrite_bounded_lifetime( lt: &ast::Lifetime, bounds: &[ast::GenericBound], - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option { let result = lt.rewrite(context, shape)?; @@ -491,13 +491,13 @@ fn rewrite_bounded_lifetime( } impl Rewrite for ast::Lifetime { - fn rewrite(&self, context: &RewriteContext, _: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, _: Shape) -> Option { Some(rewrite_ident(context, self.ident).to_owned()) } } impl Rewrite for ast::GenericBound { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match *self { ast::GenericBound::Trait(ref poly_trait_ref, trait_bound_modifier) => { let snippet = context.snippet(self.span()); @@ -516,7 +516,7 @@ impl Rewrite for ast::GenericBound { } impl Rewrite for ast::GenericBounds { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { if self.is_empty() { return Some(String::new()); } @@ -526,7 +526,7 @@ impl Rewrite for ast::GenericBounds { } impl Rewrite for ast::GenericParam { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { let mut result = String::with_capacity(128); // FIXME: If there are more than one attributes, this will force multiline. match self.attrs.rewrite(context, shape) { @@ -558,7 +558,7 @@ impl Rewrite for ast::GenericParam { } impl Rewrite for ast::PolyTraitRef { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { if let Some(lifetime_str) = rewrite_lifetime_param(context, shape, &self.bound_generic_params) { @@ -576,13 +576,13 @@ impl Rewrite for ast::PolyTraitRef { } impl Rewrite for ast::TraitRef { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { rewrite_path(context, PathContext::Type, None, &self.path, shape) } } impl Rewrite for ast::Ty { - fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { match self.node { ast::TyKind::TraitObject(ref bounds, tobj_syntax) => { // we have to consider 'dyn' keyword is used or not!!! @@ -695,7 +695,7 @@ impl Rewrite for ast::Ty { fn rewrite_bare_fn( bare_fn: &ast::BareFnTy, span: Span, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, ) -> Option { debug!("rewrite_bare_fn {:#?}", shape); @@ -759,7 +759,7 @@ fn is_generic_bounds_in_order(generic_bounds: &[ast::GenericBound]) -> bool { } fn join_bounds( - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, items: &[ast::GenericBound], need_indent: bool, @@ -815,7 +815,7 @@ fn join_bounds( Some(result) } -pub fn can_be_overflowed_type(context: &RewriteContext, ty: &ast::Ty, len: usize) -> bool { +pub fn can_be_overflowed_type(context: &RewriteContext<'_>, ty: &ast::Ty, len: usize) -> bool { match ty.node { ast::TyKind::Tup(..) => context.use_block_indent() && len == 1, ast::TyKind::Rptr(_, ref mutty) | ast::TyKind::Ptr(ref mutty) => { @@ -827,7 +827,7 @@ pub fn can_be_overflowed_type(context: &RewriteContext, ty: &ast::Ty, len: usize /// Returns `None` if there is no `LifetimeDef` in the given generic parameters. fn rewrite_lifetime_param( - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, generic_params: &[ast::GenericParam], ) -> Option { diff --git a/src/utils.rs b/src/utils.rs index 06f1ca2d8d8eb..9c70ef7d975f2 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -30,7 +30,7 @@ use crate::shape::{Indent, Shape}; pub const DEPR_SKIP_ANNOTATION: &str = "rustfmt_skip"; pub const SKIP_ANNOTATION: &str = "rustfmt::skip"; -pub fn rewrite_ident<'a>(context: &'a RewriteContext, ident: ast::Ident) -> &'a str { +pub fn rewrite_ident<'a>(context: &'a RewriteContext<'_>, ident: ast::Ident) -> &'a str { context.snippet(ident.span) } @@ -64,7 +64,7 @@ pub fn is_same_visibility(a: &Visibility, b: &Visibility) -> bool { } // Uses Cow to avoid allocating in the common cases. -pub fn format_visibility(context: &RewriteContext, vis: &Visibility) -> Cow<'static, str> { +pub fn format_visibility(context: &RewriteContext<'_>, vis: &Visibility) -> Cow<'static, str> { match vis.node { VisibilityKind::Public => Cow::from("pub "), VisibilityKind::Inherited => Cow::from(""), @@ -267,7 +267,7 @@ pub fn contains_skip(attrs: &[Attribute]) -> bool { } #[inline] -pub fn semicolon_for_expr(context: &RewriteContext, expr: &ast::Expr) -> bool { +pub fn semicolon_for_expr(context: &RewriteContext<'_>, expr: &ast::Expr) -> bool { match expr.node { ast::ExprKind::Ret(..) | ast::ExprKind::Continue(..) | ast::ExprKind::Break(..) => { context.config.trailing_semicolon() @@ -277,7 +277,7 @@ pub fn semicolon_for_expr(context: &RewriteContext, expr: &ast::Expr) -> bool { } #[inline] -pub fn semicolon_for_stmt(context: &RewriteContext, stmt: &ast::Stmt) -> bool { +pub fn semicolon_for_stmt(context: &RewriteContext<'_>, stmt: &ast::Stmt) -> bool { match stmt.node { ast::StmtKind::Semi(ref expr) => match expr.node { ast::ExprKind::While(..) @@ -424,7 +424,7 @@ pub fn first_line_ends_with(s: &str, c: char) -> bool { // States whether an expression's last line exclusively consists of closing // parens, braces, and brackets in its idiomatic formatting. -pub fn is_block_expr(context: &RewriteContext, expr: &ast::Expr, repr: &str) -> bool { +pub fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr: &str) -> bool { match expr.node { ast::ExprKind::Mac(..) | ast::ExprKind::Call(..) diff --git a/src/vertical.rs b/src/vertical.rs index cf018b7291ded..fe476c0bd40be 100644 --- a/src/vertical.rs +++ b/src/vertical.rs @@ -31,10 +31,10 @@ use crate::utils::{contains_skip, is_attributes_extendable, mk_sp, rewrite_ident pub trait AlignedItem { fn skip(&self) -> bool; fn get_span(&self) -> Span; - fn rewrite_prefix(&self, context: &RewriteContext, shape: Shape) -> Option; + fn rewrite_prefix(&self, context: &RewriteContext<'_>, shape: Shape) -> Option; fn rewrite_aligned_item( &self, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, prefix_max_width: usize, ) -> Option; @@ -49,7 +49,7 @@ impl AlignedItem for ast::StructField { self.span() } - fn rewrite_prefix(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite_prefix(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { let attrs_str = self.attrs.rewrite(context, shape)?; let missing_span = if self.attrs.is_empty() { mk_sp(self.span.lo(), self.span.lo()) @@ -71,7 +71,7 @@ impl AlignedItem for ast::StructField { fn rewrite_aligned_item( &self, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, prefix_max_width: usize, ) -> Option { @@ -88,7 +88,7 @@ impl AlignedItem for ast::Field { self.span() } - fn rewrite_prefix(&self, context: &RewriteContext, shape: Shape) -> Option { + fn rewrite_prefix(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { let attrs_str = self.attrs.rewrite(context, shape)?; let name = rewrite_ident(context, self.ident); let missing_span = if self.attrs.is_empty() { @@ -108,7 +108,7 @@ impl AlignedItem for ast::Field { fn rewrite_aligned_item( &self, - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, prefix_max_width: usize, ) -> Option { @@ -118,7 +118,7 @@ impl AlignedItem for ast::Field { pub fn rewrite_with_alignment( fields: &[T], - context: &RewriteContext, + context: &RewriteContext<'_>, shape: Shape, span: Span, one_line_width: usize, @@ -185,7 +185,7 @@ pub fn rewrite_with_alignment( } fn struct_field_prefix_max_min_width( - context: &RewriteContext, + context: &RewriteContext<'_>, fields: &[T], shape: Shape, ) -> (usize, usize) { @@ -210,7 +210,7 @@ fn struct_field_prefix_max_min_width( } fn rewrite_aligned_items_inner( - context: &RewriteContext, + context: &RewriteContext<'_>, fields: &[T], span: Span, offset: Indent, @@ -268,7 +268,7 @@ fn rewrite_aligned_items_inner( } fn group_aligned_items( - context: &RewriteContext, + context: &RewriteContext<'_>, fields: &[T], ) -> (&'static str, usize) { let mut index = 0; diff --git a/src/visitor.rs b/src/visitor.rs index 6d46adedba52b..ed4ab8675862f 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -88,7 +88,7 @@ impl<'a> Drop for FmtVisitor<'a> { } impl<'b, 'a: 'b> FmtVisitor<'a> { - fn set_parent_context(&mut self, context: &'a RewriteContext) { + fn set_parent_context(&mut self, context: &'a RewriteContext<'_>) { self.parent_context = Some(context); } @@ -255,7 +255,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { // on traits do not get handled here. fn visit_fn( &mut self, - fk: visit::FnKind, + fk: visit::FnKind<'_>, generics: &ast::Generics, fd: &ast::FnDecl, s: Span, @@ -593,7 +593,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { self.skipped_range.push((lo, hi)); } - pub fn from_context(ctx: &'a RewriteContext) -> FmtVisitor<'a> { + pub fn from_context(ctx: &'a RewriteContext<'_>) -> FmtVisitor<'a> { let mut visitor = FmtVisitor::from_source_map( ctx.parse_session, ctx.config, @@ -607,7 +607,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { pub(crate) fn from_source_map( parse_session: &'a ParseSess, config: &'a Config, - snippet_provider: &'a SnippetProvider, + snippet_provider: &'a SnippetProvider<'_>, report: FormatReport, ) -> FmtVisitor<'a> { FmtVisitor { @@ -785,7 +785,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { pub fn with_context(&mut self, f: F) -> Option where - F: Fn(&RewriteContext) -> Option, + F: Fn(&RewriteContext<'_>) -> Option, { // FIXME borrow checker fighting - can be simplified a lot with NLL. let (result, mrf) = { @@ -799,7 +799,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { result } - pub fn get_context(&self) -> RewriteContext { + pub fn get_context(&self) -> RewriteContext<'_> { RewriteContext { parse_session: self.parse_session, source_map: self.source_map, From 8183b949c49cfdd5889859162e82fab4c8e64065 Mon Sep 17 00:00:00 2001 From: Hirokazu Hata Date: Sat, 9 Feb 2019 16:20:38 +0900 Subject: [PATCH 4/4] cargo fmt --- src/cargo-fmt/main.rs | 1 - src/chains.rs | 14 +++++++++++--- src/expr.rs | 12 ++++++++++-- src/items.rs | 12 ++++++++++-- src/macros.rs | 12 ++++++++++-- src/overflow.rs | 5 ++++- src/patterns.rs | 6 +++++- 7 files changed, 50 insertions(+), 12 deletions(-) diff --git a/src/cargo-fmt/main.rs b/src/cargo-fmt/main.rs index 058617439634d..3873671781cf6 100644 --- a/src/cargo-fmt/main.rs +++ b/src/cargo-fmt/main.rs @@ -16,7 +16,6 @@ use cargo_metadata; use getopts; - use std::collections::{HashMap, HashSet}; use std::env; use std::fs; diff --git a/src/chains.rs b/src/chains.rs index 37bbde1f4ee4c..6686211632357 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -84,7 +84,11 @@ use crate::utils::{ trimmed_last_line_width, wrap_str, }; -pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext<'_>, shape: Shape) -> Option { +pub fn rewrite_chain( + expr: &ast::Expr, + context: &RewriteContext<'_>, + shape: Shape, +) -> Option { let chain = Chain::from_ast(expr, context); debug!("rewrite_chain {:?} {:?}", chain, shape); @@ -419,8 +423,12 @@ impl Rewrite for Chain { debug!("rewrite chain {:?} {:?}", self, shape); let mut formatter = match context.config.indent_style() { - IndentStyle::Block => Box::new(ChainFormatterBlock::new(self)) as Box, - IndentStyle::Visual => Box::new(ChainFormatterVisual::new(self)) as Box, + IndentStyle::Block => { + Box::new(ChainFormatterBlock::new(self)) as Box + } + IndentStyle::Visual => { + Box::new(ChainFormatterVisual::new(self)) as Box + } }; formatter.format_root(&self.parent, context, shape)?; diff --git a/src/expr.rs b/src/expr.rs index 14a5ebd28ee53..5b59a5114b513 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -590,7 +590,11 @@ impl Rewrite for ast::Stmt { } // Rewrite condition if the given expression has one. -pub fn rewrite_cond(context: &RewriteContext<'_>, expr: &ast::Expr, shape: Shape) -> Option { +pub fn rewrite_cond( + context: &RewriteContext<'_>, + expr: &ast::Expr, + shape: Shape, +) -> Option { match expr.node { ast::ExprKind::Match(ref cond, _) => { // `match `cond` {` @@ -1337,7 +1341,11 @@ pub fn is_every_expr_simple(lists: &[OverflowableItem<'_>]) -> bool { lists.iter().all(OverflowableItem::is_simple) } -pub fn can_be_overflowed_expr(context: &RewriteContext<'_>, expr: &ast::Expr, args_len: usize) -> bool { +pub fn can_be_overflowed_expr( + context: &RewriteContext<'_>, + expr: &ast::Expr, + args_len: usize, +) -> bool { match expr.node { ast::ExprKind::Match(..) => { (context.use_block_indent() && args_len == 1) diff --git a/src/items.rs b/src/items.rs index b272a42ba18b7..a18cba69d6564 100644 --- a/src/items.rs +++ b/src/items.rs @@ -998,7 +998,11 @@ fn format_struct( } } -pub fn format_trait(context: &RewriteContext<'_>, item: &ast::Item, offset: Indent) -> Option { +pub fn format_trait( + context: &RewriteContext<'_>, + item: &ast::Item, + offset: Indent, +) -> Option { if let ast::ItemKind::Trait( is_auto, unsafety, @@ -1172,7 +1176,11 @@ pub fn format_trait_alias( rewrite_assign_rhs(context, lhs, generic_bounds, shape.sub_width(1)?).map(|s| s + ";") } -fn format_unit_struct(context: &RewriteContext<'_>, p: &StructParts<'_>, offset: Indent) -> Option { +fn format_unit_struct( + context: &RewriteContext<'_>, + p: &StructParts<'_>, + offset: Indent, +) -> Option { let header_str = format_header(context, p.prefix, p.ident, p.vis); let generics_str = if let Some(generics) = p.generics { let hi = if generics.where_clause.predicates.is_empty() { diff --git a/src/macros.rs b/src/macros.rs index 8243b6a9734ba..47985a4d6c078 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1027,7 +1027,11 @@ fn wrap_macro_args_inner( // // We always try and format on one line. // FIXME: Use multi-line when every thing does not fit on one line. -fn format_macro_args(context: &RewriteContext<'_>, toks: TokenStream, shape: Shape) -> Option { +fn format_macro_args( + context: &RewriteContext<'_>, + toks: TokenStream, + shape: Shape, +) -> Option { if !context.config.format_macro_matchers() { let token_stream: TokenStream = toks.into(); let span = span_for_token_stream(&token_stream); @@ -1340,7 +1344,11 @@ impl MacroBranch { /// [pub] static ref NAME_N: TYPE_N = EXPR_N; /// } /// ``` -fn format_lazy_static(context: &RewriteContext<'_>, shape: Shape, ts: &TokenStream) -> Option { +fn format_lazy_static( + context: &RewriteContext<'_>, + shape: Shape, + ts: &TokenStream, +) -> Option { let mut result = String::with_capacity(1024); let mut parser = new_parser_from_tts(context.parse_session, ts.trees().collect()); let nested_shape = shape diff --git a/src/overflow.rs b/src/overflow.rs index 8f50f08ed2ab0..3bd57711be9ee 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -758,7 +758,10 @@ fn no_long_items(list: &[ListItem]) -> bool { } /// In case special-case style is required, returns an offset from which we start horizontal layout. -pub fn maybe_get_args_offset(callee_str: &str, args: &[OverflowableItem<'_>]) -> Option<(bool, usize)> { +pub fn maybe_get_args_offset( + callee_str: &str, + args: &[OverflowableItem<'_>], +) -> Option<(bool, usize)> { if let Some(&(_, num_args_before)) = args .get(0)? .whitelist() diff --git a/src/patterns.rs b/src/patterns.rs index 6114362e76f77..956ce56bdf1e1 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -288,7 +288,11 @@ impl<'a> Spanned for TuplePatField<'a> { } } -pub fn can_be_overflowed_pat(context: &RewriteContext<'_>, pat: &TuplePatField<'_>, len: usize) -> bool { +pub fn can_be_overflowed_pat( + context: &RewriteContext<'_>, + pat: &TuplePatField<'_>, + len: usize, +) -> bool { match *pat { TuplePatField::Pat(pat) => match pat.node { ast::PatKind::Path(..)