diff options
Diffstat (limited to 'src/expr.rs')
| -rw-r--r-- | src/expr.rs | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/src/expr.rs b/src/expr.rs index 744bc00d0de..14a5ebd28ee 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<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 @@ 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<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 @@ impl<'a> ControlFlow<'a> { 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 @@ 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<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 @@ 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<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, |
