Skip to content

Commit

Permalink
Fix rust_2018_idioms warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
h-michael committed Feb 9, 2019
1 parent e70e6eb commit 4bb90f5
Show file tree
Hide file tree
Showing 30 changed files with 299 additions and 299 deletions.
18 changes: 9 additions & 9 deletions src/attr.rs
Expand Up @@ -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 => {
Expand All @@ -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);
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -164,7 +164,7 @@ where

/// Rewrite the any doc comments which come before any other attributes.
fn rewrite_initial_doc_comments(
context: &RewriteContext,
context: &RewriteContext<'_>,
attrs: &[ast::Attribute],
shape: Shape,
) -> Option<(usize, Option<String>)> {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)?
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -318,7 +318,7 @@ where
}

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)
Expand Down Expand Up @@ -365,7 +365,7 @@ impl Rewrite for ast::Attribute {
}

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());
}
Expand Down
60 changes: 30 additions & 30 deletions src/chains.rs
Expand Up @@ -84,7 +84,7 @@ use crate::utils::{
trimmed_last_line_width, wrap_str,
};

pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -> Option<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);

Expand Down Expand Up @@ -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(..)
Expand All @@ -147,7 +147,7 @@ impl ChainItemKind {
}
}

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

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)?,
Expand All @@ -204,7 +204,7 @@ impl Rewrite for ChainItem {
}

impl ChainItem {
fn new(context: &RewriteContext, expr: &ast::Expr, tries: usize) -> ChainItem {
fn new(context: &RewriteContext<'_>, expr: &ast::Expr, tries: usize) -> ChainItem {
let (kind, span) = ChainItemKind::from_ast(context, expr);
ChainItem { kind, tries, span }
}
Expand All @@ -229,7 +229,7 @@ impl ChainItem {
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() {
Expand All @@ -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
Expand Down Expand Up @@ -376,7 +376,7 @@ impl Chain {

// Returns a Vec of the prefixes of the chain.
// E.g., for input `a.b.c` we return [`a.b.c`, `a.b`, 'a']
fn make_subexpr_list(expr: &ast::Expr, context: &RewriteContext) -> Vec<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) {
Expand All @@ -388,7 +388,7 @@ impl Chain {

// Returns the expression's subexpression, if it exists. When the subexpr
// is a try! macro, we'll convert it to shorthand when the option is set.
fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext) -> Option<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))
Expand All @@ -400,7 +400,7 @@ impl Chain {
}
}

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

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)?;
Expand Down Expand Up @@ -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>;
}
Expand Down Expand Up @@ -540,7 +540,7 @@ impl<'a> ChainFormatterShared<'a> {
fn format_last_child(
&mut self,
may_extend: bool,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
child_shape: Shape,
) -> Option<()> {
Expand Down Expand Up @@ -633,7 +633,7 @@ impl<'a> ChainFormatterShared<'a> {
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("")
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -713,7 +713,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
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)
Expand All @@ -724,7 +724,7 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
)
}

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

fn format_last_child(
&mut self,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
child_shape: Shape,
) -> Option<()> {
self.shared
.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)
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -811,14 +811,14 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {
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);
Expand All @@ -828,15 +828,15 @@ impl<'a> ChainFormatter for ChainFormatterVisual<'a> {

fn format_last_child(
&mut self,
context: &RewriteContext,
context: &RewriteContext<'_>,
shape: Shape,
child_shape: Shape,
) -> Option<()> {
self.shared
.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)
}

Expand Down

0 comments on commit 4bb90f5

Please sign in to comment.