Skip to content

Commit 67d735c

Browse files
authored
Rollup merge of #69736 - matthiaskrgr:even_more_clippy, r=Dylan-DPC
even more clippy cleanups * Don't pass &mut where immutable reference (&) is sufficient (clippy::unnecessary_mut_passed) * Use more efficient &&str to String conversion (clippy::inefficient_to_string) * Don't always eval arguments inside .expect(), use unwrap_or_else and closure. (clippy::expect_fun_call) * Use righthand '&' instead of lefthand "ref". (clippy::toplevel_ref_arg) * Use simple 'for i in x' loops instead of 'while let Some(i) = x.next()' loops on iterators. (clippy::while_let_on_iterator) * Const items have by default a static lifetime, there's no need to annotate it. (clippy::redundant_static_lifetimes) * Remove redundant patterns when matching ( x @ _ to x) (clippy::redundant_pattern)
2 parents 558115b + 84577c8 commit 67d735c

File tree

26 files changed

+56
-60
lines changed

26 files changed

+56
-60
lines changed

src/librustc/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,7 @@ impl<'tcx> TerminatorKind<'tcx> {
11981198
t: BasicBlock,
11991199
f: BasicBlock,
12001200
) -> TerminatorKind<'tcx> {
1201-
static BOOL_SWITCH_FALSE: &'static [u128] = &[0];
1201+
static BOOL_SWITCH_FALSE: &[u128] = &[0];
12021202
TerminatorKind::SwitchInt {
12031203
discr: cond,
12041204
switch_ty: tcx.types.bool,

src/librustc_builtin_macros/format.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl<'a, 'b> Context<'a, 'b> {
284284
err.tool_only_span_suggestion(
285285
sp,
286286
&format!("use the `{}` trait", name),
287-
fmt.to_string(),
287+
(*fmt).to_string(),
288288
Applicability::MaybeIncorrect,
289289
);
290290
}
@@ -476,7 +476,7 @@ impl<'a, 'b> Context<'a, 'b> {
476476
match ty {
477477
Placeholder(_) => {
478478
// record every (position, type) combination only once
479-
let ref mut seen_ty = self.arg_unique_types[arg];
479+
let seen_ty = &mut self.arg_unique_types[arg];
480480
let i = seen_ty.iter().position(|x| *x == ty).unwrap_or_else(|| {
481481
let i = seen_ty.len();
482482
seen_ty.push(ty);
@@ -526,7 +526,7 @@ impl<'a, 'b> Context<'a, 'b> {
526526

527527
// Map the arguments
528528
for i in 0..args_len {
529-
let ref arg_types = self.arg_types[i];
529+
let arg_types = &self.arg_types[i];
530530
let arg_offsets = arg_types.iter().map(|offset| sofar + *offset).collect::<Vec<_>>();
531531
self.arg_index_map.push(arg_offsets);
532532
sofar += self.arg_unique_types[i].len();
@@ -597,7 +597,7 @@ impl<'a, 'b> Context<'a, 'b> {
597597
let arg_idx = match arg_index_consumed.get_mut(i) {
598598
None => 0, // error already emitted elsewhere
599599
Some(offset) => {
600-
let ref idx_map = self.arg_index_map[i];
600+
let idx_map = &self.arg_index_map[i];
601601
// unwrap_or branch: error already emitted elsewhere
602602
let arg_idx = *idx_map.get(*offset).unwrap_or(&0);
603603
*offset += 1;
@@ -721,7 +721,7 @@ impl<'a, 'b> Context<'a, 'b> {
721721
let name = names_pos[i];
722722
let span = self.ecx.with_def_site_ctxt(e.span);
723723
pats.push(self.ecx.pat_ident(span, name));
724-
for ref arg_ty in self.arg_unique_types[i].iter() {
724+
for arg_ty in self.arg_unique_types[i].iter() {
725725
locals.push(Context::format_arg(self.ecx, self.macsp, e.span, arg_ty, name));
726726
}
727727
heads.push(self.ecx.expr_addr_of(e.span, e));

src/librustc_builtin_macros/global_allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ impl AllocFnFactory<'_, '_> {
5757
fn allocator_fn(&self, method: &AllocatorMethod) -> Stmt {
5858
let mut abi_args = Vec::new();
5959
let mut i = 0;
60-
let ref mut mk = || {
60+
let mut mk = || {
6161
let name = self.cx.ident_of(&format!("arg{}", i), self.span);
6262
i += 1;
6363
name
6464
};
65-
let args = method.inputs.iter().map(|ty| self.arg_ty(ty, &mut abi_args, mk)).collect();
65+
let args = method.inputs.iter().map(|ty| self.arg_ty(ty, &mut abi_args, &mut mk)).collect();
6666
let result = self.call_allocator(method.name, args);
6767
let (output_ty, output_expr) = self.ret_ty(&method.output, result);
6868
let decl = self.cx.fn_decl(abi_args, ast::FnRetTy::Ty(output_ty));

src/librustc_builtin_macros/test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ fn should_fail(i: &ast::Item) -> bool {
313313
fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
314314
match attr::find_by_name(&i.attrs, sym::should_panic) {
315315
Some(attr) => {
316-
let ref sd = cx.parse_sess.span_diagnostic;
316+
let sd = &cx.parse_sess.span_diagnostic;
317317

318318
match attr.meta_item_list() {
319319
// Handle #[should_panic(expected = "foo")]
@@ -378,7 +378,7 @@ fn test_type(cx: &ExtCtxt<'_>) -> TestType {
378378

379379
fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
380380
let has_should_panic_attr = attr::contains_name(&i.attrs, sym::should_panic);
381-
let ref sd = cx.parse_sess.span_diagnostic;
381+
let sd = &cx.parse_sess.span_diagnostic;
382382
if let ast::ItemKind::Fn(_, ref sig, ref generics, _) = i.kind {
383383
if let ast::Unsafe::Yes(span) = sig.header.unsafety {
384384
sd.struct_span_err(i.span, "unsafe functions cannot be used for tests")

src/librustc_builtin_macros/test_harness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
326326
/// &[&test1, &test2]
327327
fn mk_tests_slice(cx: &TestCtxt<'_>, sp: Span) -> P<ast::Expr> {
328328
debug!("building test vector from {} tests", cx.test_cases.len());
329-
let ref ecx = cx.ext_cx;
329+
let ecx = &cx.ext_cx;
330330

331331
ecx.expr_vec_slice(
332332
sp,

src/librustc_codegen_llvm/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
6060
.chain(ia.inputs.iter().map(|s| s.to_string()))
6161
.chain(ext_constraints)
6262
.chain(clobbers)
63-
.chain(arch_clobbers.iter().map(|s| s.to_string()))
63+
.chain(arch_clobbers.iter().map(|s| (*s).to_string()))
6464
.collect::<Vec<String>>()
6565
.join(",");
6666

src/librustc_incremental/persist/dirty_clean.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,8 @@ impl DirtyCleanVisitor<'tcx> {
343343
&format!("clean/dirty auto-assertions not yet defined for {:?}", node),
344344
),
345345
};
346-
let labels = Labels::from_iter(labels.iter().flat_map(|s| s.iter().map(|l| l.to_string())));
346+
let labels =
347+
Labels::from_iter(labels.iter().flat_map(|s| s.iter().map(|l| (*l).to_string())));
347348
(name, labels)
348349
}
349350

src/librustc_infer/traits/auto_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
150150
// SelectionContext to return it back to us.
151151

152152
let (new_env, user_env) = match self.evaluate_predicates(
153-
&mut infcx,
153+
&infcx,
154154
trait_did,
155155
ty,
156156
orig_env,

src/librustc_infer/traits/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13411341
stack: &TraitObligationStack<'o, 'tcx>,
13421342
) -> Result<SelectionCandidateSet<'tcx>, SelectionError<'tcx>> {
13431343
let TraitObligationStack { obligation, .. } = *stack;
1344-
let ref obligation = Obligation {
1344+
let obligation = &Obligation {
13451345
param_env: obligation.param_env,
13461346
cause: obligation.cause.clone(),
13471347
recursion_depth: obligation.recursion_depth,

src/librustc_lint/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl LintStore {
369369
return if *silent {
370370
CheckLintNameResult::Ok(&lint_ids)
371371
} else {
372-
CheckLintNameResult::Tool(Err((Some(&lint_ids), name.to_string())))
372+
CheckLintNameResult::Tool(Err((Some(&lint_ids), (*name).to_string())))
373373
};
374374
}
375375
CheckLintNameResult::Ok(&lint_ids)
@@ -404,7 +404,7 @@ impl LintStore {
404404
return if *silent {
405405
CheckLintNameResult::Tool(Err((Some(&lint_ids), complete_name)))
406406
} else {
407-
CheckLintNameResult::Tool(Err((Some(&lint_ids), name.to_string())))
407+
CheckLintNameResult::Tool(Err((Some(&lint_ids), (*name).to_string())))
408408
};
409409
}
410410
CheckLintNameResult::Tool(Err((Some(&lint_ids), complete_name)))

0 commit comments

Comments
 (0)