Skip to content

Commit d8874f2

Browse files
committed
fix more clippy::style findings
match_result_ok obfuscated_if_else single_char_add writeln_empty_string collapsible_match iter_cloned_collect unnecessary_mut_passed
1 parent d9ee0f4 commit d8874f2

File tree

16 files changed

+74
-93
lines changed

16 files changed

+74
-93
lines changed

compiler/rustc_ast_lowering/src/item.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
259259
body.as_deref(),
260260
);
261261

262-
let mut itctx = ImplTraitContext::Universal;
263-
let (generics, decl) = this.lower_generics(generics, id, &mut itctx, |this| {
262+
let itctx = ImplTraitContext::Universal;
263+
let (generics, decl) = this.lower_generics(generics, id, &itctx, |this| {
264264
let ret_id = asyncness.opt_return_id();
265265
this.lower_fn_decl(&decl, id, *fn_sig_span, FnDeclKind::Fn, ret_id)
266266
});
@@ -369,9 +369,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
369369
// method, it will not be considered an in-band
370370
// lifetime to be added, but rather a reference to a
371371
// parent lifetime.
372-
let mut itctx = ImplTraitContext::Universal;
372+
let itctx = ImplTraitContext::Universal;
373373
let (generics, (trait_ref, lowered_ty)) =
374-
self.lower_generics(ast_generics, id, &mut itctx, |this| {
374+
self.lower_generics(ast_generics, id, &itctx, |this| {
375375
let trait_ref = trait_ref.as_ref().map(|trait_ref| {
376376
this.lower_trait_ref(
377377
trait_ref,
@@ -590,9 +590,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
590590
kind: match &i.kind {
591591
ForeignItemKind::Fn(box Fn { sig, generics, .. }) => {
592592
let fdec = &sig.decl;
593-
let mut itctx = ImplTraitContext::Universal;
593+
let itctx = ImplTraitContext::Universal;
594594
let (generics, (fn_dec, fn_args)) =
595-
self.lower_generics(generics, i.id, &mut itctx, |this| {
595+
self.lower_generics(generics, i.id, &itctx, |this| {
596596
(
597597
// Disallow `impl Trait` in foreign items.
598598
this.lower_fn_decl(
@@ -1184,8 +1184,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
11841184
is_async: Option<(NodeId, Span)>,
11851185
) -> (&'hir hir::Generics<'hir>, hir::FnSig<'hir>) {
11861186
let header = self.lower_fn_header(sig.header);
1187-
let mut itctx = ImplTraitContext::Universal;
1188-
let (generics, decl) = self.lower_generics(generics, id, &mut itctx, |this| {
1187+
let itctx = ImplTraitContext::Universal;
1188+
let (generics, decl) = self.lower_generics(generics, id, &itctx, |this| {
11891189
this.lower_fn_decl(&sig.decl, id, sig.span, kind, is_async)
11901190
});
11911191
(generics, hir::FnSig { header, decl, span: self.lower_span(sig.span) })

compiler/rustc_ast_lowering/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2031,15 +2031,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20312031
&mut self,
20322032
output: &FnRetTy,
20332033
span: Span,
2034-
mut nested_impl_trait_context: ImplTraitContext,
2034+
nested_impl_trait_context: ImplTraitContext,
20352035
) -> hir::GenericBound<'hir> {
20362036
// Compute the `T` in `Future<Output = T>` from the return type.
20372037
let output_ty = match output {
20382038
FnRetTy::Ty(ty) => {
20392039
// Not `OpaqueTyOrigin::AsyncFn`: that's only used for the
20402040
// `impl Future` opaque type that `async fn` implicitly
20412041
// generates.
2042-
self.lower_ty(ty, &mut nested_impl_trait_context)
2042+
self.lower_ty(ty, &nested_impl_trait_context)
20432043
}
20442044
FnRetTy::Default(ret_ty_span) => self.arena.alloc(self.ty_tup(*ret_ty_span, &[])),
20452045
};

compiler/rustc_ast_lowering/src/pat.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
3737
qself,
3838
path,
3939
ParamMode::Optional,
40-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
40+
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
4141
);
4242
let (pats, ddpos) = self.lower_pat_tuple(pats, "tuple struct");
4343
break hir::PatKind::TupleStruct(qpath, pats, ddpos);
@@ -53,7 +53,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
5353
qself,
5454
path,
5555
ParamMode::Optional,
56-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
56+
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
5757
);
5858
break hir::PatKind::Path(qpath);
5959
}
@@ -63,7 +63,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
6363
qself,
6464
path,
6565
ParamMode::Optional,
66-
&mut ImplTraitContext::Disallowed(ImplTraitPosition::Path),
66+
&ImplTraitContext::Disallowed(ImplTraitPosition::Path),
6767
);
6868

6969
let fs = self.arena.alloc_from_iter(fields.iter().map(|f| {

compiler/rustc_borrowck/src/type_check/input_output.rs

+22-23
Original file line numberDiff line numberDiff line change
@@ -37,31 +37,30 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
3737
// those.
3838
//
3939
// e.g., `|x: FxHashMap<_, &'static u32>| ...`
40-
let user_provided_sig;
41-
if !self.tcx().is_closure(mir_def_id.to_def_id()) {
42-
user_provided_sig = None;
40+
let user_provided_sig = if !self.tcx().is_closure(mir_def_id.to_def_id()) {
41+
None
4342
} else {
4443
let typeck_results = self.tcx().typeck(mir_def_id);
45-
user_provided_sig =
46-
typeck_results.user_provided_sigs.get(&mir_def_id).map(|user_provided_poly_sig| {
47-
// Instantiate the canonicalized variables from
48-
// user-provided signature (e.g., the `_` in the code
49-
// above) with fresh variables.
50-
let poly_sig = self.instantiate_canonical_with_fresh_inference_vars(
51-
body.span,
52-
&user_provided_poly_sig,
53-
);
54-
55-
// Replace the bound items in the fn sig with fresh
56-
// variables, so that they represent the view from
57-
// "inside" the closure.
58-
self.infcx.replace_bound_vars_with_fresh_vars(
59-
body.span,
60-
LateBoundRegionConversionTime::FnCall,
61-
poly_sig,
62-
)
63-
});
64-
}
44+
45+
typeck_results.user_provided_sigs.get(&mir_def_id).map(|user_provided_poly_sig| {
46+
// Instantiate the canonicalized variables from
47+
// user-provided signature (e.g., the `_` in the code
48+
// above) with fresh variables.
49+
let poly_sig = self.instantiate_canonical_with_fresh_inference_vars(
50+
body.span,
51+
&user_provided_poly_sig,
52+
);
53+
54+
// Replace the bound items in the fn sig with fresh
55+
// variables, so that they represent the view from
56+
// "inside" the closure.
57+
self.infcx.replace_bound_vars_with_fresh_vars(
58+
body.span,
59+
LateBoundRegionConversionTime::FnCall,
60+
poly_sig,
61+
)
62+
})
63+
};
6564

6665
debug!(?normalized_input_tys, ?body.local_decls);
6766

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ pub fn compute_debuginfo_vtable_name<'tcx>(
509509
visited.clear();
510510
push_generic_params_internal(tcx, trait_ref.substs, &mut vtable_name, &mut visited);
511511
} else {
512-
vtable_name.push_str("_");
512+
vtable_name.push('_');
513513
}
514514

515515
push_close_angle_bracket(cpp_like_debuginfo, &mut vtable_name);

compiler/rustc_driver/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ fn print_crate_info(
653653
for req in &sess.opts.prints {
654654
match *req {
655655
TargetList => {
656-
let mut targets = rustc_target::spec::TARGETS.iter().copied().collect::<Vec<_>>();
656+
let mut targets = rustc_target::spec::TARGETS.to_vec();
657657
targets.sort_unstable();
658658
println!("{}", targets.join("\n"));
659659
}

compiler/rustc_errors/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1212,8 +1212,8 @@ impl HandlerInner {
12121212
self.taught_diagnostics.insert(code.clone())
12131213
}
12141214

1215-
fn force_print_diagnostic(&mut self, mut db: Diagnostic) {
1216-
self.emitter.emit_diagnostic(&mut db);
1215+
fn force_print_diagnostic(&mut self, db: Diagnostic) {
1216+
self.emitter.emit_diagnostic(&db);
12171217
}
12181218

12191219
/// Emit all stashed diagnostics.

compiler/rustc_expand/src/mbe/macro_rules.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1166,11 +1166,7 @@ fn check_matcher_core<'tt>(
11661166
err.note(&format!(
11671167
"{}{} or {}",
11681168
msg,
1169-
ts[..ts.len() - 1]
1170-
.iter()
1171-
.copied()
1172-
.collect::<Vec<_>>()
1173-
.join(", "),
1169+
ts[..ts.len() - 1].to_vec().join(", "),
11741170
ts[ts.len() - 1],
11751171
));
11761172
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
410410
tcx,
411411
param_env,
412412
item_hir_id,
413-
tcx.explicit_item_bounds(item_def_id)
414-
.iter()
415-
.copied()
416-
.collect::<Vec<_>>(),
413+
tcx.explicit_item_bounds(item_def_id).to_vec(),
417414
&FxIndexSet::default(),
418415
gat_def_id.def_id,
419416
gat_generics,

compiler/rustc_lint/src/context.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,12 @@ impl LintStore {
355355
sub: RequestedLevel { level, lint_name },
356356
});
357357
}
358-
CheckLintNameResult::Tool(result) => {
359-
if let Err((Some(_), new_name)) = result {
360-
sess.emit_warning(CheckNameDeprecated {
361-
lint_name: lint_name.clone(),
362-
new_name,
363-
sub: RequestedLevel { level, lint_name },
364-
});
365-
}
358+
CheckLintNameResult::Tool(Err((Some(_), new_name))) => {
359+
sess.emit_warning(CheckNameDeprecated {
360+
lint_name: lint_name.clone(),
361+
new_name,
362+
sub: RequestedLevel { level, lint_name },
363+
});
366364
}
367365
CheckLintNameResult::NoTool => {
368366
sess.emit_err(CheckNameUnknownTool {

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15641564
let trait_ref = self.tcx.impl_trait_ref(def_id);
15651565
if let Some(trait_ref) = trait_ref {
15661566
let trait_def = self.tcx.trait_def(trait_ref.def_id);
1567-
if let Some(mut an) = trait_def.ancestors(self.tcx, def_id).ok() {
1567+
if let Ok(mut an) = trait_def.ancestors(self.tcx, def_id) {
15681568
if let Some(specialization_graph::Node::Impl(parent)) = an.nth(1) {
15691569
self.tables.impl_parent.set(def_id.index, parent.into());
15701570
}

compiler/rustc_middle/src/hir/map/mod.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -704,12 +704,10 @@ impl<'hir> Map<'hir> {
704704
pub fn get_return_block(self, id: HirId) -> Option<HirId> {
705705
let mut iter = self.parent_iter(id).peekable();
706706
let mut ignore_tail = false;
707-
if let Some(node) = self.find(id) {
708-
if let Node::Expr(Expr { kind: ExprKind::Ret(_), .. }) = node {
709-
// When dealing with `return` statements, we don't care about climbing only tail
710-
// expressions.
711-
ignore_tail = true;
712-
}
707+
if let Some(Node::Expr(Expr { kind: ExprKind::Ret(_), .. })) = self.find(id) {
708+
// When dealing with `return` statements, we don't care about climbing only tail
709+
// expressions.
710+
ignore_tail = true;
713711
}
714712
while let Some((hir_id, node)) = iter.next() {
715713
if let (Some((_, next_node)), false) = (iter.peek(), ignore_tail) {

compiler/rustc_middle/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2894,7 +2894,7 @@ fn pretty_print_const_value<'tcx>(
28942894
if let Some(contents) = tcx.try_destructure_mir_constant(
28952895
ty::ParamEnv::reveal_all().and(ConstantKind::Val(ct, ty)),
28962896
) {
2897-
let fields = contents.fields.iter().copied().collect::<Vec<_>>();
2897+
let fields = contents.fields.to_vec();
28982898
match *ty.kind() {
28992899
ty::Array(..) => {
29002900
fmt.write_str("[")?;

compiler/rustc_monomorphize/src/partitioning/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ where
305305
);
306306
}
307307

308-
let _ = writeln!(s, "");
308+
let _ = writeln!(s);
309309
}
310310

311311
std::mem::take(s)

compiler/rustc_passes/src/check_attr.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1090,9 +1090,7 @@ impl CheckAttrVisitor<'_> {
10901090
errors::DocTestUnknownInclude {
10911091
path,
10921092
value: value.to_string(),
1093-
inner: (attr.style == AttrStyle::Inner)
1094-
.then_some("!")
1095-
.unwrap_or(""),
1093+
inner: if attr.style == AttrStyle::Inner { "!" } else { "" },
10961094
sugg: (attr.meta().unwrap().span, applicability),
10971095
}
10981096
);

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+19-24
Original file line numberDiff line numberDiff line change
@@ -1291,29 +1291,25 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
12911291

12921292
if let ObligationCauseCode::AwaitableExpr(hir_id) = obligation.cause.code().peel_derives() {
12931293
let hir = self.tcx.hir();
1294-
if let Some(node) = hir_id.and_then(|hir_id| hir.find(hir_id)) {
1295-
if let hir::Node::Expr(expr) = node {
1296-
// FIXME: use `obligation.predicate.kind()...trait_ref.self_ty()` to see if we have `()`
1297-
// and if not maybe suggest doing something else? If we kept the expression around we
1298-
// could also check if it is an fn call (very likely) and suggest changing *that*, if
1299-
// it is from the local crate.
1300-
err.span_suggestion(
1301-
span,
1302-
"remove the `.await`",
1303-
"",
1304-
Applicability::MachineApplicable,
1305-
);
1306-
// FIXME: account for associated `async fn`s.
1307-
if let hir::Expr { span, kind: hir::ExprKind::Call(base, _), .. } = expr {
1308-
if let ty::PredicateKind::Clause(ty::Clause::Trait(pred)) =
1309-
obligation.predicate.kind().skip_binder()
1310-
{
1311-
err.span_label(
1312-
*span,
1313-
&format!("this call returns `{}`", pred.self_ty()),
1314-
);
1315-
}
1316-
if let Some(typeck_results) = &self.typeck_results
1294+
if let Some(hir::Node::Expr(expr)) = hir_id.and_then(|hir_id| hir.find(hir_id)) {
1295+
// FIXME: use `obligation.predicate.kind()...trait_ref.self_ty()` to see if we have `()`
1296+
// and if not maybe suggest doing something else? If we kept the expression around we
1297+
// could also check if it is an fn call (very likely) and suggest changing *that*, if
1298+
// it is from the local crate.
1299+
err.span_suggestion(
1300+
span,
1301+
"remove the `.await`",
1302+
"",
1303+
Applicability::MachineApplicable,
1304+
);
1305+
// FIXME: account for associated `async fn`s.
1306+
if let hir::Expr { span, kind: hir::ExprKind::Call(base, _), .. } = expr {
1307+
if let ty::PredicateKind::Clause(ty::Clause::Trait(pred)) =
1308+
obligation.predicate.kind().skip_binder()
1309+
{
1310+
err.span_label(*span, &format!("this call returns `{}`", pred.self_ty()));
1311+
}
1312+
if let Some(typeck_results) = &self.typeck_results
13171313
&& let ty = typeck_results.expr_ty_adjusted(base)
13181314
&& let ty::FnDef(def_id, _substs) = ty.kind()
13191315
&& let Some(hir::Node::Item(hir::Item { ident, span, vis_span, .. })) =
@@ -1339,7 +1335,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
13391335
);
13401336
}
13411337
}
1342-
}
13431338
}
13441339
}
13451340
}

0 commit comments

Comments
 (0)