Fix rust_2018_idioms warnings

This commit is contained in:
Hirokazu Hata 2019-02-09 16:14:30 +09:00
parent e70e6eb273
commit 4bb90f5cc8
30 changed files with 299 additions and 299 deletions

View File

@ -75,7 +75,7 @@ fn argument_shape(
right: usize,
combine: bool,
shape: Shape,
context: &RewriteContext,
context: &RewriteContext<'_>,
) -> Option<Shape> {
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<String> {
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 @@ fn take_while_with_pred<'a, P>(
/// 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<String>)> {
@ -193,7 +193,7 @@ fn rewrite_initial_doc_comments(
}
impl Rewrite for ast::NestedMetaItem {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
Some(match self.node {
ast::MetaItemKind::Word => {
rewrite_path(context, PathContext::Type, None, &self.ident, shape)?
@ -268,7 +268,7 @@ fn format_arg_list<I, T, F1, F2, F3>(
get_hi: F2,
get_item_string: F3,
span: Span,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
one_line_shape: Shape,
one_line_limit: Option<usize>,
@ -318,7 +318,7 @@ fn format_arg_list<I, T, F1, F2, F3>(
}
impl Rewrite for ast::Attribute {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
}
impl<'a> Rewrite for [ast::Attribute] {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
if self.is_empty() {
return Some(String::new());
}

View File

@ -84,7 +84,7 @@
trimmed_last_line_width, wrap_str,
};
pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -> Option<String> {
pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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 @@ fn is_tup_field_access(expr: &ast::Expr) -> bool {
}
}
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 @@ fn from_ast(context: &RewriteContext, expr: &ast::Expr) -> (ChainItemKind, Span)
}
impl Rewrite for ChainItem {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
let shape = shape.sub_width(self.tries)?;
let rewrite = match self.kind {
ChainItemKind::Parent(ref expr) => expr.rewrite(context, shape)?,
@ -204,7 +204,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
}
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 @@ fn rewrite_method_call(
types: &[ast::GenericArg],
args: &[ptr::P<ast::Expr>],
span: Span,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
) -> Option<String> {
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 @@ fn handle_post_comment(
// 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<ast::Expr> {
fn make_subexpr_list(expr: &ast::Expr, context: &RewriteContext<'_>) -> Vec<ast::Expr> {
let mut subexpr_list = vec![expr.clone()];
while let Some(subexpr) = Self::pop_expr_chain(subexpr_list.last().unwrap(), context) {
@ -388,7 +388,7 @@ fn make_subexpr_list(expr: &ast::Expr, context: &RewriteContext) -> Vec<ast::Exp
// 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<ast::Expr> {
fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext<'_>) -> Option<ast::Expr> {
match expr.node {
ast::ExprKind::MethodCall(_, ref expressions) => {
Some(Self::convert_try(&expressions[0], context))
@ -400,7 +400,7 @@ fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext) -> Option<ast::Exp
}
}
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 @@ fn convert_try(expr: &ast::Expr, context: &RewriteContext) -> ast::Expr {
}
impl Rewrite for Chain {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
debug!("rewrite chain {:?} {:?}", self, shape);
let mut formatter = match context.config.indent_style() {
IndentStyle::Block => Box::new(ChainFormatterBlock::new(self)) as Box<ChainFormatter>,
IndentStyle::Visual => Box::new(ChainFormatterVisual::new(self)) as Box<ChainFormatter>,
IndentStyle::Block => Box::new(ChainFormatterBlock::new(self)) as Box<dyn ChainFormatter>,
IndentStyle::Visual => Box::new(ChainFormatterVisual::new(self)) as Box<dyn ChainFormatter>,
};
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<Shape>;
fn format_children(&mut self, context: &RewriteContext, child_shape: Shape) -> Option<()>;
fn child_shape(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<Shape>;
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<String>;
fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<String>;
// Returns `Some` if the chain is only a root, None otherwise.
fn pure_root(&mut self) -> Option<String>;
}
@ -540,7 +540,7 @@ fn pure_root(&mut self) -> Option<String> {
fn format_last_child(
&mut self,
may_extend: bool,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
child_shape: Shape,
) -> Option<()> {
@ -633,7 +633,7 @@ fn format_last_child(
Some(())
}
fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option<String> {
fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<String> {
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 @@ fn format_root(
Some(())
}
fn child_shape(&self, context: &RewriteContext, shape: Shape) -> Option<Shape> {
fn child_shape(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<Shape> {
Some(
if self.root_ends_with_block {
shape.block_indent(0)
@ -724,7 +724,7 @@ fn child_shape(&self, context: &RewriteContext, shape: Shape) -> Option<Shape> {
)
}
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 @@ fn format_children(&mut self, context: &RewriteContext, child_shape: Shape) -> O
fn format_last_child(
&mut self,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
child_shape: Shape,
) -> Option<()> {
@ -742,7 +742,7 @@ fn format_last_child(
.format_last_child(true, context, shape, child_shape)
}
fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option<String> {
fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<String> {
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 @@ fn format_root(
Some(())
}
fn child_shape(&self, context: &RewriteContext, shape: Shape) -> Option<Shape> {
fn child_shape(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<Shape> {
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 @@ fn format_children(&mut self, context: &RewriteContext, child_shape: Shape) -> O
fn format_last_child(
&mut self,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
child_shape: Shape,
) -> Option<()> {
@ -836,7 +836,7 @@ fn format_last_child(
.format_last_child(false, context, shape, child_shape)
}
fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option<String> {
fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<String> {
self.shared.join_rewrites(context, child_shape)
}

View File

@ -39,7 +39,7 @@ pub fn rewrite_closure(
fn_decl: &ast::FnDecl,
body: &ast::Expr,
span: Span,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
) -> Option<String> {
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<String> {
@ -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<String> {
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<String> {
fn allow_multi_line(expr: &ast::Expr) -> bool {
@ -207,7 +207,7 @@ fn allow_multi_line(expr: &ast::Expr) -> bool {
fn rewrite_closure_block(
block: &ast::Block,
prefix: &str,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
) -> Option<String> {
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<String> {
@ -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

View File

@ -122,7 +122,7 @@ pub fn to_str_tuplet(&self) -> (&'a str, &'a str, &'a str) {
}
}
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 compute_len(orig: &str, line: &str) -> usize {
// - 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 @@ fn new(line: &str) -> 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 @@ fn handle_line(
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<str> {
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<String> {
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<String> {
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 @@ fn next(&mut self) -> Option<Self::Item> {
pub fn recover_comment_removed(
new: String,
span: Span,
context: &RewriteContext,
context: &RewriteContext<'_>,
) -> Option<String> {
let snippet = context.snippet(span);
if snippet != new && changed_comment_content(snippet, &new) {

View File

@ -173,11 +173,11 @@ pub fn $i(&self) -> $ty {
}
)+
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 @@ pub fn is_hidden_option(name: &str) -> bool {
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); )+

View File

@ -46,7 +46,7 @@ fn from(name: source_map::FileName) -> 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 @@ pub fn from_ranges(mut ranges: HashMap<FileName, Vec<Range>>) -> 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()))
}

View File

@ -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),

View File

@ -208,7 +208,7 @@ fn get_toml_path(dir: &Path) -> Result<Option<PathBuf>, Error> {
Ok(None)
}
fn config_path(options: &CliOptions) -> Result<Option<PathBuf>, Error> {
fn config_path(options: &dyn CliOptions) -> Result<Option<PathBuf>, Error> {
let config_path_not_found = |path: &str| -> Result<Option<PathBuf>, Error> {
Err(Error::new(
ErrorKind::NotFound,

View File

@ -64,7 +64,7 @@ fn deserialize<D>(d: D) -> Result<Self, D::Error>
impl<'de, T> Visitor<'de> for StringOnly<T>
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<E>(self, value: &str) -> Result<String, E> {
@ -120,7 +120,7 @@ pub enum $e {
}
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)*),

View File

@ -47,7 +47,7 @@
use crate::visitor::FmtVisitor;
impl Rewrite for ast::Expr {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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<String> {
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<Item = &'a T>,
span: Span,
context: &'a RewriteContext,
context: &'a RewriteContext<'_>,
shape: Shape,
force_separator_tactic: Option<SeparatorTactic>,
delim_token: Option<DelimToken>,
@ -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<ast::Label>,
@ -453,7 +453,7 @@ fn rewrite_empty_block(
None
}
fn block_prefix(context: &RewriteContext, block: &ast::Block, shape: Shape) -> Option<String> {
fn block_prefix(context: &RewriteContext<'_>, block: &ast::Block, shape: Shape) -> Option<String> {
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<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
rewrite_block(self, None, None, context, shape)
}
}
@ -542,7 +542,7 @@ fn rewrite_block(
block: &ast::Block,
attrs: Option<&[ast::Attribute]>,
label: Option<ast::Label>,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
) -> Option<String> {
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<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
skip_out_of_file_lines_range!(context, self.span());
let result = match self.node {
@ -590,7 +590,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
}
// Rewrite condition if the given expression has one.
pub fn rewrite_cond(context: &RewriteContext, expr: &ast::Expr, shape: Shape) -> Option<String> {
pub fn rewrite_cond(context: &RewriteContext<'_>, expr: &ast::Expr, shape: Shape) -> Option<String> {
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<ControlFlow> {
fn to_control_flow(expr: &ast::Expr, expr_type: ExprType) -> Option<ControlFlow<'_>> {
match expr.node {
ast::ExprKind::If(ref cond, ref if_block, ref else_block) => Some(ControlFlow::new_if(
cond,
@ -767,7 +767,7 @@ fn new_for(
fn rewrite_single_line(
&self,
pat_expr_str: &str,
context: &RewriteContext,
context: &RewriteContext<'_>,
width: usize,
) -> Option<String> {
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 @@ fn rewrite_pat_expr(
fn rewrite_cond(
&self,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
alt_block_sep: &str,
) -> Option<(String, usize)> {
@ -1001,7 +1001,7 @@ fn rewrite_cond(
}
impl<'a> Rewrite for ControlFlow<'a> {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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<ast::Label>) -> Cow<'static, str> {
}
}
fn extract_comment(span: Span, context: &RewriteContext, shape: Shape) -> Option<String> {
fn extract_comment(span: Span, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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<String> {
@ -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<String> {
pub fn rewrite_literal(context: &RewriteContext<'_>, l: &ast::Lit, shape: Shape) -> Option<String> {
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<String> {
fn rewrite_string_lit(context: &RewriteContext<'_>, span: Span, shape: Shape) -> Option<String> {
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<SeparatorTactic> {
fn choose_separator_tactic(context: &RewriteContext<'_>, span: Span) -> Option<SeparatorTactic> {
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<Separ
}
pub fn rewrite_call(
context: &RewriteContext,
context: &RewriteContext<'_>,
callee: &str,
args: &[ptr::P<ast::Expr>],
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<String> {
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 @@ enum StructLitField<'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 @@ enum StructLitField<'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 @@ enum StructLitField<'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<Item = &'a T>,
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<Item = &'a T>,
span: Span,
shape: Shape,
@ -1822,7 +1822,7 @@ pub fn rewrite_tuple<'a, T: 'a + IntoOverflowableItem<'a>>(
}
pub fn rewrite_unary_prefix<R: Rewrite>(
context: &RewriteContext,
context: &RewriteContext<'_>,
prefix: &str,
rewrite: &R,
shape: Shape,
@ -1835,7 +1835,7 @@ pub fn rewrite_unary_prefix<R: Rewrite>(
// 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<R: Rewrite>(
context: &RewriteContext,
context: &RewriteContext<'_>,
suffix: &str,
rewrite: &R,
shape: Shape,
@ -1849,7 +1849,7 @@ pub fn rewrite_unary_suffix<R: Rewrite>(
}
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<S: Into<String>, R: Rewrite>(
context: &RewriteContext,
context: &RewriteContext<'_>,
lhs: S,
ex: &R,
shape: Shape,
@ -1898,7 +1898,7 @@ pub fn rewrite_assign_rhs<S: Into<String>, R: Rewrite>(
}
pub fn rewrite_assign_rhs_with<S: Into<String>, R: Rewrite>(
context: &RewriteContext,
context: &RewriteContext<'_>,
lhs: S,
ex: &R,
shape: Shape,
@ -1927,7 +1927,7 @@ pub fn rewrite_assign_rhs_with<S: Into<String>, R: Rewrite>(
}
fn choose_rhs<R: Rewrite>(
context: &RewriteContext,
context: &RewriteContext<'_>,
expr: &R,
shape: Shape,
orig_rhs: Option<String>,
@ -1968,7 +1968,7 @@ fn choose_rhs<R: Rewrite>(
}
fn shape_from_rhs_tactic(
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
rhs_tactic: RhsTactics,
) -> Option<Shape> {
@ -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,

View File

@ -111,7 +111,7 @@ fn format_project<T: FormatHandler>(
// 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,

View File

@ -146,7 +146,7 @@ fn remove_alias(&self) -> UseSegment {
}
fn from_path_segment(
context: &RewriteContext,
context: &RewriteContext<'_>,
path_seg: &ast::PathSegment,
modsep: bool,
) -> Option<UseSegment> {
@ -193,19 +193,19 @@ fn merge_use_trees_inner(trees: &mut Vec<UseTree>, 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 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
}
}
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 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl UseTree {
// Rewrite use tree with `use ` and a trailing `;`.
pub fn rewrite_top_level(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
pub fn rewrite_top_level(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
let vis = self.visibility.as_ref().map_or(Cow::from(""), |vis| {
crate::utils::format_visibility(context, &vis)
});
@ -281,7 +281,7 @@ fn from_path(path: Vec<UseSegment>, span: Span) -> UseTree {
}
pub fn from_ast_with_normalization(
context: &RewriteContext,
context: &RewriteContext<'_>,
item: &ast::Item,
) -> Option<UseTree> {
match item.node {
@ -305,7 +305,7 @@ pub fn from_ast_with_normalization(
}
fn from_ast(
context: &RewriteContext,
context: &RewriteContext<'_>,
a: &ast::UseTree,
list_item: Option<ListItem>,
visibility: Option<ast::Visibility>,
@ -710,7 +710,7 @@ fn cmp(&self, other: &UseTree) -> Ordering {
}
fn rewrite_nested_use_tree(
context: &RewriteContext,
context: &RewriteContext<'_>,
use_tree_list: &[UseTree],
shape: Shape,
) -> Option<String> {
@ -786,7 +786,7 @@ fn rewrite_nested_use_tree(
}
impl Rewrite for UseSegment {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
impl Rewrite for UseTree {
// This does NOT format attributes and visibility or add a trailing `;`.
fn rewrite(&self, context: &RewriteContext, mut shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, mut shape: Shape) -> Option<String> {
let mut result = String::with_capacity(256);
let mut iter = self.path.iter().peekable();
while let Some(ref segment) = iter.next() {

View File

@ -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",

View File

@ -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<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
debug!(
"Local::rewrite {:?} {} {:?}",
self, shape.width, shape.indent
@ -214,7 +214,7 @@ pub fn from_method_sig(
}
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 @@ pub fn from_fn_kind(
}
}
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 @@ fn to_str(&self, context: &RewriteContext) -> String {
}
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 @@ fn format_item(&mut self, item: &Item) {
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 @@ pub fn rewrite_fn(
&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 @@ fn single_line_fn(
}
}
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 @@ fn need_empty_line(a: &ast::ImplItemKind, b: &ast::ImplItemKind) -> bool {
}
pub fn format_impl(
context: &RewriteContext,
context: &RewriteContext<'_>,
item: &ast::Item,
offset: Indent,
where_span_end: Option<BytePos>,
@ -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<String> {
@ -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 @@ pub fn from_item(item: &'a ast::Item) -> Self {
}
fn format_struct(
context: &RewriteContext,
struct_parts: &StructParts,
context: &RewriteContext<'_>,
struct_parts: &StructParts<'_>,
offset: Indent,
one_line_width: Option<usize>,
) -> Option<String> {
@ -998,7 +998,7 @@ fn format_struct(
}
}
pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent) -> Option<String> {
pub fn format_trait(context: &RewriteContext<'_>, item: &ast::Item, offset: Indent) -> Option<String> {
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<String> {
fn format_unit_struct(context: &RewriteContext<'_>, p: &StructParts<'_>, offset: Indent) -> Option<String> {
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<usize>,
@ -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<String> {
@ -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<R: Rewrite>(
context: &RewriteContext,
context: &RewriteContext<'_>,
indent: Indent,
prefix: &str,
suffix: &str,
@ -1501,7 +1501,7 @@ fn rewrite_type_item<R: Rewrite>(
}
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<String> {
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<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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 @@ pub fn from_impl_item(ii: &'a ast::ImplItem) -> Self {
}
fn rewrite_static(
context: &RewriteContext,
static_parts: &StaticParts,
context: &RewriteContext<'_>,
static_parts: &StaticParts<'_>,
offset: Indent,
) -> Option<String> {
let colon = colon_spaces(
@ -1752,7 +1752,7 @@ pub fn rewrite_associated_type(
ty_opt: Option<&ptr::P<ast::Ty>>,
generics: &ast::Generics,
generic_bounds_opt: Option<&ast::GenericBounds>,
context: &RewriteContext,
context: &RewriteContext<'_>,
indent: Indent,
) -> Option<String> {
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<ast::Ty>>,
generics: &ast::Generics,
context: &RewriteContext,
context: &RewriteContext<'_>,
indent: Indent,
) -> Option<String> {
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<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
if is_named_arg(self) {
let mut result = self
.pat
@ -1863,7 +1863,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite_explicit_self(
explicit_self: &ast::ExplicitSelf,
args: &[ast::Arg],
context: &RewriteContext,
context: &RewriteContext<'_>,
) -> Option<String> {
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 @@ pub fn snuggle(&mut self) {
}
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<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
}
/// 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<String> {
pub fn rewrite_extern_crate(context: &RewriteContext<'_>, item: &ast::Item) -> Option<String> {
assert!(is_extern_crate(item));
let new_str = context.snippet(item.span);
Some(if contains_comment(new_str) {

View File

@ -249,7 +249,7 @@ pub fn has_warnings(&self) -> bool {
/// fancy output.
pub fn fancy_print(
&self,
mut t: Box<term::Terminal<Output = io::Stderr>>,
mut t: Box<dyn term::Terminal<Output = io::Stderr>>,
) -> Result<(), term::Error> {
for (file, errors) in &self.internal.borrow().0 {
for error in errors {
@ -320,7 +320,7 @@ fn target_str(space_len: usize, target_len: usize) -> String {
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 enclose_in_main_block(s: &str, config: &Config) -> String {
}
/// A session is a run of rustfmt across a single or multiple inputs.
pub struct Session<'b, T: Write + 'b> {
pub struct Session<'b, T: Write> {
pub config: Config,
pub out: Option<&'b mut T>,
pub(crate) errors: ReportedErrors,

View File

@ -270,7 +270,7 @@ pub fn definitive_tactic<I, T>(
}
// Format a list of commented items into a string.
pub fn write_list<I, T>(items: I, formatting: &ListFormatting) -> Option<String>
pub fn write_list<I, T>(items: I, formatting: &ListFormatting<'_>) -> Option<String>
where
I: IntoIterator<Item = T> + Clone,
T: AsRef<ListItem>,
@ -771,7 +771,7 @@ fn next(&mut self) -> Option<Self::Item> {
#[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>, 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<Shape>,
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

View File

@ -76,7 +76,7 @@ fn is_item(&self) -> bool {
}
impl Rewrite for ast::Item {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
let mut visitor = crate::visitor::FmtVisitor::from_context(context);
visitor.block_indent = shape.indent;
visitor.last_pos = self.span().lo();
@ -86,7 +86,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
}
impl Rewrite for MacroArg {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
match *self {
MacroArg::Expr(ref expr) => expr.rewrite(context, shape),
MacroArg::Ty(ref ty) => ty.rewrite(context, shape),
@ -145,7 +145,7 @@ macro_rules! parse_macro_arg {
/// Rewrite macro name without using pretty-printer if possible.
fn rewrite_macro_name(
context: &RewriteContext,
context: &RewriteContext<'_>,
path: &ast::Path,
extra_ident: Option<ast::Ident>,
) -> 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<String> {
@ -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 @@ fn drop(&mut self) {
pub fn rewrite_macro(
mac: &ast::Mac,
extra_ident: Option<ast::Ident>,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
position: MacroPosition,
) -> Option<String> {
@ -227,7 +227,7 @@ pub fn rewrite_macro(
pub fn rewrite_macro_inner(
mac: &ast::Mac,
extra_ident: Option<ast::Ident>,
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 @@ fn has_meta_var(&self) -> bool {
fn rewrite(
&self,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
use_multiple_lines: bool,
) -> Option<String> {
@ -722,7 +722,7 @@ struct ParsedMacroArg {
impl ParsedMacroArg {
pub fn rewrite(
&self,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
use_multiple_lines: bool,
) -> Option<String> {
@ -975,7 +975,7 @@ pub fn parse(mut self, tokens: TokenStream) -> Option<Vec<ParsedMacroArg>> {
}
fn wrap_macro_args(
context: &RewriteContext,
context: &RewriteContext<'_>,
args: &[ParsedMacroArg],
shape: Shape,
) -> Option<String> {
@ -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<String> {
fn format_macro_args(context: &RewriteContext<'_>, toks: TokenStream, shape: Shape) -> Option<String> {
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<ast::Expr> {
pub fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext<'_>) -> Option<ast::Expr> {
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<ast::
}
}
fn macro_style(mac: &ast::Mac, context: &RewriteContext) -> 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<String> {
@ -1340,7 +1340,7 @@ fn rewrite(
/// [pub] static ref NAME_N: TYPE_N = EXPR_N;
/// }
/// ```
fn format_lazy_static(context: &RewriteContext, shape: Shape, ts: &TokenStream) -> Option<String> {
fn format_lazy_static(context: &RewriteContext<'_>, shape: Shape, ts: &TokenStream) -> Option<String> {
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 @@ macro_rules! parse_or {
}
fn rewrite_macro_with_items(
context: &RewriteContext,
context: &RewriteContext<'_>,
items: &[MacroArg],
macro_name: &str,
shape: Shape,

View File

@ -67,13 +67,13 @@ fn span(&self) -> Span {
}
impl<'a> Rewrite for ArmWrapper<'a> {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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<Option<BytePos>> {
@ -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<Shape>,
) -> (bool, &'a ast::Expr) {
@ -334,7 +334,7 @@ fn flatten_arm_body<'a>(
}
fn rewrite_match_body(
context: &RewriteContext,
context: &RewriteContext<'_>,
body: &ptr::P<ast::Expr>,
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<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
match self {
ast::Guard::If(ref expr) => expr.rewrite(context, shape),
}
@ -508,7 +508,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
// The `if ...` guard on a match arm.
fn rewrite_guard(
context: &RewriteContext,
context: &RewriteContext<'_>,
guard: &Option<ast::Guard>,
shape: Shape,
// The amount of space used up on this line for the pattern in

View File

@ -79,7 +79,7 @@ pub fn format_missing_no_indent(&mut self, end: BytePos) {
})
}
fn format_missing_inner<F: Fn(&mut FmtVisitor, &str, &str)>(
fn format_missing_inner<F: Fn(&mut FmtVisitor<'_>, &str, &str)>(
&mut self,
end: BytePos,
process_last_snippet: F,
@ -144,7 +144,7 @@ fn push_vertical_spaces(&mut self, mut newline_count: usize) {
fn write_snippet<F>(&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 @@ fn write_snippet_inner<F>(
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

View File

@ -89,7 +89,7 @@ pub enum OverflowableItem<'a> {
}
impl<'a> Rewrite for OverflowableItem<'a> {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
self.map(|item| item.rewrite(context, shape))
}
}
@ -103,7 +103,7 @@ fn span(&self) -> Span {
impl<'a> OverflowableItem<'a> {
pub fn map<F, T>(&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 @@ pub fn to_expr(&self) -> Option<&'a ast::Expr> {
}
}
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 @@ pub fn into_overflowable_list<'a, T>(
}
pub fn rewrite_with_parens<'a, T: 'a + IntoOverflowableItem<'a>>(
context: &'a RewriteContext,
context: &'a RewriteContext<'_>,
ident: &'a str,
items: impl Iterator<Item = &'a T>,
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<Item = &'a T>,
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<Item = &'a T>,
shape: Shape,
@ -338,7 +338,7 @@ struct Context<'a> {
impl<'a> Context<'a> {
pub fn new<T: 'a + IntoOverflowableItem<'a>>(
context: &'a RewriteContext,
context: &'a RewriteContext<'_>,
items: impl Iterator<Item = &'a T>,
ident: &'a str,
shape: Shape,
@ -375,7 +375,7 @@ pub fn new<T: 'a + IntoOverflowableItem<'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()

View File

@ -42,7 +42,7 @@ pub(crate) fn infix(infix: &'a str) -> PairParts<'a> {
pub(crate) fn rewrite_all_pairs(
expr: &ast::Expr,
shape: Shape,
context: &RewriteContext,
context: &RewriteContext<'_>,
) -> Option<String> {
// 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<T: Rewrite>(
list: &PairList<T>,
list: &PairList<'_, '_, T>,
shape: Shape,
context: &RewriteContext,
context: &RewriteContext<'_>,
) -> Option<String> {
assert!(list.list.len() >= 2, "Not a pair?");
@ -107,9 +107,9 @@ fn rewrite_pairs_one_line<T: Rewrite>(
}
fn rewrite_pairs_multiline<T: Rewrite>(
list: &PairList<T>,
list: &PairList<'_, '_, T>,
shape: Shape,
context: &RewriteContext,
context: &RewriteContext<'_>,
) -> Option<String> {
let rhs_offset = shape.rhs_overhead(&context.config);
let nested_shape = (match context.config.indent_style() {
@ -175,8 +175,8 @@ fn rewrite_pairs_multiline<T: Rewrite>(
pub(crate) fn rewrite_pair<LHS, RHS>(
lhs: &LHS,
rhs: &RHS,
pp: PairParts,
context: &RewriteContext,
pp: PairParts<'_>,
context: &RewriteContext<'_>,
shape: Shape,
separator_place: SeparatorPlace,
) -> Option<String>
@ -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<PairList<Self>> {
fn flatten(&self, _same_op: bool) -> Option<PairList<'_, '_, Self>> {
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<PairList<ast::Expr>> {
fn flatten(&self, same_op: bool) -> Option<PairList<'_, '_, ast::Expr>> {
let top_op = match self.node {
ast::ExprKind::Binary(op, _, _) => op.node,
_ => return None,

View File

@ -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<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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<ast::FieldPat>],
ellipsis: bool,
span: Span,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
) -> Option<String> {
// 2 = ` {`
@ -240,7 +240,7 @@ fn rewrite_struct_pat(
}
impl Rewrite for FieldPat {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
match *self {
TuplePatField::Pat(p) => p.rewrite(context, shape),
TuplePatField::Dotdot(_) => Some("..".to_string()),
@ -288,7 +288,7 @@ fn span(&self) -> Span {
}
}
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<usize>,
path_str: Option<String>,
span: Span,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
) -> Option<String> {
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 {

View File

@ -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<String> {
@ -74,7 +74,7 @@ fn wrap_reorderable_items(
}
fn rewrite_reorderable_item(
context: &RewriteContext,
context: &RewriteContext<'_>,
item: &ast::Item,
shape: Shape,
) -> Option<String> {
@ -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,

View File

@ -23,11 +23,11 @@
pub trait Rewrite {
/// Rewrite self into shape.
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String>;
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String>;
}
impl<T: Rewrite> Rewrite for ptr::P<T> {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
(**self).rewrite(context, shape)
}
}

View File

@ -46,7 +46,7 @@ fn new(line_number: u32, line_number_orig: u32) -> 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<Box<term::Terminal<Output = io::Stdout>>>,
terminal: Option<Box<dyn term::Terminal<Output = io::Stdout>>>,
}
impl OutputWriter {

View File

@ -785,7 +785,7 @@ fn code_block_valid(&self) -> bool {
true
}
fn has_parsing_errors<T: Write>(&self, session: &Session<T>) -> bool {
fn has_parsing_errors<T: Write>(&self, session: &Session<'_, T>) -> bool {
if session.has_parsing_errors() {
write_message(&format!(
"\u{261d}\u{1f3fd} Cannot format {}:{}",

View File

@ -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<String>
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 @@ fn span(&self) -> Span {
}
impl<'a> Rewrite for SegmentParam<'a> {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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<String> {
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<String>
where
@ -410,7 +410,7 @@ enum ArgumentKind<T>
}
}
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<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
// FIXME: dead spans?
let result = match *self {
ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate {
@ -459,7 +459,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
}
impl Rewrite for ast::GenericArg {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
match *self {
ast::GenericArg::Lifetime(ref lt) => lt.rewrite(context, shape),
ast::GenericArg::Type(ref ty) => ty.rewrite(context, shape),
@ -470,7 +470,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite_bounded_lifetime(
lt: &ast::Lifetime,
bounds: &[ast::GenericBound],
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
) -> Option<String> {
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<String> {
fn rewrite(&self, context: &RewriteContext<'_>, _: Shape) -> Option<String> {
Some(rewrite_ident(context, self.ident).to_owned())
}
}
impl Rewrite for ast::GenericBound {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
match *self {
ast::GenericBound::Trait(ref poly_trait_ref, trait_bound_modifier) => {
let snippet = context.snippet(self.span());
@ -516,7 +516,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
}
impl Rewrite for ast::GenericBounds {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
if self.is_empty() {
return Some(String::new());
}
@ -526,7 +526,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
}
impl Rewrite for ast::GenericParam {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
}
impl Rewrite for ast::PolyTraitRef {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
if let Some(lifetime_str) =
rewrite_lifetime_param(context, shape, &self.bound_generic_params)
{
@ -576,13 +576,13 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
}
impl Rewrite for ast::TraitRef {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
rewrite_path(context, PathContext::Type, None, &self.path, shape)
}
}
impl Rewrite for ast::Ty {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
match self.node {
ast::TyKind::TraitObject(ref bounds, tobj_syntax) => {
// we have to consider 'dyn' keyword is used or not!!!
@ -695,7 +695,7 @@ fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite_bare_fn(
bare_fn: &ast::BareFnTy,
span: Span,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
) -> Option<String> {
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<String> {

View File

@ -30,7 +30,7 @@
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(..)

View File

@ -31,10 +31,10 @@
pub trait AlignedItem {
fn skip(&self) -> bool;
fn get_span(&self) -> Span;
fn rewrite_prefix(&self, context: &RewriteContext, shape: Shape) -> Option<String>;
fn rewrite_prefix(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String>;
fn rewrite_aligned_item(
&self,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
prefix_max_width: usize,
) -> Option<String>;
@ -49,7 +49,7 @@ fn get_span(&self) -> Span {
self.span()
}
fn rewrite_prefix(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite_prefix(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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 @@ fn rewrite_prefix(&self, context: &RewriteContext, shape: Shape) -> Option<Strin
fn rewrite_aligned_item(
&self,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
prefix_max_width: usize,
) -> Option<String> {
@ -88,7 +88,7 @@ fn get_span(&self) -> Span {
self.span()
}
fn rewrite_prefix(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
fn rewrite_prefix(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
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 @@ fn rewrite_prefix(&self, context: &RewriteContext, shape: Shape) -> Option<Strin
fn rewrite_aligned_item(
&self,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
prefix_max_width: usize,
) -> Option<String> {
@ -118,7 +118,7 @@ fn rewrite_aligned_item(
pub fn rewrite_with_alignment<T: AlignedItem>(
fields: &[T],
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
span: Span,
one_line_width: usize,
@ -185,7 +185,7 @@ pub fn rewrite_with_alignment<T: AlignedItem>(
}
fn struct_field_prefix_max_min_width<T: AlignedItem>(
context: &RewriteContext,
context: &RewriteContext<'_>,
fields: &[T],
shape: Shape,
) -> (usize, usize) {
@ -210,7 +210,7 @@ fn struct_field_prefix_max_min_width<T: AlignedItem>(
}
fn rewrite_aligned_items_inner<T: AlignedItem>(
context: &RewriteContext,
context: &RewriteContext<'_>,
fields: &[T],
span: Span,
offset: Indent,
@ -268,7 +268,7 @@ fn rewrite_aligned_items_inner<T: AlignedItem>(
}
fn group_aligned_items<T: AlignedItem>(
context: &RewriteContext,
context: &RewriteContext<'_>,
fields: &[T],
) -> (&'static str, usize) {
let mut index = 0;

View File

@ -88,7 +88,7 @@ fn drop(&mut self) {
}
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 @@ fn close_block(&mut self, unindent_comment: bool) {
// 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 @@ pub fn push_skipped_with_span(
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 @@ pub fn from_context(ctx: &'a RewriteContext) -> 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 @@ pub fn skip_empty_lines(&mut self, end_pos: BytePos) {
pub fn with_context<F>(&mut self, f: F) -> Option<String>
where
F: Fn(&RewriteContext) -> Option<String>,
F: Fn(&RewriteContext<'_>) -> Option<String>,
{
// FIXME borrow checker fighting - can be simplified a lot with NLL.
let (result, mrf) = {
@ -799,7 +799,7 @@ pub fn with_context<F>(&mut self, f: F) -> Option<String>
result
}
pub fn get_context(&self) -> RewriteContext {
pub fn get_context(&self) -> RewriteContext<'_> {
RewriteContext {
parse_session: self.parse_session,
source_map: self.source_map,