Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4bb90f5

Browse files
committed
Fix rust_2018_idioms warnings
1 parent e70e6eb commit 4bb90f5

30 files changed

+299
-299
lines changed

src/attr.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn argument_shape(
7575
right: usize,
7676
combine: bool,
7777
shape: Shape,
78-
context: &RewriteContext,
78+
context: &RewriteContext<'_>,
7979
) -> Option<Shape> {
8080
match context.config.indent_style() {
8181
IndentStyle::Block => {
@@ -100,7 +100,7 @@ fn format_derive(
100100
derive_args: &[Span],
101101
prefix: &str,
102102
shape: Shape,
103-
context: &RewriteContext,
103+
context: &RewriteContext<'_>,
104104
) -> Option<String> {
105105
let mut result = String::with_capacity(128);
106106
result.push_str(prefix);
@@ -133,7 +133,7 @@ fn format_derive(
133133
/// Returns the first group of attributes that fills the given predicate.
134134
/// We consider two doc comments are in different group if they are separated by normal comments.
135135
fn take_while_with_pred<'a, P>(
136-
context: &RewriteContext,
136+
context: &RewriteContext<'_>,
137137
attrs: &'a [ast::Attribute],
138138
pred: P,
139139
) -> &'a [ast::Attribute]
@@ -164,7 +164,7 @@ where
164164

165165
/// Rewrite the any doc comments which come before any other attributes.
166166
fn rewrite_initial_doc_comments(
167-
context: &RewriteContext,
167+
context: &RewriteContext<'_>,
168168
attrs: &[ast::Attribute],
169169
shape: Shape,
170170
) -> Option<(usize, Option<String>)> {
@@ -193,7 +193,7 @@ fn rewrite_initial_doc_comments(
193193
}
194194

195195
impl Rewrite for ast::NestedMetaItem {
196-
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
196+
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
197197
match self.node {
198198
ast::NestedMetaItemKind::MetaItem(ref meta_item) => meta_item.rewrite(context, shape),
199199
ast::NestedMetaItemKind::Literal(ref l) => rewrite_literal(context, l, shape),
@@ -221,7 +221,7 @@ fn has_newlines_before_after_comment(comment: &str) -> (&str, &str) {
221221
}
222222

223223
impl Rewrite for ast::MetaItem {
224-
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
224+
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
225225
Some(match self.node {
226226
ast::MetaItemKind::Word => {
227227
rewrite_path(context, PathContext::Type, None, &self.ident, shape)?
@@ -268,7 +268,7 @@ fn format_arg_list<I, T, F1, F2, F3>(
268268
get_hi: F2,
269269
get_item_string: F3,
270270
span: Span,
271-
context: &RewriteContext,
271+
context: &RewriteContext<'_>,
272272
shape: Shape,
273273
one_line_shape: Shape,
274274
one_line_limit: Option<usize>,
@@ -318,7 +318,7 @@ where
318318
}
319319

320320
impl Rewrite for ast::Attribute {
321-
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
321+
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
322322
let snippet = context.snippet(self.span);
323323
if self.is_sugared_doc {
324324
rewrite_doc_comment(snippet, shape.comment(context.config), context.config)
@@ -365,7 +365,7 @@ impl Rewrite for ast::Attribute {
365365
}
366366

367367
impl<'a> Rewrite for [ast::Attribute] {
368-
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
368+
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
369369
if self.is_empty() {
370370
return Some(String::new());
371371
}

src/chains.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ use crate::utils::{
8484
trimmed_last_line_width, wrap_str,
8585
};
8686

87-
pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -> Option<String> {
87+
pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
8888
let chain = Chain::from_ast(expr, context);
8989
debug!("rewrite_chain {:?} {:?}", chain, shape);
9090

@@ -128,7 +128,7 @@ enum ChainItemKind {
128128
}
129129

130130
impl ChainItemKind {
131-
fn is_block_like(&self, context: &RewriteContext, reps: &str) -> bool {
131+
fn is_block_like(&self, context: &RewriteContext<'_>, reps: &str) -> bool {
132132
match self {
133133
ChainItemKind::Parent(ref expr) => utils::is_block_expr(context, expr, reps),
134134
ChainItemKind::MethodCall(..)
@@ -147,7 +147,7 @@ impl ChainItemKind {
147147
}
148148
}
149149

150-
fn from_ast(context: &RewriteContext, expr: &ast::Expr) -> (ChainItemKind, Span) {
150+
fn from_ast(context: &RewriteContext<'_>, expr: &ast::Expr) -> (ChainItemKind, Span) {
151151
let (kind, span) = match expr.node {
152152
ast::ExprKind::MethodCall(ref segment, ref expressions) => {
153153
let types = if let Some(ref generic_args) = segment.args {
@@ -182,7 +182,7 @@ impl ChainItemKind {
182182
}
183183

184184
impl Rewrite for ChainItem {
185-
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
185+
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
186186
let shape = shape.sub_width(self.tries)?;
187187
let rewrite = match self.kind {
188188
ChainItemKind::Parent(ref expr) => expr.rewrite(context, shape)?,
@@ -204,7 +204,7 @@ impl Rewrite for ChainItem {
204204
}
205205

206206
impl ChainItem {
207-
fn new(context: &RewriteContext, expr: &ast::Expr, tries: usize) -> ChainItem {
207+
fn new(context: &RewriteContext<'_>, expr: &ast::Expr, tries: usize) -> ChainItem {
208208
let (kind, span) = ChainItemKind::from_ast(context, expr);
209209
ChainItem { kind, tries, span }
210210
}
@@ -229,7 +229,7 @@ impl ChainItem {
229229
types: &[ast::GenericArg],
230230
args: &[ptr::P<ast::Expr>],
231231
span: Span,
232-
context: &RewriteContext,
232+
context: &RewriteContext<'_>,
233233
shape: Shape,
234234
) -> Option<String> {
235235
let type_str = if types.is_empty() {
@@ -254,7 +254,7 @@ struct Chain {
254254
}
255255

256256
impl Chain {
257-
fn from_ast(expr: &ast::Expr, context: &RewriteContext) -> Chain {
257+
fn from_ast(expr: &ast::Expr, context: &RewriteContext<'_>) -> Chain {
258258
let subexpr_list = Self::make_subexpr_list(expr, context);
259259

260260
// Un-parse the expression tree into ChainItems
@@ -376,7 +376,7 @@ impl Chain {
376376

377377
// Returns a Vec of the prefixes of the chain.
378378
// E.g., for input `a.b.c` we return [`a.b.c`, `a.b`, 'a']
379-
fn make_subexpr_list(expr: &ast::Expr, context: &RewriteContext) -> Vec<ast::Expr> {
379+
fn make_subexpr_list(expr: &ast::Expr, context: &RewriteContext<'_>) -> Vec<ast::Expr> {
380380
let mut subexpr_list = vec![expr.clone()];
381381

382382
while let Some(subexpr) = Self::pop_expr_chain(subexpr_list.last().unwrap(), context) {
@@ -388,7 +388,7 @@ impl Chain {
388388

389389
// Returns the expression's subexpression, if it exists. When the subexpr
390390
// is a try! macro, we'll convert it to shorthand when the option is set.
391-
fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext) -> Option<ast::Expr> {
391+
fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext<'_>) -> Option<ast::Expr> {
392392
match expr.node {
393393
ast::ExprKind::MethodCall(_, ref expressions) => {
394394
Some(Self::convert_try(&expressions[0], context))
@@ -400,7 +400,7 @@ impl Chain {
400400
}
401401
}
402402

403-
fn convert_try(expr: &ast::Expr, context: &RewriteContext) -> ast::Expr {
403+
fn convert_try(expr: &ast::Expr, context: &RewriteContext<'_>) -> ast::Expr {
404404
match expr.node {
405405
ast::ExprKind::Mac(ref mac) if context.config.use_try_shorthand() => {
406406
if let Some(subexpr) = convert_try_mac(mac, context) {
@@ -415,12 +415,12 @@ impl Chain {
415415
}
416416

417417
impl Rewrite for Chain {
418-
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
418+
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
419419
debug!("rewrite chain {:?} {:?}", self, shape);
420420

421421
let mut formatter = match context.config.indent_style() {
422-
IndentStyle::Block => Box::new(ChainFormatterBlock::new(self)) as Box<ChainFormatter>,
423-
IndentStyle::Visual => Box::new(ChainFormatterVisual::new(self)) as Box<ChainFormatter>,
422+
IndentStyle::Block => Box::new(ChainFormatterBlock::new(self)) as Box<dyn ChainFormatter>,
423+
IndentStyle::Visual => Box::new(ChainFormatterVisual::new(self)) as Box<dyn ChainFormatter>,
424424
};
425425

426426
formatter.format_root(&self.parent, context, shape)?;
@@ -455,18 +455,18 @@ trait ChainFormatter {
455455
fn format_root(
456456
&mut self,
457457
parent: &ChainItem,
458-
context: &RewriteContext,
458+
context: &RewriteContext<'_>,
459459
shape: Shape,
460460
) -> Option<()>;
461-
fn child_shape(&self, context: &RewriteContext, shape: Shape) -> Option<Shape>;
462-
fn format_children(&mut self, context: &RewriteContext, child_shape: Shape) -> Option<()>;
461+
fn child_shape(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<Shape>;
462+
fn format_children(&mut self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<()>;
463463
fn format_last_child(
464464
&mut self,
465-
context: &RewriteContext,
465+
context: &RewriteContext<'_>,
466466
shape: Shape,
467467
child_shape: Shape,
468468
) -> Option<()>;
469-
fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option<String>;
469+
fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<String>;
470470
// Returns `Some` if the chain is only a root, None otherwise.
471471
fn pure_root(&mut self) -> Option<String>;
472472
}
@@ -540,7 +540,7 @@ impl<'a> ChainFormatterShared<'a> {
540540
fn format_last_child(
541541
&mut self,
542542
may_extend: bool,
543-
context: &RewriteContext,
543+
context: &RewriteContext<'_>,
544544
shape: Shape,
545545
child_shape: Shape,
546546
) -> Option<()> {
@@ -633,7 +633,7 @@ impl<'a> ChainFormatterShared<'a> {
633633
Some(())
634634
}
635635

636-
fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option<String> {
636+
fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<String> {
637637
let connector = if self.fits_single_line {
638638
// Yay, we can put everything on one line.
639639
Cow::from("")
@@ -682,7 +682,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
682682
fn format_root(
683683
&mut self,
684684
parent: &ChainItem,
685-
context: &RewriteContext,
685+
context: &RewriteContext<'_>,
686686
shape: Shape,
687687
) -> Option<()> {
688688
let mut root_rewrite: String = parent.rewrite(context, shape)?;
@@ -713,7 +713,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
713713
Some(())
714714
}
715715

716-
fn child_shape(&self, context: &RewriteContext, shape: Shape) -> Option<Shape> {
716+
fn child_shape(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<Shape> {
717717
Some(
718718
if self.root_ends_with_block {
719719
shape.block_indent(0)
@@ -724,7 +724,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
724724
)
725725
}
726726

727-
fn format_children(&mut self, context: &RewriteContext, child_shape: Shape) -> Option<()> {
727+
fn format_children(&mut self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<()> {
728728
for item in &self.shared.children[..self.shared.children.len() - 1] {
729729
let rewrite = item.rewrite(context, child_shape)?;
730730
self.shared.rewrites.push(rewrite);
@@ -734,15 +734,15 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
734734

735735
fn format_last_child(
736736
&mut self,
737-
context: &RewriteContext,
737+
context: &RewriteContext<'_>,
738738
shape: Shape,
739739
child_shape: Shape,
740740
) -> Option<()> {
741741
self.shared
742742
.format_last_child(true, context, shape, child_shape)
743743
}
744744

745-
fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option<String> {
745+
fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<String> {
746746
self.shared.join_rewrites(context, child_shape)
747747
}
748748

@@ -771,7 +771,7 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
771771
fn format_root(
772772
&mut self,
773773
parent: &ChainItem,
774-
context: &RewriteContext,
774+
context: &RewriteContext<'_>,
775775
shape: Shape,
776776
) -> Option<()> {
777777
let parent_shape = shape.visual_indent(0);
@@ -811,14 +811,14 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
811811
Some(())
812812
}
813813

814-
fn child_shape(&self, context: &RewriteContext, shape: Shape) -> Option<Shape> {
814+
fn child_shape(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<Shape> {
815815
shape
816816
.with_max_width(context.config)
817817
.offset_left(self.offset)
818818
.map(|s| s.visual_indent(0))
819819
}
820820

821-
fn format_children(&mut self, context: &RewriteContext, child_shape: Shape) -> Option<()> {
821+
fn format_children(&mut self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<()> {
822822
for item in &self.shared.children[..self.shared.children.len() - 1] {
823823
let rewrite = item.rewrite(context, child_shape)?;
824824
self.shared.rewrites.push(rewrite);
@@ -828,15 +828,15 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
828828

829829
fn format_last_child(
830830
&mut self,
831-
context: &RewriteContext,
831+
context: &RewriteContext<'_>,
832832
shape: Shape,
833833
child_shape: Shape,
834834
) -> Option<()> {
835835
self.shared
836836
.format_last_child(false, context, shape, child_shape)
837837
}
838838

839-
fn join_rewrites(&self, context: &RewriteContext, child_shape: Shape) -> Option<String> {
839+
fn join_rewrites(&self, context: &RewriteContext<'_>, child_shape: Shape) -> Option<String> {
840840
self.shared.join_rewrites(context, child_shape)
841841
}
842842

0 commit comments

Comments
 (0)