Skip to content

Commit

Permalink
fix clippy lints about borrowing
Browse files Browse the repository at this point in the history
  • Loading branch information
kadiwa4 committed Jan 9, 2024
1 parent 7b6d83f commit 220bb45
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 56 deletions.
4 changes: 2 additions & 2 deletions config_proc_macro/src/item_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn impl_doc_hint(ident: &syn::Ident, variants: &Variants) -> TokenStream {

let variant_stables = variants
.iter()
.map(|v| (&v.ident, fields_in_variant(&v), !unstable_of_variant(v)));
.map(|v| (&v.ident, fields_in_variant(v), !unstable_of_variant(v)));
let match_patterns = fold_quote(variant_stables, |(v, fields, stable)| {
quote! {
#ident::#v #fields => #stable,
Expand Down Expand Up @@ -150,7 +150,7 @@ fn impl_from_str(ident: &syn::Ident, variants: &Variants) -> TokenStream {

fn doc_hint_of_variant(variant: &syn::Variant) -> String {
let mut text = find_doc_hint(&variant.attrs).unwrap_or(variant.ident.to_string());
if unstable_of_variant(&variant) {
if unstable_of_variant(variant) {
text.push_str(" (unstable)")
};
text
Expand Down
4 changes: 2 additions & 2 deletions src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl Rewrite for ChainItem {
ChainItemKind::Parent {
ref expr,
parens: true,
} => crate::expr::rewrite_paren(context, &expr, shape, expr.span)?,
} => crate::expr::rewrite_paren(context, expr, shape, expr.span)?,
ChainItemKind::Parent {
ref expr,
parens: false,
Expand Down Expand Up @@ -338,7 +338,7 @@ impl ChainItem {
format!("::<{}>", type_list.join(", "))
};
let callee_str = format!(".{}{}", rewrite_ident(context, method_name), type_str);
rewrite_call(context, &callee_str, &args, span, shape)
rewrite_call(context, &callee_str, args, span, shape)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ impl Config {
/// Returns a `Config` if the config could be read and parsed from
/// the file, otherwise errors.
pub(super) fn from_toml_path(file_path: &Path) -> Result<Config, Error> {
let mut file = File::open(&file_path)?;
let mut file = File::open(file_path)?;
let mut toml = String::new();
file.read_to_string(&mut toml)?;
Config::from_toml(&toml, file_path.parent().unwrap())
Expand Down
22 changes: 10 additions & 12 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub(crate) fn format_expr(
) -> Option<String> {
skip_out_of_file_lines_range!(context, expr.span);

if contains_skip(&*expr.attrs) {
if contains_skip(&expr.attrs) {
return Some(context.snippet(expr.span()).to_owned());
}
let shape = if expr_type == ExprType::Statement && semicolon_for_expr(context, expr) {
Expand Down Expand Up @@ -259,9 +259,7 @@ pub(crate) fn format_expr(
shape,
SeparatorPlace::Back,
),
ast::ExprKind::Index(ref expr, ref index, _) => {
rewrite_index(&**expr, &**index, context, shape)
}
ast::ExprKind::Index(ref expr, ref index, _) => rewrite_index(expr, index, context, shape),
ast::ExprKind::Repeat(ref expr, ref repeats) => rewrite_pair(
&**expr,
&*repeats.value,
Expand Down Expand Up @@ -312,8 +310,8 @@ pub(crate) fn format_expr(
default_sp_delim(Some(lhs), Some(rhs))
};
rewrite_pair(
&*lhs,
&*rhs,
lhs,
rhs,
PairParts::infix(&sp_delim),
context,
shape,
Expand All @@ -326,15 +324,15 @@ pub(crate) fn format_expr(
} else {
default_sp_delim(None, Some(rhs))
};
rewrite_unary_prefix(context, &sp_delim, &*rhs, shape)
rewrite_unary_prefix(context, &sp_delim, rhs, shape)
}
(Some(lhs), None) => {
let sp_delim = if context.config.spaces_around_ranges() {
format!(" {delim}")
} else {
default_sp_delim(Some(lhs), None)
};
rewrite_unary_suffix(context, &sp_delim, &*lhs, shape)
rewrite_unary_suffix(context, &sp_delim, lhs, shape)
}
(None, None) => Some(delim.to_owned()),
}
Expand Down Expand Up @@ -880,7 +878,7 @@ impl<'a> ControlFlow<'a> {
let comments_span = mk_sp(comments_lo, expr.span.lo());
return rewrite_assign_rhs_with_comments(
context,
&format!("{}{}{}", matcher, pat_string, self.connector),
format!("{}{}{}", matcher, pat_string, self.connector),
expr,
cond_shape,
&RhsAssignKind::Expr(&expr.kind, expr.span),
Expand Down Expand Up @@ -1349,7 +1347,7 @@ pub(crate) fn is_simple_expr(expr: &ast::Expr) -> bool {
| ast::ExprKind::Unary(_, ref expr) => is_simple_expr(expr),
ast::ExprKind::Index(ref lhs, ref rhs, _) => is_simple_expr(lhs) && is_simple_expr(rhs),
ast::ExprKind::Repeat(ref lhs, ref rhs) => {
is_simple_expr(lhs) && is_simple_expr(&*rhs.value)
is_simple_expr(lhs) && is_simple_expr(&rhs.value)
}
_ => false,
}
Expand Down Expand Up @@ -1624,7 +1622,7 @@ fn rewrite_struct_lit<'a>(
} else {
let field_iter = fields.iter().map(StructLitField::Regular).chain(
match struct_rest {
ast::StructRest::Base(expr) => Some(StructLitField::Base(&**expr)),
ast::StructRest::Base(expr) => Some(StructLitField::Base(expr)),
ast::StructRest::Rest(span) => Some(StructLitField::Rest(*span)),
ast::StructRest::None => None,
}
Expand Down Expand Up @@ -2126,7 +2124,7 @@ fn choose_rhs<R: Rewrite>(

match (orig_rhs, new_rhs) {
(Some(ref orig_rhs), Some(ref new_rhs))
if !filtered_str_fits(&new_rhs, context.config.max_width(), new_shape) =>
if !filtered_str_fits(new_rhs, context.config.max_width(), new_shape) =>
{
Some(format!("{before_space_str}{orig_rhs}"))
}
Expand Down
16 changes: 8 additions & 8 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ impl<'a> FnSig<'a> {
constness: method_sig.header.constness,
defaultness: ast::Defaultness::Final,
ext: method_sig.header.ext,
decl: &*method_sig.decl,
decl: &method_sig.decl,
generics,
visibility,
}
Expand Down Expand Up @@ -341,7 +341,7 @@ impl<'a> FnSig<'a> {
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));
result.push_str(&format_visibility(context, self.visibility));
result.push_str(format_defaultness(self.defaultness));
result.push_str(format_constness(self.constness));
self.coroutine_kind
Expand Down Expand Up @@ -1024,7 +1024,7 @@ fn format_impl_ref_and_type(
IndentStyle::Visual => new_line_offset + trait_ref_overhead,
IndentStyle::Block => new_line_offset,
};
result.push_str(&*self_ty.rewrite(context, Shape::legacy(budget, type_offset))?);
result.push_str(&self_ty.rewrite(context, Shape::legacy(budget, type_offset))?);
Some(result)
}

Expand Down Expand Up @@ -1828,7 +1828,7 @@ fn rewrite_ty<R: Rewrite>(

// 1 = `;`
let shape = Shape::indented(indent, context.config).sub_width(1)?;
rewrite_assign_rhs(context, lhs, &*ty, &RhsAssignKind::Ty, shape).map(|s| s + ";")
rewrite_assign_rhs(context, lhs, ty, &RhsAssignKind::Ty, shape).map(|s| s + ";")
} else {
Some(format!("{result};"))
}
Expand Down Expand Up @@ -2045,7 +2045,7 @@ fn rewrite_static(
let remaining_width = context.budget(offset.block_indent + 1);
rewrite_assign_rhs_with_comments(
context,
&lhs,
lhs,
&**expr,
Shape::legacy(remaining_width, offset.block_only()),
&RhsAssignKind::Expr(&expr.kind, expr.span),
Expand Down Expand Up @@ -2182,7 +2182,7 @@ impl Rewrite for ast::Param {
!has_multiple_attr_lines && !has_doc_comments,
)?;

if !is_empty_infer(&*self.ty, self.pat.span) {
if !is_empty_infer(&self.ty, self.pat.span) {
let (before_comment, after_comment) =
get_missing_param_comments(context, self.pat.span, self.ty.span, shape);
result.push_str(&before_comment);
Expand Down Expand Up @@ -2364,7 +2364,7 @@ fn rewrite_fn_base(
let generics_str = rewrite_generics(
context,
rewrite_ident(context, ident),
&fn_sig.generics,
fn_sig.generics,
shape,
)?;
result.push_str(&generics_str);
Expand Down Expand Up @@ -3437,7 +3437,7 @@ pub(crate) fn rewrite_mod(
attrs_shape: Shape,
) -> Option<String> {
let mut result = String::with_capacity(32);
result.push_str(&*format_visibility(context, &item.vis));
result.push_str(&format_visibility(context, &item.vis));
result.push_str("mod ");
result.push_str(rewrite_ident(context, item.ident));
result.push(';');
Expand Down
6 changes: 3 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ impl MacroArgParser {

// Parse '*', '+' or '?.
for tok in iter {
self.set_last_tok(&tok);
self.set_last_tok(tok);
if first {
first = false;
}
Expand Down Expand Up @@ -947,7 +947,7 @@ impl MacroArgParser {
}
}

self.set_last_tok(&tok);
self.set_last_tok(tok);
}

// We are left with some stuff in the buffer. Since there is nothing
Expand Down Expand Up @@ -1379,7 +1379,7 @@ fn format_lazy_static(
result.push_str(&rewrite_assign_rhs(
context,
stmt,
&*expr,
expr,
&RhsAssignKind::Expr(&expr.kind, expr.span),
nested_shape.sub_width(1)?,
)?);
Expand Down
10 changes: 5 additions & 5 deletions src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ fn block_can_be_flattened<'a>(
&& is_simple_block(context, block, Some(&expr.attrs))
&& !stmt_is_expr_mac(&block.stmts[0]) =>
{
Some(&*block)
Some(block)
}
_ => None,
}
Expand Down Expand Up @@ -343,16 +343,16 @@ fn flatten_arm_body<'a>(
.and_then(|shape| rewrite_cond(context, expr, shape))
.map_or(false, |cond| cond.contains('\n'));
if cond_becomes_muti_line {
(false, &*body)
(false, body)
} else {
(can_extend(expr), &*expr)
(can_extend(expr), expr)
}
}
} else {
(false, &*body)
(false, body)
}
} else {
(can_extend(body), &*body)
(can_extend(body), body)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ impl<'a> Context<'a> {

if tactic == DefinitiveListTactic::Vertical {
if let Some((all_simple, num_args_before)) =
maybe_get_args_offset(self.ident, &self.items, &self.context.config)
maybe_get_args_offset(self.ident, &self.items, self.context.config)
{
let one_line = all_simple
&& definitive_tactic(
Expand Down
2 changes: 1 addition & 1 deletion src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn is_short_pattern_inner(pat: &ast::Pat) -> bool {
path.segments.len() <= 1 && subpats.len() <= 1
}
ast::PatKind::Box(ref p) | ast::PatKind::Ref(ref p, _) | ast::PatKind::Paren(ref p) => {
is_short_pattern_inner(&*p)
is_short_pattern_inner(p)
}
PatKind::Or(ref pats) => pats.iter().all(|p| is_short_pattern_inner(p)),
}
Expand Down
8 changes: 3 additions & 5 deletions src/reorder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ use crate::visitor::FmtVisitor;
/// Choose the ordering between the given two items.
fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
match (&a.kind, &b.kind) {
(&ast::ItemKind::Mod(..), &ast::ItemKind::Mod(..)) => {
a.ident.as_str().cmp(b.ident.as_str())
}
(&ast::ItemKind::ExternCrate(ref a_name), &ast::ItemKind::ExternCrate(ref b_name)) => {
(ast::ItemKind::Mod(..), ast::ItemKind::Mod(..)) => a.ident.as_str().cmp(b.ident.as_str()),
(ast::ItemKind::ExternCrate(a_name), ast::ItemKind::ExternCrate(b_name)) => {
// `extern crate foo as bar;`
// ^^^ Comparing this.
let a_orig_name = a_name.unwrap_or(a.ident.name);
Expand Down Expand Up @@ -267,7 +265,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> {
let item_length = items
.iter()
.take_while(|ppi| {
item_kind.is_same_item_kind(&***ppi)
item_kind.is_same_item_kind(ppi)
&& (!in_group || {
let current = self.parse_sess.lookup_line_range(ppi.span());
let in_same_group = current.lo < last.hi + 2;
Expand Down
Loading

0 comments on commit 220bb45

Please sign in to comment.