diff options
| author | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2023-11-21 20:07:32 +0100 |
|---|---|---|
| committer | Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> | 2023-11-21 20:13:40 +0100 |
| commit | 21a870515b18e5b2b90435d0f1a6d3089b5217ae (patch) | |
| tree | 4e2c8766f7f64f8a122f38338db2614f1f909a63 /compiler/rustc_hir_analysis/src/check | |
| parent | 0ff861096449f47956521b40e5e4e88caa7fe27c (diff) | |
| download | rust-21a870515b18e5b2b90435d0f1a6d3089b5217ae.tar.gz rust-21a870515b18e5b2b90435d0f1a6d3089b5217ae.zip | |
Fix `clippy::needless_borrow` in the compiler
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
Diffstat (limited to 'compiler/rustc_hir_analysis/src/check')
5 files changed, 35 insertions, 37 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index e61ca232de6..e301f0b22ef 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -222,11 +222,11 @@ fn check_opaque(tcx: TyCtxt<'_>, id: hir::ItemId) { if tcx.type_of(item.owner_id.def_id).instantiate_identity().references_error() { return; } - if check_opaque_for_cycles(tcx, item.owner_id.def_id, args, span, &origin).is_err() { + if check_opaque_for_cycles(tcx, item.owner_id.def_id, args, span, origin).is_err() { return; } - let _ = check_opaque_meets_bounds(tcx, item.owner_id.def_id, span, &origin); + let _ = check_opaque_meets_bounds(tcx, item.owner_id.def_id, span, origin); } /// Checks that an opaque type does not contain cycles. @@ -518,7 +518,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) { DefKind::TyAlias => { let pty_ty = tcx.type_of(id.owner_id).instantiate_identity(); let generics = tcx.generics_of(id.owner_id); - check_type_params_are_used(tcx, &generics, pty_ty); + check_type_params_are_used(tcx, generics, pty_ty); } DefKind::ForeignMod => { let it = tcx.hir().item(id); @@ -900,7 +900,7 @@ pub(super) fn check_packed(tcx: TyCtxt<'_>, sp: Span, def: ty::AdtDef<'_>) { let repr = def.repr(); if repr.packed() { for attr in tcx.get_attrs(def.did(), sym::repr) { - for r in attr::parse_repr_attr(&tcx.sess, attr) { + for r in attr::parse_repr_attr(tcx.sess, attr) { if let attr::ReprPacked(pack) = r && let Some(repr_pack) = repr.pack && pack as u64 != repr_pack.bytes() @@ -1150,8 +1150,8 @@ fn check_enum(tcx: TyCtxt<'_>, def_id: LocalDefId) { let has_disr = |var: &ty::VariantDef| matches!(var.discr, ty::VariantDiscr::Explicit(_)); let has_non_units = def.variants().iter().any(|var| !is_unit(var)); - let disr_units = def.variants().iter().any(|var| is_unit(&var) && has_disr(&var)); - let disr_non_unit = def.variants().iter().any(|var| !is_unit(&var) && has_disr(&var)); + let disr_units = def.variants().iter().any(|var| is_unit(var) && has_disr(var)); + let disr_non_unit = def.variants().iter().any(|var| !is_unit(var) && has_disr(var)); if disr_non_unit || (disr_units && has_non_units) { let mut err = struct_span_err!( diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index f026f78cc2b..d93bb48e0fe 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -307,7 +307,7 @@ fn compare_method_predicate_entailment<'tcx>( debug!(?impl_sig, ?trait_sig, ?terr, "sub_types failed"); let emitted = report_trait_method_mismatch( - &infcx, + infcx, cause, terr, (trait_m, trait_sig), @@ -1140,7 +1140,7 @@ fn report_trait_method_mismatch<'tcx>( ) -> ErrorGuaranteed { let tcx = infcx.tcx; let (impl_err_span, trait_err_span) = - extract_spans_for_error_reporting(&infcx, terr, &cause, impl_m, trait_m); + extract_spans_for_error_reporting(infcx, terr, &cause, impl_m, trait_m); let mut diag = struct_span_err!( tcx.sess, diff --git a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs index cd7e9917204..ba627c740df 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs @@ -307,7 +307,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { if let Err(msg) = reg.validate( asm_arch, self.tcx.sess.relocation_model(), - &target_features, + target_features, &self.tcx.sess.target, op.is_clobber(), ) { @@ -382,7 +382,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { asm.template, true, None, - &target_features, + target_features, ); } hir::InlineAsmOperand::Out { reg, late: _, expr } => { @@ -394,7 +394,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { asm.template, false, None, - &target_features, + target_features, ); } } @@ -406,7 +406,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { asm.template, false, None, - &target_features, + target_features, ); } hir::InlineAsmOperand::SplitInOut { reg, late: _, in_expr, out_expr } => { @@ -417,7 +417,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { asm.template, true, None, - &target_features, + target_features, ); if let Some(out_expr) = out_expr { self.check_asm_operand_type( @@ -427,7 +427,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { asm.template, false, Some((in_expr, in_ty)), - &target_features, + target_features, ); } } diff --git a/compiler/rustc_hir_analysis/src/check/region.rs b/compiler/rustc_hir_analysis/src/check/region.rs index 40b33117f7c..9557568b387 100644 --- a/compiler/rustc_hir_analysis/src/check/region.rs +++ b/compiler/rustc_hir_analysis/src/check/region.rs @@ -414,11 +414,11 @@ fn resolve_expr<'tcx>(visitor: &mut RegionResolutionVisitor<'tcx>, expr: &'tcx h // then we'll assign too low a count to any `yield` expressions // we encounter in 'right_expression' - they should really occur after all of the // expressions in 'left_expression'. - visitor.visit_expr(&right_expr); + visitor.visit_expr(right_expr); visitor.pessimistic_yield = prev_pessimistic; debug!("resolve_expr - restoring pessimistic_yield to {}", prev_pessimistic); - visitor.visit_expr(&left_expr); + visitor.visit_expr(left_expr); debug!("resolve_expr - fixing up counts to {}", visitor.expr_and_pat_count); // Remove and process any scopes pushed by the visitor @@ -582,7 +582,7 @@ fn resolve_local<'tcx>( // due to rule C. if let Some(expr) = init { - record_rvalue_scope_if_borrow_expr(visitor, &expr, blk_scope); + record_rvalue_scope_if_borrow_expr(visitor, expr, blk_scope); if let Some(pat) = pat { if is_binding_pat(pat) { @@ -645,21 +645,19 @@ fn resolve_local<'tcx>( match pat.kind { PatKind::Binding(hir::BindingAnnotation(hir::ByRef::Yes, _), ..) => true, - PatKind::Struct(_, field_pats, _) => { - field_pats.iter().any(|fp| is_binding_pat(&fp.pat)) - } + PatKind::Struct(_, field_pats, _) => field_pats.iter().any(|fp| is_binding_pat(fp.pat)), PatKind::Slice(pats1, pats2, pats3) => { - pats1.iter().any(|p| is_binding_pat(&p)) - || pats2.iter().any(|p| is_binding_pat(&p)) - || pats3.iter().any(|p| is_binding_pat(&p)) + pats1.iter().any(|p| is_binding_pat(p)) + || pats2.iter().any(|p| is_binding_pat(p)) + || pats3.iter().any(|p| is_binding_pat(p)) } PatKind::Or(subpats) | PatKind::TupleStruct(_, subpats, _) - | PatKind::Tuple(subpats, _) => subpats.iter().any(|p| is_binding_pat(&p)), + | PatKind::Tuple(subpats, _) => subpats.iter().any(|p| is_binding_pat(p)), - PatKind::Box(subpat) => is_binding_pat(&subpat), + PatKind::Box(subpat) => is_binding_pat(subpat), PatKind::Ref(_, _) | PatKind::Binding(hir::BindingAnnotation(hir::ByRef::No, _), ..) @@ -700,20 +698,20 @@ fn resolve_local<'tcx>( } hir::ExprKind::Struct(_, fields, _) => { for field in fields { - record_rvalue_scope_if_borrow_expr(visitor, &field.expr, blk_id); + record_rvalue_scope_if_borrow_expr(visitor, field.expr, blk_id); } } hir::ExprKind::Array(subexprs) | hir::ExprKind::Tup(subexprs) => { for subexpr in subexprs { - record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id); + record_rvalue_scope_if_borrow_expr(visitor, subexpr, blk_id); } } hir::ExprKind::Cast(subexpr, _) => { - record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id) + record_rvalue_scope_if_borrow_expr(visitor, subexpr, blk_id) } hir::ExprKind::Block(block, _) => { if let Some(subexpr) = block.expr { - record_rvalue_scope_if_borrow_expr(visitor, &subexpr, blk_id); + record_rvalue_scope_if_borrow_expr(visitor, subexpr, blk_id); } } hir::ExprKind::Call(..) | hir::ExprKind::MethodCall(..) => { @@ -795,13 +793,13 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> { // The arguments and `self` are parented to the fn. self.cx.var_parent = self.cx.parent.take(); for param in body.params { - self.visit_pat(¶m.pat); + self.visit_pat(param.pat); } // The body of the every fn is a root scope. self.cx.parent = self.cx.var_parent; if self.tcx.hir().body_owner_kind(owner_id).is_fn_or_closure() { - self.visit_expr(&body.value) + self.visit_expr(body.value) } else { // Only functions have an outer terminating (drop) scope, while // temporaries in constant initializers may be 'static, but only @@ -822,7 +820,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> { // (i.e., `'static`), which means that after `g` returns, it drops, // and all the associated destruction scope rules apply. self.cx.var_parent = None; - resolve_local(self, None, Some(&body.value)); + resolve_local(self, None, Some(body.value)); } if body.coroutine_kind.is_some() { @@ -849,7 +847,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> { resolve_expr(self, ex); } fn visit_local(&mut self, l: &'tcx Local<'tcx>) { - resolve_local(self, Some(&l.pat), l.init) + resolve_local(self, Some(l.pat), l.init) } } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index d7b50d127cd..177e4611cc9 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -584,7 +584,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>( // reflected in a where clause on the GAT itself. for (ty, ty_idx) in &types { // In our example, requires that `Self: 'a` - if ty_known_to_outlive(tcx, item_def_id, param_env, &wf_tys, *ty, *region_a) { + if ty_known_to_outlive(tcx, item_def_id, param_env, wf_tys, *ty, *region_a) { debug!(?ty_idx, ?region_a_idx); debug!("required clause: {ty} must outlive {region_a}"); // Translate into the generic parameters of the GAT. In @@ -623,7 +623,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>( if matches!(**region_b, ty::ReStatic | ty::ReError(_)) || region_a == region_b { continue; } - if region_known_to_outlive(tcx, item_def_id, param_env, &wf_tys, *region_a, *region_b) { + if region_known_to_outlive(tcx, item_def_id, param_env, wf_tys, *region_a, *region_b) { debug!(?region_a_idx, ?region_b_idx); debug!("required clause: {region_a} must outlive {region_b}"); // Translate into the generic parameters of the GAT. @@ -671,7 +671,7 @@ fn ty_known_to_outlive<'tcx>( ty: Ty<'tcx>, region: ty::Region<'tcx>, ) -> bool { - resolve_regions_with_wf_tys(tcx, id, param_env, &wf_tys, |infcx, region_bound_pairs| { + resolve_regions_with_wf_tys(tcx, id, param_env, wf_tys, |infcx, region_bound_pairs| { let origin = infer::RelateParamBound(DUMMY_SP, ty, None); let outlives = &mut TypeOutlives::new(infcx, tcx, region_bound_pairs, None, param_env); outlives.type_must_outlive(origin, ty, region, ConstraintCategory::BoringNoLocation); @@ -688,7 +688,7 @@ fn region_known_to_outlive<'tcx>( region_a: ty::Region<'tcx>, region_b: ty::Region<'tcx>, ) -> bool { - resolve_regions_with_wf_tys(tcx, id, param_env, &wf_tys, |mut infcx, _| { + resolve_regions_with_wf_tys(tcx, id, param_env, wf_tys, |mut infcx, _| { use rustc_infer::infer::outlives::obligations::TypeOutlivesDelegate; let origin = infer::RelateRegionParamBound(DUMMY_SP); // `region_a: region_b` -> `region_b <= region_a` |
