From bd3667dbe7465d306ea96cf8367ab329b0b2c276 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 6 Jun 2024 17:00:09 +1000 Subject: [PATCH] Change the return type of `Ty::kind` from `&TyKind` to `TyKind`. This is valid because `TyKind` impls `Copy`, and makes `Ty` consistent with `Predicate` and `Region`, both of which have `kind` methods that return a non-reference. The change removes more than one thousand `&` and `*` sigils, while requiring the addition of just five! It's clearly moving with the grain of the existing code. Almost all of the removed sigils fit one of the following three patterns. - Remove the dereference in the match expression: `match *ty.kind() { ... }` -> `match ty.kind() { ... }` - Remove the dereference in the match pattern: `match ty.kind() { &ty::Foo(foo) => { ... foo ... }` -> `match ty.kind() { ty::Foo(foo) => { ... foo ... }` - Remove the derefernce in the match arm: `match ty.kind() { ty::Foo(foo) => { ... *foo ... }` -> `match ty.kind() { ty::Foo(foo) => { ... foo ... }` A couple of other methods had their signatures changed. - `TypeErrCtxt::cmp_fn_sig`: `&` removed from two args. - `EncodableWithShorthand::variant`: `&` removed from return type. --- .../src/diagnostics/conflict_errors.rs | 10 +-- .../src/diagnostics/explain_borrow.rs | 57 ++++++++-------- .../rustc_borrowck/src/diagnostics/mod.rs | 12 ++-- .../src/diagnostics/mutability_errors.rs | 6 +- .../src/diagnostics/region_errors.rs | 21 +++--- .../src/diagnostics/region_name.rs | 8 +-- compiler/rustc_borrowck/src/lib.rs | 2 +- .../rustc_borrowck/src/region_infer/mod.rs | 2 +- compiler/rustc_borrowck/src/type_check/mod.rs | 28 ++++---- .../src/type_check/relate_tys.rs | 16 ++--- .../rustc_borrowck/src/universal_regions.rs | 4 +- .../rustc_codegen_cranelift/src/abi/mod.rs | 6 +- compiler/rustc_codegen_cranelift/src/base.rs | 12 ++-- .../rustc_codegen_cranelift/src/common.rs | 4 +- .../src/debuginfo/types.rs | 6 +- .../rustc_codegen_cranelift/src/global_asm.rs | 2 +- .../rustc_codegen_cranelift/src/inline_asm.rs | 4 +- .../rustc_codegen_cranelift/src/unsize.rs | 10 +-- .../src/value_and_place.rs | 24 +++---- compiler/rustc_codegen_gcc/src/int.rs | 2 +- .../rustc_codegen_gcc/src/intrinsic/mod.rs | 4 +- .../rustc_codegen_gcc/src/intrinsic/simd.rs | 68 +++++++++---------- compiler/rustc_codegen_gcc/src/type_of.rs | 8 +-- compiler/rustc_codegen_llvm/src/builder.rs | 2 +- .../src/debuginfo/metadata.rs | 17 +++-- .../src/debuginfo/metadata/enums/cpp_like.rs | 4 +- .../src/debuginfo/metadata/enums/mod.rs | 2 +- .../src/debuginfo/metadata/enums/native.rs | 4 +- .../rustc_codegen_llvm/src/debuginfo/mod.rs | 4 +- .../rustc_codegen_llvm/src/debuginfo/utils.rs | 2 +- compiler/rustc_codegen_llvm/src/intrinsic.rs | 34 +++++----- compiler/rustc_codegen_llvm/src/type_of.rs | 4 +- compiler/rustc_codegen_ssa/src/base.rs | 14 ++-- .../src/debuginfo/type_names.rs | 4 +- compiler/rustc_codegen_ssa/src/mir/block.rs | 4 +- .../rustc_codegen_ssa/src/mir/intrinsic.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 4 +- compiler/rustc_codegen_ssa/src/mono_item.rs | 2 +- .../src/check_consts/check.rs | 2 +- .../rustc_const_eval/src/check_consts/ops.rs | 6 +- .../src/const_eval/machine.rs | 2 +- .../src/const_eval/valtrees.rs | 6 +- .../rustc_const_eval/src/interpret/call.rs | 12 ++-- .../rustc_const_eval/src/interpret/cast.rs | 12 ++-- .../src/interpret/discriminant.rs | 2 +- .../src/interpret/intrinsics.rs | 2 +- .../src/interpret/projection.rs | 2 +- .../rustc_const_eval/src/interpret/stack.rs | 2 +- .../rustc_const_eval/src/interpret/step.rs | 2 +- .../rustc_const_eval/src/interpret/util.rs | 2 +- .../src/interpret/validity.rs | 6 +- .../rustc_const_eval/src/interpret/visitor.rs | 2 +- .../rustc_const_eval/src/util/type_name.rs | 2 +- .../rustc_hir_analysis/src/check/check.rs | 10 +-- .../src/check/compare_impl_item.rs | 4 +- .../src/check/compare_impl_item/refine.rs | 6 +- .../src/check/intrinsicck.rs | 6 +- compiler/rustc_hir_analysis/src/check/mod.rs | 2 +- .../rustc_hir_analysis/src/check/wfcheck.rs | 10 +-- .../src/coherence/builtin.rs | 16 ++--- .../src/coherence/inherent_impls.rs | 6 +- .../src/coherence/orphan.rs | 6 +- compiler/rustc_hir_analysis/src/collect.rs | 4 +- .../src/constrained_generic_params.rs | 2 +- .../src/hir_ty_lowering/bounds.rs | 4 +- .../src/hir_ty_lowering/errors.rs | 2 +- .../src/outlives/implicit_infer.rs | 2 +- .../src/variance/constraints.rs | 2 +- .../rustc_hir_analysis/src/variance/mod.rs | 4 +- compiler/rustc_hir_typeck/src/_match.rs | 2 +- compiler/rustc_hir_typeck/src/autoderef.rs | 2 +- compiler/rustc_hir_typeck/src/callee.rs | 10 +-- compiler/rustc_hir_typeck/src/cast.rs | 18 ++--- compiler/rustc_hir_typeck/src/closure.rs | 10 +-- compiler/rustc_hir_typeck/src/coercion.rs | 22 +++--- compiler/rustc_hir_typeck/src/expr.rs | 24 +++---- .../rustc_hir_typeck/src/expr_use_visitor.rs | 2 +- .../src/fn_ctxt/adjust_fulfillment_errors.rs | 10 +-- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 6 +- .../src/fn_ctxt/inspect_obligations.rs | 2 +- compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs | 4 +- .../src/fn_ctxt/suggestions.rs | 34 +++++----- compiler/rustc_hir_typeck/src/intrinsicck.rs | 4 +- .../rustc_hir_typeck/src/method/confirm.rs | 4 +- compiler/rustc_hir_typeck/src/method/mod.rs | 2 +- compiler/rustc_hir_typeck/src/method/probe.rs | 12 ++-- .../rustc_hir_typeck/src/method/suggest.rs | 19 +++--- compiler/rustc_hir_typeck/src/op.rs | 32 ++++----- compiler/rustc_hir_typeck/src/pat.rs | 18 ++--- compiler/rustc_hir_typeck/src/place_op.rs | 14 ++-- compiler/rustc_hir_typeck/src/upvar.rs | 4 +- compiler/rustc_hir_typeck/src/writeback.rs | 2 +- .../src/infer/canonical/canonicalizer.rs | 2 +- .../src/infer/canonical/query_response.rs | 2 +- compiler/rustc_infer/src/infer/freshen.rs | 2 +- compiler/rustc_infer/src/infer/mod.rs | 8 +-- .../rustc_infer/src/infer/opaque_types/mod.rs | 10 +-- .../src/infer/outlives/for_liveness.rs | 2 +- .../src/infer/outlives/obligations.rs | 2 +- .../rustc_infer/src/infer/outlives/verify.rs | 2 +- .../rustc_infer/src/infer/relate/combine.rs | 20 +++--- .../src/infer/relate/generalize.rs | 6 +- .../rustc_infer/src/infer/relate/lattice.rs | 12 ++-- .../src/infer/relate/type_relating.rs | 16 ++--- compiler/rustc_infer/src/infer/resolve.rs | 2 +- .../rustc_infer/src/infer/snapshot/fudge.rs | 2 +- .../rustc_infer/src/infer/type_variable.rs | 2 +- compiler/rustc_lint/src/builtin.rs | 8 +-- .../src/for_loops_over_fallibles.rs | 6 +- compiler/rustc_lint/src/foreign_modules.rs | 12 ++-- .../rustc_lint/src/impl_trait_overcaptures.rs | 6 +- compiler/rustc_lint/src/internal.rs | 4 +- compiler/rustc_lint/src/map_unit_fn.rs | 10 +-- compiler/rustc_lint/src/non_fmt_panic.rs | 2 +- .../src/opaque_hidden_inferred_bound.rs | 6 +- compiler/rustc_lint/src/reference_casting.rs | 4 +- compiler/rustc_lint/src/shadowed_into_iter.rs | 4 +- compiler/rustc_lint/src/types.rs | 14 ++-- compiler/rustc_lint/src/unused.rs | 4 +- compiler/rustc_middle/src/mir/pretty.rs | 10 +-- compiler/rustc_middle/src/mir/statement.rs | 2 +- compiler/rustc_middle/src/mir/tcx.rs | 4 +- compiler/rustc_middle/src/query/keys.rs | 2 +- compiler/rustc_middle/src/thir.rs | 4 +- compiler/rustc_middle/src/ty/cast.rs | 2 +- compiler/rustc_middle/src/ty/codec.rs | 10 +-- .../rustc_middle/src/ty/consts/valtree.rs | 4 +- compiler/rustc_middle/src/ty/context.rs | 2 +- compiler/rustc_middle/src/ty/diagnostics.rs | 8 +-- compiler/rustc_middle/src/ty/error.rs | 4 +- compiler/rustc_middle/src/ty/fold.rs | 2 +- .../rustc_middle/src/ty/inhabitedness/mod.rs | 2 +- compiler/rustc_middle/src/ty/instance.rs | 6 +- compiler/rustc_middle/src/ty/layout.rs | 10 +-- compiler/rustc_middle/src/ty/mod.rs | 6 +- compiler/rustc_middle/src/ty/opaque_types.rs | 2 +- compiler/rustc_middle/src/ty/print/mod.rs | 2 +- compiler/rustc_middle/src/ty/print/pretty.rs | 16 ++--- .../rustc_middle/src/ty/structural_impls.rs | 6 +- compiler/rustc_middle/src/ty/sty.rs | 35 +++++----- .../rustc_middle/src/ty/typeck_results.rs | 2 +- compiler/rustc_middle/src/ty/util.rs | 26 +++---- compiler/rustc_middle/src/ty/walk.rs | 2 +- .../rustc_middle/src/util/find_self_call.rs | 2 +- .../rustc_mir_build/src/build/custom/parse.rs | 2 +- .../src/build/expr/as_place.rs | 2 +- .../rustc_mir_build/src/build/matches/test.rs | 4 +- compiler/rustc_mir_build/src/build/mod.rs | 4 +- .../rustc_mir_build/src/check_unsafety.rs | 4 +- compiler/rustc_mir_build/src/lints.rs | 4 +- compiler/rustc_mir_build/src/thir/cx/expr.rs | 12 ++-- compiler/rustc_mir_build/src/thir/cx/mod.rs | 2 +- .../src/thir/pattern/check_match.rs | 4 +- .../src/thir/pattern/const_to_pat.rs | 14 ++-- .../rustc_mir_build/src/thir/pattern/mod.rs | 10 +-- .../rustc_mir_dataflow/src/elaborate_drops.rs | 6 +- .../src/impls/initialized.rs | 2 +- compiler/rustc_mir_dataflow/src/rustc_peek.rs | 2 +- .../src/abort_unwinding_calls.rs | 2 +- compiler/rustc_mir_transform/src/add_retag.rs | 2 +- .../src/check_alignment.rs | 2 +- compiler/rustc_mir_transform/src/coroutine.rs | 18 ++--- .../src/coroutine/by_move_body.rs | 4 +- .../src/dataflow_const_prop.rs | 4 +- .../src/ffi_unwind_calls.rs | 2 +- .../src/function_item_references.rs | 4 +- compiler/rustc_mir_transform/src/gvn.rs | 14 +--- compiler/rustc_mir_transform/src/inline.rs | 4 +- .../rustc_mir_transform/src/inline/cycle.rs | 6 +- .../rustc_mir_transform/src/instsimplify.rs | 6 +- .../rustc_mir_transform/src/large_enums.rs | 4 +- compiler/rustc_mir_transform/src/lib.rs | 2 +- .../src/lower_intrinsics.rs | 4 +- .../rustc_mir_transform/src/match_branches.rs | 2 +- .../rustc_mir_transform/src/promote_consts.rs | 4 +- compiler/rustc_mir_transform/src/shim.rs | 12 ++-- .../src/shim/async_destructor_ctor.rs | 8 +-- compiler/rustc_mir_transform/src/validate.rs | 6 +- compiler/rustc_monomorphize/src/collector.rs | 10 +-- .../src/collector/move_check.rs | 2 +- .../rustc_monomorphize/src/polymorphize.rs | 2 +- compiler/rustc_passes/src/abi_test.rs | 9 ++- compiler/rustc_passes/src/dead.rs | 4 +- compiler/rustc_pattern_analysis/src/rustc.rs | 36 +++++----- compiler/rustc_privacy/src/lib.rs | 2 +- .../src/cfi/typeid/itanium_cxx_abi/encode.rs | 38 +++++------ .../cfi/typeid/itanium_cxx_abi/transform.rs | 2 +- compiler/rustc_symbol_mangling/src/legacy.rs | 2 +- compiler/rustc_symbol_mangling/src/v0.rs | 7 +- .../src/error_reporting/infer/mod.rs | 58 ++++++++-------- .../error_reporting/infer/need_type_info.rs | 6 +- .../error_reporting/infer/note_and_explain.rs | 8 +-- .../error_reporting/infer/sub_relations.rs | 2 +- .../src/error_reporting/infer/suggest.rs | 6 +- .../traits/fulfillment_errors.rs | 14 ++-- .../src/error_reporting/traits/suggestions.rs | 59 ++++++++-------- .../src/solve/normalize.rs | 4 +- .../src/traits/auto_trait.rs | 2 +- .../rustc_trait_selection/src/traits/misc.rs | 4 +- .../rustc_trait_selection/src/traits/mod.rs | 2 +- .../src/traits/normalize.rs | 2 +- .../src/traits/project.rs | 10 +-- .../src/traits/query/dropck_outlives.rs | 6 +- .../src/traits/query/normalize.rs | 2 +- .../src/traits/select/_match.rs | 10 +-- .../src/traits/select/candidate_assembly.rs | 34 +++++----- .../src/traits/select/confirmation.rs | 32 ++++----- .../src/traits/select/mod.rs | 12 ++-- .../src/traits/structural_normalize.rs | 2 +- .../rustc_trait_selection/src/traits/util.rs | 4 +- .../src/traits/vtable.rs | 6 +- .../rustc_trait_selection/src/traits/wf.rs | 2 +- compiler/rustc_transmute/src/layout/tree.rs | 18 ++--- compiler/rustc_ty_utils/src/abi.rs | 12 ++-- compiler/rustc_ty_utils/src/consts.rs | 4 +- compiler/rustc_ty_utils/src/instance.rs | 8 +-- compiler/rustc_ty_utils/src/layout.rs | 6 +- compiler/rustc_ty_utils/src/needs_drop.rs | 4 +- compiler/rustc_ty_utils/src/opaque_types.rs | 4 +- .../rustc_ty_utils/src/representability.rs | 4 +- compiler/rustc_ty_utils/src/ty.rs | 4 +- src/librustdoc/clean/mod.rs | 6 +- src/librustdoc/clean/utils.rs | 6 +- .../passes/collect_intra_doc_links.rs | 2 +- src/librustdoc/scrape_examples.rs | 2 +- .../clippy_lints/src/borrow_deref_ref.rs | 2 +- .../src/casts/cast_possible_truncation.rs | 6 +- .../src/casts/cast_precision_loss.rs | 2 +- .../src/casts/cast_ptr_alignment.rs | 4 +- .../clippy_lints/src/casts/cast_sign_loss.rs | 4 +- .../src/casts/cast_slice_different_sizes.rs | 2 +- .../clippy_lints/src/casts/char_lit_as_u8.rs | 2 +- .../src/casts/fn_to_numeric_cast.rs | 2 +- .../src/casts/ptr_cast_constness.rs | 2 +- src/tools/clippy/clippy_lints/src/default.rs | 2 +- .../src/default_numeric_fallback.rs | 4 +- .../clippy/clippy_lints/src/dereference.rs | 12 ++-- .../clippy_lints/src/derivable_impls.rs | 4 +- src/tools/clippy/clippy_lints/src/derive.rs | 4 +- .../clippy/clippy_lints/src/eta_reduction.rs | 14 ++-- .../clippy/clippy_lints/src/float_literal.rs | 2 +- .../src/from_raw_with_void_ptr.rs | 2 +- .../clippy_lints/src/functions/must_use.rs | 2 +- .../src/functions/not_unsafe_ptr_arg_deref.rs | 2 +- .../clippy_lints/src/functions/result.rs | 2 +- .../clippy_lints/src/future_not_send.rs | 2 +- .../src/implied_bounds_in_impls.rs | 2 +- .../clippy_lints/src/index_refutable_slice.rs | 2 +- .../clippy_lints/src/indexing_slicing.rs | 2 +- .../src/iter_without_into_iter.rs | 2 +- .../clippy_lints/src/large_const_arrays.rs | 2 +- .../clippy_lints/src/large_enum_variant.rs | 2 +- .../clippy_lints/src/large_stack_arrays.rs | 2 +- src/tools/clippy/clippy_lints/src/len_zero.rs | 8 +-- .../src/loops/explicit_iter_loop.rs | 6 +- .../clippy_lints/src/loops/for_kv_map.rs | 2 +- .../clippy_lints/src/loops/manual_memcpy.rs | 4 +- .../src/loops/needless_range_loop.rs | 4 +- .../src/loops/unused_enumerate_index.rs | 2 +- .../src/manual_slice_size_calculation.rs | 2 +- .../clippy/clippy_lints/src/map_unit_fn.rs | 2 +- .../clippy_lints/src/matches/match_as_ref.rs | 2 +- .../clippy_lints/src/matches/match_bool.rs | 2 +- .../src/matches/match_str_case_mismatch.rs | 2 +- .../matches/significant_drop_in_scrutinee.rs | 6 +- .../clippy_lints/src/matches/single_match.rs | 8 +-- .../clippy_lints/src/methods/bytecount.rs | 2 +- .../clippy_lints/src/methods/chars_cmp.rs | 2 +- .../src/methods/cloned_instead_of_copied.rs | 2 +- .../src/methods/iter_overeager_cloned.rs | 2 +- .../clippy_lints/src/methods/map_clone.rs | 6 +- .../clippy/clippy_lints/src/methods/mod.rs | 2 +- .../methods/needless_character_iteration.rs | 4 +- .../src/methods/needless_collect.rs | 6 +- .../src/methods/unnecessary_join.rs | 2 +- .../src/methods/unnecessary_min_or_max.rs | 8 +-- .../src/methods/unnecessary_to_owned.rs | 4 +- .../clippy/clippy_lints/src/methods/utils.rs | 4 +- .../clippy_lints/src/methods/zst_offset.rs | 2 +- .../src/mixed_read_write_in_expression.rs | 2 +- .../src/multiple_unsafe_ops_per_block.rs | 2 +- .../clippy/clippy_lints/src/mutex_atomic.rs | 2 +- .../src/needless_borrows_for_generic_args.rs | 6 +- .../clippy/clippy_lints/src/non_copy_const.rs | 2 +- .../src/non_send_fields_in_send_ty.rs | 2 +- .../src/only_used_in_recursion.rs | 2 +- .../operators/absurd_extreme_comparisons.rs | 10 +-- .../clippy_lints/src/operators/identity_op.rs | 2 +- .../src/operators/modulo_arithmetic.rs | 2 +- .../clippy_lints/src/operators/modulo_one.rs | 2 +- .../clippy_lints/src/pass_by_ref_or_value.rs | 2 +- .../clippy_lints/src/pattern_type_mismatch.rs | 2 +- src/tools/clippy/clippy_lints/src/ptr.rs | 8 +-- .../clippy_lints/src/rc_clone_in_vec_init.rs | 2 +- .../clippy_lints/src/redundant_clone.rs | 2 +- .../src/significant_drop_tightening.rs | 4 +- .../src/size_of_in_element_count.rs | 2 +- .../clippy_lints/src/to_digit_is_some.rs | 2 +- .../src/transmute/crosspointer_transmute.rs | 2 +- .../src/transmute/transmute_ref_to_ref.rs | 4 +- .../src/transmute/transmute_undefined_repr.rs | 16 ++--- .../src/transmute/useless_transmute.rs | 2 +- .../src/tuple_array_conversions.rs | 5 +- .../src/unconditional_recursion.rs | 6 +- .../src/unit_types/let_unit_value.rs | 2 +- src/tools/clippy/clippy_lints/src/use_self.rs | 2 +- src/tools/clippy/clippy_utils/src/consts.rs | 20 +++--- src/tools/clippy/clippy_utils/src/lib.rs | 10 +-- .../clippy_utils/src/qualify_min_const_fn.rs | 4 +- src/tools/clippy/clippy_utils/src/ty.rs | 30 ++++---- .../clippy_utils/src/ty/type_certainty/mod.rs | 2 +- src/tools/clippy/clippy_utils/src/visitors.rs | 2 +- .../src/borrow_tracker/tree_borrows/mod.rs | 4 +- src/tools/miri/src/intrinsics/simd.rs | 4 +- 314 files changed, 1077 insertions(+), 1112 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 2b46e5597f778..fa7afe3c4797d 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -435,7 +435,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { && let hir::ExprKind::Call(call, args) = parent_expr.kind && let ty::FnDef(def_id, _) = typeck.node_type(call.hir_id).kind() { - (Some(*def_id), args, 0) + (Some(def_id), args, 0) } else { (None, &[][..], 0) }; @@ -498,7 +498,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { .contains(&Some(predicate.def_id())) && let ty::Param(param) = predicate.self_ty().kind() && let generics = self.infcx.tcx.generics_of(def_id) - && let param = generics.type_param(*param, self.infcx.tcx) + && let param = generics.type_param(param, self.infcx.tcx) && param.def_id == param_def_id { if [ @@ -870,7 +870,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { // borrowing the type, since `&mut F: FnMut` iff `F: FnMut` and similarly for `Fn`. // These types seem reasonably opaque enough that they could be instantiated with their // borrowed variants in a function body when we see a move error. - let borrow_level = match *ty.kind() { + let borrow_level = match ty.kind() { ty::Param(_) => tcx .explicit_predicates_of(self.mir_def_id().to_def_id()) .predicates @@ -1263,7 +1263,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { } else if let ty::Param(param) = ty.kind() && let Some(_clone_trait_def) = self.infcx.tcx.lang_items().clone_trait() && let generics = self.infcx.tcx.generics_of(self.mir_def_id()) - && let generic_param = generics.type_param(*param, self.infcx.tcx) + && let generic_param = generics.type_param(param, self.infcx.tcx) && let param_span = self.infcx.tcx.def_span(generic_param.def_id) && if let Some(UseSpans::FnSelfUse { kind, .. }) = use_spans && let CallKind::FnCall { fn_trait_id, self_ty } = kind @@ -1436,7 +1436,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { .into_iter() .map(|err| match err.obligation.predicate.kind().skip_binder() { PredicateKind::Clause(ty::ClauseKind::Trait(predicate)) => { - match *predicate.self_ty().kind() { + match predicate.self_ty().kind() { ty::Param(param_ty) => Ok(( generics.type_param(param_ty, tcx), predicate.trait_ref.print_trait_sugared().to_string(), diff --git a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs index d85959c9a291e..21b9e9e5b1bd6 100644 --- a/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs +++ b/compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs @@ -317,40 +317,37 @@ impl<'tcx> BorrowExplanation<'tcx> { let mut has_dyn = false; let mut failed = false; - let elaborated_args = - std::iter::zip(*args, &generics.own_params).map(|(arg, param)| { - if let Some(ty::Dynamic(obj, _, ty::Dyn)) = arg.as_type().map(Ty::kind) { - let default = tcx.object_lifetime_default(param.def_id); - - let re_static = tcx.lifetimes.re_static; - - let implied_region = match default { - // This is not entirely precise. - ObjectLifetimeDefault::Empty => re_static, - ObjectLifetimeDefault::Ambiguous => { + let elaborated_args = std::iter::zip(args, &generics.own_params).map(|(arg, param)| { + if let Some(ty::Dynamic(obj, _, ty::Dyn)) = arg.as_type().map(Ty::kind) { + let default = tcx.object_lifetime_default(param.def_id); + + let re_static = tcx.lifetimes.re_static; + + let implied_region = match default { + // This is not entirely precise. + ObjectLifetimeDefault::Empty => re_static, + ObjectLifetimeDefault::Ambiguous => { + failed = true; + re_static + } + ObjectLifetimeDefault::Param(param_def_id) => { + let index = generics.param_def_id_to_index[¶m_def_id] as usize; + args.get(index).and_then(|arg| arg.as_region()).unwrap_or_else(|| { failed = true; re_static - } - ObjectLifetimeDefault::Param(param_def_id) => { - let index = generics.param_def_id_to_index[¶m_def_id] as usize; - args.get(index).and_then(|arg| arg.as_region()).unwrap_or_else( - || { - failed = true; - re_static - }, - ) - } - ObjectLifetimeDefault::Static => re_static, - }; + }) + } + ObjectLifetimeDefault::Static => re_static, + }; - has_dyn = true; + has_dyn = true; - Ty::new_dynamic(tcx, obj, implied_region, ty::Dyn).into() - } else { - arg - } - }); - let elaborated_ty = Ty::new_adt(tcx, *def, tcx.mk_args_from_iter(elaborated_args)); + Ty::new_dynamic(tcx, obj, implied_region, ty::Dyn).into() + } else { + arg + } + }); + let elaborated_ty = Ty::new_adt(tcx, def, tcx.mk_args_from_iter(elaborated_args)); if has_dyn && !failed { err.note(format!( diff --git a/compiler/rustc_borrowck/src/diagnostics/mod.rs b/compiler/rustc_borrowck/src/diagnostics/mod.rs index a2e5c7b85145a..9cc31e50cd144 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mod.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mod.rs @@ -112,7 +112,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { .. } = &terminator.kind { - if let ty::FnDef(id, _) = *const_.ty().kind() { + if let ty::FnDef(id, _) = const_.ty().kind() { debug!("add_moved_or_invoked_closure_note: id={:?}", id); if self.infcx.tcx.is_lang_item(self.infcx.tcx.parent(id), LangItem::FnOnce) { let closure = match args.first() { @@ -348,7 +348,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { // If the type is a box, the field is described from the boxed type self.describe_field_from_ty(ty.boxed_ty(), field, variant_index, including_tuple_field) } else { - match *ty.kind() { + match ty.kind() { ty::Adt(def, _) => { let variant = if let Some(idx) = variant_index { assert!(def.is_enum()); @@ -459,7 +459,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { // this by hooking into the pretty printer and telling it to label the // lifetimes without names with the value `'0`. if let ty::Ref(region, ..) = ty.kind() { - match **region { + match *region { ty::ReBound(_, ty::BoundRegion { kind: br, .. }) | ty::RePlaceholder(ty::PlaceholderRegion { bound: ty::BoundRegion { kind: br, .. }, @@ -479,7 +479,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { let mut printer = ty::print::FmtPrinter::new(self.infcx.tcx, Namespace::TypeNS); let region = if let ty::Ref(region, ..) = ty.kind() { - match **region { + match *region { ty::ReBound(_, ty::BoundRegion { kind: br, .. }) | ty::RePlaceholder(ty::PlaceholderRegion { bound: ty::BoundRegion { kind: br, .. }, @@ -740,7 +740,7 @@ impl<'tcx> BorrowedContentSource<'tcx> { } fn from_call(func: Ty<'tcx>, tcx: TyCtxt<'tcx>) -> Option { - match *func.kind() { + match func.kind() { ty::FnDef(def_id, args) => { let trait_id = tcx.trait_of_item(def_id)?; @@ -1048,7 +1048,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { // LL | blk(); // | ----- this value implements `FnOnce`, which causes it to be moved when called // ``` - if let ty::Param(param_ty) = *self_ty.kind() + if let ty::Param(param_ty) = self_ty.kind() && let generics = self.infcx.tcx.generics_of(self.mir_def_id()) && let param = generics.type_param(param_ty, self.infcx.tcx) && let Some(hir_generics) = self diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 0303b80cace45..3c3e4ffe2c8e8 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -377,7 +377,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { if suggest { self.construct_mut_suggestion_for_local_binding_patterns(&mut err, local); let tcx = self.infcx.tcx; - if let ty::Closure(id, _) = *the_place_err.ty(self.body, tcx).ty.kind() { + if let ty::Closure(id, _) = the_place_err.ty(self.body, tcx).ty.kind() { self.show_mutating_upvar(tcx, id.expect_local(), the_place_err, &mut err); } } @@ -431,7 +431,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { let tcx = self.infcx.tcx; if let ty::Ref(_, ty, Mutability::Mut) = the_place_err.ty(self.body, tcx).ty.kind() - && let ty::Closure(id, _) = *ty.kind() + && let ty::Closure(id, _) = ty.kind() { self.show_mutating_upvar(tcx, id.expect_local(), the_place_err, &mut err); } @@ -953,7 +953,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { if let Some(ty::FnDef(def_id, _)) = typeck_results.node_type_opt(expr.hir_id).as_ref().map(|ty| ty.kind()) { - Some((*def_id, expr.span, *args)) + Some((def_id, expr.span, *args)) } else { None } diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 451e8bcb16da4..d8fe023d6378b 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -507,14 +507,14 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { ty::VarianceDiagInfo::Invariant { ty, param_index } => { let (desc, note) = match ty.kind() { ty::RawPtr(ty, mutbl) => { - assert_eq!(*mutbl, rustc_hir::Mutability::Mut); + assert_eq!(mutbl, rustc_hir::Mutability::Mut); ( format!("a mutable pointer to `{}`", ty), "mutable pointers are invariant over their type parameter".to_string(), ) } ty::Ref(_, inner_ty, mutbl) => { - assert_eq!(*mutbl, rustc_hir::Mutability::Mut); + assert_eq!(mutbl, rustc_hir::Mutability::Mut); ( format!("a mutable reference to `{inner_ty}`"), "mutable references are invariant over their type parameter" @@ -525,7 +525,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { let generic_arg = args[param_index as usize]; let identity_args = GenericArgs::identity_for_item(self.infcx.tcx, adt.did()); - let base_ty = Ty::new_adt(self.infcx.tcx, *adt, identity_args); + let base_ty = Ty::new_adt(self.infcx.tcx, adt, identity_args); let base_generic_arg = identity_args[param_index as usize]; let adt_desc = adt.descr(); @@ -538,8 +538,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { (desc, note) } ty::FnDef(def_id, _) => { - let name = self.infcx.tcx.item_name(*def_id); - let identity_args = GenericArgs::identity_for_item(self.infcx.tcx, *def_id); + let name = self.infcx.tcx.item_name(def_id); + let identity_args = GenericArgs::identity_for_item(self.infcx.tcx, def_id); let desc = format!("a function pointer to `{name}`"); let note = format!( "the function `{name}` is invariant over the parameter `{}`", @@ -591,7 +591,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { let ErrorConstraintInfo { outlived_fr, span, .. } = errci; let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty; - if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *output_ty.kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = output_ty.kind() { output_ty = self.infcx.tcx.type_of(def_id).instantiate_identity() }; @@ -600,7 +600,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { let err = FnMutError { span: *span, ty_err: match output_ty.kind() { - ty::Coroutine(def, ..) if self.infcx.tcx.coroutine_is_async(*def) => { + ty::Coroutine(def, ..) if self.infcx.tcx.coroutine_is_async(def) => { FnMutReturnTypeErr::ReturnAsyncBlock { span: *span } } _ if output_ty.contains_closure() => { @@ -949,7 +949,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { if let Ok(Some(instance)) = ty::Instance::try_resolve( tcx, self.param_env, - *fn_did, + fn_did, self.infcx.resolve_vars_if_possible(args), ) { instance @@ -1061,8 +1061,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { else { return; }; - let ty::Closure(_, args) = *tcx.type_of(closure_def_id).instantiate_identity().kind() - else { + let ty::Closure(_, args) = tcx.type_of(closure_def_id).instantiate_identity().kind() else { return; }; let args = args.as_closure(); @@ -1083,7 +1082,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> { let liberated_sig = tcx.liberate_late_bound_regions(closure_def_id.to_def_id(), args.sig()); let mut peeled_ty = liberated_sig.output(); let mut count = 0; - while let ty::Ref(_, ref_ty, _) = *peeled_ty.kind() { + while let ty::Ref(_, ref_ty, _) = peeled_ty.kind() { peeled_ty = ref_ty; count += 1; } diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index 12aedf6fe088b..288dbc6f37a87 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -523,7 +523,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> { } // Otherwise, let's descend into the referent types. - search_stack.push((*referent_ty, referent_hir_ty.ty)); + search_stack.push((referent_ty, referent_hir_ty.ty)); } // Match up something like `Foo<'1>` @@ -552,17 +552,17 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, '_, 'tcx> { // The following cases don't have lifetimes, so we // just worry about trying to match up the rustc type // with the HIR types: - (&ty::Tuple(elem_tys), hir::TyKind::Tup(elem_hir_tys)) => { + (ty::Tuple(elem_tys), hir::TyKind::Tup(elem_hir_tys)) => { search_stack.extend(iter::zip(elem_tys, *elem_hir_tys)); } (ty::Slice(elem_ty), hir::TyKind::Slice(elem_hir_ty)) | (ty::Array(elem_ty, _), hir::TyKind::Array(elem_hir_ty, _)) => { - search_stack.push((*elem_ty, elem_hir_ty)); + search_stack.push((elem_ty, elem_hir_ty)); } (ty::RawPtr(mut_ty, _), hir::TyKind::Ptr(mut_hir_ty)) => { - search_stack.push((*mut_ty, mut_hir_ty.ty)); + search_stack.push((mut_ty, mut_hir_ty.ty)); } _ => { diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 30dd45d847c9b..c8ce699d56f71 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -265,7 +265,7 @@ fn do_mir_borrowck<'tcx>( // The first argument is the coroutine type passed by value if let Some(local) = body.local_decls.raw.get(1) // Get the interior types and args which typeck computed - && let ty::Coroutine(def_id, _) = *local.ty.kind() + && let ty::Coroutine(def_id, _) = local.ty.kind() && tcx.coroutine_movability(def_id) == hir::Movability::Movable { true diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index c8dc012de4a29..ba52fcfc789f6 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -1067,7 +1067,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { use ty::TypeSuperFoldable as _; let tcx = self.tcx; - let &ty::Alias(ty::Opaque, ty::AliasTy { args, def_id, .. }) = t.kind() else { + let ty::Alias(ty::Opaque, ty::AliasTy { args, def_id, .. }) = t.kind() else { return t.super_fold_with(self); }; let args = std::iter::zip(args, tcx.variances_of(def_id)).map(|(arg, v)| { diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 9e0724b0948cc..a76d60c3daece 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -397,7 +397,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { } } - if let ty::FnDef(def_id, args) = *constant.const_.ty().kind() { + if let ty::FnDef(def_id, args) = constant.const_.ty().kind() { let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, args); self.cx.normalize_and_prove_instantiated_predicates( def_id, @@ -435,7 +435,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { // then remove the outermost reference so we can check the // type annotation for the remaining type. if let ty::Ref(_, rty, _) = local_decl.ty.kind() { - *rty + rty } else { bug!("{:?} with ref binding has wrong type {}", local, local_decl.ty); } @@ -649,7 +649,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { PlaceTy::from_ty(match base_ty.kind() { ty::Array(inner, _) => { assert!(!from_end, "array subslices should not use from_end"); - Ty::new_array(tcx, *inner, to - from) + Ty::new_array(tcx, inner, to - from) } ty::Slice(..) => { assert!(from_end, "slice subslices should use from_end"); @@ -773,7 +773,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { let tcx = self.tcx(); let (variant, args) = match base_ty { - PlaceTy { ty, variant_index: Some(variant_index) } => match *ty.kind() { + PlaceTy { ty, variant_index: Some(variant_index) } => match ty.kind() { ty::Adt(adt_def, args) => (adt_def.variant(variant_index), args), ty::Coroutine(def_id, args) => { let mut variants = args.as_coroutine().state_tys(def_id, tcx); @@ -791,7 +791,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { } _ => bug!("can't have downcast of non-adt non-coroutine type"), }, - PlaceTy { ty, variant_index: None } => match *ty.kind() { + PlaceTy { ty, variant_index: None } => match ty.kind() { ty::Adt(adt_def, args) if !adt_def.is_enum() => { (adt_def.variant(FIRST_VARIANT), args) } @@ -1605,7 +1605,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } let func_ty = func.ty(body, self.infcx.tcx); - if let ty::FnDef(def_id, _) = *func_ty.kind() { + if let ty::FnDef(def_id, _) = func_ty.kind() { // Some of the SIMD intrinsics are special: they need a particular argument to be a constant. // (Eventually this should use const-generics, but those are not up for the task yet: // https://github.com/rust-lang/rust/issues/85229.) @@ -2104,7 +2104,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let outlives_predicate = tcx.mk_predicate(Binder::dummy( ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives( - ty::OutlivesPredicate(self_ty, *region), + ty::OutlivesPredicate(self_ty, region), )), )); self.prove_predicate( @@ -2125,8 +2125,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { return; }; if let Err(terr) = self.sub_types( - *ty_from, - *ty_to, + ty_from, + ty_to, location.to_locations(), ConstraintCategory::Cast { unsize_to: None }, ) { @@ -2146,7 +2146,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { let opt_ty_elem_mut = match ty_from.kind() { ty::RawPtr(array_ty, array_mut) => match array_ty.kind() { - ty::Array(ty_elem, _) => Some((ty_elem, *array_mut)), + ty::Array(ty_elem, _) => Some((ty_elem, array_mut)), _ => None, }, _ => None, @@ -2163,7 +2163,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { }; let (ty_to, ty_to_mut) = match ty.kind() { - ty::RawPtr(ty_to, ty_to_mut) => (ty_to, *ty_to_mut), + ty::RawPtr(ty_to, ty_to_mut) => (ty_to, ty_to_mut), _ => { span_mirbug!( self, @@ -2187,8 +2187,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } if let Err(terr) = self.sub_types( - *ty_elem, - *ty_to, + ty_elem, + ty_to, location.to_locations(), ConstraintCategory::Cast { unsize_to: None }, ) { @@ -2903,7 +2903,7 @@ fn freshen_single_trait_object_lifetime<'tcx>( infcx: &BorrowckInferCtxt<'tcx>, ty: Ty<'tcx>, ) -> Ty<'tcx> { - let &ty::Dynamic(tty, _, dyn_kind @ ty::Dyn) = ty.kind() else { bug!("expected trait object") }; + let ty::Dynamic(tty, _, dyn_kind @ ty::Dyn) = ty.kind() else { bug!("expected trait object") }; let fresh = infcx .next_region_var(rustc_infer::infer::RegionVariableOrigin::MiscVariable(DUMMY_SP), || { diff --git a/compiler/rustc_borrowck/src/type_check/relate_tys.rs b/compiler/rustc_borrowck/src/type_check/relate_tys.rs index 8da4d80badfec..806da86e90487 100644 --- a/compiler/rustc_borrowck/src/type_check/relate_tys.rs +++ b/compiler/rustc_borrowck/src/type_check/relate_tys.rs @@ -143,8 +143,8 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> { }; let (a, b) = match (a.kind(), b.kind()) { - (&ty::Alias(ty::Opaque, ..), _) => (a, enable_subtyping(b, true)?), - (_, &ty::Alias(ty::Opaque, ..)) => (enable_subtyping(a, false)?, b), + (ty::Alias(ty::Opaque, ..), _) => (a, enable_subtyping(b, true)?), + (_, ty::Alias(ty::Opaque, ..)) => (enable_subtyping(a, false)?, b), _ => unreachable!( "expected at least one opaque type in `relate_opaques`, got {a} and {b}." ), @@ -346,20 +346,20 @@ impl<'bccx, 'tcx> TypeRelation> for NllTypeRelating<'_, 'bccx, 'tcx } match (a.kind(), b.kind()) { - (_, &ty::Infer(ty::TyVar(_))) => { + (_, ty::Infer(ty::TyVar(_))) => { span_bug!( self.span(), "should not be relating type variables on the right in MIR typeck" ); } - (&ty::Infer(ty::TyVar(a_vid)), _) => { + (ty::Infer(ty::TyVar(a_vid)), _) => { infcx.instantiate_ty_var(self, true, a_vid, self.ambient_variance, b)? } ( - &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }), - &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }), + ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }), + ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }), ) if a_def_id == b_def_id || infcx.next_trait_solver() => { infcx.super_combine_tys(self, a, b).map(|_| ()).or_else(|err| { // This behavior is only there for the old solver, the new solver @@ -373,8 +373,8 @@ impl<'bccx, 'tcx> TypeRelation> for NllTypeRelating<'_, 'bccx, 'tcx if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) } })?; } - (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _) - | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) + (ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _) + | (_, ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) if def_id.is_local() && !self.type_checker.infcx.next_trait_solver() => { self.relate_opaques(a, b)?; diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index 1ad80cb122ab6..f2fcb4a62fd0e 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -592,7 +592,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { let defining_ty = self.infcx.replace_free_regions_with_nll_infer_vars(FR, defining_ty); - match *defining_ty.kind() { + match defining_ty.kind() { ty::Closure(def_id, args) => DefiningTy::Closure(def_id, args), ty::Coroutine(def_id, args) => DefiningTy::Coroutine(def_id, args), ty::CoroutineClosure(def_id, args) => { @@ -715,7 +715,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { let (&output, tuplized_inputs) = inputs_and_output.skip_binder().split_last().unwrap(); assert_eq!(tuplized_inputs.len(), 1, "multiple closure inputs"); - let &ty::Tuple(inputs) = tuplized_inputs[0].kind() else { + let ty::Tuple(inputs) = tuplized_inputs[0].kind() else { bug!("closure inputs not a tuple: {:?}", tuplized_inputs[0]); }; diff --git a/compiler/rustc_codegen_cranelift/src/abi/mod.rs b/compiler/rustc_codegen_cranelift/src/abi/mod.rs index 24cf3f061a567..6aec4c451ab54 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/mod.rs @@ -249,7 +249,7 @@ pub(crate) fn codegen_fn_prelude<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, start_ // individual function arguments. let tupled_arg_tys = match arg_ty.kind() { - ty::Tuple(ref tys) => tys, + ty::Tuple(tys) => tys, _ => bug!("spread argument isn't a tuple?! but {:?}", arg_ty), }; @@ -370,7 +370,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( let ret_place = codegen_place(fx, destination); // Handle special calls like intrinsics and empty drop glue. - let instance = if let ty::FnDef(def_id, fn_args) = *func.layout().ty.kind() { + let instance = if let ty::FnDef(def_id, fn_args) = func.layout().ty.kind() { let instance = ty::Instance::expect_resolve( fx.tcx, ty::ParamEnv::reveal_all(), @@ -466,7 +466,7 @@ pub(crate) fn codegen_terminator_call<'tcx>( }; let tupled_arguments = match pack_arg.value.layout().ty.kind() { - ty::Tuple(ref tupled_arguments) => tupled_arguments, + ty::Tuple(tupled_arguments) => tupled_arguments, _ => bug!("argument to function with \"rust-call\" ABI is not a tuple"), }; diff --git a/compiler/rustc_codegen_cranelift/src/base.rs b/compiler/rustc_codegen_cranelift/src/base.rs index 9bc7b57c53745..2c4e9e54bcddf 100644 --- a/compiler/rustc_codegen_cranelift/src/base.rs +++ b/compiler/rustc_codegen_cranelift/src/base.rs @@ -657,7 +657,7 @@ fn codegen_stmt<'tcx>( ) => { let from_ty = fx.monomorphize(operand.ty(&fx.mir.local_decls, fx.tcx)); let to_layout = fx.layout_of(fx.monomorphize(to_ty)); - match *from_ty.kind() { + match from_ty.kind() { ty::FnDef(def_id, args) => { let func_ref = fx.get_function_ref( Instance::resolve_for_fn_ptr( @@ -745,7 +745,7 @@ fn codegen_stmt<'tcx>( _to_ty, ) => { let operand = codegen_operand(fx, operand); - match *operand.layout().ty.kind() { + match operand.layout().ty.kind() { ty::Closure(def_id, args) => { let instance = Instance::resolve_closure( fx.tcx, @@ -941,7 +941,7 @@ fn codegen_stmt<'tcx>( } fn codegen_array_len<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, place: CPlace<'tcx>) -> Value { - match *place.layout().ty.kind() { + match place.layout().ty.kind() { ty::Array(_elem_ty, len) => { let len = fx.monomorphize(len).eval_target_usize(fx.tcx, ParamEnv::reveal_all()) as i64; fx.bcx.ins().iconst(fx.pointer_type, len) @@ -991,16 +991,16 @@ pub(crate) fn codegen_place<'tcx>( match cplace.layout().ty.kind() { ty::Array(elem_ty, _len) => { assert!(!from_end, "array subslices are never `from_end`"); - let elem_layout = fx.layout_of(*elem_ty); + let elem_layout = fx.layout_of(elem_ty); let ptr = cplace.to_ptr(); cplace = CPlace::for_ptr( ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * (from as i64)), - fx.layout_of(Ty::new_array(fx.tcx, *elem_ty, to - from)), + fx.layout_of(Ty::new_array(fx.tcx, elem_ty, to - from)), ); } ty::Slice(elem_ty) => { assert!(from_end, "slice subslices should be `from_end`"); - let elem_layout = fx.layout_of(*elem_ty); + let elem_layout = fx.layout_of(elem_ty); let (ptr, len) = cplace.to_ptr_unsized(); cplace = CPlace::for_ptr_with_extra( ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * (from as i64)), diff --git a/compiler/rustc_codegen_cranelift/src/common.rs b/compiler/rustc_codegen_cranelift/src/common.rs index b9000a3874f5d..12f26c8c09636 100644 --- a/compiler/rustc_codegen_cranelift/src/common.rs +++ b/compiler/rustc_codegen_cranelift/src/common.rs @@ -71,7 +71,7 @@ fn clif_type_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option pointer_ty(tcx), ty::RawPtr(pointee_ty, _) | ty::Ref(_, pointee_ty, _) => { - if has_ptr_meta(tcx, *pointee_ty) { + if has_ptr_meta(tcx, pointee_ty) { return None; } else { pointer_ty(tcx) @@ -91,7 +91,7 @@ fn clif_pair_type_from_ty<'tcx>( (clif_type_from_ty(tcx, types[0])?, clif_type_from_ty(tcx, types[1])?) } ty::RawPtr(pointee_ty, _) | ty::Ref(_, pointee_ty, _) => { - if has_ptr_meta(tcx, *pointee_ty) { + if has_ptr_meta(tcx, pointee_ty) { (pointer_ty(tcx), pointer_ty(tcx)) } else { return None; diff --git a/compiler/rustc_codegen_cranelift/src/debuginfo/types.rs b/compiler/rustc_codegen_cranelift/src/debuginfo/types.rs index 7baf0a3868d2c..70dcdcd78bf2d 100644 --- a/compiler/rustc_codegen_cranelift/src/debuginfo/types.rs +++ b/compiler/rustc_codegen_cranelift/src/debuginfo/types.rs @@ -43,20 +43,20 @@ impl DebugContext { tcx, type_dbg, ty, - *elem_ty, + elem_ty, len.eval_target_usize(tcx, ty::ParamEnv::reveal_all()), ), // ty::Slice(_) | ty::Str // ty::Dynamic // ty::Foreign ty::RawPtr(pointee_type, _) | ty::Ref(_, pointee_type, _) => { - self.pointer_type(tcx, type_dbg, ty, *pointee_type) + self.pointer_type(tcx, type_dbg, ty, pointee_type) } // ty::Adt(def, args) if def.is_box() && args.get(1).map_or(true, |arg| cx.layout_of(arg.expect_ty()).is_1zst()) // ty::FnDef(..) | ty::FnPtr(..) // ty::Closure(..) // ty::Adt(def, ..) - ty::Tuple(components) => self.tuple_type(tcx, type_dbg, ty, *components), + ty::Tuple(components) => self.tuple_type(tcx, type_dbg, ty, components), // ty::Param(_) // FIXME implement remaining types and add unreachable!() to the fallback branch _ => self.placeholder_for_type(tcx, type_dbg, ty), diff --git a/compiler/rustc_codegen_cranelift/src/global_asm.rs b/compiler/rustc_codegen_cranelift/src/global_asm.rs index 0c99a5ce12f6e..00b313aea36ce 100644 --- a/compiler/rustc_codegen_cranelift/src/global_asm.rs +++ b/compiler/rustc_codegen_cranelift/src/global_asm.rs @@ -65,7 +65,7 @@ pub(crate) fn codegen_global_asm_item(tcx: TyCtxt<'_>, global_asm: &mut String, let ty = tcx.typeck_body(anon_const.body).node_type(anon_const.hir_id); let instance = match ty.kind() { - &ty::FnDef(def_id, args) => Instance::new(def_id, args), + ty::FnDef(def_id, args) => Instance::new(def_id, args), _ => span_bug!(op_sp, "asm sym is not a function"), }; let symbol = tcx.symbol_name(instance); diff --git a/compiler/rustc_codegen_cranelift/src/inline_asm.rs b/compiler/rustc_codegen_cranelift/src/inline_asm.rs index 16edec47e1029..aaafd9d741b04 100644 --- a/compiler/rustc_codegen_cranelift/src/inline_asm.rs +++ b/compiler/rustc_codegen_cranelift/src/inline_asm.rs @@ -89,7 +89,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>( } let const_ = fx.monomorphize(value.const_); - if let ty::FnDef(def_id, args) = *const_.ty().kind() { + if let ty::FnDef(def_id, args) = const_.ty().kind() { let instance = ty::Instance::resolve_for_fn_ptr( fx.tcx, ty::ParamEnv::reveal_all(), @@ -253,7 +253,7 @@ pub(crate) fn codegen_naked_asm<'tcx>( ty::ParamEnv::reveal_all(), ty::EarlyBinder::bind(value.const_), ); - if let ty::FnDef(def_id, args) = *const_.ty().kind() { + if let ty::FnDef(def_id, args) = const_.ty().kind() { let instance = ty::Instance::resolve_for_fn_ptr( tcx, ty::ParamEnv::reveal_all(), diff --git a/compiler/rustc_codegen_cranelift/src/unsize.rs b/compiler/rustc_codegen_cranelift/src/unsize.rs index e09cd16e89a64..848fe0921dfe4 100644 --- a/compiler/rustc_codegen_cranelift/src/unsize.rs +++ b/compiler/rustc_codegen_cranelift/src/unsize.rs @@ -67,11 +67,11 @@ fn unsize_ptr<'tcx>( dst_layout: TyAndLayout<'tcx>, old_info: Option, ) -> (Value, Value) { - match (&src_layout.ty.kind(), &dst_layout.ty.kind()) { - (&ty::Ref(_, a, _), &ty::Ref(_, b, _)) - | (&ty::Ref(_, a, _), &ty::RawPtr(b, _)) - | (&ty::RawPtr(a, _), &ty::RawPtr(b, _)) => (src, unsized_info(fx, *a, *b, old_info)), - (&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => { + match (src_layout.ty.kind(), dst_layout.ty.kind()) { + (ty::Ref(_, a, _), ty::Ref(_, b, _)) + | (ty::Ref(_, a, _), ty::RawPtr(b, _)) + | (ty::RawPtr(a, _), ty::RawPtr(b, _)) => (src, unsized_info(fx, a, b, old_info)), + (ty::Adt(def_a, _), ty::Adt(def_b, _)) => { assert_eq!(def_a, def_b); if src_layout == dst_layout { diff --git a/compiler/rustc_codegen_cranelift/src/value_and_place.rs b/compiler/rustc_codegen_cranelift/src/value_and_place.rs index fd77502224e4c..d6c3f1d1bb0cb 100644 --- a/compiler/rustc_codegen_cranelift/src/value_and_place.rs +++ b/compiler/rustc_codegen_cranelift/src/value_and_place.rs @@ -803,7 +803,7 @@ impl<'tcx> CPlace<'tcx> { ) -> CPlace<'tcx> { let (elem_layout, ptr) = match self.layout().ty.kind() { ty::Array(elem_ty, _) => { - let elem_layout = fx.layout_of(*elem_ty); + let elem_layout = fx.layout_of(elem_ty); match self.inner { CPlaceInner::Addr(addr, None) => (elem_layout, addr), CPlaceInner::Var(_, _) @@ -811,7 +811,7 @@ impl<'tcx> CPlace<'tcx> { | CPlaceInner::VarPair(_, _, _) => bug!("Can't index into {self:?}"), } } - ty::Slice(elem_ty) => (fx.layout_of(*elem_ty), self.to_ptr_unsized().0), + ty::Slice(elem_ty) => (fx.layout_of(elem_ty), self.to_ptr_unsized().0), _ => bug!("place_index({:?})", self.layout().ty), }; @@ -869,10 +869,10 @@ pub(crate) fn assert_assignable<'tcx>( } match (from_ty.kind(), to_ty.kind()) { (ty::Ref(_, a, _), ty::Ref(_, b, _)) | (ty::RawPtr(a, _), ty::RawPtr(b, _)) => { - assert_assignable(fx, *a, *b, limit - 1); + assert_assignable(fx, a, b, limit - 1); } (ty::Ref(_, a, _), ty::RawPtr(b, _)) | (ty::RawPtr(a, _), ty::Ref(_, b, _)) => { - assert_assignable(fx, *a, *b, limit - 1); + assert_assignable(fx, a, b, limit - 1); } (ty::FnPtr(..), ty::FnPtr(..)) => { let from_sig = fx.tcx.normalize_erasing_late_bound_regions( @@ -920,7 +920,7 @@ pub(crate) fn assert_assignable<'tcx>( ); // fn(&T) -> for<'l> fn(&'l T) is allowed } - (&ty::Dynamic(from_traits, _, _from_kind), &ty::Dynamic(to_traits, _, _to_kind)) => { + (ty::Dynamic(from_traits, _, _from_kind), ty::Dynamic(to_traits, _, _to_kind)) => { // FIXME(dyn-star): Do the right thing with DynKinds for (from, to) in from_traits.iter().zip(to_traits) { let from = @@ -934,7 +934,7 @@ pub(crate) fn assert_assignable<'tcx>( } // dyn for<'r> Trait<'r> -> dyn Trait<'_> is allowed } - (&ty::Tuple(types_a), &ty::Tuple(types_b)) => { + (ty::Tuple(types_a), ty::Tuple(types_b)) => { let mut types_a = types_a.iter(); let mut types_b = types_b.iter(); loop { @@ -945,7 +945,7 @@ pub(crate) fn assert_assignable<'tcx>( } } } - (&ty::Adt(adt_def_a, args_a), &ty::Adt(adt_def_b, args_b)) + (ty::Adt(adt_def_a, args_a), ty::Adt(adt_def_b, args_b)) if adt_def_a.did() == adt_def_b.did() => { let mut types_a = args_a.types(); @@ -958,10 +958,8 @@ pub(crate) fn assert_assignable<'tcx>( } } } - (ty::Array(a, _), ty::Array(b, _)) => assert_assignable(fx, *a, *b, limit - 1), - (&ty::Closure(def_id_a, args_a), &ty::Closure(def_id_b, args_b)) - if def_id_a == def_id_b => - { + (ty::Array(a, _), ty::Array(b, _)) => assert_assignable(fx, a, b, limit - 1), + (ty::Closure(def_id_a, args_a), ty::Closure(def_id_b, args_b)) if def_id_a == def_id_b => { let mut types_a = args_a.types(); let mut types_b = args_b.types(); loop { @@ -972,7 +970,7 @@ pub(crate) fn assert_assignable<'tcx>( } } } - (&ty::Coroutine(def_id_a, args_a), &ty::Coroutine(def_id_b, args_b)) + (ty::Coroutine(def_id_a, args_a), ty::Coroutine(def_id_b, args_b)) if def_id_a == def_id_b => { let mut types_a = args_a.types(); @@ -985,7 +983,7 @@ pub(crate) fn assert_assignable<'tcx>( } } } - (&ty::CoroutineWitness(def_id_a, args_a), &ty::CoroutineWitness(def_id_b, args_b)) + (ty::CoroutineWitness(def_id_a, args_a), ty::CoroutineWitness(def_id_b, args_b)) if def_id_a == def_id_b => { let mut types_a = args_a.types(); diff --git a/compiler/rustc_codegen_gcc/src/int.rs b/compiler/rustc_codegen_gcc/src/int.rs index 92d5c1cbbb80a..ee2dbd1ac7fb7 100644 --- a/compiler/rustc_codegen_gcc/src/int.rs +++ b/compiler/rustc_codegen_gcc/src/int.rs @@ -265,7 +265,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> { use rustc_middle::ty::UintTy::*; use rustc_middle::ty::{Int, Uint}; - let new_kind = match *typ.kind() { + let new_kind = match typ.kind() { Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.pointer_width)), Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.pointer_width)), t @ (Uint(_) | Int(_)) => t, diff --git a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs index 9352a67e362fb..c592b814e7829 100644 --- a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs +++ b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs @@ -106,7 +106,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { let tcx = self.tcx; let callee_ty = instance.ty(tcx, ty::ParamEnv::reveal_all()); - let (def_id, fn_args) = match *callee_ty.kind() { + let (def_id, fn_args) = match callee_ty.kind() { ty::FnDef(def_id, fn_args) => (def_id, fn_args), _ => bug!("expected fn item type, found {}", callee_ty), }; @@ -599,7 +599,7 @@ fn int_type_width_signed<'gcc, 'tcx>( ty: Ty<'tcx>, cx: &CodegenCx<'gcc, 'tcx>, ) -> Option<(u64, bool)> { - match *ty.kind() { + match ty.kind() { ty::Int(t) => Some(( match t { rustc_middle::ty::IntTy::Isize => u64::from(cx.tcx.sess.target.pointer_width), diff --git a/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs b/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs index 8da1df3be1534..a2e4c8da6cf23 100644 --- a/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs +++ b/compiler/rustc_codegen_gcc/src/intrinsic/simd.rs @@ -71,11 +71,11 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( let expected_bytes = len / 8 + ((len % 8 > 0) as u64); let mask_ty = arg_tys[0]; - let mut mask = match *mask_ty.kind() { + let mut mask = match mask_ty.kind() { ty::Int(i) if i.bit_width() == Some(expected_int_bits) => args[0].immediate(), ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => args[0].immediate(), ty::Array(elem, len) - if matches!(*elem.kind(), ty::Uint(ty::UintTy::U8)) + if matches!(elem.kind(), ty::Uint(ty::UintTy::U8)) && len.try_eval_target_usize(bx.tcx, ty::ParamEnv::reveal_all()) == Some(expected_bytes) => { @@ -355,8 +355,8 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( if name == sym::simd_shuffle { // Make sure this is actually an array, since typeck only checks the length-suffixed // version of this intrinsic. - let n: u64 = match *args[2].layout.ty.kind() { - ty::Array(ty, len) if matches!(*ty.kind(), ty::Uint(ty::UintTy::U32)) => { + let n: u64 = match args[2].layout.ty.kind() { + ty::Array(ty, len) if matches!(ty.kind(), ty::Uint(ty::UintTy::U32)) => { len.try_eval_target_usize(bx.cx.tcx, ty::ParamEnv::reveal_all()).unwrap_or_else( || span_bug!(span, "could not evaluate shuffle index array length"), ) @@ -429,7 +429,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( m_len == v_len, InvalidMonomorphization::MismatchedLengths { span, name, m_len, v_len } ); - match *m_elem_ty.kind() { + match m_elem_ty.kind() { ty::Int(_) => {} _ => return_error!(InvalidMonomorphization::MaskType { span, name, ty: m_elem_ty }), } @@ -452,7 +452,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( } ); - match *in_elem.kind() { + match in_elem.kind() { ty::RawPtr(p_ty, _) => { let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| { bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty) @@ -466,7 +466,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( return_error!(InvalidMonomorphization::ExpectedPointer { span, name, ty: in_elem }) } } - match *out_elem.kind() { + match out_elem.kind() { ty::RawPtr(p_ty, _) => { let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| { bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty) @@ -509,13 +509,13 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( } ); - match *in_elem.kind() { + match in_elem.kind() { ty::RawPtr(_, _) => {} _ => { return_error!(InvalidMonomorphization::ExpectedPointer { span, name, ty: in_elem }) } } - match *out_elem.kind() { + match out_elem.kind() { ty::Uint(ty::UintTy::Usize) => {} _ => return_error!(InvalidMonomorphization::ExpectedUsize { span, name, ty: out_elem }), } @@ -548,11 +548,11 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( } ); - match *in_elem.kind() { + match in_elem.kind() { ty::Uint(ty::UintTy::Usize) => {} _ => return_error!(InvalidMonomorphization::ExpectedUsize { span, name, ty: in_elem }), } - match *out_elem.kind() { + match out_elem.kind() { ty::RawPtr(_, _) => {} _ => { return_error!(InvalidMonomorphization::ExpectedPointer { span, name, ty: out_elem }) @@ -597,13 +597,13 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( Unsupported, } - let in_style = match *in_elem.kind() { + let in_style = match in_elem.kind() { ty::Int(_) | ty::Uint(_) => Style::Int, ty::Float(_) => Style::Float, _ => Style::Unsupported, }; - let out_style = match *out_elem.kind() { + let out_style = match out_elem.kind() { ty::Int(_) | ty::Uint(_) => Style::Int, ty::Float(_) => Style::Float, _ => Style::Unsupported, @@ -630,7 +630,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( macro_rules! arith_binary { ($($name: ident: $($($p: ident),* => $call: ident),*;)*) => { $(if name == sym::$name { - match *in_elem.kind() { + match in_elem.kind() { $($(ty::$p(_))|* => { return Ok(bx.$call(args[0].immediate(), args[1].immediate())) })* @@ -678,13 +678,13 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( << bx.context.new_rvalue_from_int(result_type, i as i32)); } - match *ret_ty.kind() { + match ret_ty.kind() { ty::Uint(i) if i.bit_width() == Some(expected_int_bits) => { // Zero-extend iN to the bitmask type: return Ok(result); } ty::Array(elem, len) - if matches!(*elem.kind(), ty::Uint(ty::UintTy::U8)) + if matches!(elem.kind(), ty::Uint(ty::UintTy::U8)) && len.try_eval_target_usize(bx.tcx, ty::ParamEnv::reveal_all()) == Some(expected_bytes) => { @@ -723,8 +723,8 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( return Err(()); }}; } - let (elem_ty_str, elem_ty) = if let ty::Float(ref f) = *in_elem.kind() { - let elem_ty = bx.cx.type_float_from_ty(*f); + let (elem_ty_str, elem_ty) = if let ty::Float(f) = in_elem.kind() { + let elem_ty = bx.cx.type_float_from_ty(f); match f.bit_width() { 32 => ("f", elem_ty), 64 => ("", elem_ty), @@ -732,7 +732,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( return_error!(InvalidMonomorphization::FloatingPointVector { span, name, - f_ty: *f, + f_ty: f, in_ty }); } @@ -819,7 +819,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( vec_len: u64, ) -> Type<'gcc> { // FIXME: use cx.layout_of(ty).llvm_type() ? - let elem_ty = match *elem_ty.kind() { + let elem_ty = match elem_ty.kind() { ty::Int(v) => cx.type_int_from_ty(v), ty::Uint(v) => cx.type_uint_from_ty(v), ty::Float(v) => cx.type_float_from_ty(v), @@ -930,7 +930,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( // This counts how many pointers fn ptr_count(t: Ty<'_>) -> usize { - match *t.kind() { + match t.kind() { ty::RawPtr(p_ty, _) => 1 + ptr_count(p_ty), _ => 0, } @@ -938,7 +938,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( // Non-ptr type fn non_ptr(t: Ty<'_>) -> Ty<'_> { - match *t.kind() { + match t.kind() { ty::RawPtr(p_ty, _) => non_ptr(p_ty), _ => t, } @@ -948,7 +948,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( // to the element type of the first argument let (_, element_ty0) = arg_tys[0].simd_size_and_type(bx.tcx()); let (_, element_ty1) = arg_tys[1].simd_size_and_type(bx.tcx()); - let (pointer_count, underlying_ty) = match *element_ty1.kind() { + let (pointer_count, underlying_ty) = match element_ty1.kind() { ty::RawPtr(p_ty, _) if p_ty == in_elem => { (ptr_count(element_ty1), non_ptr(element_ty1)) } @@ -974,7 +974,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( // The element type of the third argument must be a signed integer type of any width: let (_, element_ty2) = arg_tys[2].simd_size_and_type(bx.tcx()); - match *element_ty2.kind() { + match element_ty2.kind() { ty::Int(_) => (), _ => { require!( @@ -1046,7 +1046,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( // This counts how many pointers fn ptr_count(t: Ty<'_>) -> usize { - match *t.kind() { + match t.kind() { ty::RawPtr(p_ty, _) => 1 + ptr_count(p_ty), _ => 0, } @@ -1054,7 +1054,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( // Non-ptr type fn non_ptr(t: Ty<'_>) -> Ty<'_> { - match *t.kind() { + match t.kind() { ty::RawPtr(p_ty, _) => non_ptr(p_ty), _ => t, } @@ -1065,7 +1065,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( let (_, element_ty0) = arg_tys[0].simd_size_and_type(bx.tcx()); let (_, element_ty1) = arg_tys[1].simd_size_and_type(bx.tcx()); let (_, element_ty2) = arg_tys[2].simd_size_and_type(bx.tcx()); - let (pointer_count, underlying_ty) = match *element_ty1.kind() { + let (pointer_count, underlying_ty) = match element_ty1.kind() { ty::RawPtr(p_ty, mutbl) if p_ty == in_elem && mutbl == hir::Mutability::Mut => { (ptr_count(element_ty1), non_ptr(element_ty1)) } @@ -1090,7 +1090,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( assert_eq!(underlying_ty, non_ptr(element_ty0)); // The element type of the third argument must be a signed integer type of any width: - match *element_ty2.kind() { + match element_ty2.kind() { ty::Int(_) => (), _ => { require!( @@ -1148,7 +1148,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( macro_rules! arith_unary { ($($name: ident: $($($p: ident),* => $call: ident),*;)*) => { $(if name == sym::$name { - match *in_elem.kind() { + match in_elem.kind() { $($(ty::$p(_))|* => { return Ok(bx.$call(args[0].immediate())) })* @@ -1169,7 +1169,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( let rhs = args[1].immediate(); let is_add = name == sym::simd_saturating_add; let ptr_bits = bx.tcx().data_layout.pointer_size.bits() as _; - let (signed, elem_width, elem_ty) = match *in_elem.kind() { + let (signed, elem_width, elem_ty) = match in_elem.kind() { ty::Int(i) => (true, i.bit_width().unwrap_or(ptr_bits) / 8, bx.cx.type_int_from_ty(i)), ty::Uint(i) => { (false, i.bit_width().unwrap_or(ptr_bits) / 8, bx.cx.type_uint_from_ty(i)) @@ -1272,7 +1272,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( ret_ty == in_elem, InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty } ); - return match *in_elem.kind() { + return match in_elem.kind() { ty::Int(_) | ty::Uint(_) => { let r = bx.vector_reduce_op(args[0].immediate(), $vec_op); if $ordered { @@ -1341,7 +1341,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( ret_ty == in_elem, InvalidMonomorphization::ReturnType { span, name, in_elem, in_ty, ret_ty } ); - return match *in_elem.kind() { + return match in_elem.kind() { ty::Int(_) | ty::Uint(_) => Ok(bx.$int_red(args[0].immediate())), ty::Float(_) => Ok(bx.$float_red(args[0].immediate())), _ => return_error!(InvalidMonomorphization::UnsupportedSymbol { @@ -1370,7 +1370,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( ); args[0].immediate() } else { - match *in_elem.kind() { + match in_elem.kind() { ty::Int(_) | ty::Uint(_) => {} _ => return_error!(InvalidMonomorphization::UnsupportedSymbol { span, @@ -1384,7 +1384,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>( args[0].immediate() }; - return match *in_elem.kind() { + return match in_elem.kind() { ty::Int(_) | ty::Uint(_) => { let r = bx.vector_reduce_op(input, $op); Ok(if !$boolean { diff --git a/compiler/rustc_codegen_gcc/src/type_of.rs b/compiler/rustc_codegen_gcc/src/type_of.rs index b7b1be5369c42..04517929fce95 100644 --- a/compiler/rustc_codegen_gcc/src/type_of.rs +++ b/compiler/rustc_codegen_gcc/src/type_of.rs @@ -84,7 +84,7 @@ fn uncached_gcc_type<'gcc, 'tcx>( Abi::Uninhabited | Abi::Aggregate { .. } => {} } - let name = match *layout.ty.kind() { + let name = match layout.ty.kind() { // FIXME(eddyb) producing readable type names for trait objects can result // in problematically distinct types due to HRTB and subtyping (see #47638). // ty::Dynamic(..) | @@ -97,14 +97,14 @@ fn uncached_gcc_type<'gcc, 'tcx>( if !cx.sess().fewer_names() => { let mut name = with_no_trimmed_paths!(layout.ty.to_string()); - if let (&ty::Adt(def, _), &Variants::Single { index }) = + if let (ty::Adt(def, _), &Variants::Single { index }) = (layout.ty.kind(), &layout.variants) { if def.is_enum() && !def.variants().is_empty() { write!(&mut name, "::{}", def.variant(index).name).unwrap(); } } - if let (&ty::Coroutine(_, _), &Variants::Single { index }) = + if let (ty::Coroutine(_, _), &Variants::Single { index }) = (layout.ty.kind(), &layout.variants) { write!(&mut name, "::{}", ty::CoroutineArgs::variant_name(index)).unwrap(); @@ -209,7 +209,7 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> { if let Some(&ty) = cx.scalar_types.borrow().get(&self.ty) { return ty; } - let ty = match *self.ty.kind() { + let ty = match self.ty.kind() { // NOTE: we cannot remove this match like in the LLVM codegen because the call // to fn_ptr_backend_type handle the on-stack attribute. // TODO(antoyo): find a less hackish way to hande the on-stack attribute. diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index cc081f29e128e..0c0870d85dddd 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -399,7 +399,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { let new_kind = match ty.kind() { Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.pointer_width)), Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.pointer_width)), - t @ (Uint(_) | Int(_)) => *t, + t @ (Uint(_) | Int(_)) => t, _ => panic!("tried to get overflow intrinsic for op applied to non-int type"), }; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 87bea22d8ddaf..6e9ff8ae12625 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -119,7 +119,7 @@ fn build_fixed_size_array_di_node<'ll, 'tcx>( bug!("build_fixed_size_array_di_node() called with non-ty::Array type `{:?}`", array_type) }; - let element_type_di_node = type_di_node(cx, *element_type); + let element_type_di_node = type_di_node(cx, element_type); return_if_di_node_created_in_meantime!(cx, unique_type_id); @@ -406,7 +406,7 @@ fn build_slice_type_di_node<'ll, 'tcx>( unique_type_id: UniqueTypeId<'tcx>, ) -> DINodeCreationResult<'ll> { let element_type = match slice_type.kind() { - ty::Slice(element_type) => *element_type, + ty::Slice(element_type) => element_type, ty::Str => cx.tcx.types.u8, _ => { bug!( @@ -435,7 +435,7 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D debug!("type_di_node: {:?} kind: {:?}", t, t.kind()); - let DINodeCreationResult { di_node, already_stored_in_typemap } = match *t.kind() { + let DINodeCreationResult { di_node, already_stored_in_typemap } = match t.kind() { ty::Never | ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) => { build_basic_type_di_node(cx, t) } @@ -816,7 +816,7 @@ fn build_foreign_type_di_node<'ll, 'tcx>( ) -> DINodeCreationResult<'ll> { debug!("build_foreign_type_di_node: {:?}", t); - let &ty::Foreign(def_id) = unique_type_id.expect_ty().kind() else { + let ty::Foreign(def_id) = unique_type_id.expect_ty().kind() else { bug!( "build_foreign_type_di_node() called with unexpected type: {:?}", unique_type_id.expect_ty() @@ -1109,7 +1109,7 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>( closure_or_coroutine_ty: Ty<'tcx>, closure_or_coroutine_di_node: &'ll DIType, ) -> SmallVec<&'ll DIType> { - let (&def_id, up_var_tys) = match closure_or_coroutine_ty.kind() { + let (def_id, up_var_tys) = match closure_or_coroutine_ty.kind() { ty::Coroutine(def_id, args) => (def_id, args.as_coroutine().prefix_tys()), ty::Closure(def_id, args) => (def_id, args.as_closure().upvar_tys()), ty::CoroutineClosure(def_id, args) => (def_id, args.as_coroutine_closure().upvar_tys()), @@ -1152,7 +1152,7 @@ fn build_tuple_type_di_node<'ll, 'tcx>( unique_type_id: UniqueTypeId<'tcx>, ) -> DINodeCreationResult<'ll> { let tuple_type = unique_type_id.expect_ty(); - let &ty::Tuple(component_types) = tuple_type.kind() else { + let ty::Tuple(component_types) = tuple_type.kind() else { bug!("build_tuple_type_di_node() called with non-tuple-type: {:?}", tuple_type) }; @@ -1198,8 +1198,7 @@ fn build_closure_env_di_node<'ll, 'tcx>( unique_type_id: UniqueTypeId<'tcx>, ) -> DINodeCreationResult<'ll> { let closure_env_type = unique_type_id.expect_ty(); - let &(ty::Closure(def_id, _) | ty::CoroutineClosure(def_id, _)) = closure_env_type.kind() - else { + let (ty::Closure(def_id, _) | ty::CoroutineClosure(def_id, _)) = closure_env_type.kind() else { bug!("build_closure_env_di_node() called with non-closure-type: {:?}", closure_env_type) }; let containing_scope = get_namespace_for_item(cx, def_id); @@ -1277,7 +1276,7 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>, ) -> SmallVec<&'ll DIType> { - if let ty::Adt(def, args) = *ty.kind() { + if let ty::Adt(def, args) = ty.kind() { if args.types().next().is_some() { let generics = cx.tcx.generics_of(def.did()); let names = get_parameter_names(cx, generics); diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs index 13006638bb3a3..f0f7d20d0a14b 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs @@ -183,7 +183,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( unique_type_id: UniqueTypeId<'tcx>, ) -> DINodeCreationResult<'ll> { let enum_type = unique_type_id.expect_ty(); - let &ty::Adt(enum_adt_def, _) = enum_type.kind() else { + let ty::Adt(enum_adt_def, _) = enum_type.kind() else { bug!("build_enum_type_di_node() called with non-enum type: `{:?}`", enum_type) }; @@ -665,7 +665,7 @@ fn build_union_fields_for_direct_tag_coroutine<'ll, 'tcx>( }; let (coroutine_def_id, coroutine_args) = match coroutine_type_and_layout.ty.kind() { - &ty::Coroutine(def_id, args) => (def_id, args.as_coroutine()), + ty::Coroutine(def_id, args) => (def_id, args.as_coroutine()), _ => unreachable!(), }; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs index fc3adaf068111..121fa961f3c23 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/mod.rs @@ -33,7 +33,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( unique_type_id: UniqueTypeId<'tcx>, ) -> DINodeCreationResult<'ll> { let enum_type = unique_type_id.expect_ty(); - let &ty::Adt(enum_adt_def, _) = enum_type.kind() else { + let ty::Adt(enum_adt_def, _) = enum_type.kind() else { bug!("build_enum_type_di_node() called with non-enum type: `{:?}`", enum_type) }; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs index d7e3b47e0bd5b..8dd31ede346b4 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs @@ -44,7 +44,7 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>( unique_type_id: UniqueTypeId<'tcx>, ) -> DINodeCreationResult<'ll> { let enum_type = unique_type_id.expect_ty(); - let &ty::Adt(enum_adt_def, _) = enum_type.kind() else { + let ty::Adt(enum_adt_def, _) = enum_type.kind() else { bug!("build_enum_type_di_node() called with non-enum type: `{:?}`", enum_type) }; @@ -124,7 +124,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>( unique_type_id: UniqueTypeId<'tcx>, ) -> DINodeCreationResult<'ll> { let coroutine_type = unique_type_id.expect_ty(); - let &ty::Coroutine(coroutine_def_id, coroutine_args) = coroutine_type.kind() else { + let ty::Coroutine(coroutine_def_id, coroutine_args) = coroutine_type.kind() else { bug!("build_coroutine_di_node() called with non-coroutine type: `{:?}`", coroutine_type) }; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs index b23e05182ca1b..6c1728f17d4c8 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs @@ -450,9 +450,9 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { let t = arg.layout.ty; let t = match t.kind() { ty::Array(ct, _) - if (*ct == cx.tcx.types.u8) || cx.layout_of(*ct).is_zst() => + if (ct == cx.tcx.types.u8) || cx.layout_of(ct).is_zst() => { - Ty::new_imm_ptr(cx.tcx, *ct) + Ty::new_imm_ptr(cx.tcx, ct) } _ => t, }; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs b/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs index e542aa96e8a23..5982d77dc90f3 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/utils.rs @@ -75,7 +75,7 @@ pub(crate) fn fat_pointer_kind<'ll, 'tcx>( return None; } - match *pointee_tail_ty.kind() { + match pointee_tail_ty.kind() { ty::Str | ty::Slice(_) => Some(FatPtrKind::Slice), ty::Dynamic(..) => Some(FatPtrKind::Dyn), ty::Foreign(_) => { diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index f5558723d11bf..b25832c0a1e13 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -160,7 +160,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> { let tcx = self.tcx; let callee_ty = instance.ty(tcx, ty::ParamEnv::reveal_all()); - let ty::FnDef(def_id, fn_args) = *callee_ty.kind() else { + let ty::FnDef(def_id, fn_args) = callee_ty.kind() else { bug!("expected fn item type, found {}", callee_ty); }; @@ -526,9 +526,9 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> { { let (size, elem_ty) = ty.simd_size_and_type(self.tcx()); let elem_ll_ty = match elem_ty.kind() { - ty::Float(f) => self.type_float_from_ty(*f), - ty::Int(i) => self.type_int_from_ty(*i), - ty::Uint(u) => self.type_uint_from_ty(*u), + ty::Float(f) => self.type_float_from_ty(f), + ty::Int(i) => self.type_int_from_ty(i), + ty::Uint(u) => self.type_uint_from_ty(u), ty::RawPtr(_, _) => self.type_ptr(), _ => unreachable!(), }; @@ -546,9 +546,9 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> { { let (size, elem_ty) = ret_ty.simd_size_and_type(self.tcx()); let elem_ll_ty = match elem_ty.kind() { - ty::Float(f) => self.type_float_from_ty(*f), - ty::Int(i) => self.type_int_from_ty(*i), - ty::Uint(u) => self.type_uint_from_ty(*u), + ty::Float(f) => self.type_float_from_ty(f), + ty::Int(i) => self.type_int_from_ty(i), + ty::Uint(u) => self.type_uint_from_ty(u), ty::RawPtr(_, _) => self.type_ptr(), _ => unreachable!(), }; @@ -1497,7 +1497,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>( } let (elem_ty_str, elem_ty) = if let ty::Float(f) = in_elem.kind() { - let elem_ty = bx.cx.type_float_from_ty(*f); + let elem_ty = bx.cx.type_float_from_ty(f); match f.bit_width() { 16 => ("f16", elem_ty), 32 => ("f32", elem_ty), @@ -1506,7 +1506,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>( _ => return_error!(InvalidMonomorphization::FloatingPointVector { span, name, - f_ty: *f, + f_ty: f, in_ty, }), } @@ -1575,7 +1575,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>( // https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Function.h#L182 // https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Intrinsics.h#L81 fn llvm_vector_str(bx: &Builder<'_, '_, '_>, elem_ty: Ty<'_>, vec_len: u64) -> String { - match *elem_ty.kind() { + match elem_ty.kind() { ty::Int(v) => format!( "v{}i{}", vec_len, @@ -1595,7 +1595,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>( } fn llvm_vector_ty<'ll>(cx: &CodegenCx<'ll, '_>, elem_ty: Ty<'_>, vec_len: u64) -> &'ll Type { - let elem_ty = match *elem_ty.kind() { + let elem_ty = match elem_ty.kind() { ty::Int(v) => cx.type_int_from_ty(v), ty::Uint(v) => cx.type_uint_from_ty(v), ty::Float(v) => cx.type_float_from_ty(v), @@ -1654,7 +1654,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>( require!( matches!( - *element_ty1.kind(), + element_ty1.kind(), ty::RawPtr(p_ty, _) if p_ty == in_elem && p_ty.kind() == element_ty0.kind() ), InvalidMonomorphization::ExpectedElementType { @@ -1761,7 +1761,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>( require!( matches!( - *pointer_ty.kind(), + pointer_ty.kind(), ty::RawPtr(p_ty, _) if p_ty == values_elem && p_ty.kind() == values_elem.kind() ), InvalidMonomorphization::ExpectedElementType { @@ -1854,7 +1854,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>( // The second argument must be a mutable pointer type matching the element type require!( matches!( - *pointer_ty.kind(), + pointer_ty.kind(), ty::RawPtr(p_ty, p_mutbl) if p_ty == values_elem && p_ty.kind() == values_elem.kind() && p_mutbl.is_mut() ), InvalidMonomorphization::ExpectedElementType { @@ -1952,7 +1952,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>( require!( matches!( - *element_ty1.kind(), + element_ty1.kind(), ty::RawPtr(p_ty, p_mutbl) if p_ty == in_elem && p_mutbl.is_mut() && p_ty.kind() == element_ty0.kind() ), @@ -2430,7 +2430,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>( sym::simd_bswap | sym::simd_bitreverse | sym::simd_ctlz | sym::simd_ctpop | sym::simd_cttz ) { let vec_ty = bx.cx.type_vector( - match *in_elem.kind() { + match in_elem.kind() { ty::Int(i) => bx.cx.type_int_from_ty(i), ty::Uint(i) => bx.cx.type_uint_from_ty(i), _ => return_error!(InvalidMonomorphization::UnsupportedOperation { @@ -2507,7 +2507,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>( let rhs = args[1].immediate(); let is_add = name == sym::simd_saturating_add; let ptr_bits = bx.tcx().data_layout.pointer_size.bits() as _; - let (signed, elem_width, elem_ty) = match *in_elem.kind() { + let (signed, elem_width, elem_ty) = match in_elem.kind() { ty::Int(i) => (true, i.bit_width().unwrap_or(ptr_bits), bx.cx.type_int_from_ty(i)), ty::Uint(i) => (false, i.bit_width().unwrap_or(ptr_bits), bx.cx.type_uint_from_ty(i)), _ => { diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs index 4755fa08afb7c..e0e0d9cdfbff4 100644 --- a/compiler/rustc_codegen_llvm/src/type_of.rs +++ b/compiler/rustc_codegen_llvm/src/type_of.rs @@ -34,14 +34,14 @@ fn uncached_llvm_type<'a, 'tcx>( if !cx.sess().fewer_names() => { let mut name = with_no_visible_paths!(with_no_trimmed_paths!(layout.ty.to_string())); - if let (&ty::Adt(def, _), &Variants::Single { index }) = + if let (ty::Adt(def, _), &Variants::Single { index }) = (layout.ty.kind(), &layout.variants) { if def.is_enum() && !def.variants().is_empty() { write!(&mut name, "::{}", def.variant(index).name).unwrap(); } } - if let (&ty::Coroutine(_, _), &Variants::Single { index }) = + if let (ty::Coroutine(_, _), &Variants::Single { index }) = (layout.ty.kind(), &layout.variants) { write!(&mut name, "::{}", ty::CoroutineArgs::variant_name(index)).unwrap(); diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index f1e7f87f56767..456d331b34d56 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -145,10 +145,10 @@ pub fn unsized_info<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let (source, target) = cx.tcx().struct_lockstep_tails_for_codegen(source, target, bx.param_env()); match (source.kind(), target.kind()) { - (&ty::Array(_, len), &ty::Slice(_)) => { + (ty::Array(_, len), ty::Slice(_)) => { cx.const_usize(len.eval_target_usize(cx.tcx(), ty::ParamEnv::reveal_all())) } - (&ty::Dynamic(data_a, _, src_dyn_kind), &ty::Dynamic(data_b, _, target_dyn_kind)) + (ty::Dynamic(data_a, _, src_dyn_kind), ty::Dynamic(data_b, _, target_dyn_kind)) if src_dyn_kind == target_dyn_kind => { let old_info = @@ -191,12 +191,12 @@ pub fn unsize_ptr<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( ) -> (Bx::Value, Bx::Value) { debug!("unsize_ptr: {:?} => {:?}", src_ty, dst_ty); match (src_ty.kind(), dst_ty.kind()) { - (&ty::Ref(_, a, _), &ty::Ref(_, b, _) | &ty::RawPtr(b, _)) - | (&ty::RawPtr(a, _), &ty::RawPtr(b, _)) => { + (ty::Ref(_, a, _), ty::Ref(_, b, _) | ty::RawPtr(b, _)) + | (ty::RawPtr(a, _), ty::RawPtr(b, _)) => { assert_eq!(bx.cx().type_is_sized(a), old_info.is_none()); (src, unsized_info(bx, a, b, old_info)) } - (&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => { + (ty::Adt(def_a, _), ty::Adt(def_b, _)) => { assert_eq!(def_a, def_b); // implies same number of fields let src_layout = bx.cx().layout_of(src_ty); let dst_layout = bx.cx().layout_of(dst_ty); @@ -258,7 +258,7 @@ pub fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let src_ty = src.layout.ty; let dst_ty = dst.layout.ty; match (src_ty.kind(), dst_ty.kind()) { - (&ty::Ref(..), &ty::Ref(..) | &ty::RawPtr(..)) | (&ty::RawPtr(..), &ty::RawPtr(..)) => { + (ty::Ref(..), ty::Ref(..) | ty::RawPtr(..)) | (ty::RawPtr(..), ty::RawPtr(..)) => { let (base, info) = match bx.load_operand(src).val { OperandValue::Pair(base, info) => unsize_ptr(bx, base, src_ty, dst_ty, Some(info)), OperandValue::Immediate(base) => unsize_ptr(bx, base, src_ty, dst_ty, None), @@ -267,7 +267,7 @@ pub fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( OperandValue::Pair(base, info).store(bx, dst); } - (&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => { + (ty::Adt(def_a, _), ty::Adt(def_b, _)) => { assert_eq!(def_a, def_b); // implies same number of fields for i in def_a.variant(FIRST_VARIANT).fields.indices() { diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index 359043a6d78ec..2e6f232b7697b 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -59,7 +59,7 @@ fn push_debuginfo_type_name<'tcx>( // .natvis visualizers (and perhaps other existing native debuggers?) let cpp_like_debuginfo = cpp_like_debuginfo(tcx); - match *t.kind() { + match t.kind() { ty::Bool => output.push_str("bool"), ty::Char => output.push_str("char"), ty::Str => { @@ -700,7 +700,7 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S // FIXME: directly extract the bits from a valtree instead of evaluating an // alreay evaluated `Const` in order to get the bits. let bits = ct.eval_bits(tcx, ty::ParamEnv::reveal_all()); - let val = Integer::from_int_ty(&tcx, *ity).size().sign_extend(bits) as i128; + let val = Integer::from_int_ty(&tcx, ity).size().sign_extend(bits) as i128; write!(output, "{val}") } ty::Uint(_) => { diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 817e2ca72ec12..7fc53379afb2e 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -832,7 +832,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { // Create the callee. This is a fn ptr or zero-sized and hence a kind of scalar. let callee = self.codegen_operand(bx, func); - let (instance, mut llfn) = match *callee.layout.ty.kind() { + let (instance, mut llfn) = match callee.layout.ty.kind() { ty::FnDef(def_id, args) => ( Some( ty::Instance::expect_resolve( @@ -1197,7 +1197,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } mir::InlineAsmOperand::SymFn { ref value } => { let const_ = self.monomorphize(value.const_); - if let ty::FnDef(def_id, args) = *const_.ty().kind() { + if let ty::FnDef(def_id, args) = const_.ty().kind() { let instance = ty::Instance::resolve_for_fn_ptr( bx.tcx(), ty::ParamEnv::reveal_all(), diff --git a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs index 4acbc04c505e8..3422304730c96 100644 --- a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs +++ b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs @@ -61,7 +61,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ) -> Result<(), ty::Instance<'tcx>> { let callee_ty = instance.ty(bx.tcx(), ty::ParamEnv::reveal_all()); - let ty::FnDef(def_id, fn_args) = *callee_ty.kind() else { + let ty::FnDef(def_id, fn_args) = callee_ty.kind() else { bug!("expected fn item type, found {}", callee_ty); }; diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 3c2c29ac7f7d2..49c59d3f667b3 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -465,7 +465,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { OperandValue::Immediate(lladdr) } mir::CastKind::PointerCoercion(PointerCoercion::ReifyFnPointer) => { - match *operand.layout.ty.kind() { + match operand.layout.ty.kind() { ty::FnDef(def_id, args) => { let instance = ty::Instance::resolve_for_fn_ptr( bx.tcx(), @@ -481,7 +481,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } } mir::CastKind::PointerCoercion(PointerCoercion::ClosureFnPointer(_)) => { - match *operand.layout.ty.kind() { + match operand.layout.ty.kind() { ty::Closure(def_id, args) => { let instance = Instance::resolve_closure( bx.cx().tcx(), diff --git a/compiler/rustc_codegen_ssa/src/mono_item.rs b/compiler/rustc_codegen_ssa/src/mono_item.rs index 64fcefdc860cd..f765fdd306ebc 100644 --- a/compiler/rustc_codegen_ssa/src/mono_item.rs +++ b/compiler/rustc_codegen_ssa/src/mono_item.rs @@ -76,7 +76,7 @@ impl<'a, 'tcx: 'a> MonoItemExt<'a, 'tcx> for MonoItem<'tcx> { .typeck_body(anon_const.body) .node_type(anon_const.hir_id); let instance = match ty.kind() { - &ty::FnDef(def_id, args) => Instance::new(def_id, args), + ty::FnDef(def_id, args) => Instance::new(def_id, args), _ => span_bug!(*op_sp, "asm sym is not a function"), }; diff --git a/compiler/rustc_const_eval/src/check_consts/check.rs b/compiler/rustc_const_eval/src/check_consts/check.rs index 32a9247bcc70a..c0d0a6d1bbc98 100644 --- a/compiler/rustc_const_eval/src/check_consts/check.rs +++ b/compiler/rustc_const_eval/src/check_consts/check.rs @@ -723,7 +723,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> { let fn_ty = func.ty(body, tcx); - let (mut callee, mut fn_args) = match *fn_ty.kind() { + let (mut callee, mut fn_args) = match fn_ty.kind() { ty::FnDef(def_id, fn_args) => (def_id, fn_args), ty::FnPtr(..) => { diff --git a/compiler/rustc_const_eval/src/check_consts/ops.rs b/compiler/rustc_const_eval/src/check_consts/ops.rs index c6361710ac9ca..23128b8f14266 100644 --- a/compiler/rustc_const_eval/src/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/check_consts/ops.rs @@ -188,8 +188,8 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> { CallKind::FnCall { fn_trait_id, self_ty } => { let note = match self_ty.kind() { FnDef(def_id, ..) => { - let span = tcx.def_span(*def_id); - if ccx.tcx.is_const_fn_raw(*def_id) { + let span = tcx.def_span(def_id); + if ccx.tcx.is_const_fn_raw(def_id) { span_bug!(span, "calling const FnDef errored when it shouldn't"); } @@ -230,7 +230,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> { let mut tmp_ty = self_ty; while let rustc_middle::ty::Ref(_, inner_ty, _) = tmp_ty.kind() { num_refs += 1; - tmp_ty = *inner_ty; + tmp_ty = inner_ty; } let deref = "*".repeat(num_refs); diff --git a/compiler/rustc_const_eval/src/const_eval/machine.rs b/compiler/rustc_const_eval/src/const_eval/machine.rs index a075bdc191181..0fd0480ef52a1 100644 --- a/compiler/rustc_const_eval/src/const_eval/machine.rs +++ b/compiler/rustc_const_eval/src/const_eval/machine.rs @@ -715,7 +715,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> { // If it's a frozen shared reference that's not already immutable, make it immutable. // (Do nothing on `None` provenance, that cannot store immutability anyway.) if let ty::Ref(_, ty, mutbl) = val.layout.ty.kind() - && *mutbl == Mutability::Not + && mutbl == Mutability::Not && val.to_scalar_and_meta().0.to_pointer(ecx)?.provenance.is_some_and(|p| !p.immutable()) // That next check is expensive, that's why we have all the guards above. && ty.is_freeze(*ecx.tcx, ecx.param_env) diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs index c96296eddb844..2e7677f55024f 100644 --- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs +++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs @@ -104,7 +104,7 @@ fn const_to_valtree_inner<'tcx>( // The valtree of the base type is the same as the valtree of the pattern type. // Since the returned valtree does not contain the type or layout, we can just // switch to the base type. - place.layout = ecx.layout_of(*base).unwrap(); + place.layout = ecx.layout_of(base).unwrap(); ensure_sufficient_stack(|| const_to_valtree_inner(ecx, &place, num_nodes)) }, @@ -284,7 +284,7 @@ pub fn valtree_to_const_value<'tcx>( let (param_env, ty) = param_env_ty.into_parts(); - match *ty.kind() { + match ty.kind() { ty::FnDef(..) => { assert!(valtree.unwrap_branch().is_empty()); mir::ConstValue::ZeroSized @@ -397,7 +397,7 @@ fn valtree_into_mplace<'tcx>( ecx.write_immediate(Immediate::Scalar(scalar_int.into()), place).unwrap(); } ty::Ref(_, inner_ty, _) => { - let imm = valtree_to_ref(ecx, valtree, *inner_ty); + let imm = valtree_to_ref(ecx, valtree, inner_ty); debug!(?imm); ecx.write_immediate(imm, place).unwrap(); } diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index 917a2fa7c6dd4..b5054b9187990 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -80,7 +80,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { may_unfold: impl Fn(AdtDef<'tcx>) -> bool, ) -> TyAndLayout<'tcx> { match layout.ty.kind() { - ty::Adt(adt_def, _) if adt_def.repr().transparent() && may_unfold(*adt_def) => { + ty::Adt(adt_def, _) if adt_def.repr().transparent() && may_unfold(adt_def) => { assert!(!adt_def.is_enum()); // Find the non-1-ZST field, and recurse. let (_, field) = layout.non_1zst_field(self).unwrap(); @@ -131,7 +131,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // Option<&T> behaves like &T, and same for fn() inner } - ty::Adt(def, _) if is_npo(*def) => { + ty::Adt(def, _) if is_npo(def) => { // Once we found a `nonnull_optimization_guaranteed` type, further strip off // newtype structs from it to find the underlying ABI type. self.unfold_transparent(inner, /* may_unfold */ |def| def.is_struct()) @@ -186,8 +186,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { let pointee_ty = |ty: Ty<'tcx>| -> InterpResult<'tcx, Option>> { // We cannot use `builtin_deref` here since we need to reject `Box`. Ok(Some(match ty.kind() { - ty::Ref(_, ty, _) => *ty, - ty::RawPtr(ty, _) => *ty, + ty::Ref(_, ty, _) => ty, + ty::RawPtr(ty, _) => ty, // We only accept `Box` with the default allocator. _ if ty.is_box_global(*self.tcx) => ty.boxed_ty(), _ => return Ok(None), @@ -209,8 +209,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { // `char` counts as `u32.` let int_ty = |ty: Ty<'tcx>| { Some(match ty.kind() { - ty::Int(ity) => (Integer::from_int_ty(&self.tcx, *ity), /* signed */ true), - ty::Uint(uty) => (Integer::from_uint_ty(&self.tcx, *uty), /* signed */ false), + ty::Int(ity) => (Integer::from_int_ty(&self.tcx, ity), /* signed */ true), + ty::Uint(uty) => (Integer::from_uint_ty(&self.tcx, uty), /* signed */ false), ty::Char => (Integer::I32, /* signed */ false), _ => return None, }) diff --git a/compiler/rustc_const_eval/src/interpret/cast.rs b/compiler/rustc_const_eval/src/interpret/cast.rs index 4901e4b2a4158..cd32c9976f3d6 100644 --- a/compiler/rustc_const_eval/src/interpret/cast.rs +++ b/compiler/rustc_const_eval/src/interpret/cast.rs @@ -77,7 +77,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { ensure_monomorphic_enough(*self.tcx, src.layout.ty)?; // The src operand does not matter, just its type - match *src.layout.ty.kind() { + match src.layout.ty.kind() { ty::FnDef(def_id, args) => { let instance = ty::Instance::resolve_for_fn_ptr( *self.tcx, @@ -110,7 +110,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { ensure_monomorphic_enough(*self.tcx, src.layout.ty)?; // The src operand does not matter, just its type - match *src.layout.ty.kind() { + match src.layout.ty.kind() { ty::Closure(def_id, args) => { let instance = ty::Instance::resolve_closure( *self.tcx, @@ -279,10 +279,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { _ => span_bug!(self.cur_span(), "invalid int-like cast from {}", src_layout.ty), }; - Ok(match *cast_ty.kind() { + Ok(match cast_ty.kind() { // int -> int Int(_) | Uint(_) => { - let size = match *cast_ty.kind() { + let size = match cast_ty.kind() { Int(t) => Integer::from_int_ty(self, t).size(), Uint(t) => Integer::from_uint_ty(self, t).size(), _ => bug!(), @@ -342,7 +342,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { if f2.is_nan() { M::generate_nan(ecx, &[f1]) } else { f2 } } - match *dest_ty.kind() { + match dest_ty.kind() { // float -> uint Uint(t) => { let size = Integer::from_uint_ty(self, t).size(); @@ -480,7 +480,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { trace!("Unsizing {:?} of type {} into {}", *src, src.layout.ty, cast_ty.ty); match (&src.layout.ty.kind(), &cast_ty.ty.kind()) { (&ty::Ref(_, s, _), &ty::Ref(_, c, _) | &ty::RawPtr(c, _)) - | (&ty::RawPtr(s, _), &ty::RawPtr(c, _)) => self.unsize_into_ptr(src, dest, *s, *c), + | (&ty::RawPtr(s, _), &ty::RawPtr(c, _)) => self.unsize_into_ptr(src, dest, s, c), (&ty::Adt(def_a, _), &ty::Adt(def_b, _)) => { assert_eq!(def_a, def_b); // implies same number of fields diff --git a/compiler/rustc_const_eval/src/interpret/discriminant.rs b/compiler/rustc_const_eval/src/interpret/discriminant.rs index 0008a15722bde..ed9ecdaced96c 100644 --- a/compiler/rustc_const_eval/src/interpret/discriminant.rs +++ b/compiler/rustc_const_eval/src/interpret/discriminant.rs @@ -130,7 +130,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { let discr_val = self.int_to_int_or_float(&tag_val, discr_layout).unwrap(); let discr_bits = discr_val.to_scalar().to_bits(discr_layout.size)?; // Convert discriminant to variant index, and catch invalid discriminants. - let index = match *ty.kind() { + let index = match ty.kind() { ty::Adt(adt, _) => { adt.discriminants(*self.tcx).find(|(_, var)| var.val == discr_bits) } diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index aef39b9af2f1f..26535686fc556 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -64,7 +64,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>( ty::Alias(..) | ty::Param(_) | ty::Placeholder(_) | ty::Infer(_) => { throw_inval!(TooGeneric) } - ty::Pat(_, pat) => match **pat { + ty::Pat(_, pat) => match *pat { ty::PatternKind::Range { .. } => ConstValue::from_target_usize(0u64, &tcx), // Future pattern kinds may have more variants }, diff --git a/compiler/rustc_const_eval/src/interpret/projection.rs b/compiler/rustc_const_eval/src/interpret/projection.rs index dd8dd21e0e8b9..093c419d4b426 100644 --- a/compiler/rustc_const_eval/src/interpret/projection.rs +++ b/compiler/rustc_const_eval/src/interpret/projection.rs @@ -324,7 +324,7 @@ where // It is not nice to match on the type, but that seems to be the only way to // implement this. ty::Array(inner, _) => { - (MemPlaceMeta::None, Ty::new_array(self.tcx.tcx, *inner, inner_len)) + (MemPlaceMeta::None, Ty::new_array(self.tcx.tcx, inner, inner_len)) } ty::Slice(..) => { let len = Scalar::from_target_usize(inner_len, self); diff --git a/compiler/rustc_const_eval/src/interpret/stack.rs b/compiler/rustc_const_eval/src/interpret/stack.rs index 0f6bf5c03364c..a43c528f13bca 100644 --- a/compiler/rustc_const_eval/src/interpret/stack.rs +++ b/compiler/rustc_const_eval/src/interpret/stack.rs @@ -500,7 +500,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { ty::Tuple(tys) => tys.last().is_none_or(|ty| is_very_trivially_sized(*ty)), - ty::Pat(ty, ..) => is_very_trivially_sized(*ty), + ty::Pat(ty, ..) => is_very_trivially_sized(ty), // We don't want to do any queries, so there is not much we can do with ADTs. ty::Adt(..) => false, diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index aaee6f6d247f8..abdb3dc46accb 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -423,7 +423,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { let extra_args = self.tcx.mk_type_list_from_iter(extra_args.iter().map(|arg| arg.layout().ty)); - let (callee, fn_abi, with_caller_location) = match *func.layout.ty.kind() { + let (callee, fn_abi, with_caller_location) = match func.layout.ty.kind() { ty::FnPtr(..) => { let fn_ptr = self.read_pointer(&func)?; let fn_val = self.get_ptr_fn(fn_ptr)?; diff --git a/compiler/rustc_const_eval/src/interpret/util.rs b/compiler/rustc_const_eval/src/interpret/util.rs index 6f5bcebbbb66f..d75a8604386cb 100644 --- a/compiler/rustc_const_eval/src/interpret/util.rs +++ b/compiler/rustc_const_eval/src/interpret/util.rs @@ -39,7 +39,7 @@ where return ControlFlow::Continue(()); } - match *ty.kind() { + match ty.kind() { ty::Param(_) => ControlFlow::Break(FoundParam), ty::Closure(def_id, args) | ty::CoroutineClosure(def_id, args, ..) diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index 26b7251f6dbc5..bfb56f1dbe8c9 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -613,7 +613,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> { Ok(true) } ty::Ref(_, _ty, mutbl) => { - self.check_safe_pointer(value, PointerKind::Ref(*mutbl))?; + self.check_safe_pointer(value, PointerKind::Ref(mutbl))?; Ok(true) } ty::FnPtr(..) => { @@ -903,7 +903,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt, // This is the length of the array/slice. let len = op.len(self.ecx)?; // This is the element type size. - let layout = self.ecx.layout_of(*tys)?; + let layout = self.ecx.layout_of(tys)?; // This is the size in bytes of the whole array. (This checks for overflow.) let size = layout.size * len; // If the size is 0, there is nothing to check. @@ -962,7 +962,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValueVisitor<'tcx, M> for ValidityVisitor<'rt, // Fast path for arrays and slices of ZSTs. We only need to check a single ZST element // of an array and not all of them, because there's only a single value of a specific // ZST type, so either validation fails for all elements or none. - ty::Array(tys, ..) | ty::Slice(tys) if self.ecx.layout_of(*tys)?.is_zst() => { + ty::Array(tys, ..) | ty::Slice(tys) if self.ecx.layout_of(tys)?.is_zst() => { // Validate just the first element (if any). if op.len(self.ecx)? > 0 { self.visit_field(op, 0, &self.ecx.project_index(op, 0)?)?; diff --git a/compiler/rustc_const_eval/src/interpret/visitor.rs b/compiler/rustc_const_eval/src/interpret/visitor.rs index fd649d608c691..8a76c863fa1b2 100644 --- a/compiler/rustc_const_eval/src/interpret/visitor.rs +++ b/compiler/rustc_const_eval/src/interpret/visitor.rs @@ -86,7 +86,7 @@ pub trait ValueVisitor<'tcx, M: Machine<'tcx>>: Sized { trace!("walk_value: type: {ty}"); // Special treatment for special types, where the (static) layout is not sufficient. - match *ty.kind() { + match ty.kind() { // If it is a trait object, switch to the real type that was used to create it. ty::Dynamic(data, _, ty::Dyn) => { // Dyn types. This is unsized, and the actual dynamic type of the data is given by the diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index 36c7bed5c1194..4960da7df7ee1 100644 --- a/compiler/rustc_const_eval/src/util/type_name.rs +++ b/compiler/rustc_const_eval/src/util/type_name.rs @@ -22,7 +22,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { } fn print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError> { - match *ty.kind() { + match ty.kind() { // Types without identity. ty::Bool | ty::Char diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 2e778fd375961..56a20483a61d0 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -162,7 +162,7 @@ fn check_union_fields(tcx: TyCtxt<'_>, span: Span, item_def_id: LocalDefId) -> b } ty::Array(elem, _len) => { // Like `Copy`, we do *not* special-case length 0. - allowed_union_field(*elem, tcx, param_env) + allowed_union_field(elem, tcx, param_env) } _ => { // Fallback case: allow `ManuallyDrop` and things that are `Copy`, @@ -656,7 +656,7 @@ fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) { if tcx.codegen_fn_attrs(def_id).import_linkage.is_some() { if match tcx.type_of(def_id).instantiate_identity().kind() { ty::RawPtr(_, _) => false, - ty::Adt(adt_def, args) => !is_enum_of_nonnullable_ptr(tcx, *adt_def, *args), + ty::Adt(adt_def, args) => !is_enum_of_nonnullable_ptr(tcx, adt_def, args), _ => true, } { tcx.dcx().emit_err(errors::LinkageType { span: tcx.def_span(def_id) }); @@ -1257,7 +1257,7 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>) ) -> ControlFlow<(&'static str, DefId, GenericArgsRef<'tcx>, bool)> { match t.kind() { ty::Tuple(list) => list.iter().try_for_each(|t| check_non_exhaustive(tcx, t)), - ty::Array(ty, _) => check_non_exhaustive(tcx, *ty), + ty::Array(ty, _) => check_non_exhaustive(tcx, ty), ty::Adt(def, args) => { if !def.did().is_local() { let non_exhaustive = def.is_variant_list_non_exhaustive() @@ -1639,7 +1639,7 @@ fn opaque_type_cycle_error( } impl<'tcx> ty::visit::TypeVisitor> for OpaqueTypeCollector { fn visit_ty(&mut self, t: Ty<'tcx>) { - match *t.kind() { + match t.kind() { ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => { self.opaques.push(def); } @@ -1676,7 +1676,7 @@ fn opaque_type_cycle_error( && let ty::Alias( ty::Opaque, ty::AliasTy { def_id: captured_def_id, .. }, - ) = *ty.kind() + ) = ty.kind() && captured_def_id == opaque_def_id.to_def_id() { err.span_label( 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 35577613800b2..0c24462a25ff5 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -860,7 +860,7 @@ impl<'tcx> ty::FallibleTypeFolder> for RemapHiddenTyRegions<'tcx> { } fn try_fold_ty(&mut self, t: Ty<'tcx>) -> Result, Self::Error> { - if let ty::Alias(ty::Opaque, ty::AliasTy { args, def_id, .. }) = *t.kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { args, def_id, .. }) = t.kind() { let mut mapped_args = Vec::with_capacity(args.len()); for (arg, v) in std::iter::zip(args, self.tcx.variances_of(def_id)) { mapped_args.push(match (arg.unpack(), v) { @@ -2264,7 +2264,7 @@ fn try_report_async_mismatch<'tcx>( } let ty::Alias(ty::Projection, ty::AliasTy { def_id: async_future_def_id, .. }) = - *tcx.fn_sig(trait_m.def_id).skip_binder().skip_binder().output().kind() + tcx.fn_sig(trait_m.def_id).skip_binder().skip_binder().output().kind() else { bug!("expected `async fn` to return an RPITIT"); }; diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs index 80daaa60324a3..c3252bea2cbb6 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs @@ -76,7 +76,7 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>( let hidden_ty = hidden_tys[&trait_projection.def_id].instantiate(tcx, impl_opaque_args); // If the hidden type is not an opaque, then we have "refined" the trait signature. - let ty::Alias(ty::Opaque, impl_opaque) = *hidden_ty.kind() else { + let ty::Alias(ty::Opaque, impl_opaque) = hidden_ty.kind() else { report_mismatched_rpitit_signature( tcx, trait_m_sig_with_self_for_diag, @@ -212,7 +212,7 @@ struct ImplTraitInTraitCollector<'tcx> { impl<'tcx> TypeVisitor> for ImplTraitInTraitCollector<'tcx> { fn visit_ty(&mut self, ty: Ty<'tcx>) { - if let ty::Alias(ty::Projection, proj) = *ty.kind() + if let ty::Alias(ty::Projection, proj) = ty.kind() && self.tcx.is_impl_trait_in_trait(proj.def_id) { if self.types.insert(proj) { @@ -304,7 +304,7 @@ fn report_mismatched_rpitit_signature<'tcx>( } fn type_visibility<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option> { - match *ty.kind() { + match ty.kind() { ty::Ref(_, ty, _) => type_visibility(tcx, ty), ty::Adt(def, args) => { if def.is_fundamental() { diff --git a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs index 3d5a22fce85af..451c6b14a3a90 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsicck.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsicck.rs @@ -57,7 +57,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { width => bug!("unsupported pointer width: {width}"), }; - match *ty.kind() { + match ty.kind() { ty::Int(IntTy::I8) | ty::Uint(UintTy::U8) => Some(InlineAsmType::I8), ty::Int(IntTy::I16) | ty::Uint(UintTy::U16) => Some(InlineAsmType::I16), ty::Int(IntTy::I32) | ty::Uint(UintTy::U32) => Some(InlineAsmType::I32), @@ -79,7 +79,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { if let Some(len) = len.try_eval_target_usize(self.tcx, self.tcx.param_env(adt.did())) { - (len, *ty) + (len, ty) } else { return None; } @@ -136,7 +136,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> { bug!("inference variable in asm operand ty: {:?} {:?}", expr, ty); } - let asm_ty = match *ty.kind() { + let asm_ty = match ty.kind() { // `!` is allowed for input but not for output (issue #87802) ty::Never if is_input => return None, _ if ty.references_error() => return None, diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index 678b8c89a5054..ee4b57c84ceec 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -460,7 +460,7 @@ fn fn_sig_suggestion<'tcx>( let mut output = sig.output(); let asyncness = if tcx.asyncness(assoc.def_id).is_async() { - output = if let ty::Alias(_, alias_ty) = *output.kind() { + output = if let ty::Alias(_, alias_ty) = output.kind() { tcx.explicit_item_super_predicates(alias_ty.def_id) .iter_instantiated_copied(tcx, alias_ty.args) .find_map(|(bound, _)| { diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index d3b928fc17c5b..5d2fabb229d34 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -147,13 +147,13 @@ where for ty in assumed_wf_types.iter() { match ty.kind() { ty::Adt(def, _) => { - if is_bevy_paramset(*def) { + if is_bevy_paramset(def) { break 'is_bevy true; } } ty::Ref(_, ty, _) => match ty.kind() { ty::Adt(def, _) => { - if is_bevy_paramset(*def) { + if is_bevy_paramset(def) { break 'is_bevy true; } } @@ -998,11 +998,11 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(), match ty.kind() { ty::Adt(adt_def, ..) => adt_def.did().is_local(), // Arrays and slices use the inner type's `ConstParamTy`. - ty::Array(ty, ..) => ty_is_local(*ty), - ty::Slice(ty) => ty_is_local(*ty), + ty::Array(ty, ..) => ty_is_local(ty), + ty::Slice(ty) => ty_is_local(ty), // `&` references use the inner type's `ConstParamTy`. // `&mut` are not supported. - ty::Ref(_, ty, ast::Mutability::Not) => ty_is_local(*ty), + ty::Ref(_, ty, ast::Mutability::Not) => ty_is_local(ty), // Say that a tuple is local if any of its components are local. // This is not strictly correct, but it's likely that the user can fix the local component. ty::Tuple(tys) => tys.iter().any(|ty| ty_is_local(ty)), diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index fecd78bc38f47..e028c6eb05c36 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -225,11 +225,9 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<() // even if they do not carry that attribute. use rustc_type_ir::TyKind::*; match (source.kind(), target.kind()) { - (&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b)) if r_a == *r_b && mutbl_a == *mutbl_b => { - Ok(()) - } - (&RawPtr(_, a_mutbl), &RawPtr(_, b_mutbl)) if a_mutbl == b_mutbl => Ok(()), - (&Adt(def_a, args_a), &Adt(def_b, args_b)) if def_a.is_struct() && def_b.is_struct() => { + (Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b)) if r_a == r_b && mutbl_a == mutbl_b => Ok(()), + (RawPtr(_, a_mutbl), RawPtr(_, b_mutbl)) if a_mutbl == b_mutbl => Ok(()), + (Adt(def_a, args_a), Adt(def_b, args_b)) if def_a.is_struct() && def_b.is_struct() => { if def_a != def_b { let source_path = tcx.def_path_str(def_a.did()); let target_path = tcx.def_path_str(def_b.did()); @@ -373,26 +371,26 @@ pub fn coerce_unsized_info<'tcx>( (mt_a.ty, mt_b.ty, unsize_trait, None) }; let (source, target, trait_def_id, kind) = match (source.kind(), target.kind()) { - (&ty::Ref(r_a, ty_a, mutbl_a), &ty::Ref(r_b, ty_b, mutbl_b)) => { + (ty::Ref(r_a, ty_a, mutbl_a), ty::Ref(r_b, ty_b, mutbl_b)) => { infcx.sub_regions(infer::RelateObjectBound(span), r_b, r_a); let mt_a = ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a }; let mt_b = ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b }; check_mutbl(mt_a, mt_b, &|ty| Ty::new_imm_ref(tcx, r_b, ty)) } - (&ty::Ref(_, ty_a, mutbl_a), &ty::RawPtr(ty_b, mutbl_b)) => check_mutbl( + (ty::Ref(_, ty_a, mutbl_a), ty::RawPtr(ty_b, mutbl_b)) => check_mutbl( ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a }, ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b }, &|ty| Ty::new_imm_ptr(tcx, ty), ), - (&ty::RawPtr(ty_a, mutbl_a), &ty::RawPtr(ty_b, mutbl_b)) => check_mutbl( + (ty::RawPtr(ty_a, mutbl_a), ty::RawPtr(ty_b, mutbl_b)) => check_mutbl( ty::TypeAndMut { ty: ty_a, mutbl: mutbl_a }, ty::TypeAndMut { ty: ty_b, mutbl: mutbl_b }, &|ty| Ty::new_imm_ptr(tcx, ty), ), - (&ty::Adt(def_a, args_a), &ty::Adt(def_b, args_b)) + (ty::Adt(def_a, args_a), ty::Adt(def_b, args_b)) if def_a.is_struct() && def_b.is_struct() => { if def_a != def_b { diff --git a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs index 89acb778d6c29..7f5f335b98e95 100644 --- a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs +++ b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs @@ -123,7 +123,7 @@ impl<'tcx> InherentCollect<'tcx> { let span = self.tcx.def_span(impl_def_id); let mut note = None; if let ty::Ref(_, subty, _) = ty.kind() { - note = Some(errors::InherentPrimitiveTyNote { subty: *subty }); + note = Some(errors::InherentPrimitiveTyNote { subty }); } return Err(self.tcx.dcx().emit_err(errors::InherentPrimitiveTy { span, note })); } @@ -148,10 +148,10 @@ impl<'tcx> InherentCollect<'tcx> { let mut self_ty = self.tcx.peel_off_weak_alias_tys(self_ty); // We allow impls on pattern types exactly when we allow impls on the base type. // FIXME(pattern_types): Figure out the exact coherence rules we want here. - while let ty::Pat(base, _) = *self_ty.kind() { + while let ty::Pat(base, _) = self_ty.kind() { self_ty = base; } - match *self_ty.kind() { + match self_ty.kind() { ty::Adt(def, _) => self.check_def_id(id, self_ty, def.did()), ty::Foreign(did) => self.check_def_id(id, self_ty, did), ty::Dynamic(data, ..) if data.principal_def_id().is_some() => { diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index dcd0e3111a489..2cf6f0dd8bc36 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -401,7 +401,7 @@ fn emit_orphan_check_error<'tcx>( let is_foreign = !trait_ref.def_id.is_local() && matches!(is_target_ty, IsFirstInputType::No); - match *ty.kind() { + match ty.kind() { ty::Slice(_) => { if is_foreign { diag.subdiagnostic(errors::OnlyCurrentTraitsForeign { span }); @@ -519,7 +519,7 @@ impl<'tcx> TypeVisitor> for UncoveredTyParamCollector<'_, 'tcx> { if !ty.has_type_flags(ty::TypeFlags::HAS_TY_INFER) { return; } - let ty::Infer(ty::TyVar(vid)) = *ty.kind() else { + let ty::Infer(ty::TyVar(vid)) = ty.kind() else { return ty.super_visit_with(self); }; let origin = self.infcx.type_var_origin(vid); @@ -549,7 +549,7 @@ impl<'cx, 'tcx> TypeFolder> for TyVarReplacer<'cx, 'tcx> { if !ty.has_type_flags(ty::TypeFlags::HAS_TY_INFER) { return ty; } - let ty::Infer(ty::TyVar(vid)) = *ty.kind() else { + let ty::Infer(ty::TyVar(vid)) = ty.kind() else { return ty.super_fold_with(self); }; let origin = self.infcx.type_var_origin(vid); diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 91fa066ec6a1d..d21b24ae24311 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -1015,7 +1015,7 @@ impl<'tcx> FieldUniquenessCheckContext<'tcx> { // Here we don't care about the generic parameters, so `instantiate_identity` is enough. match self.tcx.type_of(field.did).instantiate_identity().kind() { ty::Adt(adt_def, _) => { - self.check_field_in_nested_adt(*adt_def, unnamed_field_span); + self.check_field_in_nested_adt(adt_def, unnamed_field_span); } ty_kind => span_bug!( self.tcx.def_span(field.did), @@ -1596,7 +1596,7 @@ pub fn suggest_impl_trait<'tcx>( item_ty: Ty<'tcx>| { let trait_name = tcx.item_name(trait_def_id); let args_tuple = args.type_at(1); - let ty::Tuple(types) = *args_tuple.kind() else { + let ty::Tuple(types) = args_tuple.kind() else { return None; }; let types = types.make_suggestable(tcx, false, None)?; diff --git a/compiler/rustc_hir_analysis/src/constrained_generic_params.rs b/compiler/rustc_hir_analysis/src/constrained_generic_params.rs index 620170164f535..a032e12c55a53 100644 --- a/compiler/rustc_hir_analysis/src/constrained_generic_params.rs +++ b/compiler/rustc_hir_analysis/src/constrained_generic_params.rs @@ -62,7 +62,7 @@ struct ParameterCollector { impl<'tcx> TypeVisitor> for ParameterCollector { fn visit_ty(&mut self, t: Ty<'tcx>) { - match *t.kind() { + match t.kind() { // Projections are not injective in general. ty::Alias(ty::Projection | ty::Inherent | ty::Opaque, _) if !self.include_nonconstraining => diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs index 7f4c75d3a6a21..509325be335dd 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs @@ -377,7 +377,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { // Next, we need to check that the return-type notation is being used on // an RPITIT (return-position impl trait in trait) or AFIT (async fn in trait). let output = tcx.fn_sig(assoc_item.def_id).skip_binder().output(); - let output = if let ty::Alias(ty::Projection, alias_ty) = *output.skip_binder().kind() + let output = if let ty::Alias(ty::Projection, alias_ty) = output.skip_binder().kind() && tcx.is_impl_trait_in_trait(alias_ty.def_id) { alias_ty.into() @@ -635,7 +635,7 @@ impl<'tcx> TypeVisitor> for GenericParamAndBoundVarCollector<'_, 't ty::Param(param) => { self.params.insert(param.index); } - ty::Bound(db, bt) if *db >= self.depth => { + ty::Bound(db, bt) if db >= self.depth => { self.vars.insert(match bt.kind { ty::BoundTyKind::Param(def_id, name) => (def_id, name), ty::BoundTyKind::Anon => { diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs index d77cbe3053653..868467c761419 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs @@ -1575,7 +1575,7 @@ fn generics_args_err_extend<'a>( GenericsArgsErrExtend::SelfTyAlias { def_id, span } => { let ty = tcx.at(span).type_of(def_id).instantiate_identity(); let span_of_impl = tcx.span_of_impl(def_id); - let def_id = match *ty.kind() { + let def_id = match ty.kind() { ty::Adt(self_def, _) => self_def.did(), _ => return, }; diff --git a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs index 454c20d3e6485..c797b481e2247 100644 --- a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs +++ b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs @@ -113,7 +113,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => continue, }; - match *leaf_ty.kind() { + match leaf_ty.kind() { ty::Ref(region, rty, _) => { // The type is `&'a T` which means that we will have // a predicate requirement of `T: 'a` (`T` outlives `'a`). diff --git a/compiler/rustc_hir_analysis/src/variance/constraints.rs b/compiler/rustc_hir_analysis/src/variance/constraints.rs index ce9e73bf24503..79d19dea88551 100644 --- a/compiler/rustc_hir_analysis/src/variance/constraints.rs +++ b/compiler/rustc_hir_analysis/src/variance/constraints.rs @@ -223,7 +223,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { ) { debug!("add_constraints_from_ty(ty={:?}, variance={:?})", ty, variance); - match *ty.kind() { + match ty.kind() { ty::Bool | ty::Char | ty::Int(_) diff --git a/compiler/rustc_hir_analysis/src/variance/mod.rs b/compiler/rustc_hir_analysis/src/variance/mod.rs index 8a4114c3e4bca..19477c5c68660 100644 --- a/compiler/rustc_hir_analysis/src/variance/mod.rs +++ b/compiler/rustc_hir_analysis/src/variance/mod.rs @@ -115,9 +115,9 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc fn visit_ty(&mut self, t: Ty<'tcx>) { match t.kind() { ty::Alias(_, ty::AliasTy { def_id, args, .. }) - if matches!(self.tcx.def_kind(*def_id), DefKind::OpaqueTy) => + if matches!(self.tcx.def_kind(def_id), DefKind::OpaqueTy) => { - self.visit_opaque(*def_id, args); + self.visit_opaque(def_id, args); } _ => t.super_visit_with(self), } diff --git a/compiler/rustc_hir_typeck/src/_match.rs b/compiler/rustc_hir_typeck/src/_match.rs index bc0ed4a7fa99d..d2a4df3057fc2 100644 --- a/compiler/rustc_hir_typeck/src/_match.rs +++ b/compiler/rustc_hir_typeck/src/_match.rs @@ -589,7 +589,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expectation: Expectation<'tcx>, ) -> Option { let expected_ty = expectation.to_option(self)?; - let (def_id, args) = match *expected_ty.kind() { + let (def_id, args) = match expected_ty.kind() { // FIXME: Could also check that the RPIT is not defined ty::Alias(ty::Opaque, alias_ty) => (alias_ty.def_id.as_local()?, alias_ty.args), // FIXME(-Znext-solver): Remove this branch once `replace_opaque_types_with_infer` is gone. diff --git a/compiler/rustc_hir_typeck/src/autoderef.rs b/compiler/rustc_hir_typeck/src/autoderef.rs index 69c4889d7a4b2..bd600cf46c443 100644 --- a/compiler/rustc_hir_typeck/src/autoderef.rs +++ b/compiler/rustc_hir_typeck/src/autoderef.rs @@ -49,7 +49,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.try_overloaded_deref(autoderef.span(), source).and_then( |InferOk { value: method, obligations: o }| { obligations.extend(o); - if let ty::Ref(region, _, mutbl) = *method.sig.output().kind() { + if let ty::Ref(region, _, mutbl) = method.sig.output().kind() { Some(OverloadedDeref { region, mutbl, span: autoderef.span() }) } else { None diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index 44cb08e44eb81..5ecac2e1e63fd 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -136,7 +136,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.structurally_resolve_type(autoderef.span(), autoderef.final_ty(false)); // If the callee is a bare function or a closure, then we're all set. - match *adjusted_ty.kind() { + match adjusted_ty.kind() { ty::FnDef(..) | ty::FnPtr(..) => { let adjustments = self.adjust_steps(autoderef); self.apply_adjustments(callee_expr, adjustments); @@ -319,10 +319,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // For initial two-phase borrow // deployment, conservatively omit // overloaded function call ops. - let mutbl = AutoBorrowMutability::new(*mutbl, AllowTwoPhase::No); + let mutbl = AutoBorrowMutability::new(mutbl, AllowTwoPhase::No); autoref = Some(Adjustment { - kind: Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)), + kind: Adjust::Borrow(AutoBorrow::Ref(region, mutbl)), target: method.sig.inputs()[0], }); } @@ -433,7 +433,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { arg_exprs: &'tcx [hir::Expr<'tcx>], expected: Expectation<'tcx>, ) -> Ty<'tcx> { - let (fn_sig, def_id) = match *callee_ty.kind() { + let (fn_sig, def_id) = match callee_ty.kind() { ty::FnDef(def_id, args) => { self.enforce_context_effects(call_expr.span, def_id, args); let fn_sig = self.tcx.fn_sig(def_id).instantiate(self.tcx, args); @@ -547,7 +547,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // in the function signature (`F: FnOnce`), so I did not bother to add another check here. // // This check is here because there is currently no way to express a trait bound for `FnDef` types only. - if let ty::FnDef(def_id, _args) = *arg_ty.kind() { + if let ty::FnDef(def_id, _args) = arg_ty.kind() { let fn_once_def_id = self.tcx.require_lang_item(hir::LangItem::FnOnce, Some(span)); let fn_once_output_def_id = diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 7cd97166ed1e9..875c774b2cf21 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -99,7 +99,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let t = self.try_structurally_resolve_type(span, t); - Ok(match *t.kind() { + Ok(match t.kind() { ty::Slice(_) | ty::Str => Some(PointerKind::Length), ty::Dynamic(tty, _, ty::Dyn) => Some(PointerKind::VTable(tty)), ty::Adt(def, args) if def.is_struct() => match def.non_enum_variant().tail_opt() { @@ -363,15 +363,15 @@ impl<'a, 'tcx> CastCheck<'tcx> { ); let mut sugg = None; let mut sugg_mutref = false; - if let ty::Ref(reg, cast_ty, mutbl) = *self.cast_ty.kind() { - if let ty::RawPtr(expr_ty, _) = *self.expr_ty.kind() + if let ty::Ref(reg, cast_ty, mutbl) = self.cast_ty.kind() { + if let ty::RawPtr(expr_ty, _) = self.expr_ty.kind() && fcx.can_coerce( Ty::new_ref(fcx.tcx, fcx.tcx.lifetimes.re_erased, expr_ty, mutbl), self.cast_ty, ) { sugg = Some((format!("&{}*", mutbl.prefix_str()), cast_ty == expr_ty)); - } else if let ty::Ref(expr_reg, expr_ty, expr_mutbl) = *self.expr_ty.kind() + } else if let ty::Ref(expr_reg, expr_ty, expr_mutbl) = self.expr_ty.kind() && expr_mutbl == Mutability::Not && mutbl == Mutability::Mut && fcx.can_coerce(Ty::new_mut_ref(fcx.tcx, expr_reg, expr_ty), self.cast_ty) @@ -388,7 +388,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { { sugg = Some((format!("&{}", mutbl.prefix_str()), false)); } - } else if let ty::RawPtr(_, mutbl) = *self.cast_ty.kind() + } else if let ty::RawPtr(_, mutbl) = self.cast_ty.kind() && fcx.can_coerce( Ty::new_ref(fcx.tcx, fcx.tcx.lifetimes.re_erased, self.expr_ty, mutbl), self.cast_ty, @@ -682,7 +682,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { (Some(t_from), Some(t_cast)) => (t_from, t_cast), // Function item types may need to be reified before casts. (None, Some(t_cast)) => { - match *self.expr_ty.kind() { + match self.expr_ty.kind() { ty::FnDef(..) => { // Attempt a coercion to a fn pointer type. let f = fcx.normalize(self.expr_span, self.expr_ty.fn_sig(fcx.tcx)); @@ -707,7 +707,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { // a cast. ty::Ref(_, inner_ty, mutbl) => { return match t_cast { - Int(_) | Float => match *inner_ty.kind() { + Int(_) | Float => match inner_ty.kind() { ty::Int(_) | ty::Uint(_) | ty::Float(_) @@ -731,7 +731,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { } _ => return Err(CastError::NonScalar), }; - if let ty::Adt(adt_def, _) = *self.expr_ty.kind() { + if let ty::Adt(adt_def, _) = self.expr_ty.kind() { if adt_def.did().krate != LOCAL_CRATE { if adt_def.variants().iter().any(VariantDef::is_field_list_non_exhaustive) { return Err(CastError::ForeignNonExhaustiveAdt); @@ -979,7 +979,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { }); // this will report a type mismatch if needed - fcx.demand_eqtype(self.span, *ety, m_cast.ty); + fcx.demand_eqtype(self.span, ety, m_cast.ty); return Ok(CastKind::ArrayPtrCast); } } diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 589a9c5a71914..d809cbb410b0e 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -309,7 +309,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected_ty: Ty<'tcx>, closure_kind: hir::ClosureKind, ) -> (Option>, Option) { - match *expected_ty.kind() { + match expected_ty.kind() { ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => self .deduce_closure_signature_from_predicates( expected_ty, @@ -502,7 +502,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let arg_param_ty = projection.skip_binder().projection_term.args.type_at(1); debug!(?arg_param_ty); - let ty::Tuple(input_tys) = *arg_param_ty.kind() else { + let ty::Tuple(input_tys) = arg_param_ty.kind() else { return None; }; @@ -549,7 +549,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let arg_param_ty = projection.skip_binder().projection_term.args.type_at(1); debug!(?arg_param_ty); - let ty::Tuple(input_tys) = *arg_param_ty.kind() else { + let ty::Tuple(input_tys) = arg_param_ty.kind() else { return None; }; @@ -558,7 +558,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // but none of them would be useful, since async closures return // concrete anonymous future types, and their futures are not coerced // into any other type within the body of the async closure. - let ty::Infer(ty::TyVar(return_vid)) = *projection.skip_binder().term.expect_type().kind() + let ty::Infer(ty::TyVar(return_vid)) = projection.skip_binder().term.expect_type().kind() else { return None; }; @@ -954,7 +954,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } }; - let output_ty = match *ret_ty.kind() { + let output_ty = match ret_ty.kind() { ty::Infer(ty::TyVar(ret_vid)) => { self.obligations_for_self_ty(ret_vid).into_iter().find_map(|obligation| { get_future_output(obligation.predicate, obligation.cause.span) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 0c83d50ad121c..9d8dbcfa233c7 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -203,7 +203,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { } // Examine the supertype and consider auto-borrowing. - match *b.kind() { + match b.kind() { ty::RawPtr(_, b_mutbl) => { return self.coerce_unsafe_ptr(a, b, b_mutbl); } @@ -216,7 +216,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { _ => {} } - match *a.kind() { + match a.kind() { ty::FnDef(..) => { // Function items are coercible to any closure // type; function pointers are not (that would @@ -306,7 +306,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { // to type check, we will construct the type that `&M*expr` would // yield. - let (r_a, mt_a) = match *a.kind() { + let (r_a, mt_a) = match a.kind() { ty::Ref(r_a, ty, mutbl) => { let mt_a = ty::TypeAndMut { ty, mutbl }; coerce_mutbls(mt_a.mutbl, mutbl_b)?; @@ -470,7 +470,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { }; let mutbl = AutoBorrowMutability::new(mutbl_b, self.allow_two_phase); adjustments.push(Adjustment { - kind: Adjust::Borrow(AutoBorrow::Ref(*r_borrow, mutbl)), + kind: Adjust::Borrow(AutoBorrow::Ref(r_borrow, mutbl)), target: ty, }); @@ -516,7 +516,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { // Handle reborrows before selecting `Source: CoerceUnsized`. let reborrow = match (source.kind(), target.kind()) { - (&ty::Ref(_, ty_a, mutbl_a), &ty::Ref(_, _, mutbl_b)) => { + (ty::Ref(_, ty_a, mutbl_a), ty::Ref(_, _, mutbl_b)) => { coerce_mutbls(mutbl_a, mutbl_b)?; let coercion = Coercion(self.cause.span); @@ -535,7 +535,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { }, )) } - (&ty::Ref(_, ty_a, mt_a), &ty::RawPtr(_, mt_b)) => { + (ty::Ref(_, ty_a, mt_a), ty::RawPtr(_, mt_b)) => { coerce_mutbls(mt_a, mt_b)?; Some(( @@ -628,7 +628,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { let unsize_ty = trait_pred.trait_ref.args[1].expect_ty(); debug!("coerce_unsized: ambiguous unsize case for {:?}", trait_pred); match (self_ty.kind(), unsize_ty.kind()) { - (&ty::Infer(ty::TyVar(v)), ty::Dynamic(..)) + (ty::Infer(ty::TyVar(v)), ty::Dynamic(..)) if self.type_var_is_sized(v) => { debug!("coerce_unsized: have sized infer {:?}", v); @@ -843,7 +843,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { match b.kind() { ty::FnPtr(_, b_hdr) => { let a_sig = a.fn_sig(self.tcx); - if let ty::FnDef(def_id, _) = *a.kind() { + if let ty::FnDef(def_id, _) = a.kind() { // Intrinsics are not coercible to function pointers if self.tcx.intrinsic(def_id).is_some() { return Err(TypeError::IntrinsicCast); @@ -944,7 +944,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { ) -> CoerceResult<'tcx> { debug!("coerce_unsafe_ptr(a={:?}, b={:?})", a, b); - let (is_ref, mt_a) = match *a.kind() { + let (is_ref, mt_a) = match a.kind() { ty::Ref(_, ty, mutbl) => (true, ty::TypeAndMut { ty, mutbl }), ty::RawPtr(ty, mutbl) => (false, ty::TypeAndMut { ty, mutbl }), _ => return self.unify_and(a, b, identity), @@ -1096,7 +1096,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Function items or non-capturing closures of differing IDs or GenericArgs. let (a_sig, b_sig) = { let is_capturing_closure = |ty: Ty<'tcx>| { - if let &ty::Closure(closure_def_id, _args) = ty.kind() { + if let ty::Closure(closure_def_id, _args) = ty.kind() { self.tcx.upvars_mentioned(closure_def_id.expect_local()).is_some() } else { false @@ -1224,7 +1224,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Adjustment { kind: Adjust::Deref(_), .. }, Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(_, mutbl_adj)), .. }, ] => { - match *self.node_ty(expr.hir_id).kind() { + match self.node_ty(expr.hir_id).kind() { ty::Ref(_, _, mt_orig) => { let mutbl_adj: hir::Mutability = mutbl_adj.into(); // Reborrow that we can safely ignore, because diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index fec6efdc0f71b..8f2207f003258 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -383,7 +383,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { hir::UnOp::Not => { let result = self.check_user_unop(expr, oprnd_t, unop, expected_inner); // If it's builtin, we can reuse the type, this helps inference. - if !(oprnd_t.is_integral() || *oprnd_t.kind() == ty::Bool) { + if !(oprnd_t.is_integral() || oprnd_t.kind() == ty::Bool) { oprnd_t = result; } } @@ -414,9 +414,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Places may legitimately have unsized types. // For example, dereferences of a fat pointer and // the last field of a struct can be unsized. - ExpectHasType(*ty) + ExpectHasType(ty) } else { - Expectation::rvalue_hint(self, *ty) + Expectation::rvalue_hint(self, ty) } } _ => NoExpectation, @@ -532,7 +532,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } }; - if let ty::FnDef(did, _) = *ty.kind() { + if let ty::FnDef(did, _) = ty.kind() { let fn_sig = ty.fn_sig(tcx); if tcx.is_intrinsic(did, sym::transmute) { @@ -1404,7 +1404,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let element_ty = if !args.is_empty() { let coerce_to = expected .to_option(self) - .and_then(|uty| match *uty.kind() { + .and_then(|uty| match uty.kind() { ty::Array(ty, _) | ty::Slice(ty) => Some(ty), _ => None, }) @@ -1488,7 +1488,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } let uty = match expected { - ExpectHasType(uty) => match *uty.kind() { + ExpectHasType(uty) => match uty.kind() { ty::Array(ty, _) | ty::Slice(ty) => Some(ty), _ => None, }, @@ -1543,7 +1543,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // out into a separate constant (or a const block in the future), so we check that // to tell them that in the diagnostic. Does not affect typeck. let is_constable = match element.kind { - hir::ExprKind::Call(func, _args) => match *self.node_ty(func.hir_id).kind() { + hir::ExprKind::Call(func, _args) => match self.node_ty(func.hir_id).kind() { ty::FnDef(def_id, _) if tcx.is_const_fn(def_id) => traits::IsConstable::Fn, _ => traits::IsConstable::No, }, @@ -1849,7 +1849,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // `MyStruct<'a, _, F2, C>`, as opposed to just `_`... // This is important to allow coercions to happen in // `other_struct` itself. See `coerce-in-base-expr.rs`. - let fresh_base_ty = Ty::new_adt(self.tcx, *adt, fresh_args); + let fresh_base_ty = Ty::new_adt(self.tcx, adt, fresh_args); self.check_expr_has_type_or_error( base_expr, self.resolve_vars_if_possible(fresh_base_ty), @@ -2410,7 +2410,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } let mut field_path = SmallVec::new(); - if self.find_adt_field(*base_def, ident, &mut field_path) { + if self.find_adt_field(base_def, ident, &mut field_path) { let (first_idx, _) = field_path[0]; let (_, last_field) = field_path.last().unwrap(); @@ -2616,7 +2616,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); let mut err = self.no_such_field_err(ident, base_ty, base.hir_id); - match *base_ty.peel_refs().kind() { + match base_ty.peel_refs().kind() { ty::Array(_, len) => { self.maybe_suggest_array_indexing(&mut err, base, ident, len); } @@ -2951,7 +2951,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // For compile-time reasons put a limit on number of fields we search .take(100) .collect::>(), - *args, + args, )); } _ => None, @@ -3276,7 +3276,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // function. if is_input { let ty = self.structurally_resolve_type(expr.span, ty); - match *ty.kind() { + match ty.kind() { ty::FnDef(..) => { let fnptr_ty = Ty::new_fn_ptr(self.tcx, ty.fn_sig(self.tcx)); self.demand_coerce(expr, ty, fnptr_ty, None, AllowTwoPhase::No); diff --git a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs index 548d5a7cc4ccd..3788768b278e2 100644 --- a/compiler/rustc_hir_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_hir_typeck/src/expr_use_visitor.rs @@ -1472,7 +1472,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx let base_ty = self.expr_ty_adjusted(base)?; let ty::Ref(region, _, mutbl) = - *self.cx.try_structurally_resolve_type(base.span, base_ty).kind() + self.cx.try_structurally_resolve_type(base.span, base_ty).kind() else { span_bug!(expr.span, "cat_overloaded_place: base is not a reference"); }; diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs index 130fd130ec837..3afa28da65479 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs @@ -49,7 +49,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { predicate_args.iter().find_map(|arg| { arg.walk().find_map(|arg| { if let ty::GenericArgKind::Type(ty) = arg.unpack() - && let ty::Param(param_ty) = *ty.kind() + && let ty::Param(param_ty) = ty.kind() && matches(ty::ParamTerm::Ty(param_ty)) { Some(arg) @@ -340,7 +340,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { impl<'tcx> TypeVisitor> for FindAmbiguousParameter<'_, 'tcx> { type Result = ControlFlow>; fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { - if let ty::Infer(ty::TyVar(vid)) = *ty.kind() + if let ty::Infer(ty::TyVar(vid)) = ty.kind() && let Some(def_id) = self.0.type_var_origin(vid).param_def_id && let generics = self.0.tcx.generics_of(self.1) && let Some(index) = generics.param_def_id_to_index(self.0.tcx, def_id) @@ -366,7 +366,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { )) = error.code && let ty::Closure(def_id, _) | ty::Coroutine(def_id, ..) = expected_trait_ref.self_ty().kind() - && span.overlaps(self.tcx.def_span(*def_id)) + && span.overlaps(self.tcx.def_span(def_id)) { true } else { @@ -650,7 +650,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return self.blame_specific_part_of_expr_corresponding_to_generic_param( param, borrowed_expr, - (*ty_ref_type).into(), + ty_ref_type.into(), ); } @@ -884,7 +884,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .variant_with_id(variant_def_id) .fields .iter() - .map(|field| field.ty(self.tcx, *in_ty_adt_generic_args)) + .map(|field| field.ty(self.tcx, in_ty_adt_generic_args)) .enumerate() .filter(|(_index, field_type)| find_param_in_ty((*field_type).into(), param)), ) else { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 7720faddba376..250926661788e 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -1601,7 +1601,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Ok((variant, ty.normalized)) } else { - Err(match *ty.normalized.kind() { + Err(match ty.normalized.kind() { ty::Error(guar) => { // E0071 might be caused by a spelling error, which will have // already caused an error message and probably a suggestion @@ -2204,7 +2204,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && let Some(callee_ty) = callee_ty { let callee_ty = callee_ty.peel_refs(); - match *callee_ty.kind() { + match callee_ty.kind() { ty::Param(param) => { let param = self.tcx.generics_of(self.body_id).type_param(param, self.tcx); if param.kind.is_synthetic() { @@ -2453,7 +2453,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if rcvr.hir_id.owner == typeck.hir_owner && let Some(rcvr_ty) = typeck.node_type_opt(rcvr.hir_id) && let ty::Closure(call_def_id, _) = rcvr_ty.kind() - && def_id == *call_def_id + && def_id == call_def_id && let Some(idx) = expected_idx && let Some(arg) = args.get(idx) && let Some(arg_ty) = typeck.node_type_opt(arg.hir_id) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs index be4db2934b7b1..cce92f163d6de 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs @@ -63,7 +63,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty = self.shallow_resolve(ty); debug!(?ty); - match *ty.kind() { + match ty.kind() { ty::Infer(ty::TyVar(found_vid)) => { self.root_var(expected_vid) == self.root_var(found_vid) } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs index 33f80dd3773fa..1d209de36a879 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs @@ -307,7 +307,7 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option> { match ty.kind() { - ty::Adt(adt_def, _) => Some(*adt_def), + ty::Adt(adt_def, _) => Some(adt_def), // FIXME(#104767): Should we handle bound regions here? ty::Alias(ty::Projection | ty::Inherent | ty::Weak, _) if !ty.has_escaping_bound_vars() => @@ -328,7 +328,7 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> { if let ty::Alias(ty::Projection | ty::Weak, ty::AliasTy { args, def_id, .. }) = ty.kind() { - self.add_required_obligations_for_hir(span, *def_id, args, hir_id); + self.add_required_obligations_for_hir(span, def_id, args, hir_id); } self.normalize(span, ty) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 703273968c5bb..44a2574b52f32 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -349,7 +349,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } if self.suggest_fn_call(err, expr, found, |output| self.can_coerce(output, expected)) - && let ty::FnDef(def_id, ..) = *found.kind() + && let ty::FnDef(def_id, ..) = found.kind() && let Some(sp) = self.tcx.hir().span_if_local(def_id) { let name = self.tcx.item_name(def_id); @@ -425,7 +425,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Some((found_ty_inner, expected_ty_inner, error_tys)) = self.deconstruct_option_or_result(found, expected) - && let ty::Ref(_, peeled, hir::Mutability::Not) = *expected_ty_inner.kind() + && let ty::Ref(_, peeled, hir::Mutability::Not) = expected_ty_inner.kind() { // Suggest removing any stray borrows (unless there's macro shenanigans involved). let inner_expr = expr.peel_borrows(); @@ -605,7 +605,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { found: Ty<'tcx>, ) -> bool { if let (ty::FnPtr(..), ty::Closure(def_id, _)) = (expected.kind(), found.kind()) { - if let Some(upvars) = self.tcx.upvars_mentioned(*def_id) { + if let Some(upvars) = self.tcx.upvars_mentioned(def_id) { // Report upto four upvars being captured to reduce the amount error messages // reported back to the user. let spans_and_labels = upvars @@ -1222,8 +1222,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Ref(_, inner_expected_ty, _), ) => { expr = *inner_expr; - expr_ty = *inner_expr_ty; - expected_ty = *inner_expected_ty; + expr_ty = inner_expr_ty; + expected_ty = inner_expected_ty; } (hir::ExprKind::Block(blk, _), _, _) => { self.suggest_block_to_brackets(diag, *blk, expr_ty, expected_ty); @@ -1243,7 +1243,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> bool { if let ty::Ref(_, inner_ty, hir::Mutability::Not) = expr_ty.kind() && let Some(clone_trait_def) = self.tcx.lang_items().clone_trait() - && expected_ty == *inner_ty + && expected_ty == inner_ty && self .infcx .type_implements_trait( @@ -1292,7 +1292,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { { let expr_inner_ty = args.type_at(0); let expected_inner_ty = expected_args.type_at(0); - if let &ty::Ref(_, ty, _mutability) = expr_inner_ty.kind() + if let ty::Ref(_, ty, _mutability) = expr_inner_ty.kind() && self.can_eq(self.param_env, ty, expected_inner_ty) { let def_path = self.tcx.def_path_str(adt_def.did()); @@ -1480,7 +1480,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && let ty::Infer(_) = elem_ty.kind() && size.try_eval_target_usize(self.tcx, self.param_env) == Some(0) { - let slice = Ty::new_slice(self.tcx, *elem_ty); + let slice = Ty::new_slice(self.tcx, elem_ty); Ty::new_imm_ref(self.tcx, self.tcx.lifetimes.re_static, slice) } else { provided_ty @@ -1510,7 +1510,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected_ty: Ty<'tcx>, ) { if let ty::Slice(elem_ty) | ty::Array(elem_ty, _) = expected_ty.kind() { - if self.can_coerce(blk_ty, *elem_ty) + if self.can_coerce(blk_ty, elem_ty) && blk.stmts.is_empty() && blk.rules == hir::BlockCheckMode::DefaultBlock { @@ -1780,7 +1780,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // diagnostic in cases where we have `(&&T).clone()` and we expect `T`). && !results.expr_adjustments(callee_expr).iter().any(|adj| matches!(adj.kind, ty::adjustment::Adjust::Deref(..))) // Check that we're in fact trying to clone into the expected type - && self.can_coerce(*pointee_ty, expected_ty) + && self.can_coerce(pointee_ty, expected_ty) && let trait_ref = ty::TraitRef::new(self.tcx, clone_trait_did, [expected_ty]) // And the expected type doesn't implement `Clone` && !self.predicate_must_hold_considering_regions(&traits::Obligation::new( @@ -2512,8 +2512,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let expr = expr.peel_drop_temps(); match (&expr.kind, expected.kind(), checked_ty.kind()) { - (_, &ty::Ref(_, exp, _), &ty::Ref(_, check, _)) => match (exp.kind(), check.kind()) { - (&ty::Str, &ty::Array(arr, _) | &ty::Slice(arr)) if arr == self.tcx.types.u8 => { + (_, ty::Ref(_, exp, _), ty::Ref(_, check, _)) => match (exp.kind(), check.kind()) { + (ty::Str, ty::Array(arr, _) | ty::Slice(arr)) if arr == self.tcx.types.u8 => { if let hir::ExprKind::Lit(_) = expr.kind && let Ok(src) = sm.span_to_snippet(sp) && replace_prefix(&src, "b\"", "\"").is_some() @@ -2528,7 +2528,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { )); } } - (&ty::Array(arr, _) | &ty::Slice(arr), &ty::Str) if arr == self.tcx.types.u8 => { + (ty::Array(arr, _) | ty::Slice(arr), ty::Str) if arr == self.tcx.types.u8 => { if let hir::ExprKind::Lit(_) = expr.kind && let Ok(src) = sm.span_to_snippet(sp) && replace_prefix(&src, "\"", "b\"").is_some() @@ -2544,7 +2544,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } _ => {} }, - (_, &ty::Ref(_, _, mutability), _) => { + (_, ty::Ref(_, _, mutability), _) => { // Check if it can work when put into a ref. For example: // // ``` @@ -2650,7 +2650,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { kind: hir::ExprKind::Binary(_, lhs, ..), .. }) = self.tcx.parent_hir_node(expr.hir_id) - && let &ty::Ref(..) = self.check_expr(lhs).kind() + && let ty::Ref(..) = self.check_expr(lhs).kind() { let (sugg, verbose) = make_sugg(lhs, lhs.span, "*"); @@ -2674,7 +2674,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { )); } } - (hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, expr), _, &ty::Ref(_, checked, _)) + (hir::ExprKind::AddrOf(hir::BorrowKind::Ref, _, expr), _, ty::Ref(_, checked, _)) if self.can_eq(self.param_env, checked, expected) => { let make_sugg = |start: Span, end: BytePos| { @@ -2713,7 +2713,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return make_sugg(sp, expr.span.lo()); } } - (_, &ty::RawPtr(ty_b, mutbl_b), &ty::Ref(_, ty_a, mutbl_a)) => { + (_, ty::RawPtr(ty_b, mutbl_b), ty::Ref(_, ty_a, mutbl_a)) => { if let Some(steps) = self.deref_steps(ty_a, ty_b) // Only suggest valid if dereferencing needed. && steps > 0 diff --git a/compiler/rustc_hir_typeck/src/intrinsicck.rs b/compiler/rustc_hir_typeck/src/intrinsicck.rs index a9c929e76d5bf..e0a2b12435308 100644 --- a/compiler/rustc_hir_typeck/src/intrinsicck.rs +++ b/compiler/rustc_hir_typeck/src/intrinsicck.rs @@ -13,7 +13,7 @@ use super::FnCtxt; /// If the type is `Option`, it will return `T`, otherwise /// the type itself. Works on most `Option`-like types. fn unpack_option_like<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Ty<'tcx> { - let ty::Adt(def, args) = *ty.kind() else { return ty }; + let ty::Adt(def, args) = ty.kind() else { return ty }; if def.variants().len() == 2 && !def.repr().c() && def.repr().int.is_none() { let data_idx; @@ -74,7 +74,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Special-case transmuting from `typeof(function)` and // `Option` to present a clearer error. let from = unpack_option_like(tcx, from); - if let (&ty::FnDef(..), SizeSkeleton::Known(size_to, _)) = (from.kind(), sk_to) + if let (ty::FnDef(..), SizeSkeleton::Known(size_to, _)) = (from.kind(), sk_to) && size_to == Pointer(dl.instruction_address_space).size(&tcx) { struct_span_code_err!(self.dcx(), span, E0591, "can't transmute zero-sized type") diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index e0c0adac0767c..66c959feeae93 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -206,7 +206,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { if unsize { let unsized_ty = if let ty::Array(elem_ty, _) = base_ty.kind() { - Ty::new_slice(self.tcx, *elem_ty) + Ty::new_slice(self.tcx, elem_ty) } else { bug!( "AutorefOrPtrAdjustment's unsize flag should only be set for array ty, found {}", @@ -222,7 +222,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { } Some(probe::AutorefOrPtrAdjustment::ToConstPtr) => { target = match target.kind() { - &ty::RawPtr(ty, mutbl) => { + ty::RawPtr(ty, mutbl) => { assert!(mutbl.is_mut()); Ty::new_imm_ptr(self.tcx, ty) } diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index d6110ab94c15a..a7ce99ccf1a7c 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -207,7 +207,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Some(span) = result.illegal_sized_bound { let mut needs_mut = false; if let ty::Ref(region, t_type, mutability) = self_ty.kind() { - let trait_type = Ty::new_ref(self.tcx, *region, *t_type, mutability.invert()); + let trait_type = Ty::new_ref(self.tcx, region, t_type, mutability.invert()); // We probe again to see if there might be a borrow mutability discrepancy. match self.lookup_probe( segment.ident, diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 28f537c87c4ee..41461fcc69fbc 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -425,7 +425,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .probe_instantiate_query_response(span, &orig_values, ty) .unwrap_or_else(|_| span_bug!(span, "instantiating {:?} failed?", ty)); let ty = self.resolve_vars_if_possible(ty.value); - let guar = match *ty.kind() { + let guar = match ty.kind() { ty::Infer(ty::TyVar(_)) => { let raw_ptr_call = bad_ty.reached_raw_pointer && !self.tcx.features().arbitrary_self_types; @@ -554,7 +554,7 @@ fn method_autoderef_steps<'tcx>( steps.push(CandidateStep { self_ty: infcx.make_query_response_ignoring_pending_obligations( inference_vars, - Ty::new_slice(infcx.tcx, *elem_ty), + Ty::new_slice(infcx.tcx, elem_ty), ), autoderefs: dereferences, // this could be from an unsafe deref if we had @@ -653,7 +653,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { #[instrument(level = "debug", skip(self))] fn assemble_probe(&mut self, self_ty: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>) { let raw_self_ty = self_ty.value.value; - match *raw_self_ty.kind() { + match raw_self_ty.kind() { ty::Dynamic(data, ..) if let Some(p) = data.principal() => { // Subtle: we can't use `instantiate_query_response` here: using it will // commit to all of the type equalities assumed by inference going through @@ -795,7 +795,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { let bound_predicate = predicate.kind(); match bound_predicate.skip_binder() { ty::ClauseKind::Trait(trait_predicate) => { - match *trait_predicate.trait_ref.self_ty().kind() { + match trait_predicate.trait_ref.self_ty().kind() { ty::Param(p) if p == param_ty => { Some(bound_predicate.rebind(trait_predicate.trait_ref)) } @@ -1123,7 +1123,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { pick.autoderefs = step.autoderefs; // Insert a `&*` or `&mut *` if this is a reference type: - if let ty::Ref(_, _, mutbl) = *step.self_ty.value.value.kind() { + if let ty::Ref(_, _, mutbl) = step.self_ty.value.value.kind() { pick.autoderefs += 1; pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::Autoref { mutbl, @@ -1173,7 +1173,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { return None; } - let &ty::RawPtr(ty, hir::Mutability::Mut) = self_ty.kind() else { + let ty::RawPtr(ty, hir::Mutability::Mut) = self_ty.kind() else { return None; }; diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 3b71e2f19b168..d07440dffa858 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -118,7 +118,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let Some(arg_ty) = args[0].as_type() else { return false; }; - let ty::Param(param) = *arg_ty.kind() else { + let ty::Param(param) = arg_ty.kind() else { return false; }; // Is `generic_param` the same as the arg for this trait predicate? @@ -149,7 +149,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return false; } - match *ty.peel_refs().kind() { + match ty.peel_refs().kind() { ty::Param(param) => { let generics = self.tcx.generics_of(self.body_id); let generic_param = generics.type_param(param, self.tcx); @@ -351,8 +351,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } if let ty::Ref(region, t_type, mutability) = rcvr_ty.kind() { if needs_mut { - let trait_type = - Ty::new_ref(self.tcx, *region, *t_type, mutability.invert()); + let trait_type = Ty::new_ref(self.tcx, region, t_type, mutability.invert()); let msg = format!("you need `{trait_type}` instead of `{rcvr_ty}`"); let mut kind = &self_expr.kind; while let hir::ExprKind::AddrOf(_, _, expr) @@ -779,7 +778,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // on pointers, check if the method would exist on a reference if let SelfSource::MethodCall(rcvr_expr) = source - && let ty::RawPtr(ty, ptr_mutbl) = *rcvr_ty.kind() + && let ty::RawPtr(ty, ptr_mutbl) = rcvr_ty.kind() && let Ok(pick) = self.lookup_probe_for_diagnostic( item_name, Ty::new_ref(tcx, ty::Region::new_error_misc(tcx), ty, ptr_mutbl), @@ -787,7 +786,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ProbeScope::TraitsInScope, None, ) - && let ty::Ref(_, _, sugg_mutbl) = *pick.self_ty.kind() + && let ty::Ref(_, _, sugg_mutbl) = pick.self_ty.kind() && (sugg_mutbl.is_not() || ptr_mutbl.is_mut()) { let (method, method_anchor) = match sugg_mutbl { @@ -1385,7 +1384,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { )), _ => arg, })); - let rcvr_ty = Ty::new_adt(tcx, *def, new_args); + let rcvr_ty = Ty::new_adt(tcx, def, new_args); if let Ok(method) = self.lookup_method_for_diagnostic( rcvr_ty, &item_segment, @@ -2843,7 +2842,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Target wrapper types - types that wrap or pretend to wrap another type, // perhaps this inner type is meant to be called? ty::AdtKind::Struct | ty::AdtKind::Union => { - let [first] = ***args else { + let [first] = **args else { return; }; let ty::GenericArgKind::Type(ty) = first.unpack() else { @@ -3776,9 +3775,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .sort_by_key(|&info| (!info.def_id.is_local(), self.tcx.def_path_str(info.def_id))); candidates.dedup(); - let param_type = match *rcvr_ty.kind() { + let param_type = match rcvr_ty.kind() { ty::Param(param) => Some(param), - ty::Ref(_, ty, _) => match *ty.kind() { + ty::Ref(_, ty, _) => match ty.kind() { ty::Param(param) => Some(param), _ => None, }, diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index c54f6cfd0999a..da129279c582d 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -256,9 +256,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let by_ref_binop = !op.node.is_by_value(); if is_assign == IsAssign::Yes || by_ref_binop { if let ty::Ref(region, _, mutbl) = method.sig.inputs()[0].kind() { - let mutbl = AutoBorrowMutability::new(*mutbl, AllowTwoPhase::Yes); + let mutbl = AutoBorrowMutability::new(mutbl, AllowTwoPhase::Yes); let autoref = Adjustment { - kind: Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)), + kind: Adjust::Borrow(AutoBorrow::Ref(region, mutbl)), target: method.sig.inputs()[0], }; self.apply_adjustments(lhs_expr, vec![autoref]); @@ -268,10 +268,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let ty::Ref(region, _, mutbl) = method.sig.inputs()[1].kind() { // Allow two-phase borrows for binops in initial deployment // since they desugar to methods - let mutbl = AutoBorrowMutability::new(*mutbl, AllowTwoPhase::Yes); + let mutbl = AutoBorrowMutability::new(mutbl, AllowTwoPhase::Yes); let autoref = Adjustment { - kind: Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)), + kind: Adjust::Borrow(AutoBorrow::Ref(region, mutbl)), target: method.sig.inputs()[1], }; // HACK(eddyb) Bypass checks due to reborrows being in @@ -507,12 +507,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } else if is_assign == IsAssign::No && let Ref(region, lhs_deref_ty, mutbl) = lhs_ty.kind() { - if self.type_is_copy_modulo_regions(self.param_env, *lhs_deref_ty) { - suggest_deref_binop(&mut err, *lhs_deref_ty); + if self.type_is_copy_modulo_regions(self.param_env, lhs_deref_ty) { + suggest_deref_binop(&mut err, lhs_deref_ty); } else { let lhs_inv_mutbl = mutbl.invert(); let lhs_inv_mutbl_ty = - Ty::new_ref(self.tcx, *region, *lhs_deref_ty, lhs_inv_mutbl); + Ty::new_ref(self.tcx, region, lhs_deref_ty, lhs_inv_mutbl); suggest_different_borrow( &mut err, @@ -525,7 +525,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let Ref(region, rhs_deref_ty, mutbl) = rhs_ty.kind() { let rhs_inv_mutbl = mutbl.invert(); let rhs_inv_mutbl_ty = - Ty::new_ref(self.tcx, *region, *rhs_deref_ty, rhs_inv_mutbl); + Ty::new_ref(self.tcx, region, rhs_deref_ty, rhs_inv_mutbl); suggest_different_borrow( &mut err, @@ -704,12 +704,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |ty: Ty<'tcx>| ty.ty_adt_def().is_some_and(|ty_def| Some(ty_def.did()) == string_type); match (lhs_ty.kind(), rhs_ty.kind()) { - (&Ref(_, l_ty, _), &Ref(_, r_ty, _)) // &str or &String + &str, &String or &&str - if (*l_ty.kind() == Str || is_std_string(l_ty)) - && (*r_ty.kind() == Str + (Ref(_, l_ty, _), Ref(_, r_ty, _)) // &str or &String + &str, &String or &&str + if (l_ty.kind() == Str || is_std_string(l_ty)) + && (r_ty.kind() == Str || is_std_string(r_ty) || matches!( - r_ty.kind(), Ref(_, inner_ty, _) if *inner_ty.kind() == Str + r_ty.kind(), Ref(_, inner_ty, _) if inner_ty.kind() == Str )) => { if let IsAssign::No = is_assign { // Do not supply this message if `&str += &str` @@ -733,8 +733,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } true } - (&Ref(_, l_ty, _), &Adt(..)) // Handle `&str` & `&String` + `String` - if (*l_ty.kind() == Str || is_std_string(l_ty)) && is_std_string(rhs_ty) => + (Ref(_, l_ty, _), Adt(..)) // Handle `&str` & `&String` + `String` + if (l_ty.kind() == Str || is_std_string(l_ty)) && is_std_string(rhs_ty) => { err.span_label( op.span, @@ -858,7 +858,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } Str | Never | Char | Tuple(_) | Array(_, _) => {} - Ref(_, lty, _) if *lty.kind() == Str => {} + Ref(_, lty, _) if lty.kind() == Str => {} _ => { self.note_unmet_impls_on_type(&mut err, errors, true); } @@ -1071,7 +1071,7 @@ enum Op { /// Dereferences a single level of immutable referencing. fn deref_ty_if_possible(ty: Ty<'_>) -> Ty<'_> { match ty.kind() { - ty::Ref(_, ty, hir::Mutability::Not) => *ty, + ty::Ref(_, ty, hir::Mutability::Not) => ty, _ => ty, } } diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index c4f74adb4207b..a2ce965398a4f 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -421,7 +421,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // // See the examples in `ui/match-defbm*.rs`. let mut pat_adjustments = vec![]; - while let ty::Ref(_, inner_ty, inner_mutability) = *expected.kind() { + while let ty::Ref(_, inner_ty, inner_mutability) = expected.kind() { debug!("inspecting {:?}", expected); debug!("current discriminant is Ref, inserting implicit deref"); @@ -476,7 +476,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut pat_ty = ty; if let hir::ExprKind::Lit(Spanned { node: ast::LitKind::ByteStr(..), .. }) = lt.kind { let expected = self.structurally_resolve_type(span, expected); - if let ty::Ref(_, inner_ty, _) = *expected.kind() + if let ty::Ref(_, inner_ty, _) = expected.kind() && self.try_structurally_resolve_type(span, inner_ty).is_slice() { let tcx = self.tcx; @@ -809,7 +809,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { match (expected.kind(), actual.kind(), ba) { (ty::Ref(_, inner_ty, _), _, BindingMode::NONE) - if self.can_eq(self.param_env, *inner_ty, actual) => + if self.can_eq(self.param_env, inner_ty, actual) => { err.span_suggestion_verbose( span.shrink_to_lo(), @@ -819,7 +819,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); } (_, ty::Ref(_, inner_ty, _), BindingMode::REF) - if self.can_eq(self.param_env, expected, *inner_ty) => + if self.can_eq(self.param_env, expected, inner_ty) => { err.span_suggestion_verbose( span.with_hi(span.lo() + BytePos(4)), @@ -1030,7 +1030,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return Ty::new_error(tcx, e); } Res::SelfCtor(def_id) => { - if let ty::Adt(adt_def, _) = *tcx.type_of(def_id).skip_binder().kind() + if let ty::Adt(adt_def, _) = tcx.type_of(def_id).skip_binder().kind() && adt_def.is_struct() && let Some((CtorKind::Const, _)) = adt_def.non_enum_variant().ctor { @@ -2162,7 +2162,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected = self.try_structurally_resolve_type(pat.span, expected); if new_match_ergonomics { if let ByRef::Yes(inh_mut) = pat_info.binding_mode { - if !ref_pat_eat_one_layer_2024 && let ty::Ref(_, _, r_mutbl) = *expected.kind() { + if !ref_pat_eat_one_layer_2024 && let ty::Ref(_, _, r_mutbl) = expected.kind() { // Don't attempt to consume inherited reference pat_info.binding_mode = pat_info.binding_mode.cap_ref_mutability(r_mutbl); } else { @@ -2225,7 +2225,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // to avoid creating needless variables. This also helps with // the bad interactions of the given hack detailed in (note_1). debug!("check_pat_ref: expected={:?}", expected); - match *expected.kind() { + match expected.kind() { ty::Ref(_, r_ty, r_mutbl) if (no_ref_mut_behind_and && r_mutbl >= pat_mutbl) || r_mutbl == pat_mutbl => @@ -2362,7 +2362,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let expected = self.structurally_resolve_type(span, expected); debug!(?expected); - let (element_ty, opt_slice_ty, inferred) = match *expected.kind() { + let (element_ty, opt_slice_ty, inferred) = match expected.kind() { // An array, so we might have something like `let [a, b, c] = [0, 1, 2];`. ty::Array(element_ty, len) => { let min = before.len() as u64 + after.len() as u64; @@ -2574,7 +2574,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Adt(adt_def, _) if self.tcx.is_diagnostic_item(sym::Vec, adt_def.did()) => { (true, ty) } - ty::Ref(_, ty, _) => self.is_slice_or_array_or_vector(*ty), + ty::Ref(_, ty, _) => self.is_slice_or_array_or_vector(ty), ty::Slice(..) | ty::Array(..) => (true, ty), _ => (false, ty), } diff --git a/compiler/rustc_hir_typeck/src/place_op.rs b/compiler/rustc_hir_typeck/src/place_op.rs index ad04b6b8b1df5..06f133511530d 100644 --- a/compiler/rustc_hir_typeck/src/place_op.rs +++ b/compiler/rustc_hir_typeck/src/place_op.rs @@ -32,7 +32,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.apply_adjustments( oprnd_expr, vec![Adjustment { - kind: Adjust::Borrow(AutoBorrow::Ref(*region, AutoBorrowMutability::Not)), + kind: Adjust::Borrow(AutoBorrow::Ref(region, AutoBorrowMutability::Not)), target: method.sig.inputs()[0], }], ); @@ -140,7 +140,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if unsize { // We only unsize arrays here. if let ty::Array(element_ty, _) = adjusted_ty.kind() { - self_ty = Ty::new_slice(self.tcx, *element_ty); + self_ty = Ty::new_slice(self.tcx, element_ty); } else { continue; } @@ -160,8 +160,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut adjustments = self.adjust_steps(autoderef); if let ty::Ref(region, _, hir::Mutability::Not) = method.sig.inputs()[0].kind() { adjustments.push(Adjustment { - kind: Adjust::Borrow(AutoBorrow::Ref(*region, AutoBorrowMutability::Not)), - target: Ty::new_imm_ref(self.tcx, *region, adjusted_ty), + kind: Adjust::Borrow(AutoBorrow::Ref(region, AutoBorrowMutability::Not)), + target: Ty::new_imm_ref(self.tcx, region, adjusted_ty), }); } else { span_bug!(expr.span, "input to index is not a ref?"); @@ -291,7 +291,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { let method = self.register_infer_ok_obligations(ok); - if let ty::Ref(region, _, mutbl) = *method.sig.output().kind() { + if let ty::Ref(region, _, mutbl) = method.sig.output().kind() { *deref = OverloadedDeref { region, mutbl, span: deref.span }; } // If this is a union field, also throw an error for `DerefMut` of `ManuallyDrop` (see RFC 2514). @@ -393,8 +393,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // not the case today. allow_two_phase_borrow: AllowTwoPhase::No, }; - adjustment.kind = Adjust::Borrow(AutoBorrow::Ref(*region, mutbl)); - adjustment.target = Ty::new_ref(self.tcx, *region, source, mutbl.into()); + adjustment.kind = Adjust::Borrow(AutoBorrow::Ref(region, mutbl)); + adjustment.target = Ty::new_ref(self.tcx, region, source, mutbl.into()); } source = adjustment.target; } diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index 55f002291f071..c9a6a1616158b 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -171,7 +171,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { // Extract the type of the closure. let ty = self.node_ty(closure_hir_id); - let (closure_def_id, args, infer_kind) = match *ty.kind() { + let (closure_def_id, args, infer_kind) = match ty.kind() { ty::Closure(def_id, args) => { (def_id, UpvarArgs::Closure(args), self.closure_kind(ty).is_none()) } @@ -457,7 +457,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // for the inner coroutine may actually be more restrictive. if infer_kind { let ty::Coroutine(_, coroutine_args) = - *self.typeck_results.borrow().expr_ty(body.value).kind() + self.typeck_results.borrow().expr_ty(body.value).kind() else { bug!(); }; diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index 0327a3097eca2..a501d9479a530 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -219,7 +219,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { if let hir::ExprKind::Index(ref base, ref index, _) = e.kind { // All valid indexing looks like this; might encounter non-valid indexes at this point. let base_ty = self.typeck_results.expr_ty_adjusted(base); - if let ty::Ref(_, base_ty_inner, _) = *base_ty.kind() { + if let ty::Ref(_, base_ty_inner, _) = base_ty.kind() { let index_ty = self.typeck_results.expr_ty_adjusted(index); if self.is_builtin_index(e, base_ty_inner, index_ty) { // Remove the method call record diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index db5139172b022..5296b1feff64a 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -340,7 +340,7 @@ impl<'cx, 'tcx> TypeFolder> for Canonicalizer<'cx, 'tcx> { } fn fold_ty(&mut self, mut t: Ty<'tcx>) -> Ty<'tcx> { - match *t.kind() { + match t.kind() { ty::Infer(ty::TyVar(mut vid)) => { // We need to canonicalize the *root* of our ty var. // This is so that our canonical response correctly reflects diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index 85e3cfbcce1c1..82f84f7a4d209 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -432,7 +432,7 @@ impl<'tcx> InferCtxt<'tcx> { match result_value.unpack() { GenericArgKind::Type(result_value) => { // e.g., here `result_value` might be `?0` in the example above... - if let ty::Bound(debruijn, b) = *result_value.kind() { + if let ty::Bound(debruijn, b) = result_value.kind() { // ...in which case we would set `canonical_vars[0]` to `Some(?U)`. // We only allow a `ty::INNERMOST` index in generic parameters. diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index c4294111ebe85..f3a2942f1d9df 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -129,7 +129,7 @@ impl<'a, 'tcx> TypeFolder> for TypeFreshener<'a, 'tcx> { if !t.has_infer() && !t.has_erasable_regions() { t } else { - match *t.kind() { + match t.kind() { ty::Infer(v) => self.fold_infer_ty(v).unwrap_or(t), // This code is hot enough that a non-debug assertion here makes a noticeable diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index f2fc25a2d2e10..f189cc6023108 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -837,7 +837,7 @@ impl<'tcx> InferCtxt<'tcx> { let r_a = self.shallow_resolve(predicate.skip_binder().a); let r_b = self.shallow_resolve(predicate.skip_binder().b); match (r_a.kind(), r_b.kind()) { - (&ty::Infer(ty::TyVar(a_vid)), &ty::Infer(ty::TyVar(b_vid))) => { + (ty::Infer(ty::TyVar(a_vid)), ty::Infer(ty::TyVar(b_vid))) => { return Err((a_vid, b_vid)); } _ => {} @@ -1121,7 +1121,7 @@ impl<'tcx> InferCtxt<'tcx> { } pub fn shallow_resolve(&self, ty: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Infer(v) = *ty.kind() { + if let ty::Infer(v) = ty.kind() { match v { ty::TyVar(v) => { // Not entirely obvious: if `typ` is a type variable, @@ -1371,7 +1371,7 @@ impl<'tcx> InferCtxt<'tcx> { /// closure in the current function, in which case its /// `ClosureKind` may not yet be known. pub fn closure_kind(&self, closure_ty: Ty<'tcx>) -> Option { - let unresolved_kind_ty = match *closure_ty.kind() { + let unresolved_kind_ty = match closure_ty.kind() { ty::Closure(_, args) => args.as_closure().kind_ty(), ty::CoroutineClosure(_, args) => args.as_coroutine_closure().kind_ty(), _ => bug!("unexpected type {closure_ty}"), @@ -1594,7 +1594,7 @@ impl<'tcx> TyOrConstInferVar { /// Tries to extract an inference variable from a type, returns `None` /// for types other than `ty::Infer(_)` (or `InferTy::Fresh*`). fn maybe_from_ty(ty: Ty<'tcx>) -> Option { - match *ty.kind() { + match ty.kind() { ty::Infer(ty::TyVar(v)) => Some(TyOrConstInferVar::Ty(v)), ty::Infer(ty::IntVar(v)) => Some(TyOrConstInferVar::TyInt(v)), ty::Infer(ty::FloatVar(v)) => Some(TyOrConstInferVar::TyFloat(v)), diff --git a/compiler/rustc_infer/src/infer/opaque_types/mod.rs b/compiler/rustc_infer/src/infer/opaque_types/mod.rs index e9726ee8ebf3b..55df31beac1ae 100644 --- a/compiler/rustc_infer/src/infer/opaque_types/mod.rs +++ b/compiler/rustc_infer/src/infer/opaque_types/mod.rs @@ -58,7 +58,7 @@ impl<'tcx> InferCtxt<'tcx> { tcx: self.tcx, lt_op: |lt| lt, ct_op: |ct| ct, - ty_op: |ty| match *ty.kind() { + ty_op: |ty| match ty.kind() { ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) if self.can_define_opaque_ty(def_id) && !ty.has_escaping_bound_vars() => { @@ -97,7 +97,7 @@ impl<'tcx> InferCtxt<'tcx> { span: Span, param_env: ty::ParamEnv<'tcx>, ) -> Result>>, TypeError<'tcx>> { - let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() { + let process = |a: Ty<'tcx>, b: Ty<'tcx>| match a.kind() { ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) if def_id.is_local() => { let def_id = def_id.expect_local(); if self.intercrate { @@ -147,7 +147,7 @@ impl<'tcx> InferCtxt<'tcx> { return None; } - if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }) = *b.kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }) = b.kind() { // We could accept this, but there are various ways to handle this situation, and we don't // want to make a decision on it right now. Likely this case is so super rare anyway, that // no one encounters it in practice. @@ -438,7 +438,7 @@ where ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { // Skip lifetime parameters that are not captures. - let variances = self.tcx.variances_of(*def_id); + let variances = self.tcx.variances_of(def_id); for (v, s) in std::iter::zip(variances, args.iter()) { if *v != ty::Bivariant { @@ -577,7 +577,7 @@ impl<'tcx> InferCtxt<'tcx> { for (predicate, _) in item_bounds.iter_instantiated_copied(tcx, args) { let predicate = predicate.fold_with(&mut BottomUpFolder { tcx, - ty_op: |ty| match *ty.kind() { + ty_op: |ty| match ty.kind() { // We can't normalize associated types from `rustc_infer`, // but we can eagerly register inference variables for them. // FIXME(RPITIT): Don't replace RPITITs with inference vars. diff --git a/compiler/rustc_infer/src/infer/outlives/for_liveness.rs b/compiler/rustc_infer/src/infer/outlives/for_liveness.rs index c02ab98b2baeb..3b9ffae9351b3 100644 --- a/compiler/rustc_infer/src/infer/outlives/for_liveness.rs +++ b/compiler/rustc_infer/src/infer/outlives/for_liveness.rs @@ -97,7 +97,7 @@ where } else { // Skip lifetime parameters that are not captures. let variances = match kind { - ty::Opaque => Some(self.tcx.variances_of(*def_id)), + ty::Opaque => Some(self.tcx.variances_of(def_id)), _ => None, }; diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index 88b004adc9418..eb6962dd72ab8 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -406,7 +406,7 @@ where // will be invoked with `['b => ^1]` and so we will get `^1` returned. let bound = bound_outlives.skip_binder(); let ty::Alias(_, alias_ty) = bound.0.kind() else { bug!("expected AliasTy") }; - self.verify_bound.declared_bounds_from_definition(*alias_ty).all(|r| r != bound.1) + self.verify_bound.declared_bounds_from_definition(alias_ty).all(|r| r != bound.1) }); // If declared bounds list is empty, the only applicable rule is diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index 1908e1e09c3d5..dd848b5aba8b3 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -230,7 +230,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { (r, p) ); // Fast path for the common case. - match (&p, erased_ty.kind()) { + match (p, erased_ty.kind()) { // In outlive routines, all types are expected to be fully normalized. // And therefore we can safely use structural equality for alias types. (GenericKind::Param(p1), ty::Param(p2)) if p1 == p2 => {} diff --git a/compiler/rustc_infer/src/infer/relate/combine.rs b/compiler/rustc_infer/src/infer/relate/combine.rs index 5751ce466d982..96268d0592f72 100644 --- a/compiler/rustc_infer/src/infer/relate/combine.rs +++ b/compiler/rustc_infer/src/infer/relate/combine.rs @@ -82,37 +82,37 @@ impl<'tcx> InferCtxt<'tcx> { match (a.kind(), b.kind()) { // Relate integral variables to other types - (&ty::Infer(ty::IntVar(a_id)), &ty::Infer(ty::IntVar(b_id))) => { + (ty::Infer(ty::IntVar(a_id)), ty::Infer(ty::IntVar(b_id))) => { self.inner.borrow_mut().int_unification_table().union(a_id, b_id); Ok(a) } - (&ty::Infer(ty::IntVar(v_id)), &ty::Int(v)) => { + (ty::Infer(ty::IntVar(v_id)), ty::Int(v)) => { self.unify_integral_variable(v_id, IntType(v)); Ok(b) } - (&ty::Int(v), &ty::Infer(ty::IntVar(v_id))) => { + (ty::Int(v), ty::Infer(ty::IntVar(v_id))) => { self.unify_integral_variable(v_id, IntType(v)); Ok(a) } - (&ty::Infer(ty::IntVar(v_id)), &ty::Uint(v)) => { + (ty::Infer(ty::IntVar(v_id)), ty::Uint(v)) => { self.unify_integral_variable(v_id, UintType(v)); Ok(b) } - (&ty::Uint(v), &ty::Infer(ty::IntVar(v_id))) => { + (ty::Uint(v), ty::Infer(ty::IntVar(v_id))) => { self.unify_integral_variable(v_id, UintType(v)); Ok(a) } // Relate floating-point variables to other types - (&ty::Infer(ty::FloatVar(a_id)), &ty::Infer(ty::FloatVar(b_id))) => { + (ty::Infer(ty::FloatVar(a_id)), ty::Infer(ty::FloatVar(b_id))) => { self.inner.borrow_mut().float_unification_table().union(a_id, b_id); Ok(a) } - (&ty::Infer(ty::FloatVar(v_id)), &ty::Float(v)) => { + (ty::Infer(ty::FloatVar(v_id)), ty::Float(v)) => { self.unify_float_variable(v_id, ty::FloatVarValue::Known(v)); Ok(b) } - (&ty::Float(v), &ty::Infer(ty::FloatVar(v_id))) => { + (ty::Float(v), ty::Infer(ty::FloatVar(v_id))) => { self.unify_float_variable(v_id, ty::FloatVarValue::Known(v)); Ok(a) } @@ -146,7 +146,7 @@ impl<'tcx> InferCtxt<'tcx> { } // All other cases of inference are errors - (&ty::Infer(_), _) | (_, &ty::Infer(_)) => { + (ty::Infer(_), _) | (_, ty::Infer(_)) => { Err(TypeError::Sorts(ExpectedFound::new(true, a, b))) } @@ -154,7 +154,7 @@ impl<'tcx> InferCtxt<'tcx> { // equal to any other type (except for possibly itself). This is an // extremely heavy hammer, but can be relaxed in a fowards-compatible // way later. - (&ty::Alias(ty::Opaque, _), _) | (_, &ty::Alias(ty::Opaque, _)) if self.intercrate => { + (ty::Alias(ty::Opaque, _), _) | (_, ty::Alias(ty::Opaque, _)) if self.intercrate => { relation.register_predicates([ty::Binder::dummy(ty::PredicateKind::Ambiguous)]); Ok(a) } diff --git a/compiler/rustc_infer/src/infer/relate/generalize.rs b/compiler/rustc_infer/src/infer/relate/generalize.rs index 542104fa10ba0..4d0b98fe13c08 100644 --- a/compiler/rustc_infer/src/infer/relate/generalize.rs +++ b/compiler/rustc_infer/src/infer/relate/generalize.rs @@ -60,7 +60,7 @@ impl<'tcx> InferCtxt<'tcx> { )?; // Constrain `b_vid` to the generalized type `generalized_ty`. - if let &ty::Infer(ty::TyVar(generalized_vid)) = generalized_ty.kind() { + if let ty::Infer(ty::TyVar(generalized_vid)) = generalized_ty.kind() { self.inner.borrow_mut().type_variables().equate(target_vid, generalized_vid); } else { self.inner.borrow_mut().type_variables().instantiate(target_vid, generalized_ty); @@ -100,7 +100,7 @@ impl<'tcx> InferCtxt<'tcx> { relation.register_predicates([ty::PredicateKind::AliasRelate(lhs, rhs, direction)]); } else { match source_ty.kind() { - &ty::Alias(ty::Projection, data) => { + ty::Alias(ty::Projection, data) => { // FIXME: This does not handle subtyping correctly, we could // instead create a new inference variable `?normalized_source`, emitting // `Projection(normalized_source, ?ty_normalized)` and `?normalized_source <: generalized_ty`. @@ -458,7 +458,7 @@ impl<'tcx> TypeRelation> for Generalizer<'_, 'tcx> { // any other type variable related to `vid` via // subtyping. This is basically our "occurs check", preventing // us from creating infinitely sized types. - let g = match *t.kind() { + let g = match t.kind() { ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { bug!("unexpected infer type: {t}") } diff --git a/compiler/rustc_infer/src/infer/relate/lattice.rs b/compiler/rustc_infer/src/infer/relate/lattice.rs index f555fedbb5bcd..a7b200349d90b 100644 --- a/compiler/rustc_infer/src/infer/relate/lattice.rs +++ b/compiler/rustc_infer/src/infer/relate/lattice.rs @@ -83,24 +83,24 @@ where // is (e.g.) `Box`. A more obvious solution might be to // iterate on the subtype obligations that are returned, but I // think this suffices. -nmatsakis - (&ty::Infer(TyVar(..)), _) => { + (ty::Infer(TyVar(..)), _) => { let v = infcx.next_ty_var(this.cause().span); this.relate_bound(v, b, a)?; Ok(v) } - (_, &ty::Infer(TyVar(..))) => { + (_, ty::Infer(TyVar(..))) => { let v = infcx.next_ty_var(this.cause().span); this.relate_bound(v, a, b)?; Ok(v) } ( - &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }), - &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }), + ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }), + ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }), ) if a_def_id == b_def_id => infcx.super_combine_tys(this, a, b), - (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _) - | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) + (ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _) + | (_, ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) if this.define_opaque_types() == DefineOpaqueTypes::Yes && def_id.is_local() && !this.infcx().next_trait_solver() => diff --git a/compiler/rustc_infer/src/infer/relate/type_relating.rs b/compiler/rustc_infer/src/infer/relate/type_relating.rs index ec600c60b240b..89ec91d03dd20 100644 --- a/compiler/rustc_infer/src/infer/relate/type_relating.rs +++ b/compiler/rustc_infer/src/infer/relate/type_relating.rs @@ -78,7 +78,7 @@ impl<'tcx> TypeRelation> for TypeRelating<'_, '_, 'tcx> { let b = infcx.shallow_resolve(b); match (a.kind(), b.kind()) { - (&ty::Infer(TyVar(a_id)), &ty::Infer(TyVar(b_id))) => { + (ty::Infer(TyVar(a_id)), ty::Infer(TyVar(b_id))) => { match self.ambient_variance { ty::Covariant => { // can't make progress on `A <: B` if both A and B are @@ -115,10 +115,10 @@ impl<'tcx> TypeRelation> for TypeRelating<'_, '_, 'tcx> { } } - (&ty::Infer(TyVar(a_vid)), _) => { + (ty::Infer(TyVar(a_vid)), _) => { infcx.instantiate_ty_var(self, true, a_vid, self.ambient_variance, b)?; } - (_, &ty::Infer(TyVar(b_vid))) => { + (_, ty::Infer(TyVar(b_vid))) => { infcx.instantiate_ty_var( self, false, @@ -128,20 +128,20 @@ impl<'tcx> TypeRelation> for TypeRelating<'_, '_, 'tcx> { )?; } - (&ty::Error(e), _) | (_, &ty::Error(e)) => { + (ty::Error(e), _) | (_, ty::Error(e)) => { infcx.set_tainted_by_errors(e); return Ok(Ty::new_error(self.cx(), e)); } ( - &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }), - &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }), + ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }), + ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }), ) if a_def_id == b_def_id => { infcx.super_combine_tys(self, a, b)?; } - (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _) - | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) + (ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _) + | (_, ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) if self.fields.define_opaque_types == DefineOpaqueTypes::Yes && def_id.is_local() && !infcx.next_trait_solver() => diff --git a/compiler/rustc_infer/src/infer/resolve.rs b/compiler/rustc_infer/src/infer/resolve.rs index 34625ffb77879..f815ff24d9205 100644 --- a/compiler/rustc_infer/src/infer/resolve.rs +++ b/compiler/rustc_infer/src/infer/resolve.rs @@ -131,7 +131,7 @@ impl<'a, 'tcx> FallibleTypeFolder> for FullTypeResolver<'a, 'tcx> { Ok(t) // micro-optimize -- if there is nothing in this type that this fold affects... } else { let t = self.infcx.shallow_resolve(t); - match *t.kind() { + match t.kind() { ty::Infer(ty::TyVar(vid)) => Err(FixupError::UnresolvedTy(vid)), ty::Infer(ty::IntVar(vid)) => Err(FixupError::UnresolvedIntTy(vid)), ty::Infer(ty::FloatVar(vid)) => Err(FixupError::UnresolvedFloatTy(vid)), diff --git a/compiler/rustc_infer/src/infer/snapshot/fudge.rs b/compiler/rustc_infer/src/infer/snapshot/fudge.rs index bc954054ea281..f79376f4bb118 100644 --- a/compiler/rustc_infer/src/infer/snapshot/fudge.rs +++ b/compiler/rustc_infer/src/infer/snapshot/fudge.rs @@ -185,7 +185,7 @@ impl<'a, 'tcx> TypeFolder> for InferenceFudger<'a, 'tcx> { } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - match *ty.kind() { + match ty.kind() { ty::Infer(ty::InferTy::TyVar(vid)) => { if self.type_vars.0.contains(&vid) { // This variable was created during the fudging. diff --git a/compiler/rustc_infer/src/infer/type_variable.rs b/compiler/rustc_infer/src/infer/type_variable.rs index f022b8ab637eb..ce413d798e5ee 100644 --- a/compiler/rustc_infer/src/infer/type_variable.rs +++ b/compiler/rustc_infer/src/infer/type_variable.rs @@ -186,7 +186,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> { /// instantiated, then return the with which it was /// instantiated. Otherwise, returns `t`. pub fn replace_if_possible(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - match *t.kind() { + match t.kind() { ty::Infer(ty::TyVar(v)) => match self.probe(v) { TypeVariableValue::Unknown { .. } => t, TypeVariableValue::Known { value } => value, diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 6b36944b20889..92317fe4aa64b 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -492,7 +492,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc { let impl_ty = cx.tcx.type_of(parent).instantiate_identity(); let outerdef = match impl_ty.kind() { ty::Adt(def, _) => Some(def.did()), - ty::Foreign(def_id) => Some(*def_id), + ty::Foreign(def_id) => Some(def_id), _ => None, }; let is_hidden = match outerdef { @@ -1131,7 +1131,7 @@ declare_lint_pass!(MutableTransmutes => [MUTABLE_TRANSMUTES]); impl<'tcx> LateLintPass<'tcx> for MutableTransmutes { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &hir::Expr<'_>) { - if let Some((&ty::Ref(_, _, from_mutbl), &ty::Ref(_, _, to_mutbl))) = + if let Some((ty::Ref(_, _, from_mutbl), ty::Ref(_, _, to_mutbl))) = get_transmute_from_to(cx, expr).map(|(ty1, ty2)| (ty1.kind(), ty2.kind())) { if from_mutbl < to_mutbl { @@ -2564,7 +2564,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { let span = cx.tcx.def_span(adt_def.did()); let mut potential_variants = adt_def.variants().iter().filter_map(|variant| { let definitely_inhabited = match variant - .inhabited_predicate(cx.tcx, *adt_def) + .inhabited_predicate(cx.tcx, adt_def) .instantiate(cx.tcx, args) .apply_any_module(cx.tcx, cx.param_env) { @@ -2621,7 +2621,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue { Array(ty, len) => { if matches!(len.try_eval_target_usize(cx.tcx, cx.param_env), Some(v) if v > 0) { // Array length known at array non-empty -- recurse. - ty_find_init_error(cx, *ty, init) + ty_find_init_error(cx, ty, init) } else { // Empty array or size unknown. None diff --git a/compiler/rustc_lint/src/for_loops_over_fallibles.rs b/compiler/rustc_lint/src/for_loops_over_fallibles.rs index 2793d48dc512b..dd32744f8a57c 100644 --- a/compiler/rustc_lint/src/for_loops_over_fallibles.rs +++ b/compiler/rustc_lint/src/for_loops_over_fallibles.rs @@ -52,9 +52,9 @@ impl<'tcx> LateLintPass<'tcx> for ForLoopsOverFallibles { let ty = cx.typeck_results().expr_ty(arg); let (adt, args, ref_mutability) = match ty.kind() { - &ty::Adt(adt, args) => (adt, args, None), - &ty::Ref(_, ty, mutability) => match ty.kind() { - &ty::Adt(adt, args) => (adt, args, Some(mutability)), + ty::Adt(adt, args) => (adt, args, None), + ty::Ref(_, ty, mutability) => match ty.kind() { + ty::Adt(adt, args) => (adt, args, Some(mutability)), _ => return, }, _ => return, diff --git a/compiler/rustc_lint/src/foreign_modules.rs b/compiler/rustc_lint/src/foreign_modules.rs index 5da1cbc2283b6..89fee7da95654 100644 --- a/compiler/rustc_lint/src/foreign_modules.rs +++ b/compiler/rustc_lint/src/foreign_modules.rs @@ -229,7 +229,7 @@ fn structurally_same_type_impl<'tcx>( // type unless the newtype makes the type non-null. let non_transparent_ty = |mut ty: Ty<'tcx>| -> Ty<'tcx> { loop { - if let ty::Adt(def, args) = *ty.kind() { + if let ty::Adt(def, args) = ty.kind() { let is_transparent = def.repr().transparent(); let is_non_null = types::nonnull_optimization_guaranteed(tcx, def); debug!( @@ -283,7 +283,7 @@ fn structurally_same_type_impl<'tcx>( #[allow(rustc::usage_of_ty_tykind)] let is_primitive_or_pointer = - |kind: &ty::TyKind<'_>| kind.is_primitive() || matches!(kind, RawPtr(..) | Ref(..)); + |kind: ty::TyKind<'_>| kind.is_primitive() || matches!(kind, RawPtr(..) | Ref(..)); ensure_sufficient_stack(|| { match (a_kind, b_kind) { @@ -318,23 +318,23 @@ fn structurally_same_type_impl<'tcx>( // For arrays, we also check the constness of the type. a_const.kind() == b_const.kind() && structurally_same_type_impl( - seen_types, tcx, param_env, *a_ty, *b_ty, ckind, + seen_types, tcx, param_env, a_ty, b_ty, ckind, ) } (Slice(a_ty), Slice(b_ty)) => { - structurally_same_type_impl(seen_types, tcx, param_env, *a_ty, *b_ty, ckind) + structurally_same_type_impl(seen_types, tcx, param_env, a_ty, b_ty, ckind) } (RawPtr(a_ty, a_mutbl), RawPtr(b_ty, b_mutbl)) => { a_mutbl == b_mutbl && structurally_same_type_impl( - seen_types, tcx, param_env, *a_ty, *b_ty, ckind, + seen_types, tcx, param_env, a_ty, b_ty, ckind, ) } (Ref(_a_region, a_ty, a_mut), Ref(_b_region, b_ty, b_mut)) => { // For structural sameness, we don't need the region to be same. a_mut == b_mut && structurally_same_type_impl( - seen_types, tcx, param_env, *a_ty, *b_ty, ckind, + seen_types, tcx, param_env, a_ty, b_ty, ckind, ) } (FnDef(..), FnDef(..)) => { diff --git a/compiler/rustc_lint/src/impl_trait_overcaptures.rs b/compiler/rustc_lint/src/impl_trait_overcaptures.rs index e914169f4c373..8b4d56fa4ebf7 100644 --- a/compiler/rustc_lint/src/impl_trait_overcaptures.rs +++ b/compiler/rustc_lint/src/impl_trait_overcaptures.rs @@ -192,7 +192,7 @@ impl<'tcx> TypeVisitor> for VisitOpaqueTypes<'tcx> { return; } - if let ty::Alias(ty::Projection, opaque_ty) = *t.kind() + if let ty::Alias(ty::Projection, opaque_ty) = t.kind() && self.tcx.is_impl_trait_in_trait(opaque_ty.def_id) { // visit the opaque of the RPITIT @@ -200,7 +200,7 @@ impl<'tcx> TypeVisitor> for VisitOpaqueTypes<'tcx> { .type_of(opaque_ty.def_id) .instantiate(self.tcx, opaque_ty.args) .visit_with(self) - } else if let ty::Alias(ty::Opaque, opaque_ty) = *t.kind() + } else if let ty::Alias(ty::Opaque, opaque_ty) = t.kind() && let Some(opaque_def_id) = opaque_ty.def_id.as_local() // Don't recurse infinitely on an opaque && self.seen.insert(opaque_def_id) @@ -402,7 +402,7 @@ fn extract_def_id_from_arg<'tcx>( _ => unreachable!(), }, ty::GenericArgKind::Type(ty) => { - let ty::Param(param_ty) = *ty.kind() else { + let ty::Param(param_ty) = ty.kind() else { bug!(); }; generics.type_param(param_ty, tcx).def_id diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 044c9413f0b31..2edada41a98ce 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -69,7 +69,7 @@ fn typeck_results_of_method_fn<'tcx>( Some((segment.ident.span, def_id, cx.typeck_results().node_args(expr.hir_id))) } _ => match cx.typeck_results().node_type(expr.hir_id).kind() { - &ty::FnDef(def_id, args) => Some((expr.span, def_id, args)), + ty::FnDef(def_id, args) => Some((expr.span, def_id, args)), _ => None, }, } @@ -419,7 +419,7 @@ impl LateLintPass<'_> for Diagnostics { let (span, def_id, fn_gen_args, call_tys) = match expr.kind { ExprKind::Call(callee, args) => { match cx.typeck_results().node_type(callee.hir_id).kind() { - &ty::FnDef(def_id, fn_gen_args) => { + ty::FnDef(def_id, fn_gen_args) => { let call_tys: Vec<_> = args.iter().map(|arg| cx.typeck_results().expr_ty(arg)).collect(); (callee.span, def_id, fn_gen_args, call_tys) diff --git a/compiler/rustc_lint/src/map_unit_fn.rs b/compiler/rustc_lint/src/map_unit_fn.rs index 3b27e45613690..395c7e85ae98a 100644 --- a/compiler/rustc_lint/src/map_unit_fn.rs +++ b/compiler/rustc_lint/src/map_unit_fn.rs @@ -64,10 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for MapUnitFn { MAP_UNIT_FN, span, MappingToUnit { - function_label: cx - .tcx - .span_of_impl(*id) - .unwrap_or(default_span), + function_label: cx.tcx.span_of_impl(id).unwrap_or(default_span), argument_label: args[0].span, map_label: arg_ty.default_span(cx.tcx), suggestion: path.ident.span, @@ -83,10 +80,7 @@ impl<'tcx> LateLintPass<'tcx> for MapUnitFn { MAP_UNIT_FN, span, MappingToUnit { - function_label: cx - .tcx - .span_of_impl(*id) - .unwrap_or(default_span), + function_label: cx.tcx.span_of_impl(id).unwrap_or(default_span), argument_label: args[0].span, map_label: arg_ty.default_span(cx.tcx), suggestion: path.ident.span, diff --git a/compiler/rustc_lint/src/non_fmt_panic.rs b/compiler/rustc_lint/src/non_fmt_panic.rs index 10a517bfbcb76..409f6d55ed856 100644 --- a/compiler/rustc_lint/src/non_fmt_panic.rs +++ b/compiler/rustc_lint/src/non_fmt_panic.rs @@ -51,7 +51,7 @@ declare_lint_pass!(NonPanicFmt => [NON_FMT_PANICS]); impl<'tcx> LateLintPass<'tcx> for NonPanicFmt { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'tcx>) { if let hir::ExprKind::Call(f, [arg]) = &expr.kind { - if let &ty::FnDef(def_id, _) = cx.typeck_results().expr_ty(f).kind() { + if let ty::FnDef(def_id, _) = cx.typeck_results().expr_ty(f).kind() { let f_diagnostic_name = cx.tcx.get_diagnostic_name(def_id); if cx.tcx.is_lang_item(def_id, LangItem::BeginPanic) diff --git a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs index e0ba6a912f120..e728755c96883 100644 --- a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs +++ b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs @@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { let Some(proj_term) = proj.term.as_type() else { return }; // HACK: `impl Trait` from an RPIT is "ok"... - if let ty::Alias(ty::Opaque, opaque_ty) = *proj_term.kind() + if let ty::Alias(ty::Opaque, opaque_ty) = proj_term.kind() && cx.tcx.parent(opaque_ty.def_id) == def_id && matches!( opaque.origin, @@ -100,7 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { // HACK: `async fn() -> Self` in traits is "ok"... // This is not really that great, but it's similar to why the `-> Self` // return type is well-formed in traits even when `Self` isn't sized. - if let ty::Param(param_ty) = *proj_term.kind() + if let ty::Param(param_ty) = proj_term.kind() && param_ty.name == kw::SelfUpper && matches!(opaque.origin, hir::OpaqueTyOrigin::AsyncFn(_)) && opaque.in_trait @@ -158,7 +158,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), ty::ClauseKind::Trait(trait_pred), ) => Some(AddBound { - suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(), + suggest_span: cx.tcx.def_span(def_id).shrink_to_hi(), trait_ref: trait_pred.print_modifiers_and_trait_path(), }), _ => None, diff --git a/compiler/rustc_lint/src/reference_casting.rs b/compiler/rustc_lint/src/reference_casting.rs index 5e8c39c0023eb..ec29c0bbef6cc 100644 --- a/compiler/rustc_lint/src/reference_casting.rs +++ b/compiler/rustc_lint/src/reference_casting.rs @@ -218,7 +218,7 @@ fn is_cast_to_bigger_memory_layout<'tcx>( return None; } - let from_layout = cx.layout_of(*inner_start_ty).ok()?; + let from_layout = cx.layout_of(inner_start_ty).ok()?; // if the type isn't sized, we bail out, instead of potentially giving // the user a meaningless warning. @@ -227,7 +227,7 @@ fn is_cast_to_bigger_memory_layout<'tcx>( } let alloc_layout = cx.layout_of(alloc_ty).ok()?; - let to_layout = cx.layout_of(*inner_end_ty).ok()?; + let to_layout = cx.layout_of(inner_end_ty).ok()?; if to_layout.layout.size() > from_layout.layout.size() && to_layout.layout.size() > alloc_layout.layout.size() diff --git a/compiler/rustc_lint/src/shadowed_into_iter.rs b/compiler/rustc_lint/src/shadowed_into_iter.rs index 4fe35a6a0a3bc..5e3e6439ac947 100644 --- a/compiler/rustc_lint/src/shadowed_into_iter.rs +++ b/compiler/rustc_lint/src/shadowed_into_iter.rs @@ -92,13 +92,13 @@ impl<'tcx> LateLintPass<'tcx> for ShadowedIntoIter { [receiver_ty].into_iter().chain(adjustments.iter().map(|adj| adj.target)).collect(); fn is_ref_to_array(ty: Ty<'_>) -> bool { - if let ty::Ref(_, pointee_ty, _) = *ty.kind() { pointee_ty.is_array() } else { false } + if let ty::Ref(_, pointee_ty, _) = ty.kind() { pointee_ty.is_array() } else { false } } fn is_boxed_slice(ty: Ty<'_>) -> bool { ty.is_box() && ty.boxed_ty().is_slice() } fn is_ref_to_boxed_slice(ty: Ty<'_>) -> bool { - if let ty::Ref(_, pointee_ty, _) = *ty.kind() { + if let ty::Ref(_, pointee_ty, _) = ty.kind() { is_boxed_slice(pointee_ty) } else { false diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 54bf73a40dd52..ec52f0ef035dc 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -541,7 +541,7 @@ fn lint_literal<'tcx>( e: &'tcx hir::Expr<'tcx>, lit: &hir::Lit, ) { - match *cx.typeck_results().node_type(e.hir_id).kind() { + match cx.typeck_results().node_type(e.hir_id).kind() { ty::Int(t) => { match lit.node { ast::LitKind::Int(v, ast::LitIntType::Signed(_) | ast::LitIntType::Unsuffixed) => { @@ -673,14 +673,14 @@ fn lint_wide_pointer<'tcx>( // here we remove any "implicit" references and count the number // of them to correctly suggest the right number of deref while let ty::Ref(_, inner_ty, _) = ty.kind() { - ty = *inner_ty; + ty = inner_ty; refs += 1; } // get the inner type of a pointer (or akin) let mut modifiers = String::new(); ty = match ty.kind() { - ty::RawPtr(ty, _) => *ty, + ty::RawPtr(ty, _) => ty, ty::Adt(def, args) if cx.tcx.is_diagnostic_item(sym::NonNull, def.did()) => { modifiers.push_str(".as_ptr()"); args.type_at(0) @@ -856,7 +856,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits { // Normalize the binop so that the literal is always on the RHS in // the comparison let norm_binop = if swap { rev_binop(binop) } else { binop }; - match *cx.typeck_results().node_type(expr.hir_id).kind() { + match cx.typeck_results().node_type(expr.hir_id).kind() { ty::Int(int_ty) => { let (min, max) = int_ty_range(int_ty); let lit_val: i128 = match lit.kind { @@ -1026,7 +1026,7 @@ fn ty_is_known_nonnull<'tcx>( ty::Ref(..) => true, ty::Adt(def, _) if def.is_box() && matches!(mode, CItemKind::Definition) => true, ty::Adt(def, args) if def.repr().transparent() && !def.is_union() => { - let marked_non_null = nonnull_optimization_guaranteed(tcx, *def); + let marked_non_null = nonnull_optimization_guaranteed(tcx, def); if marked_non_null { return true; @@ -1055,7 +1055,7 @@ fn get_nullable_type<'tcx>( ) -> Option> { let ty = tcx.try_normalize_erasing_regions(param_env, ty).unwrap_or(ty); - Some(match *ty.kind() { + Some(match ty.kind() { ty::Adt(field_def, field_args) => { let inner_field_ty = { let mut first_non_zst_ty = @@ -1290,7 +1290,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { return FfiSafe; } - match *ty.kind() { + match ty.kind() { ty::Adt(def, args) => { if def.is_box() && matches!(self.mode, CItemKind::Definition) { if ty.boxed_ty().is_sized(tcx, self.cx.param_env) { diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 553d9db12c572..9017d245f0dd3 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -116,7 +116,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { && let ty = cx.typeck_results().expr_ty(await_expr) && let ty::Alias(ty::Opaque, ty::AliasTy { def_id: future_def_id, .. }) = ty.kind() && cx.tcx.ty_is_opaque_future(ty) - && let async_fn_def_id = cx.tcx.parent(*future_def_id) + && let async_fn_def_id = cx.tcx.parent(future_def_id) && matches!(cx.tcx.def_kind(async_fn_def_id), DefKind::Fn | DefKind::AssocFn) // Check that this `impl Future` actually comes from an `async fn` && cx.tcx.asyncness(async_fn_def_id).is_async() @@ -282,7 +282,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { return Some(MustUsePath::Suppressed); } - match *ty.kind() { + match ty.kind() { ty::Adt(..) if ty.is_box() => { let boxed_ty = ty.boxed_ty(); is_ty_must_use(cx, boxed_ty, expr, span) diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index f2d8781413096..00dc429682bb2 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -1299,7 +1299,7 @@ impl<'tcx> ExtraComments<'tcx> { } fn use_verbose(ty: Ty<'_>, fn_def: bool) -> bool { - match *ty.kind() { + match ty.kind() { ty::Int(_) | ty::Uint(_) | ty::Bool | ty::Char | ty::Float(_) => false, // Unit type ty::Tuple(g_args) if g_args.is_empty() => false, @@ -1768,13 +1768,13 @@ fn pretty_print_const_value_tcx<'tcx>( return Ok(()); } } - (_, ty::Ref(_, inner_ty, _)) if matches!(inner_ty.kind(), ty::Slice(t) if *t == u8_type) => { + (_, ty::Ref(_, inner_ty, _)) if matches!(inner_ty.kind(), ty::Slice(t) if t == u8_type) => { if let Some(data) = ct.try_get_slice_bytes_for_diagnostics(tcx) { pretty_print_byte_str(fmt, data)?; return Ok(()); } } - (ConstValue::Indirect { alloc_id, offset }, ty::Array(t, n)) if *t == u8_type => { + (ConstValue::Indirect { alloc_id, offset }, ty::Array(t, n)) if t == u8_type => { let n = n.try_to_target_usize(tcx).unwrap(); let alloc = tcx.global_alloc(alloc_id).unwrap_memory(); // cast is ok because we already checked for pointer size (32 or 64 bit) above @@ -1796,7 +1796,7 @@ fn pretty_print_const_value_tcx<'tcx>( let ty = tcx.lift(ty).unwrap(); if let Some(contents) = tcx.try_destructure_mir_constant_for_user_output(ct, ty) { let fields: Vec<(ConstValue<'_>, Ty<'_>)> = contents.fields.to_vec(); - match *ty.kind() { + match ty.kind() { ty::Array(..) => { fmt.write_str("[")?; comma_sep(tcx, fmt, fields)?; @@ -1863,7 +1863,7 @@ fn pretty_print_const_value_tcx<'tcx>( (ConstValue::ZeroSized, ty::FnDef(d, s)) => { let mut cx = FmtPrinter::new(tcx, Namespace::ValueNS); cx.print_alloc_ids = true; - cx.print_value_path(*d, s)?; + cx.print_value_path(d, s)?; fmt.write_str(&cx.into_buffer())?; return Ok(()); } diff --git a/compiler/rustc_middle/src/mir/statement.rs b/compiler/rustc_middle/src/mir/statement.rs index 3009ca8d8097a..8f2e0e0f20033 100644 --- a/compiler/rustc_middle/src/mir/statement.rs +++ b/compiler/rustc_middle/src/mir/statement.rs @@ -381,7 +381,7 @@ impl<'tcx> Operand<'tcx> { /// find as the `func` in a [`TerminatorKind::Call`]. pub fn const_fn_def(&self) -> Option<(DefId, GenericArgsRef<'tcx>)> { let const_ty = self.constant()?.const_.ty(); - if let ty::FnDef(def_id, args) = *const_ty.kind() { Some((def_id, args)) } else { None } + if let ty::FnDef(def_id, args) = const_ty.kind() { Some((def_id, args)) } else { None } } } diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs index 1075344dc00f3..2f967705dbaa4 100644 --- a/compiler/rustc_middle/src/mir/tcx.rs +++ b/compiler/rustc_middle/src/mir/tcx.rs @@ -91,11 +91,11 @@ impl<'tcx> PlaceTy<'tcx> { ProjectionElem::Subslice { from, to, from_end } => { PlaceTy::from_ty(match self.ty.kind() { ty::Slice(..) => self.ty, - ty::Array(inner, _) if !from_end => Ty::new_array(tcx, *inner, to - from), + ty::Array(inner, _) if !from_end => Ty::new_array(tcx, inner, to - from), ty::Array(inner, size) if from_end => { let size = size.eval_target_usize(tcx, param_env); let len = size - from - to; - Ty::new_array(tcx, *inner, len) + Ty::new_array(tcx, inner, len) } _ => bug!("cannot subslice non-array type: `{:?}`", self), }) diff --git a/compiler/rustc_middle/src/query/keys.rs b/compiler/rustc_middle/src/query/keys.rs index 6562d46d7b866..bd985a504c732 100644 --- a/compiler/rustc_middle/src/query/keys.rs +++ b/compiler/rustc_middle/src/query/keys.rs @@ -415,7 +415,7 @@ impl<'tcx> Key for Ty<'tcx> { } fn ty_def_id(&self) -> Option { - match *self.kind() { + match self.kind() { ty::Adt(adt, _) => Some(adt.did()), ty::Coroutine(def_id, ..) => Some(def_id), _ => None, diff --git a/compiler/rustc_middle/src/thir.rs b/compiler/rustc_middle/src/thir.rs index f2ea32275f9b1..8c2a0c56f52d0 100644 --- a/compiler/rustc_middle/src/thir.rs +++ b/compiler/rustc_middle/src/thir.rs @@ -848,7 +848,7 @@ impl<'tcx> PatRange<'tcx> { /// Whether this range covers the full extent of possible values (best-effort, we ignore floats). #[inline] pub fn is_full_range(&self, tcx: TyCtxt<'tcx>) -> Option { - let (min, max, size, bias) = match *self.ty.kind() { + let (min, max, size, bias) = match self.ty.kind() { ty::Char => (0, std::char::MAX as u128, Size::from_bits(32), 0), ty::Int(ity) => { let size = Integer::from_int_ty(&tcx, ity).size(); @@ -1058,7 +1058,7 @@ impl<'tcx> PatRangeBoundary<'tcx> { a.partial_cmp(&b) } ty::Int(ity) => { - let size = rustc_target::abi::Integer::from_int_ty(&tcx, *ity).size(); + let size = rustc_target::abi::Integer::from_int_ty(&tcx, ity).size(); let a = size.sign_extend(a) as i128; let b = size.sign_extend(b) as i128; Some(a.cmp(&b)) diff --git a/compiler/rustc_middle/src/ty/cast.rs b/compiler/rustc_middle/src/ty/cast.rs index 46f3765953678..8ff0592ed2cb1 100644 --- a/compiler/rustc_middle/src/ty/cast.rs +++ b/compiler/rustc_middle/src/ty/cast.rs @@ -60,7 +60,7 @@ impl<'tcx> CastTy<'tcx> { /// Returns `Some` for integral/pointer casts. /// Casts like unsizing casts will return `None`. pub fn from_ty(t: Ty<'tcx>) -> Option> { - match *t.kind() { + match t.kind() { ty::Bool => Some(CastTy::Int(IntTy::Bool)), ty::Char => Some(CastTy::Int(IntTy::Char)), ty::Int(_) => Some(CastTy::Int(IntTy::I)), diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 401f6da6526aa..fb83a749d35a3 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -32,7 +32,7 @@ pub const SHORTHAND_OFFSET: usize = 0x80; pub trait EncodableWithShorthand: Copy + Eq + Hash { type Variant: Encodable; - fn variant(&self) -> &Self::Variant; + fn variant(&self) -> Self::Variant; // njn: removed `&` } #[allow(rustc::usage_of_ty_tykind)] @@ -40,7 +40,7 @@ impl<'tcx, E: TyEncoder>> EncodableWithShorthand for Ty<'tcx type Variant = ty::TyKind<'tcx>; #[inline] - fn variant(&self) -> &Self::Variant { + fn variant(&self) -> Self::Variant { self.kind() } } @@ -49,8 +49,8 @@ impl<'tcx, E: TyEncoder>> EncodableWithShorthand for ty::Pre type Variant = ty::PredicateKind<'tcx>; #[inline] - fn variant(&self) -> &Self::Variant { - self + fn variant(&self) -> Self::Variant { + *self // njn: added `*` } } @@ -91,7 +91,7 @@ where // The shorthand encoding uses the same usize as the // discriminant, with an offset so they can't conflict. - let discriminant = intrinsics::discriminant_value(variant); + let discriminant = intrinsics::discriminant_value(&variant); assert!(SHORTHAND_OFFSET > discriminant as usize); let shorthand = start + SHORTHAND_OFFSET; diff --git a/compiler/rustc_middle/src/ty/consts/valtree.rs b/compiler/rustc_middle/src/ty/consts/valtree.rs index 9f9bf41c3355a..23483548d61f0 100644 --- a/compiler/rustc_middle/src/ty/consts/valtree.rs +++ b/compiler/rustc_middle/src/ty/consts/valtree.rs @@ -91,12 +91,12 @@ impl<'tcx> ValTree<'tcx> { // `&str` can be interpreted as raw bytes ty::Str => {} // `&[u8]` can be interpreted as raw bytes - ty::Slice(slice_ty) if *slice_ty == tcx.types.u8 => {} + ty::Slice(slice_ty) if slice_ty == tcx.types.u8 => {} // other `&_` can't be interpreted as raw bytes _ => return None, }, // `[u8; N]` can be interpreted as raw bytes - ty::Array(array_ty, _) if *array_ty == tcx.types.u8 => {} + ty::Array(array_ty, _) if array_ty == tcx.types.u8 => {} // Otherwise, type cannot be interpreted as raw bytes _ => return None, } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 83799e40868fc..567ef8d897286 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2523,7 +2523,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn signature_unclosure(self, sig: PolyFnSig<'tcx>, safety: hir::Safety) -> PolyFnSig<'tcx> { sig.map_bound(|s| { let params = match s.inputs()[0].kind() { - ty::Tuple(params) => *params, + ty::Tuple(params) => params, _ => bug!(), }; self.mk_fn_sig(params, s.output(), s.c_variadic, safety, abi::Abi::Rust) diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index c14dadc68c903..e233a3c8f7934 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -542,7 +542,7 @@ impl<'tcx> TypeVisitor> for IsSuggestableVisitor<'tcx> { type Result = ControlFlow<()>; fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result { - match *t.kind() { + match t.kind() { Infer(InferTy::TyVar(_)) if self.infer_suggestable => {} FnDef(..) @@ -561,7 +561,7 @@ impl<'tcx> TypeVisitor> for IsSuggestableVisitor<'tcx> { let parent_ty = self.tcx.type_of(parent).instantiate_identity(); if let DefKind::TyAlias | DefKind::AssocTy = self.tcx.def_kind(parent) && let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = - *parent_ty.kind() + parent_ty.kind() && parent_opaque_def_id == def_id { // Okay @@ -627,7 +627,7 @@ impl<'tcx> FallibleTypeFolder> for MakeSuggestableFolder<'tcx> { } fn try_fold_ty(&mut self, t: Ty<'tcx>) -> Result, Self::Error> { - let t = match *t.kind() { + let t = match t.kind() { Infer(InferTy::TyVar(_)) if self.infer_suggestable => t, FnDef(def_id, args) if self.placeholder.is_none() => { @@ -656,7 +656,7 @@ impl<'tcx> FallibleTypeFolder> for MakeSuggestableFolder<'tcx> { if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent) && let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, .. }) = - *parent_ty.kind() + parent_ty.kind() && parent_opaque_def_id == def_id { t diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index d974a86a3036f..0f115df665795 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -123,7 +123,7 @@ impl<'tcx> TypeError<'tcx> { impl<'tcx> Ty<'tcx> { pub fn sort_string(self, tcx: TyCtxt<'tcx>) -> Cow<'static, str> { - match *self.kind() { + match self.kind() { ty::Foreign(def_id) => format!("extern type `{}`", tcx.def_path_str(def_id)).into(), ty::FnDef(def_id, ..) => match tcx.def_kind(def_id) { DefKind::Ctor(CtorOf::Struct, _) => "struct constructor".into(), @@ -167,7 +167,7 @@ impl<'tcx> Ty<'tcx> { } pub fn prefix_string(self, tcx: TyCtxt<'_>) -> Cow<'static, str> { - match *self.kind() { + match self.kind() { ty::Infer(_) | ty::Error(_) | ty::Bool diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 7892ef818194a..57f4965b630d7 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -191,7 +191,7 @@ where } fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - match *t.kind() { + match t.kind() { ty::Bound(debruijn, bound_ty) if debruijn == self.current_index => { let ty = self.delegate.replace_ty(bound_ty); debug_assert!(!ty.has_vars_bound_above(ty::INNERMOST)); diff --git a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs index 698104b0462e3..da567fff711f1 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs @@ -202,7 +202,7 @@ impl<'tcx> Ty<'tcx> { /// N.B. this query should only be called through `Ty::inhabited_predicate` fn inhabited_predicate_type<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> InhabitedPredicate<'tcx> { - match *ty.kind() { + match ty.kind() { Adt(adt, args) => tcx.inhabited_predicate_adt(adt.did()).instantiate(tcx, args), Tuple(tys) => { diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 6f19739de45ff..4ecee66b247e5 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -808,7 +808,7 @@ impl<'tcx> Instance<'tcx> { trait_id: DefId, rcvr_args: ty::GenericArgsRef<'tcx>, ) -> Option> { - let ty::Coroutine(coroutine_def_id, args) = *rcvr_args.type_at(0).kind() else { + let ty::Coroutine(coroutine_def_id, args) = rcvr_args.type_at(0).kind() else { return None; }; let coroutine_kind = tcx.coroutine_kind(coroutine_def_id).unwrap(); @@ -839,7 +839,7 @@ impl<'tcx> Instance<'tcx> { }; if tcx.is_lang_item(trait_item_id, coroutine_callable_item) { - let ty::Coroutine(_, id_args) = *tcx.type_of(coroutine_def_id).skip_binder().kind() + let ty::Coroutine(_, id_args) = tcx.type_of(coroutine_def_id).skip_binder().kind() else { bug!() }; @@ -984,7 +984,7 @@ fn polymorphize<'tcx>( fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { debug!("fold_ty: ty={:?}", ty); - match *ty.kind() { + match ty.kind() { ty::Closure(def_id, args) => { let polymorphized_args = polymorphize(self.tcx, ty::InstanceKind::Item(def_id), args); diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 619981bf021e4..d9dce9f3f9990 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -358,7 +358,7 @@ impl<'tcx> SizeSkeleton<'tcx> { ) => return Err(e), }; - match *ty.kind() { + match ty.kind() { ty::Ref(_, pointee, _) | ty::RawPtr(pointee, _) => { let non_zero = !ty.is_unsafe_ptr(); @@ -385,7 +385,7 @@ impl<'tcx> SizeSkeleton<'tcx> { } ty::Error(guar) => { // Fixes ICE #124031 - return Err(tcx.arena.alloc(LayoutError::ReferencesError(*guar))); + return Err(tcx.arena.alloc(LayoutError::ReferencesError(guar))); } _ => bug!( "SizeSkeleton::compute({ty}): layout errored ({err:?}), yet \ @@ -795,7 +795,7 @@ where } }; - match *this.ty.kind() { + match this.ty.kind() { ty::Bool | ty::Char | ty::Int(_) @@ -978,7 +978,7 @@ where let tcx = cx.tcx(); let param_env = cx.param_env(); - let pointee_info = match *this.ty.kind() { + let pointee_info = match this.ty.kind() { ty::RawPtr(p_ty, _) if offset.bytes() == 0 => { tcx.layout_of(param_env.and(p_ty)).ok().map(|layout| PointeeInfo { size: layout.size, @@ -1104,7 +1104,7 @@ where } fn is_never(this: TyAndLayout<'tcx>) -> bool { - this.ty.kind() == &ty::Never + this.ty.kind() == ty::Never } fn is_tuple(this: TyAndLayout<'tcx>) -> bool { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 1e3b5800cbac6..548f1f0c05c2e 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -443,7 +443,7 @@ impl<'tcx> rustc_type_ir::inherent::IntoKind for Ty<'tcx> { type Kind = TyKind<'tcx>; fn kind(self) -> TyKind<'tcx> { - *self.kind() + self.kind() } } @@ -615,7 +615,7 @@ impl<'tcx> Term<'tcx> { pub fn to_alias_term(self) -> Option> { match self.unpack() { - TermKind::Ty(ty) => match *ty.kind() { + TermKind::Ty(ty) => match ty.kind() { ty::Alias(_kind, alias_ty) => Some(alias_ty.into()), _ => None, }, @@ -1859,7 +1859,7 @@ impl<'tcx> TyCtxt<'tcx> { // If we have a `Coroutine` that comes from an coroutine-closure, // then it may be a by-move or by-ref body. let ty::Coroutine(_, identity_args) = - *self.type_of(def_id).instantiate_identity().kind() + self.type_of(def_id).instantiate_identity().kind() else { unreachable!(); }; diff --git a/compiler/rustc_middle/src/ty/opaque_types.rs b/compiler/rustc_middle/src/ty/opaque_types.rs index d3f44326c272d..23d0ce04873f1 100644 --- a/compiler/rustc_middle/src/ty/opaque_types.rs +++ b/compiler/rustc_middle/src/ty/opaque_types.rs @@ -150,7 +150,7 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - match *ty.kind() { + match ty.kind() { ty::Closure(def_id, args) => { let args = self.fold_closure_args(def_id, args); Ty::new_closure(self.tcx, def_id, args) diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index cc7467467603a..9419f6b258dba 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -258,7 +258,7 @@ fn characteristic_def_id_of_type_cached<'a>( ty: Ty<'a>, visited: &mut SsoHashSet>, ) -> Option { - match *ty.kind() { + match ty.kind() { ty::Adt(adt_def, _) => Some(adt_def.did()), ty::Dynamic(data, ..) => data.principal_def_id(), diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 56ddf146636c8..faefe0b43ce99 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -660,7 +660,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { fn pretty_print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError> { define_scoped_cx!(self); - match *ty.kind() { + match ty.kind() { ty::Bool => p!("bool"), ty::Char => p!("char"), ty::Int(t) => p!(write("{}", t.name_str())), @@ -775,7 +775,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { // NOTE: I know we should check for NO_QUERIES here, but it's alright. // `type_of` on a type alias or assoc type should never cause a cycle. if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: d, .. }) = - *self.tcx().type_of(parent).instantiate_identity().kind() + self.tcx().type_of(parent).instantiate_identity().kind() { if d == def_id { // If the type alias directly starts with the `impl` of the @@ -1812,7 +1812,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { let u8_type = self.tcx().types.u8; match (valtree, ty.kind()) { (ty::ValTree::Branch(_), ty::Ref(_, inner_ty, _)) => match inner_ty.kind() { - ty::Slice(t) if *t == u8_type => { + ty::Slice(t) if t == u8_type => { let bytes = valtree.try_to_raw_bytes(self.tcx(), ty).unwrap_or_else(|| { bug!( "expected to convert valtree {:?} to raw bytes for type {:?}", @@ -1831,11 +1831,11 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { } _ => { p!("&"); - p!(pretty_print_const_valtree(valtree, *inner_ty, print_ty)); + p!(pretty_print_const_valtree(valtree, inner_ty, print_ty)); return Ok(()); } }, - (ty::ValTree::Branch(_), ty::Array(t, _)) if *t == u8_type => { + (ty::ValTree::Branch(_), ty::Array(t, _)) if t == u8_type => { let bytes = valtree.try_to_raw_bytes(self.tcx(), ty).unwrap_or_else(|| { bug!("expected to convert valtree to raw bytes for type {:?}", t) }); @@ -1848,7 +1848,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { let contents = self.tcx().destructure_const(ty::Const::new_value(self.tcx(), valtree, ty)); let fields = contents.fields.iter().copied(); - match *ty.kind() { + match ty.kind() { ty::Array(..) => { p!("[", comma_sep(fields), "]"); } @@ -1899,7 +1899,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write { } (ty::ValTree::Leaf(leaf), ty::Ref(_, inner_ty, _)) => { p!(write("&")); - return self.pretty_print_const_scalar_int(leaf, *inner_ty, print_ty); + return self.pretty_print_const_scalar_int(leaf, inner_ty, print_ty); } (ty::ValTree::Leaf(leaf), _) => { return self.pretty_print_const_scalar_int(leaf, ty, print_ty); @@ -2550,7 +2550,7 @@ impl<'a, 'tcx> ty::TypeFolder> for RegionFolder<'a, 'tcx> { } fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - match *t.kind() { + match t.kind() { _ if t.has_vars_bound_at_or_above(self.current_index) || t.has_placeholders() => { return t.super_fold_with(self); } diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 80b33c2cda929..45cdb9e001af1 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -83,7 +83,7 @@ impl fmt::Debug for ty::LateParamRegion { impl<'tcx> fmt::Debug for Ty<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - with_no_trimmed_paths!(fmt::Debug::fmt(self.kind(), f)) + with_no_trimmed_paths!(fmt::Debug::fmt(&self.kind(), f)) // njn: added `&` } } @@ -362,7 +362,7 @@ impl<'tcx> TypeSuperFoldable> for Ty<'tcx> { self, folder: &mut F, ) -> Result { - let kind = match *self.kind() { + let kind = match self.kind() { ty::RawPtr(ty, mutbl) => ty::RawPtr(ty.try_fold_with(folder)?, mutbl), ty::Array(typ, sz) => ty::Array(typ.try_fold_with(folder)?, sz.try_fold_with(folder)?), ty::Slice(typ) => ty::Slice(typ.try_fold_with(folder)?), @@ -404,7 +404,7 @@ impl<'tcx> TypeSuperFoldable> for Ty<'tcx> { | ty::Foreign(..) => return Ok(self), }; - Ok(if *self.kind() == kind { self } else { folder.cx().mk_ty_from_kind(kind) }) + Ok(if self.kind() == kind { self } else { folder.cx().mk_ty_from_kind(kind) }) } } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 0a277fea49c12..d71c4e7637f73 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -971,8 +971,9 @@ impl<'tcx> rustc_type_ir::inherent::Ty> for Ty<'tcx> { /// Type utilities impl<'tcx> Ty<'tcx> { #[inline(always)] - pub fn kind(self) -> &'tcx TyKind<'tcx> { - self.0.0 + // njn: removed `&'tcx` + pub fn kind(self) -> TyKind<'tcx> { + **self.0.0 // njn: added `**` } // FIXME(compiler-errors): Think about removing this. @@ -1017,7 +1018,7 @@ impl<'tcx> Ty<'tcx> { #[inline] pub fn ty_vid(self) -> Option { match self.kind() { - &Infer(TyVar(vid)) => Some(vid), + Infer(TyVar(vid)) => Some(vid), _ => None, } } @@ -1034,13 +1035,13 @@ impl<'tcx> Ty<'tcx> { #[inline] pub fn is_bool(self) -> bool { - *self.kind() == Bool + self.kind() == Bool } /// Returns `true` if this type is a `str`. #[inline] pub fn is_str(self) -> bool { - *self.kind() == Str + self.kind() == Str } #[inline] @@ -1080,7 +1081,7 @@ impl<'tcx> Ty<'tcx> { pub fn sequence_element_type(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match self.kind() { - Array(ty, _) | Slice(ty) => *ty, + Array(ty, _) | Slice(ty) => ty, Str => tcx.types.u8, _ => bug!("`sequence_element_type` called on non-sequence value: {}", self), } @@ -1101,7 +1102,7 @@ impl<'tcx> Ty<'tcx> { // The way we evaluate the `N` in `[T; N]` here only works since we use // `simd_size_and_type` post-monomorphization. It will probably start to ICE // if we use it in generic code. See the `simd-array-trait` ui test. - (f0_len.eval_target_usize(tcx, ParamEnv::empty()), *f0_elem_ty) + (f0_len.eval_target_usize(tcx, ParamEnv::empty()), f0_elem_ty) } // Otherwise, the fields of this Adt are the SIMD components (and we assume they // all have the same type). @@ -1121,7 +1122,7 @@ impl<'tcx> Ty<'tcx> { #[inline] pub fn ref_mutability(self) -> Option { match self.kind() { - Ref(_, _, mutability) => Some(*mutability), + Ref(_, _, mutability) => Some(mutability), _ => None, } } @@ -1315,7 +1316,7 @@ impl<'tcx> Ty<'tcx> { /// The parameter `explicit` indicates if this is an *explicit* dereference. /// Some types -- notably unsafe ptrs -- can only be dereferenced explicitly. pub fn builtin_deref(self, explicit: bool) -> Option> { - match *self.kind() { + match self.kind() { Adt(def, _) if def.is_box() => Some(self.boxed_ty()), Ref(_, ty, _) => Some(ty), RawPtr(ty, _) if explicit => Some(ty), @@ -1326,15 +1327,15 @@ impl<'tcx> Ty<'tcx> { /// Returns the type of `ty[i]`. pub fn builtin_index(self) -> Option> { match self.kind() { - Array(ty, _) | Slice(ty) => Some(*ty), + Array(ty, _) | Slice(ty) => Some(ty), _ => None, } } pub fn fn_sig(self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'tcx> { match self.kind() { - FnDef(def_id, args) => tcx.fn_sig(*def_id).instantiate(tcx, args), - FnPtr(sig_tys, hdr) => sig_tys.with(*hdr), + FnDef(def_id, args) => tcx.fn_sig(def_id).instantiate(tcx, args), + FnPtr(sig_tys, hdr) => sig_tys.with(hdr), Error(_) => { // ignore errors (#54954) Binder::dummy(ty::FnSig { @@ -1369,7 +1370,7 @@ impl<'tcx> Ty<'tcx> { #[inline] pub fn ty_adt_def(self) -> Option> { match self.kind() { - Adt(adt, _) => Some(*adt), + Adt(adt, _) => Some(adt), _ => None, } } @@ -1391,9 +1392,7 @@ impl<'tcx> Ty<'tcx> { pub fn variant_range(self, tcx: TyCtxt<'tcx>) -> Option> { match self.kind() { TyKind::Adt(adt, _) => Some(adt.variant_range()), - TyKind::Coroutine(def_id, args) => { - Some(args.as_coroutine().variant_range(*def_id, tcx)) - } + TyKind::Coroutine(def_id, args) => Some(args.as_coroutine().variant_range(def_id, tcx)), _ => None, } } @@ -1413,7 +1412,7 @@ impl<'tcx> Ty<'tcx> { Some(adt.discriminant_for_variant(tcx, variant_index)) } TyKind::Coroutine(def_id, args) => { - Some(args.as_coroutine().discriminant_for_variant(*def_id, tcx, variant_index)) + Some(args.as_coroutine().discriminant_for_variant(def_id, tcx, variant_index)) } _ => None, } @@ -1482,7 +1481,7 @@ impl<'tcx> Ty<'tcx> { AsyncDropGlueMorphology::Custom => (), } - match *self.kind() { + match self.kind() { ty::Param(_) | ty::Alias(..) | ty::Infer(ty::TyVar(_)) => { let assoc_items = tcx .associated_item_def_ids(tcx.require_lang_item(LangItem::AsyncDestruct, None)); diff --git a/compiler/rustc_middle/src/ty/typeck_results.rs b/compiler/rustc_middle/src/ty/typeck_results.rs index a92bdb2eae0de..2f5987a1823d8 100644 --- a/compiler/rustc_middle/src/ty/typeck_results.rs +++ b/compiler/rustc_middle/src/ty/typeck_results.rs @@ -751,7 +751,7 @@ impl<'tcx> IsIdentity for CanonicalUserType<'tcx> { GenericArgKind::Type(ty) => match ty.kind() { ty::Bound(debruijn, b) => { // We only allow a `ty::INNERMOST` index in generic parameters. - assert_eq!(*debruijn, ty::INNERMOST); + assert_eq!(debruijn, ty::INNERMOST); cvar == b.var } _ => false, diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index b9bf17cbb5ce6..5ba9382f0ea89 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -56,7 +56,7 @@ pub enum NotUniqueParam<'tcx> { impl<'tcx> fmt::Display for Discr<'tcx> { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - match *self.ty.kind() { + match self.ty.kind() { ty::Int(ity) => { let size = ty::tls::with(|tcx| Integer::from_int_ty(&tcx, ity).size()); let x = self.val; @@ -216,7 +216,7 @@ impl<'tcx> TyCtxt<'tcx> { .emit_err(crate::error::RecursionLimitReached { ty, suggested_limit }); return Ty::new_error(self, reported); } - match *ty.kind() { + match ty.kind() { ty::Adt(def, args) => { if !def.is_struct() { break; @@ -471,7 +471,7 @@ impl<'tcx> TyCtxt<'tcx> { // , and then look up which of the impl args refer to // parameters marked as pure. - let impl_args = match *self.type_of(impl_def_id).instantiate_identity().kind() { + let impl_args = match self.type_of(impl_def_id).instantiate_identity().kind() { ty::Adt(def_, args) if def_ == def => args, _ => span_bug!(self.def_span(impl_def_id), "expected ADT for self type of `Drop` impl"), }; @@ -488,7 +488,7 @@ impl<'tcx> TyCtxt<'tcx> { // Error: not a region param _ => false, }, - GenericArgKind::Type(ty) => match *ty.kind() { + GenericArgKind::Type(ty) => match ty.kind() { ty::Param(pt) => !impl_generics.type_param(pt, self).pure_wrt_drop, // Error: not a type param _ => false, @@ -1079,7 +1079,7 @@ impl<'tcx> TypeFolder> for OpaqueTypeExpander<'tcx> { } fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - let mut t = if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) = *t.kind() { + let mut t = if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) = t.kind() { self.expand_opaque_ty(def_id, args).unwrap_or(t) } else if t.has_opaque_types() || t.has_coroutines() { t.super_fold_with(self) @@ -1087,7 +1087,7 @@ impl<'tcx> TypeFolder> for OpaqueTypeExpander<'tcx> { t }; if self.expand_coroutines { - if let ty::CoroutineWitness(def_id, args) = *t.kind() { + if let ty::CoroutineWitness(def_id, args) = t.kind() { t = self.expand_coroutine(def_id, args).unwrap_or(t); } } @@ -1166,7 +1166,7 @@ pub enum AsyncDropGlueMorphology { impl<'tcx> Ty<'tcx> { /// Returns the `Size` for primitive types (bool, uint, int, char, float). pub fn primitive_size(self, tcx: TyCtxt<'tcx>) -> Size { - match *self.kind() { + match self.kind() { ty::Bool => Size::from_bytes(1), ty::Char => Size::from_bytes(4), ty::Int(ity) => Integer::from_int_ty(&tcx, ity).size(), @@ -1177,7 +1177,7 @@ impl<'tcx> Ty<'tcx> { } pub fn int_size_and_signed(self, tcx: TyCtxt<'tcx>) -> (Size, bool) { - match *self.kind() { + match self.kind() { ty::Int(ity) => (Integer::from_int_ty(&tcx, ity).size(), true), ty::Uint(uty) => (Integer::from_uint_ty(&tcx, uty).size(), false), _ => bug!("non integer discriminant"), @@ -1382,7 +1382,7 @@ impl<'tcx> Ty<'tcx> { ty::Closure(did, _) | ty::CoroutineClosure(did, _) | ty::Coroutine(did, _) - | ty::CoroutineWitness(did, _) => tcx.async_drop_glue_morphology(*did), + | ty::CoroutineWitness(did, _) => tcx.async_drop_glue_morphology(did), ty::Alias(..) | ty::Param(_) | ty::Bound(..) | ty::Placeholder(..) | ty::Infer(_) => { // No specifics, but would usually mean forwarding async drop glue @@ -1573,7 +1573,7 @@ impl<'tcx> Ty<'tcx> { pub fn peel_refs(self) -> Ty<'tcx> { let mut ty = self; while let ty::Ref(_, inner_ty, _) = ty.kind() { - ty = *inner_ty; + ty = inner_ty; } ty } @@ -1624,7 +1624,7 @@ impl<'tcx> ExplicitSelf<'tcx> { { use self::ExplicitSelf::*; - match *self_arg_ty.kind() { + match self_arg_ty.kind() { _ if is_self_ty(self_arg_ty) => ByValue, ty::Ref(region, ty, mutbl) if is_self_ty(ty) => ByReference(region, mutbl), ty::RawPtr(ty, mutbl) if is_self_ty(ty) => ByRawPointer(mutbl), @@ -1656,7 +1656,7 @@ pub fn needs_drop_components_with_async<'tcx>( ty: Ty<'tcx>, asyncness: Asyncness, ) -> Result; 2]>, AlwaysRequiresDrop> { - match *ty.kind() { + match ty.kind() { ty::Infer(ty::FreshIntTy(_)) | ty::Infer(ty::FreshFloatTy(_)) | ty::Bool @@ -1720,7 +1720,7 @@ pub fn needs_drop_components_with_async<'tcx>( } pub fn is_trivially_const_drop(ty: Ty<'_>) -> bool { - match *ty.kind() { + match ty.kind() { ty::Bool | ty::Char | ty::Int(_) diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index abd6df17514bb..1b9e499d44843 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -120,7 +120,7 @@ impl<'tcx> ty::Const<'tcx> { /// types as they are written). fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) { match parent.unpack() { - GenericArgKind::Type(parent_ty) => match *parent_ty.kind() { + GenericArgKind::Type(parent_ty) => match parent_ty.kind() { ty::Bool | ty::Char | ty::Int(_) diff --git a/compiler/rustc_middle/src/util/find_self_call.rs b/compiler/rustc_middle/src/util/find_self_call.rs index ec6051d0a771a..39602b292c0dd 100644 --- a/compiler/rustc_middle/src/util/find_self_call.rs +++ b/compiler/rustc_middle/src/util/find_self_call.rs @@ -20,7 +20,7 @@ pub fn find_self_call<'tcx>( { debug!("find_self_call: func={:?}", func); if let Operand::Constant(box ConstOperand { const_, .. }) = func { - if let ty::FnDef(def_id, fn_args) = *const_.ty().kind() { + if let ty::FnDef(def_id, fn_args) = const_.ty().kind() { if let Some(ty::AssocItem { fn_has_self_parameter: true, .. }) = tcx.opt_associated_item(def_id) { diff --git a/compiler/rustc_mir_build/src/build/custom/parse.rs b/compiler/rustc_mir_build/src/build/custom/parse.rs index 646aefa08829e..ba198c5a1ca9a 100644 --- a/compiler/rustc_mir_build/src/build/custom/parse.rs +++ b/compiler/rustc_mir_build/src/build/custom/parse.rs @@ -46,7 +46,7 @@ macro_rules! parse_by_kind { ExprKind::Call { ty, fun: _, args: $args, .. } if { match ty.kind() { ty::FnDef(did, _) => { - $self.tcx.is_diagnostic_item(rustc_span::sym::$name, *did) + $self.tcx.is_diagnostic_item(rustc_span::sym::$name, did) } _ => false, } diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs index b80d9de70c8da..c84c92160b7ef 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs @@ -435,7 +435,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { unpack!(block = this.expr_as_place(block, lhs, mutability, fake_borrow_temps,)); if let ty::Adt(adt_def, _) = lhs_expr.ty.kind() { if adt_def.is_enum() { - place_builder = place_builder.downcast(*adt_def, variant_index); + place_builder = place_builder.downcast(adt_def, variant_index); } } block.and(place_builder.field(name, expr.ty)) diff --git a/compiler/rustc_mir_build/src/build/matches/test.rs b/compiler/rustc_mir_build/src/build/matches/test.rs index 7af1ede24a4f4..b3932428e6ec8 100644 --- a/compiler/rustc_mir_build/src/build/matches/test.rs +++ b/compiler/rustc_mir_build/src/build/matches/test.rs @@ -407,7 +407,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { (Some((region, elem_ty, _)), _) | (None, Some((region, elem_ty, _))) => { let tcx = self.tcx; // make both a slice - ty = Ty::new_imm_ref(tcx, *region, Ty::new_slice(tcx, *elem_ty)); + ty = Ty::new_imm_ref(tcx, region, Ty::new_slice(tcx, elem_ty)); if opt_ref_ty.is_some() { let temp = self.temp(ty, source_info.span); self.cfg.push_assign( @@ -446,7 +446,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // which have their comparison defined in `core`. // (Interestingly this means that exhaustiveness analysis relies, for soundness, // on the `PartialEq` impls for `str` and `[u8]` to b correct!) - let compare_ty = match *ty.kind() { + let compare_ty = match ty.kind() { ty::Ref(_, deref_ty, _) if deref_ty == self.tcx.types.str_ || deref_ty != self.tcx.types.u8 => { diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index b98deda8fd022..c01f5b6e92be2 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -671,7 +671,7 @@ fn construct_error(tcx: TyCtxt<'_>, def_id: LocalDefId, guar: ErrorGuaranteed) - tcx, args.parent_args(), args.kind_ty(), - tcx.coroutine_for_closure(*did), + tcx.coroutine_for_closure(did), Ty::new_error(tcx, guar), ), None, @@ -817,7 +817,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let mut closure_env_projs = vec![]; if let ty::Ref(_, ty, _) = closure_ty.kind() { closure_env_projs.push(ProjectionElem::Deref); - closure_ty = *ty; + closure_ty = ty; } let upvar_args = match closure_ty.kind() { diff --git a/compiler/rustc_mir_build/src/check_unsafety.rs b/compiler/rustc_mir_build/src/check_unsafety.rs index 54a4204da71e8..69e2fe1da1f30 100644 --- a/compiler/rustc_mir_build/src/check_unsafety.rs +++ b/compiler/rustc_mir_build/src/check_unsafety.rs @@ -431,12 +431,12 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> { ExprKind::Call { fun, ty: _, args: _, from_hir_call: _, fn_span: _ } => { if self.thir[fun].ty.fn_sig(self.tcx).safety() == hir::Safety::Unsafe { let func_id = if let ty::FnDef(func_id, _) = self.thir[fun].ty.kind() { - Some(*func_id) + Some(func_id) } else { None }; self.requires_unsafe(expr.span, CallToUnsafeFunction(func_id)); - } else if let &ty::FnDef(func_did, _) = self.thir[fun].ty.kind() { + } else if let ty::FnDef(func_did, _) = self.thir[fun].ty.kind() { // If the called function has target features the calling function hasn't, // the call requires `unsafe`. Don't check this on wasm // targets, though. For more information on wasm see the diff --git a/compiler/rustc_mir_build/src/lints.rs b/compiler/rustc_mir_build/src/lints.rs index 80e91811b1c5f..36236095268d4 100644 --- a/compiler/rustc_mir_build/src/lints.rs +++ b/compiler/rustc_mir_build/src/lints.rs @@ -82,7 +82,7 @@ pub fn check_drop_recursion<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) { if let ty::Ref(_, dropped_ty, _) = tcx.liberate_late_bound_regions(def_id.to_def_id(), sig.input(0)).kind() { - check_recursion(tcx, body, RecursiveDrop { drop_for: *dropped_ty }); + check_recursion(tcx, body, RecursiveDrop { drop_for: dropped_ty }); } } } @@ -137,7 +137,7 @@ impl<'tcx> TerminatorClassifier<'tcx> for CallRecursion<'tcx> { let param_env = tcx.param_env(caller); let func_ty = func.ty(body, tcx); - if let ty::FnDef(callee, args) = *func_ty.kind() { + if let ty::FnDef(callee, args) = func_ty.kind() { let Ok(normalized_args) = tcx.try_normalize_erasing_regions(param_env, args) else { return false; }; diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index d4de5fac96eb0..06c3e4e9d68d0 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -502,7 +502,7 @@ impl<'tcx> Cx<'tcx> { let user_ty = user_provided_types.get(expr.hir_id).copied().map(Box::new); debug!("make_mirror_unadjusted: (struct/union) user_ty={:?}", user_ty); ExprKind::Adt(Box::new(AdtExpr { - adt_def: *adt, + adt_def: adt, variant_index: FIRST_VARIANT, args, user_ty, @@ -529,7 +529,7 @@ impl<'tcx> Cx<'tcx> { user_provided_types.get(expr.hir_id).copied().map(Box::new); debug!("make_mirror_unadjusted: (variant) user_ty={:?}", user_ty); ExprKind::Adt(Box::new(AdtExpr { - adt_def: *adt, + adt_def: adt, variant_index: index, args, user_ty, @@ -550,7 +550,7 @@ impl<'tcx> Cx<'tcx> { hir::ExprKind::Closure { .. } => { let closure_ty = self.typeck_results().expr_ty(expr); - let (def_id, args, movability) = match *closure_ty.kind() { + let (def_id, args, movability) = match closure_ty.kind() { ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args), None), ty::Coroutine(def_id, args) => { (def_id, UpvarArgs::Coroutine(args), Some(tcx.coroutine_movability(def_id))) @@ -687,7 +687,7 @@ impl<'tcx> Cx<'tcx> { span_bug!(expr.span, "unexpected repeat expr ty: {:?}", ty); }; - ExprKind::Repeat { value: self.mirror_expr(v), count: *count } + ExprKind::Repeat { value: self.mirror_expr(v), count } } hir::ExprKind::Ret(v) => ExprKind::Return { value: v.map(|v| self.mirror_expr(v)) }, hir::ExprKind::Become(call) => ExprKind::Become { value: self.mirror_expr(call) }, @@ -923,7 +923,7 @@ impl<'tcx> Cx<'tcx> { // A unit struct/variant which is used as a value. // We return a completely different ExprKind here to account for this special case. ty::Adt(adt_def, args) => ExprKind::Adt(Box::new(AdtExpr { - adt_def: *adt_def, + adt_def, variant_index: adt_def.variant_index_with_ctor_id(def_id), args, user_ty, @@ -1014,7 +1014,7 @@ impl<'tcx> Cx<'tcx> { // Reconstruct the output assuming it's a reference with the // same region and mutability as the receiver. This holds for // `Deref(Mut)::Deref(_mut)` and `Index(Mut)::index(_mut)`. - let ty::Ref(region, _, mutbl) = *self.thir[args[0]].ty.kind() else { + let ty::Ref(region, _, mutbl) = self.thir[args[0]].ty.kind() else { span_bug!(span, "overloaded_place: receiver is not a reference"); }; let ref_ty = Ty::new_ref(self.tcx, region, place_ty, mutbl); diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs index 6120b1453cfab..4b5b5b537374d 100644 --- a/compiler/rustc_mir_build/src/thir/cx/mod.rs +++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs @@ -124,7 +124,7 @@ impl<'tcx> Cx<'tcx> { } let closure_ty = self.typeck_results.node_type(expr_id); - Some(match *closure_ty.kind() { + Some(match closure_ty.kind() { ty::Coroutine(..) => { Param { ty: closure_ty, pat: None, ty_span: None, self_kind: None, hir_id: None } } diff --git a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs index 85b9dacb1293c..fc92d64470929 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/check_match.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/check_match.rs @@ -704,7 +704,7 @@ impl<'p, 'tcx> MatchVisitor<'p, 'tcx> { { let variant_inhabited = adt .variant(*variant_index) - .inhabited_predicate(self.tcx, *adt) + .inhabited_predicate(self.tcx, adt) .instantiate(self.tcx, args); variant_inhabited.apply(self.tcx, cx.param_env, cx.module) && !variant_inhabited.apply_ignore_module(self.tcx, cx.param_env) @@ -1251,7 +1251,7 @@ fn report_adt_defined_here<'tcx>( }; let mut variants = vec![]; - for span in maybe_point_at_variant(tcx, *def, witnesses.iter().take(5)) { + for span in maybe_point_at_variant(tcx, def, witnesses.iter().take(5)) { variants.push(Variant { span }); } Some(AdtDefinedHere { adt_def_span, ty, variants }) diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs index 6f8d17b772aaa..54bce926263f6 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs @@ -204,7 +204,7 @@ impl<'tcx> ConstToPat<'tcx> { let (&variant_index, fields) = cv.unwrap_branch().split_first().unwrap(); let variant_index = VariantIdx::from_u32(variant_index.unwrap_leaf().to_u32()); PatKind::Variant { - adt_def: *adt_def, + adt_def, args, variant_index, subpatterns: self.field_pats( @@ -237,7 +237,7 @@ impl<'tcx> ConstToPat<'tcx> { prefix: cv .unwrap_branch() .iter() - .map(|val| self.valtree_to_pat(*val, *elem_ty)) + .map(|val| self.valtree_to_pat(*val, elem_ty)) .collect(), slice: None, suffix: Box::new([]), @@ -246,12 +246,12 @@ impl<'tcx> ConstToPat<'tcx> { prefix: cv .unwrap_branch() .iter() - .map(|val| self.valtree_to_pat(*val, *elem_ty)) + .map(|val| self.valtree_to_pat(*val, elem_ty)) .collect(), slice: None, suffix: Box::new([]), }, - ty::Ref(_, pointee_ty, ..) => match *pointee_ty.kind() { + ty::Ref(_, pointee_ty, ..) => match pointee_ty.kind() { // `&str` is represented as a valtree, let's keep using this // optimization for now. ty::Str => PatKind::Constant { @@ -262,7 +262,7 @@ impl<'tcx> ConstToPat<'tcx> { // deref pattern. _ => { if !pointee_ty.is_sized(tcx, param_env) && !pointee_ty.is_slice() { - let err = UnsizedPattern { span, non_sm_ty: *pointee_ty }; + let err = UnsizedPattern { span, non_sm_ty: pointee_ty }; let e = tcx.dcx().emit_err(err); // We errored. Signal that in the pattern, so that follow up errors can be silenced. PatKind::Error(e) @@ -273,11 +273,11 @@ impl<'tcx> ConstToPat<'tcx> { // as slices. This means we turn `&[T; N]` constants into slice patterns, which // has no negative effects on pattern matching, even if we're actually matching on // arrays. - let pointee_ty = match *pointee_ty.kind() { + let pointee_ty = match pointee_ty.kind() { ty::Array(elem_ty, _) if self.treat_byte_string_as_slice => { Ty::new_slice(tcx, elem_ty) } - _ => *pointee_ty, + _ => pointee_ty, }; // References have the same valtree representation as their pointee. let subpattern = self.valtree_to_pat(cv, pointee_ty); diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index 615070034b96b..f37f0fafe880d 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -111,7 +111,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { let suggestion_str: String = adjustments .iter() .map(|ref_ty| { - let &ty::Ref(_, _, mutbl) = ref_ty.kind() else { + let ty::Ref(_, _, mutbl) = ref_ty.kind() else { span_bug!(pat.span, "pattern implicitly dereferences a non-ref type"); }; @@ -193,11 +193,11 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { }; let (min, max): (i128, u128) = match ty.kind() { ty::Int(ity) => { - let size = Integer::from_int_ty(&self.tcx, *ity).size(); + let size = Integer::from_int_ty(&self.tcx, ity).size(); (size.signed_int_min(), size.signed_int_max() as u128) } ty::Uint(uty) => { - let size = Integer::from_uint_ty(&self.tcx, *uty).size(); + let size = Integer::from_uint_ty(&self.tcx, uty).size(); (0, size.unsigned_int_max()) } _ => { @@ -355,7 +355,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { let var_ty = ty; if let hir::ByRef::Yes(_) = mode.0 { if let ty::Ref(_, rty, _) = ty.kind() { - ty = *rty; + ty = rty; } else { bug!("`ref {}` has wrong type {}", ident, ty); } @@ -474,7 +474,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { ty::Adt(_, args) | ty::FnDef(_, args) => args, ty::Error(e) => { // Avoid ICE (#50585) - return PatKind::Error(*e); + return PatKind::Error(e); } _ => bug!("inappropriate type for def: {:?}", ty), }; diff --git a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs index 2ec3b53bc9814..cfdd20b19909a 100644 --- a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs +++ b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs @@ -866,13 +866,13 @@ where // See librustc_body/transform/coroutine.rs for more details. ty::Coroutine(_, args) => self.open_drop_for_tuple(args.as_coroutine().upvar_tys()), ty::Tuple(fields) => self.open_drop_for_tuple(fields), - ty::Adt(def, args) => self.open_drop_for_adt(*def, args), + ty::Adt(def, args) => self.open_drop_for_adt(def, args), ty::Dynamic(..) => self.complete_drop(self.succ, self.unwind), ty::Array(ety, size) => { let size = size.try_eval_target_usize(self.tcx(), self.elaborator.param_env()); - self.open_drop_for_array(*ety, size) + self.open_drop_for_array(ety, size) } - ty::Slice(ety) => self.drop_loop_pair(*ety), + ty::Slice(ety) => self.drop_loop_pair(ety), _ => span_bug!(self.source_info.span, "open drop from non-ADT `{:?}`", ty), } diff --git a/compiler/rustc_mir_dataflow/src/impls/initialized.rs b/compiler/rustc_mir_dataflow/src/impls/initialized.rs index 7822fb17f7298..f7fb39b1c8ab6 100644 --- a/compiler/rustc_mir_dataflow/src/impls/initialized.rs +++ b/compiler/rustc_mir_dataflow/src/impls/initialized.rs @@ -761,7 +761,7 @@ fn switch_on_enum_discriminant<'mir, 'tcx>( if *lhs == switch_on => { match discriminated.ty(body, tcx).ty.kind() { - ty::Adt(def, _) => return Some((*discriminated, *def)), + ty::Adt(def, _) => return Some((*discriminated, def)), // `Rvalue::Discriminant` is also used to get the active yield point for a // coroutine, but we do not need edge-specific effects in that case. This may diff --git a/compiler/rustc_mir_dataflow/src/rustc_peek.rs b/compiler/rustc_mir_dataflow/src/rustc_peek.rs index 0171cc8591809..37d0a1e2b3ab0 100644 --- a/compiler/rustc_mir_dataflow/src/rustc_peek.rs +++ b/compiler/rustc_mir_dataflow/src/rustc_peek.rs @@ -199,7 +199,7 @@ impl PeekCall { if let mir::TerminatorKind::Call { func: Operand::Constant(func), args, .. } = &terminator.kind { - if let ty::FnDef(def_id, fn_args) = *func.const_.ty().kind() { + if let ty::FnDef(def_id, fn_args) = func.const_.ty().kind() { if tcx.intrinsic(def_id)?.name != sym::rustc_peek { return None; } diff --git a/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs b/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs index edb6bc4fbea2f..ae899dd5213e6 100644 --- a/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs +++ b/compiler/rustc_mir_transform/src/abort_unwinding_calls.rs @@ -65,7 +65,7 @@ impl<'tcx> MirPass<'tcx> for AbortUnwindingCalls { let sig = ty.fn_sig(tcx); let fn_def_id = match ty.kind() { ty::FnPtr(..) => None, - &ty::FnDef(def_id, _) => Some(def_id), + ty::FnDef(def_id, _) => Some(def_id), _ => span_bug!(span, "invalid callee of type {:?}", ty), }; layout::fn_can_unwind(tcx, fn_def_id, sig.abi()) diff --git a/compiler/rustc_mir_transform/src/add_retag.rs b/compiler/rustc_mir_transform/src/add_retag.rs index 16977a63c598e..cacefe2620961 100644 --- a/compiler/rustc_mir_transform/src/add_retag.rs +++ b/compiler/rustc_mir_transform/src/add_retag.rs @@ -32,7 +32,7 @@ fn may_contain_reference<'tcx>(ty: Ty<'tcx>, depth: u32, tcx: TyCtxt<'tcx>) -> b // Compound types: recurse ty::Array(ty, _) | ty::Slice(ty) => { // This does not branch so we keep the depth the same. - may_contain_reference(*ty, depth, tcx) + may_contain_reference(ty, depth, tcx) } ty::Tuple(tys) => { depth == 0 || tys.iter().any(|ty| may_contain_reference(ty, depth - 1, tcx)) diff --git a/compiler/rustc_mir_transform/src/check_alignment.rs b/compiler/rustc_mir_transform/src/check_alignment.rs index a1dbd7dc50ec7..b107d799f23a9 100644 --- a/compiler/rustc_mir_transform/src/check_alignment.rs +++ b/compiler/rustc_mir_transform/src/check_alignment.rs @@ -114,7 +114,7 @@ impl<'tcx, 'a> Visitor<'tcx> for PointerFinder<'tcx, 'a> { // Try to detect types we are sure have an alignment of 1 and skip the check // We don't need to look for str and slices, we already rejected unsized types above let element_ty = match pointee_ty.kind() { - ty::Array(ty, _) => *ty, + ty::Array(ty, _) => ty, _ => pointee_ty, }; if [self.tcx.types.bool, self.tcx.types.i8, self.tcx.types.u8].contains(&element_ty) { diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index 82528109be9ab..2abb1e7bd1082 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -273,8 +273,8 @@ impl<'tcx> TransformVisitor<'tcx> { } // `async gen` continues to return `Poll::Ready(None)` CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _) => { - let ty::Adt(_poll_adt, args) = *self.old_yield_ty.kind() else { bug!() }; - let ty::Adt(_option_adt, args) = *args.type_at(0).kind() else { bug!() }; + let ty::Adt(_poll_adt, args) = self.old_yield_ty.kind() else { bug!() }; + let ty::Adt(_option_adt, args) = args.type_at(0).kind() else { bug!() }; let yield_ty = args.type_at(0); Rvalue::Use(Operand::Constant(Box::new(ConstOperand { span: source_info.span, @@ -377,8 +377,8 @@ impl<'tcx> TransformVisitor<'tcx> { } CoroutineKind::Desugared(CoroutineDesugaring::AsyncGen, _) => { if is_return { - let ty::Adt(_poll_adt, args) = *self.old_yield_ty.kind() else { bug!() }; - let ty::Adt(_option_adt, args) = *args.type_at(0).kind() else { bug!() }; + let ty::Adt(_poll_adt, args) = self.old_yield_ty.kind() else { bug!() }; + let ty::Adt(_option_adt, args) = args.type_at(0).kind() else { bug!() }; let yield_ty = args.type_at(0); Rvalue::Use(Operand::Constant(Box::new(ConstOperand { span: source_info.span, @@ -645,7 +645,7 @@ fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { match &bb_data.terminator().kind { TerminatorKind::Call { func, .. } => { let func_ty = func.ty(body, tcx); - if let ty::FnDef(def_id, _) = *func_ty.kind() { + if let ty::FnDef(def_id, _) = func_ty.kind() { if def_id == get_context_def_id { let local = eliminate_get_context_call(&mut body[bb]); replace_resume_ty_local(tcx, body, local, context_mut_ref); @@ -698,7 +698,7 @@ fn replace_resume_ty_local<'tcx>( { if let ty::Adt(resume_ty_adt, _) = local_ty.kind() { let expected_adt = tcx.adt_def(tcx.require_lang_item(LangItem::ResumeTy, None)); - assert_eq!(*resume_ty_adt, expected_adt); + assert_eq!(resume_ty_adt, expected_adt); } else { panic!("expected `ResumeTy`, found `{:?}`", local_ty); }; @@ -1566,7 +1566,7 @@ pub(crate) fn mir_coroutine_witnesses<'tcx>( // The first argument is the coroutine type passed by value let coroutine_ty = body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty; - let movable = match *coroutine_ty.kind() { + let movable = match coroutine_ty.kind() { ty::Coroutine(def_id, _) => tcx.coroutine_movability(def_id) == hir::Movability::Movable, ty::Error(_) => return None, _ => span_bug!(body.span, "unexpected coroutine type {}", coroutine_ty), @@ -1638,7 +1638,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform { let coroutine_kind = body.coroutine_kind().unwrap(); // Get the discriminant type and args which typeck computed - let (discr_ty, movable) = match *coroutine_ty.kind() { + let (discr_ty, movable) = match coroutine_ty.kind() { ty::Coroutine(_, args) => { let args = args.as_coroutine(); (args.discr_ty(tcx), coroutine_kind.movability() == hir::Movability::Movable) @@ -1993,7 +1993,7 @@ fn check_must_not_suspend_ty<'tcx>( debug!("Checking must_not_suspend for {}", ty); - match *ty.kind() { + match ty.kind() { ty::Adt(_, args) if ty.is_box() => { let boxed_ty = args.type_at(0); let allocator_ty = args.type_at(1); diff --git a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs index 69d21a63f557b..20b28af663882 100644 --- a/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs +++ b/compiler/rustc_mir_transform/src/coroutine/by_move_body.rs @@ -106,14 +106,14 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody { return; } - let ty::Coroutine(_, args) = *coroutine_ty.kind() else { bug!("{body:#?}") }; + let ty::Coroutine(_, args) = coroutine_ty.kind() else { bug!("{body:#?}") }; let args = args.as_coroutine(); let coroutine_kind = args.kind_ty().to_opt_closure_kind().unwrap(); let parent_def_id = tcx.local_parent(coroutine_def_id); let ty::CoroutineClosure(_, parent_args) = - *tcx.type_of(parent_def_id).instantiate_identity().kind() + tcx.type_of(parent_def_id).instantiate_identity().kind() else { bug!(); }; diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index 0fc4d6b9f4e1e..d1d66d945bcd0 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -199,7 +199,7 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> { && let operand_ty = operand.ty(self.local_decls, self.tcx) && let Some(operand_ty) = operand_ty.builtin_deref(true) && let ty::Array(_, len) = operand_ty.kind() - && let Some(len) = Const::Ty(self.tcx.types.usize, *len) + && let Some(len) = Const::Ty(self.tcx.types.usize, len) .try_eval_scalar_int(self.tcx, self.param_env) { state.insert_value_idx(target_len, FlatSet::Elem(len.into()), self.map()); @@ -218,7 +218,7 @@ impl<'tcx> ValueAnalysis<'tcx> for ConstAnalysis<'_, 'tcx> { Rvalue::Len(place) => { let place_ty = place.ty(self.local_decls, self.tcx); if let ty::Array(_, len) = place_ty.ty.kind() { - Const::Ty(self.tcx.types.usize, *len) + Const::Ty(self.tcx.types.usize, len) .try_eval_scalar(self.tcx, self.param_env) .map_or(FlatSet::Top, FlatSet::Elem) } else if let [ProjectionElem::Deref] = place.projection[..] { diff --git a/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs b/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs index 9a2cc057232f3..c13b5f5fdb63d 100644 --- a/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs +++ b/compiler/rustc_mir_transform/src/ffi_unwind_calls.rs @@ -58,7 +58,7 @@ fn has_ffi_unwind_calls(tcx: TyCtxt<'_>, local_def_id: LocalDefId) -> bool { let fn_def_id = match ty.kind() { ty::FnPtr(..) => None, - &ty::FnDef(def_id, _) => { + ty::FnDef(def_id, _) => { // Rust calls cannot themselves create foreign unwinds (even if they use a non-Rust ABI). // So the leak of the foreign unwind into Rust can only be elsewhere, not here. if !tcx.is_foreign_item(def_id) { diff --git a/compiler/rustc_mir_transform/src/function_item_references.rs b/compiler/rustc_mir_transform/src/function_item_references.rs index b7873e73c18c7..819a5ea4517cd 100644 --- a/compiler/rustc_mir_transform/src/function_item_references.rs +++ b/compiler/rustc_mir_transform/src/function_item_references.rs @@ -42,7 +42,7 @@ impl<'tcx> Visitor<'tcx> for FunctionItemRefChecker<'_, 'tcx> { { let source_info = *self.body.source_info(location); let func_ty = func.ty(self.body, self.tcx); - if let ty::FnDef(def_id, args_ref) = *func_ty.kind() { + if let ty::FnDef(def_id, args_ref) = func_ty.kind() { // Handle calls to `transmute` if self.tcx.is_diagnostic_item(sym::transmute, def_id) { let arg_ty = args[0].node.ty(self.body, self.tcx); @@ -127,7 +127,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> { }; referent_ty .map(|ref_ty| { - if let ty::FnDef(def_id, args_ref) = *ref_ty.kind() { + if let ty::FnDef(def_id, args_ref) = ref_ty.kind() { Some((def_id, args_ref)) } else { None diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index e16911d79c378..4c294c3f650ba 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -1052,7 +1052,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { && let ty::Array(_, len) = from.builtin_deref(true).unwrap().kind() => { return self.insert_constant(Const::from_ty_const( - *len, + len, self.tcx.types.usize, self.tcx, )); @@ -1314,11 +1314,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { // Trivial case: we are fetching a statically known length. let place_ty = place.ty(self.local_decls, self.tcx).ty; if let ty::Array(_, len) = place_ty.kind() { - return self.insert_constant(Const::from_ty_const( - *len, - self.tcx.types.usize, - self.tcx, - )); + return self.insert_constant(Const::from_ty_const(len, self.tcx.types.usize, self.tcx)); } let mut inner = self.simplify_place_value(place, location)?; @@ -1340,11 +1336,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> { && let Some(to) = to.builtin_deref(true) && let ty::Slice(..) = to.kind() { - return self.insert_constant(Const::from_ty_const( - *len, - self.tcx.types.usize, - self.tcx, - )); + return self.insert_constant(Const::from_ty_const(len, self.tcx.types.usize, self.tcx)); } // Fallback: a symbolic `Len`. diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 324ddc5e799d5..11ab0e2f229cf 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -265,7 +265,7 @@ impl<'tcx> Inliner<'tcx> { self_arg.map(|self_arg| self_arg.node.ty(&caller_body.local_decls, self.tcx)); let arg_tuple_ty = arg_tuple.node.ty(&caller_body.local_decls, self.tcx); - let ty::Tuple(arg_tuple_tys) = *arg_tuple_ty.kind() else { + let ty::Tuple(arg_tuple_tys) = arg_tuple_ty.kind() else { bug!("Closure arguments are not passed as a tuple"); }; @@ -395,7 +395,7 @@ impl<'tcx> Inliner<'tcx> { // FIXME(explicit_tail_calls): figure out if we can inline tail calls if let TerminatorKind::Call { ref func, fn_span, .. } = terminator.kind { let func_ty = func.ty(caller_body, self.tcx); - if let ty::FnDef(def_id, args) = *func_ty.kind() { + if let ty::FnDef(def_id, args) = func_ty.kind() { // To resolve an instance its args have to be fully normalized. let args = self.tcx.try_normalize_erasing_regions(self.param_env, args).ok()?; let callee = diff --git a/compiler/rustc_mir_transform/src/inline/cycle.rs b/compiler/rustc_mir_transform/src/inline/cycle.rs index f5274c664cfa7..d0908669049c0 100644 --- a/compiler/rustc_mir_transform/src/inline/cycle.rs +++ b/compiler/rustc_mir_transform/src/inline/cycle.rs @@ -171,15 +171,15 @@ pub(crate) fn mir_inliner_callees<'tcx>( let ty::FnDef(def_id, generic_args) = ty.kind() else { continue; }; - let call = if tcx.is_intrinsic(*def_id, sym::const_eval_select) { + let call = if tcx.is_intrinsic(def_id, sym::const_eval_select) { let func = &call_args[2].node; let ty = func.ty(&body.local_decls, tcx); let ty::FnDef(def_id, generic_args) = ty.kind() else { continue; }; - (*def_id, *generic_args) + (def_id, generic_args) } else { - (*def_id, *generic_args) + (def_id, generic_args) }; calls.insert(call); } diff --git a/compiler/rustc_mir_transform/src/instsimplify.rs b/compiler/rustc_mir_transform/src/instsimplify.rs index 1589653968c2e..87c86b77c33da 100644 --- a/compiler/rustc_mir_transform/src/instsimplify.rs +++ b/compiler/rustc_mir_transform/src/instsimplify.rs @@ -163,7 +163,7 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> { fn simplify_len(&self, source_info: &SourceInfo, rvalue: &mut Rvalue<'tcx>) { if let Rvalue::Len(ref place) = *rvalue { let place_ty = place.ty(self.local_decls, self.tcx).ty; - if let ty::Array(_, len) = *place_ty.kind() { + if let ty::Array(_, len) = place_ty.kind() { if !self.should_simplify(source_info, rvalue) { return; } @@ -280,7 +280,7 @@ impl<'tcx> InstSimplifyContext<'tcx, '_> { // doing DefId lookups to figure out what we're actually calling. let arg_ty = arg.node.ty(self.local_decls, self.tcx); - let ty::Ref(_region, inner_ty, Mutability::Not) = *arg_ty.kind() else { return }; + let ty::Ref(_region, inner_ty, Mutability::Not) = arg_ty.kind() else { return }; if !inner_ty.is_trivially_pure_clone_copy() { return; @@ -385,7 +385,7 @@ fn resolve_rust_intrinsic<'tcx>( tcx: TyCtxt<'tcx>, func_ty: Ty<'tcx>, ) -> Option<(Symbol, GenericArgsRef<'tcx>)> { - if let ty::FnDef(def_id, args) = *func_ty.kind() { + if let ty::FnDef(def_id, args) = func_ty.kind() { let intrinsic = tcx.intrinsic(def_id)?; return Some((intrinsic.name, args)); } diff --git a/compiler/rustc_mir_transform/src/large_enums.rs b/compiler/rustc_mir_transform/src/large_enums.rs index e407929c9a7fd..fd53471624f9e 100644 --- a/compiler/rustc_mir_transform/src/large_enums.rs +++ b/compiler/rustc_mir_transform/src/large_enums.rs @@ -75,7 +75,7 @@ impl EnumSizeOpt { return None; } if let Some(alloc_id) = alloc_cache.get(&ty) { - return Some((*adt_def, num_discrs, *alloc_id)); + return Some((adt_def, num_discrs, *alloc_id)); } let data_layout = tcx.data_layout(); @@ -114,7 +114,7 @@ impl EnumSizeOpt { Mutability::Not, ); let alloc = tcx.reserve_and_set_memory_alloc(tcx.mk_const_alloc(alloc)); - Some((*adt_def, num_discrs, *alloc_cache.entry(ty).or_insert(alloc))) + Some((adt_def, num_discrs, *alloc_cache.entry(ty).or_insert(alloc))) } fn optim<'tcx>(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { let mut alloc_cache = FxHashMap::default(); diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 1f214bc42cbe6..e7e7d1471ea01 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -155,7 +155,7 @@ fn remap_mir_for_const_eval_select<'tcx>( unwind, fn_span, .. - } if let ty::FnDef(def_id, _) = *const_.ty().kind() + } if let ty::FnDef(def_id, _) = const_.ty().kind() && tcx.is_intrinsic(def_id, sym::const_eval_select) => { let Ok([tupled_args, called_in_const, called_at_rt]) = take_array(args) else { diff --git a/compiler/rustc_mir_transform/src/lower_intrinsics.rs b/compiler/rustc_mir_transform/src/lower_intrinsics.rs index a9bdff95fe5ac..ef6101d9437d7 100644 --- a/compiler/rustc_mir_transform/src/lower_intrinsics.rs +++ b/compiler/rustc_mir_transform/src/lower_intrinsics.rs @@ -16,7 +16,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics { let terminator = block.terminator.as_mut().unwrap(); if let TerminatorKind::Call { func, args, destination, target, .. } = &mut terminator.kind - && let ty::FnDef(def_id, generic_args) = *func.ty(local_decls, tcx).kind() + && let ty::FnDef(def_id, generic_args) = func.ty(local_decls, tcx).kind() && let Some(intrinsic) = tcx.intrinsic(def_id) { match intrinsic.name { @@ -284,7 +284,7 @@ impl<'tcx> MirPass<'tcx> for LowerIntrinsics { let target = target.unwrap(); let pointer_ty = generic_args.type_at(0); let kind = if let ty::RawPtr(pointee_ty, mutability) = pointer_ty.kind() { - AggregateKind::RawPtr(*pointee_ty, *mutability) + AggregateKind::RawPtr(pointee_ty, mutability) } else { span_bug!( terminator.source_info.span, diff --git a/compiler/rustc_mir_transform/src/match_branches.rs b/compiler/rustc_mir_transform/src/match_branches.rs index 47758b56f8c90..998edd76020e8 100644 --- a/compiler/rustc_mir_transform/src/match_branches.rs +++ b/compiler/rustc_mir_transform/src/match_branches.rs @@ -277,7 +277,7 @@ fn can_cast( Int(_) => from_scalar.to_int(src_layout.size) as u128, _ => unreachable!("invalid int"), }; - let size = match *cast_ty.kind() { + let size = match cast_ty.kind() { Int(t) => Integer::from_int_ty(&tcx, t).size(), Uint(t) => Integer::from_uint_ty(&tcx, t).size(), _ => unreachable!("invalid int"), diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index 48a3266ae6f0d..e0547307d71c5 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -648,7 +648,7 @@ impl<'tcx> Validator<'_, 'tcx> { // Functions marked `#[rustc_promotable]` are explicitly allowed to be promoted, so we can // accept them at this point. let fn_ty = callee.ty(self.body, self.tcx); - if let ty::FnDef(def_id, _) = *fn_ty.kind() { + if let ty::FnDef(def_id, _) = fn_ty.kind() { if self.tcx.is_promotable_const_fn(def_id) { return Ok(()); } @@ -666,7 +666,7 @@ impl<'tcx> Validator<'_, 'tcx> { return Err(Unpromotable); } // Make sure the callee is a `const fn`. - let is_const_fn = match *fn_ty.kind() { + let is_const_fn = match fn_ty.kind() { ty::FnDef(def_id, _) => self.tcx.is_const_fn_raw(def_id), _ => false, }; diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 09b4e5e07113b..95aa267ab4967 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -86,9 +86,9 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceKind<'tcx>) -> Body< // FIXME(#91576): Drop shims for coroutines aren't subject to the MIR passes at the end // of this function. Is this intentional? if let Some(ty::Coroutine(coroutine_def_id, args)) = ty.map(Ty::kind) { - let coroutine_body = tcx.optimized_mir(*coroutine_def_id); + let coroutine_body = tcx.optimized_mir(coroutine_def_id); - let ty::Coroutine(_, id_args) = *tcx.type_of(coroutine_def_id).skip_binder().kind() + let ty::Coroutine(_, id_args) = tcx.type_of(coroutine_def_id).skip_binder().kind() else { bug!() }; @@ -444,8 +444,8 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) - } ty::Tuple(..) => builder.tuple_like_shim(dest, src, self_ty.tuple_fields()), ty::Coroutine(coroutine_def_id, args) => { - assert_eq!(tcx.coroutine_movability(*coroutine_def_id), hir::Movability::Movable); - builder.coroutine_shim(dest, src, *coroutine_def_id, args.as_coroutine()) + assert_eq!(tcx.coroutine_movability(coroutine_def_id), hir::Movability::Movable); + builder.coroutine_shim(dest, src, coroutine_def_id, args.as_coroutine()) } _ => bug!("clone shim for `{:?}` which is not `Copy` and is not an aggregate", self_ty), }; @@ -1031,7 +1031,7 @@ fn build_construct_coroutine_by_move_shim<'tcx>( ) -> Body<'tcx> { let mut self_ty = tcx.type_of(coroutine_closure_def_id).instantiate_identity(); let mut self_local: Place<'tcx> = Local::from_usize(1).into(); - let ty::CoroutineClosure(_, args) = *self_ty.kind() else { + let ty::CoroutineClosure(_, args) = self_ty.kind() else { bug!(); }; @@ -1063,7 +1063,7 @@ fn build_construct_coroutine_by_move_shim<'tcx>( ) }); let sig = tcx.liberate_late_bound_regions(coroutine_closure_def_id, poly_sig); - let ty::Coroutine(coroutine_def_id, coroutine_args) = *sig.output().kind() else { + let ty::Coroutine(coroutine_def_id, coroutine_args) = sig.output().kind() else { bug!(); }; diff --git a/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs b/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs index ea4f5fca59e67..bc5c101fe36b4 100644 --- a/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs +++ b/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs @@ -142,8 +142,8 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> { }; match self_ty.kind() { - ty::Array(elem_ty, _) => self.build_slice(true, *elem_ty), - ty::Slice(elem_ty) => self.build_slice(false, *elem_ty), + ty::Array(elem_ty, _) => self.build_slice(true, elem_ty), + ty::Slice(elem_ty) => self.build_slice(false, elem_ty), ty::Tuple(elem_tys) => self.build_chain(None, elem_tys.iter()), ty::Adt(adt_def, args) if adt_def.is_struct() => { @@ -156,7 +156,7 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> { } ty::Adt(adt_def, args) if adt_def.is_enum() => { - self.build_enum(*adt_def, *args, surface_drop_kind()) + self.build_enum(adt_def, args, surface_drop_kind()) } ty::Adt(adt_def, _) => { @@ -561,7 +561,7 @@ impl<'tcx> AsyncDestructorCtorShimBuilder<'tcx> { // If projection of Discriminant then compare with `Ty::discriminant_ty` if let ty::Alias(ty::Projection, ty::AliasTy { args, def_id, .. }) = expected_ty.kind() - && self.tcx.is_lang_item(*def_id, LangItem::Discriminant) + && self.tcx.is_lang_item(def_id, LangItem::Discriminant) && args.first().unwrap().as_type().unwrap().discriminant_ty(self.tcx) == operand_ty { return; diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs index 491ae1c0d083f..109ab5aaca583 100644 --- a/compiler/rustc_mir_transform/src/validate.rs +++ b/compiler/rustc_mir_transform/src/validate.rs @@ -676,7 +676,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { }; let kind = match parent_ty.ty.kind() { - &ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => { self.tcx.type_of(def_id).instantiate(self.tcx, args).kind() } kind => kind, @@ -725,7 +725,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { }; check_equal(self, location, f_ty); } - &ty::Coroutine(def_id, args) => { + ty::Coroutine(def_id, args) => { let f_ty = if let Some(var) = parent_ty.variant_index { // If we're currently validating an inlined copy of this body, // then it will no longer be parameterized over the original @@ -971,7 +971,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { let data_ptr_ty = data_ptr.ty(self.body, self.tcx); let metadata_ty = metadata.ty(self.body, self.tcx); if let ty::RawPtr(in_pointee, in_mut) = data_ptr_ty.kind() { - if *in_mut != mutability { + if in_mut != mutability { self.fail(location, "input and output mutability must match"); } diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 0ae635f9b73e5..20ebf471f4524 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -709,7 +709,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { // *Before* monomorphizing, record that we already handled this mention. self.used_mentioned_items.insert(MentionedItem::Closure(source_ty)); let source_ty = self.monomorphize(source_ty); - if let ty::Closure(def_id, args) = *source_ty.kind() { + if let ty::Closure(def_id, args) = source_ty.kind() { let instance = Instance::resolve_closure(self.tcx, def_id, args, ty::ClosureKind::FnOnce); if self.tcx.should_codegen_locally(instance) { @@ -852,7 +852,7 @@ fn visit_fn_use<'tcx>( source: Span, output: &mut MonoItems<'tcx>, ) { - if let ty::FnDef(def_id, args) = *ty.kind() { + if let ty::FnDef(def_id, args) = ty.kind() { let instance = if is_direct_call { ty::Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, source) } else { @@ -1035,7 +1035,7 @@ fn find_vtable_types_for_unsizing<'tcx>( match (&source_ty.kind(), &target_ty.kind()) { (&ty::Ref(_, a, _), &ty::Ref(_, b, _) | &ty::RawPtr(b, _)) - | (&ty::RawPtr(a, _), &ty::RawPtr(b, _)) => ptr_vtable(*a, *b), + | (&ty::RawPtr(a, _), &ty::RawPtr(b, _)) => ptr_vtable(a, b), (&ty::Adt(def_a, _), &ty::Adt(def_b, _)) if def_a.is_box() && def_b.is_box() => { ptr_vtable(source_ty.boxed_ty(), target_ty.boxed_ty()) } @@ -1255,7 +1255,7 @@ fn visit_mentioned_item<'tcx>( ) { match *item { MentionedItem::Fn(ty) => { - if let ty::FnDef(def_id, args) = *ty.kind() { + if let ty::FnDef(def_id, args) = ty.kind() { let instance = Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args, span); // `visit_instance_use` was written for "used" item collection but works just as well @@ -1281,7 +1281,7 @@ fn visit_mentioned_item<'tcx>( } } MentionedItem::Closure(source_ty) => { - if let ty::Closure(def_id, args) = *source_ty.kind() { + if let ty::Closure(def_id, args) = source_ty.kind() { let instance = Instance::resolve_closure(tcx, def_id, args, ty::ClosureKind::FnOnce); if tcx.should_codegen_locally(instance) { diff --git a/compiler/rustc_monomorphize/src/collector/move_check.rs b/compiler/rustc_monomorphize/src/collector/move_check.rs index 851f86e86b8e8..649193b463ad8 100644 --- a/compiler/rustc_monomorphize/src/collector/move_check.rs +++ b/compiler/rustc_monomorphize/src/collector/move_check.rs @@ -61,7 +61,7 @@ impl<'a, 'tcx> MirUsedCollector<'a, 'tcx> { } // Allow large moves into container types that themselves are cheap to move - let ty::FnDef(def_id, _) = *callee_ty.kind() else { + let ty::FnDef(def_id, _) = callee_ty.kind() else { return; }; if self diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index 5a24202db65ec..7a320e34d0126 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -312,7 +312,7 @@ impl<'a, 'tcx> TypeVisitor> for MarkUsedGenericParams<'a, 'tcx> { return; } - match *ty.kind() { + match ty.kind() { ty::Closure(def_id, args) | ty::Coroutine(def_id, args, ..) => { debug!(?def_id); // Avoid cycle errors with coroutines. diff --git a/compiler/rustc_passes/src/abi_test.rs b/compiler/rustc_passes/src/abi_test.rs index d0cc123c41a8a..888f63cef3eb0 100644 --- a/compiler/rustc_passes/src/abi_test.rs +++ b/compiler/rustc_passes/src/abi_test.rs @@ -135,8 +135,7 @@ fn dump_abi_of_fn_type(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribut }; let abi = unwrap_fn_abi( tcx.fn_abi_of_fn_ptr( - param_env - .and((sig_tys.with(*hdr), /* extra_args */ ty::List::empty())), + param_env.and((sig_tys.with(hdr), /* extra_args */ ty::List::empty())), ), tcx, item_def_id, @@ -152,7 +151,7 @@ fn dump_abi_of_fn_type(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribut "`#[rustc_abi(assert_eq)]` on a type alias requires pair type" ); }; - let [field1, field2] = ***fields else { + let [field1, field2] = **fields else { span_bug!( meta_item.span(), "`#[rustc_abi(assert_eq)]` on a type alias requires pair type" @@ -167,7 +166,7 @@ fn dump_abi_of_fn_type(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribut let abi1 = unwrap_fn_abi( tcx.fn_abi_of_fn_ptr( param_env - .and((sig_tys1.with(*hdr1), /* extra_args */ ty::List::empty())), + .and((sig_tys1.with(hdr1), /* extra_args */ ty::List::empty())), ), tcx, item_def_id, @@ -181,7 +180,7 @@ fn dump_abi_of_fn_type(tcx: TyCtxt<'_>, item_def_id: LocalDefId, attr: &Attribut let abi2 = unwrap_fn_abi( tcx.fn_abi_of_fn_ptr( param_env - .and((sig_tys2.with(*hdr2), /* extra_args */ ty::List::empty())), + .and((sig_tys2.with(hdr2), /* extra_args */ ty::List::empty())), ), tcx, item_def_id, diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 7ae5c9040042c..2134d5fa8c6c7 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -478,7 +478,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { //// method of a private type is used, but the type itself is never //// called directly. let self_ty = self.tcx.type_of(item).instantiate_identity(); - match *self_ty.kind() { + match self_ty.kind() { ty::Adt(def, _) => self.check_def_id(def.did()), ty::Foreign(did) => self.check_def_id(did), ty::Dynamic(data, ..) => { @@ -603,7 +603,7 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> { let res = self.typeck_results().qpath_res(qpath, expr.hir_id); self.handle_res(res); if let ty::Adt(adt, _) = self.typeck_results().expr_ty(expr).kind() { - self.mark_as_used_if_union(*adt, fields); + self.mark_as_used_if_union(adt, fields); } } hir::ExprKind::Closure(cls) => { diff --git a/compiler/rustc_pattern_analysis/src/rustc.rs b/compiler/rustc_pattern_analysis/src/rustc.rs index bcd3d3092c352..4d9c5f3a46aef 100644 --- a/compiler/rustc_pattern_analysis/src/rustc.rs +++ b/compiler/rustc_pattern_analysis/src/rustc.rs @@ -114,7 +114,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { #[inline] pub fn reveal_opaque_ty(&self, ty: Ty<'tcx>) -> RevealedTy<'tcx> { fn reveal_inner<'tcx>(cx: &RustcPatCtxt<'_, 'tcx>, ty: Ty<'tcx>) -> RevealedTy<'tcx> { - let ty::Alias(ty::Opaque, alias_ty) = *ty.kind() else { bug!() }; + let ty::Alias(ty::Opaque, alias_ty) = ty.kind() else { bug!() }; if let Some(local_def_id) = alias_ty.def_id.as_local() { let key = ty::OpaqueTypeKey { def_id: local_def_id, args: alias_ty.args }; if let Some(ty) = cx.reveal_opaque_key(key) { @@ -227,8 +227,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { // patterns. If we're here we can assume this is a box pattern. reveal_and_alloc(cx, once(args.type_at(0))) } else { - let variant = - &adt.variant(RustcPatCtxt::variant_index_for_adt(&ctor, *adt)); + let variant = &adt.variant(RustcPatCtxt::variant_index_for_adt(&ctor, adt)); // In the cases of either a `#[non_exhaustive]` field list or a non-public // field, we skip uninhabited fields in order not to reveal the @@ -248,10 +247,10 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { _ => bug!("Unexpected type for constructor `{ctor:?}`: {ty:?}"), }, Ref => match ty.kind() { - ty::Ref(_, rty, _) => reveal_and_alloc(cx, once(*rty)), + ty::Ref(_, rty, _) => reveal_and_alloc(cx, once(rty)), _ => bug!("Unexpected type for `Ref` constructor: {ty:?}"), }, - Slice(slice) => match *ty.kind() { + Slice(slice) => match ty.kind() { ty::Slice(ty) | ty::Array(ty, _) => { let arity = slice.arity(); reveal_and_alloc(cx, (0..arity).map(|_| ty)) @@ -279,7 +278,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { // patterns. If we're here we can assume this is a box pattern. 1 } else { - let variant_idx = RustcPatCtxt::variant_index_for_adt(&ctor, *adt); + let variant_idx = RustcPatCtxt::variant_index_for_adt(&ctor, adt); adt.variant(variant_idx).fields.len() } } @@ -322,7 +321,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { range_2: Some(make_uint_range('\u{E000}' as u128, '\u{10FFFF}' as u128)), } } - &ty::Int(ity) => { + ty::Int(ity) => { let range = if ty.is_ptr_sized_integral() { // The min/max values of `isize` are not allowed to be observed. IntRange { @@ -339,7 +338,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { }; ConstructorSet::Integers { range_1: range, range_2: None } } - &ty::Uint(uty) => { + ty::Uint(uty) => { let range = if ty.is_ptr_sized_integral() { // The max value of `usize` is not allowed to be observed. let lo = MaybeInfiniteInt::new_finite_uint(0); @@ -353,13 +352,13 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { } ty::Slice(sub_ty) => ConstructorSet::Slice { array_len: None, - subtype_is_empty: cx.is_uninhabited(*sub_ty), + subtype_is_empty: cx.is_uninhabited(sub_ty), }, ty::Array(sub_ty, len) => { // We treat arrays of a constant but unknown length like slices. ConstructorSet::Slice { array_len: len.try_eval_target_usize(cx.tcx, cx.param_env).map(|l| l as usize), - subtype_is_empty: cx.is_uninhabited(*sub_ty), + subtype_is_empty: cx.is_uninhabited(sub_ty), } } ty::Adt(def, args) if def.is_enum() => { @@ -373,7 +372,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { let variant_def_id = def.variant(idx).def_id; // Visibly uninhabited variants. let is_inhabited = v - .inhabited_predicate(cx.tcx, *def) + .inhabited_predicate(cx.tcx, def) .instantiate(cx.tcx, args) .apply_revealing_opaque(cx.tcx, cx.param_env, cx.module, &|key| { cx.reveal_opaque_key(key) @@ -437,7 +436,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { PatRangeBoundary::NegInfinity => MaybeInfiniteInt::NegInfinity, PatRangeBoundary::Finite(value) => { let bits = value.eval_bits(self.tcx, self.param_env); - match *ty.kind() { + match ty.kind() { ty::Int(ity) => { let size = Integer::from_int_ty(&self.tcx, ity).size().bits(); MaybeInfiniteInt::new_finite_int(bits, size) @@ -526,8 +525,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { PatKind::Variant { variant_index, .. } => Variant(variant_index), _ => bug!(), }; - let variant = - &adt.variant(RustcPatCtxt::variant_index_for_adt(&ctor, *adt)); + let variant = &adt.variant(RustcPatCtxt::variant_index_for_adt(&ctor, adt)); arity = variant.fields.len(); fields = subpatterns .iter() @@ -555,7 +553,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { ty::Char | ty::Int(_) | ty::Uint(_) => { ctor = match value.try_eval_bits(cx.tcx, cx.param_env) { Some(bits) => { - let x = match *ty.kind() { + let x = match ty.kind() { ty::Int(ity) => { let size = Integer::from_int_ty(&cx.tcx, ity).size().bits(); MaybeInfiniteInt::new_finite_int(bits, size) @@ -625,7 +623,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { // `Ref`), and has one field. That field has constructor `Str(value)` and no // subfields. // Note: `t` is `str`, not `&str`. - let ty = self.reveal_opaque_ty(*t); + let ty = self.reveal_opaque_ty(t); let subpattern = DeconstructedPat::new(Str(*value), Vec::new(), 0, ty, pat); ctor = Ref; fields = vec![subpattern.at_index(0)]; @@ -755,7 +753,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { NegInfinity => PatRangeBoundary::NegInfinity, Finite(_) => { let size = ty.primitive_size(tcx); - let bits = match *ty.kind() { + let bits = match ty.kind() { ty::Int(_) => miint.as_finite_int(size.bits()).unwrap(), _ => miint.as_finite_uint().unwrap(), }; @@ -835,7 +833,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> { PatKind::Box { subpattern: hoist(&pat.fields[0]) } } Struct | Variant(_) | UnionField => { - let enum_info = match *pat.ty().kind() { + let enum_info = match pat.ty().kind() { ty::Adt(adt_def, _) if adt_def.is_enum() => EnumInfo::Enum { adt_def, variant_index: RustcPatCtxt::variant_index_for_adt(pat.ctor(), adt_def), @@ -955,7 +953,7 @@ impl<'p, 'tcx: 'p> PatCx for RustcPatCtxt<'p, 'tcx> { if adt.is_box() { write!(f, "Box")? } else { - let variant = adt.variant(Self::variant_index_for_adt(ctor, *adt)); + let variant = adt.variant(Self::variant_index_for_adt(ctor, adt)); write!(f, "{}", variant.name)?; } } diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index d1d1e5e901f29..693585af546cd 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -176,7 +176,7 @@ where let tcx = self.def_id_visitor.tcx(); // GenericArgs are not visited here because they are visited below // in `super_visit_with`. - match *ty.kind() { + match ty.kind() { ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), ..) | ty::Foreign(def_id) | ty::FnDef(def_id, ..) diff --git a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs index a4e4f50e8f2d4..0efb5631da217 100644 --- a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs +++ b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/encode.rs @@ -134,7 +134,7 @@ fn encode_const<'tcx>( match ct_ty.kind() { ty::Int(ity) => { let bits = c.eval_bits(tcx, ty::ParamEnv::reveal_all()); - let val = Integer::from_int_ty(&tcx, *ity).size().sign_extend(bits) as i128; + let val = Integer::from_int_ty(&tcx, ity).size().sign_extend(bits) as i128; if val < 0 { s.push('n'); } @@ -416,7 +416,7 @@ pub fn encode_ty<'tcx>( let len = len.eval_target_usize(tcx, ty::ParamEnv::reveal_all()); let mut s = String::from("A"); let _ = write!(s, "{len}"); - s.push_str(&encode_ty(tcx, *ty0, dict, options)); + s.push_str(&encode_ty(tcx, ty0, dict, options)); compress(dict, DictKey::Ty(ty, TyQ::None), &mut s); typeid.push_str(&s); } @@ -424,8 +424,8 @@ pub fn encode_ty<'tcx>( ty::Pat(ty0, pat) => { // u3patIE as vendor extended type let mut s = String::from("u3patI"); - s.push_str(&encode_ty(tcx, *ty0, dict, options)); - write!(s, "{:?}", **pat).unwrap(); + s.push_str(&encode_ty(tcx, ty0, dict, options)); + write!(s, "{:?}", pat).unwrap(); s.push('E'); compress(dict, DictKey::Ty(ty, TyQ::None), &mut s); typeid.push_str(&s); @@ -434,7 +434,7 @@ pub fn encode_ty<'tcx>( ty::Slice(ty0) => { // u5sliceIE as vendor extended type let mut s = String::from("u5sliceI"); - s.push_str(&encode_ty(tcx, *ty0, dict, options)); + s.push_str(&encode_ty(tcx, ty0, dict, options)); s.push('E'); compress(dict, DictKey::Ty(ty, TyQ::None), &mut s); typeid.push_str(&s); @@ -507,7 +507,7 @@ pub fn encode_ty<'tcx>( ty::Foreign(def_id) => { // , where is let mut s = String::new(); - if let Some(cfi_encoding) = tcx.get_attr(*def_id, sym::cfi_encoding) { + if let Some(cfi_encoding) = tcx.get_attr(def_id, sym::cfi_encoding) { // Use user-defined CFI encoding for type if let Some(value_str) = cfi_encoding.value_str() { if !value_str.to_string().trim().is_empty() { @@ -528,7 +528,7 @@ pub fn encode_ty<'tcx>( bug!("encode_ty: invalid `cfi_encoding` for `{:?}`", ty.kind()); } } else { - let name = tcx.item_name(*def_id).to_string(); + let name = tcx.item_name(def_id).to_string(); let _ = write!(s, "{}{}", name.len(), name); } compress(dict, DictKey::Ty(ty, TyQ::None), &mut s); @@ -540,9 +540,9 @@ pub fn encode_ty<'tcx>( // u[IE], where is , // as vendor extended type. let mut s = String::new(); - let name = encode_ty_name(tcx, *def_id); + let name = encode_ty_name(tcx, def_id); let _ = write!(s, "u{}{}", name.len(), name); - s.push_str(&encode_args(tcx, args, *def_id, false, dict, options)); + s.push_str(&encode_args(tcx, args, def_id, false, dict, options)); compress(dict, DictKey::Ty(ty, TyQ::None), &mut s); typeid.push_str(&s); } @@ -551,10 +551,10 @@ pub fn encode_ty<'tcx>( // u[IE], where is , // as vendor extended type. let mut s = String::new(); - let name = encode_ty_name(tcx, *def_id); + let name = encode_ty_name(tcx, def_id); let _ = write!(s, "u{}{}", name.len(), name); let parent_args = tcx.mk_args(args.as_coroutine_closure().parent_args()); - s.push_str(&encode_args(tcx, parent_args, *def_id, false, dict, options)); + s.push_str(&encode_args(tcx, parent_args, def_id, false, dict, options)); compress(dict, DictKey::Ty(ty, TyQ::None), &mut s); typeid.push_str(&s); } @@ -563,13 +563,13 @@ pub fn encode_ty<'tcx>( // u[IE], where is , // as vendor extended type. let mut s = String::new(); - let name = encode_ty_name(tcx, *def_id); + let name = encode_ty_name(tcx, def_id); let _ = write!(s, "u{}{}", name.len(), name); // Encode parent args only s.push_str(&encode_args( tcx, tcx.mk_args(args.as_coroutine().parent_args()), - *def_id, + def_id, false, dict, options, @@ -583,9 +583,9 @@ pub fn encode_ty<'tcx>( // [U3mut]u3refIE as vendor extended type qualifier and type let mut s = String::new(); s.push_str("u3refI"); - s.push_str(&encode_ty(tcx, *ty0, dict, options)); + s.push_str(&encode_ty(tcx, ty0, dict, options)); s.push('E'); - compress(dict, DictKey::Ty(Ty::new_imm_ref(tcx, *region, *ty0), TyQ::None), &mut s); + compress(dict, DictKey::Ty(Ty::new_imm_ref(tcx, region, ty0), TyQ::None), &mut s); if ty.is_mutable_ptr() { s = format!("{}{}", "U3mut", s); compress(dict, DictKey::Ty(ty, TyQ::Mut), &mut s); @@ -597,10 +597,10 @@ pub fn encode_ty<'tcx>( // FIXME: This can definitely not be so spaghettified. // P[K] let mut s = String::new(); - s.push_str(&encode_ty(tcx, *ptr_ty, dict, options)); + s.push_str(&encode_ty(tcx, ptr_ty, dict, options)); if !ty.is_mutable_ptr() { s = format!("{}{}", "K", s); - compress(dict, DictKey::Ty(*ptr_ty, TyQ::Const), &mut s); + compress(dict, DictKey::Ty(ptr_ty, TyQ::Const), &mut s); }; s = format!("{}{}", "P", s); compress(dict, DictKey::Ty(ty, TyQ::None), &mut s); @@ -612,7 +612,7 @@ pub fn encode_ty<'tcx>( let mut s = String::from("P"); s.push_str(&encode_fnsig( tcx, - &sig_tys.with(*hdr).skip_binder(), + &sig_tys.with(hdr).skip_binder(), dict, TypeIdOptions::empty(), )); @@ -629,7 +629,7 @@ pub fn encode_ty<'tcx>( ty::DynStar => "u7dynstarI", }); s.push_str(&encode_predicates(tcx, predicates, dict, options)); - s.push_str(&encode_region(*region, dict)); + s.push_str(&encode_region(region, dict)); s.push('E'); compress(dict, DictKey::Ty(ty, TyQ::None), &mut s); typeid.push_str(&s); diff --git a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs index e628c17aca3cb..fb6d8c6595aab 100644 --- a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs +++ b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs @@ -341,7 +341,7 @@ pub fn transform_instance<'tcx>( tcx.mk_poly_existential_predicates_from_iter(preds.into_iter().filter(|pred| { !matches!(pred.skip_binder(), ty::ExistentialPredicate::AutoTrait(..)) })); - Ty::new_dynamic(tcx, filtered_preds, *lifetime, *kind) + Ty::new_dynamic(tcx, filtered_preds, lifetime, kind) } else { // If there's no principal type, re-encode it as a unit, since we don't know anything // about it. This technically discards the knowledge that it was a type that was made diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index 0f91684a3a48b..0a10adb52bb75 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -228,7 +228,7 @@ impl<'tcx> Printer<'tcx> for SymbolPrinter<'tcx> { } fn print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError> { - match *ty.kind() { + match ty.kind() { // Print all nominal types as paths (unlike `pretty_print_type`). ty::FnDef(def_id, args) | ty::Alias(ty::Projection | ty::Opaque, ty::AliasTy { def_id, args, .. }) diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 3a606f244e37a..fdfff1dea891e 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -346,7 +346,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> { } let start = self.out.len(); - match *ty.kind() { + match ty.kind() { // Basic types, handled above. ty::Bool | ty::Char | ty::Str | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Never => { unreachable!() @@ -583,8 +583,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> { // Negative integer values are mangled using `n` as a "sign prefix". if let ty::Int(ity) = ct_ty.kind() { - let val = - Integer::from_int_ty(&self.tcx, *ity).size().sign_extend(bits) as i128; + let val = Integer::from_int_ty(&self.tcx, ity).size().sign_extend(bits) as i128; if val < 0 { self.push("n"); } @@ -647,7 +646,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> { Ok(()) }; - match *ct_ty.kind() { + match ct_ty.kind() { ty::Array(..) | ty::Slice(_) => { self.push("A"); print_field_list(self)?; diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index 5193333be8e90..ace1d4e749e40 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -162,7 +162,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option> { - let (def_id, args) = match *ty.kind() { + let (def_id, args) = match ty.kind() { ty::Alias(_, ty::AliasTy { def_id, args, .. }) if matches!(self.tcx.def_kind(def_id), DefKind::OpaqueTy) => { @@ -308,7 +308,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { TypeError::Sorts(ref exp_found) => { // if they are both "path types", there's a chance of ambiguity // due to different versions of the same crate - if let (&ty::Adt(exp_adt, _), &ty::Adt(found_adt, _)) = + if let (ty::Adt(exp_adt, _), ty::Adt(found_adt, _)) = (exp_found.expected.kind(), exp_found.found.kind()) { report_path_match(err, exp_adt.did(), found_adt.did()); @@ -644,11 +644,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { /// Given two `fn` signatures highlight only sub-parts that are different. fn cmp_fn_sig( &self, - sig1: &ty::PolyFnSig<'tcx>, - sig2: &ty::PolyFnSig<'tcx>, + sig1: ty::PolyFnSig<'tcx>, // njn: removed `&` + sig2: ty::PolyFnSig<'tcx>, // njn: removed `&` ) -> (DiagStyledString, DiagStyledString) { - let sig1 = &(self.normalize_fn_sig)(*sig1); - let sig2 = &(self.normalize_fn_sig)(*sig2); + let sig1 = &(self.normalize_fn_sig)(sig1); + let sig2 = &(self.normalize_fn_sig)(sig2); let get_lifetimes = |sig| { use rustc_hir::def::Namespace; @@ -829,7 +829,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { // process starts here match (t1.kind(), t2.kind()) { - (&ty::Adt(def1, sub1), &ty::Adt(def2, sub2)) => { + (ty::Adt(def1, sub1), ty::Adt(def2, sub2)) => { let did1 = def1.did(); let did2 = def2.did(); @@ -1037,20 +1037,20 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } // When finding `&T != &T`, compare the references, then recurse into pointee type - (&ty::Ref(r1, ref_ty1, mutbl1), &ty::Ref(r2, ref_ty2, mutbl2)) => { + (ty::Ref(r1, ref_ty1, mutbl1), ty::Ref(r2, ref_ty2, mutbl2)) => { let mut values = (DiagStyledString::new(), DiagStyledString::new()); cmp_ty_refs(r1, mutbl1, r2, mutbl2, &mut values); recurse(ref_ty1, ref_ty2, &mut values); values } // When finding T != &T, highlight the borrow - (&ty::Ref(r1, ref_ty1, mutbl1), _) => { + (ty::Ref(r1, ref_ty1, mutbl1), _) => { let mut values = (DiagStyledString::new(), DiagStyledString::new()); push_ref(r1, mutbl1, &mut values.0); recurse(ref_ty1, t2, &mut values); values } - (_, &ty::Ref(r2, ref_ty2, mutbl2)) => { + (_, ty::Ref(r2, ref_ty2, mutbl2)) => { let mut values = (DiagStyledString::new(), DiagStyledString::new()); push_ref(r2, mutbl2, &mut values.1); recurse(t1, ref_ty2, &mut values); @@ -1058,7 +1058,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } // When encountering tuples of the same size, highlight only the differing types - (&ty::Tuple(args1), &ty::Tuple(args2)) if args1.len() == args2.len() => { + (ty::Tuple(args1), ty::Tuple(args2)) if args1.len() == args2.len() => { let mut values = (DiagStyledString::normal("("), DiagStyledString::normal("(")); let len = args1.len(); for (i, (left, right)) in args1.iter().zip(args2).enumerate() { @@ -1076,11 +1076,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } (ty::FnDef(did1, args1), ty::FnDef(did2, args2)) => { - let sig1 = self.tcx.fn_sig(*did1).instantiate(self.tcx, args1); - let sig2 = self.tcx.fn_sig(*did2).instantiate(self.tcx, args2); - let mut values = self.cmp_fn_sig(&sig1, &sig2); - let path1 = format!(" {{{}}}", self.tcx.def_path_str_with_args(*did1, args1)); - let path2 = format!(" {{{}}}", self.tcx.def_path_str_with_args(*did2, args2)); + let sig1 = self.tcx.fn_sig(did1).instantiate(self.tcx, args1); + let sig2 = self.tcx.fn_sig(did2).instantiate(self.tcx, args2); + let mut values = self.cmp_fn_sig(sig1, sig2); + let path1 = format!(" {{{}}}", self.tcx.def_path_str_with_args(did1, args1)); + let path2 = format!(" {{{}}}", self.tcx.def_path_str_with_args(did2, args2)); let same_path = path1 == path2; values.0.push(path1, !same_path); values.1.push(path2, !same_path); @@ -1088,26 +1088,26 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } (ty::FnDef(did1, args1), ty::FnPtr(sig_tys2, hdr2)) => { - let sig1 = self.tcx.fn_sig(*did1).instantiate(self.tcx, args1); - let mut values = self.cmp_fn_sig(&sig1, &sig_tys2.with(*hdr2)); + let sig1 = self.tcx.fn_sig(did1).instantiate(self.tcx, args1); + let mut values = self.cmp_fn_sig(sig1, sig_tys2.with(hdr2)); values.0.push_highlighted(format!( " {{{}}}", - self.tcx.def_path_str_with_args(*did1, args1) + self.tcx.def_path_str_with_args(did1, args1) )); values } (ty::FnPtr(sig_tys1, hdr1), ty::FnDef(did2, args2)) => { - let sig2 = self.tcx.fn_sig(*did2).instantiate(self.tcx, args2); - let mut values = self.cmp_fn_sig(&sig_tys1.with(*hdr1), &sig2); + let sig2 = self.tcx.fn_sig(did2).instantiate(self.tcx, args2); + let mut values = self.cmp_fn_sig(sig_tys1.with(hdr1), sig2); values .1 - .push_normal(format!(" {{{}}}", self.tcx.def_path_str_with_args(*did2, args2))); + .push_normal(format!(" {{{}}}", self.tcx.def_path_str_with_args(did2, args2))); values } (ty::FnPtr(sig_tys1, hdr1), ty::FnPtr(sig_tys2, hdr2)) => { - self.cmp_fn_sig(&sig_tys1.with(*hdr1), &sig_tys2.with(*hdr2)) + self.cmp_fn_sig(sig_tys1.with(hdr1), sig_tys2.with(hdr2)) } _ => { @@ -1365,7 +1365,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let path = self.tcx.def_path(expected.did()).data; let name = path.last().unwrap().data.get_opt_name(); if name == Some(primitive) { - return Some(Similar::PrimitiveFound { expected: *expected, found }); + return Some(Similar::PrimitiveFound { expected, found }); } } else if let Some(primitive) = expected.primitive_symbol() && let ty::Adt(found, _) = found.kind() @@ -1373,7 +1373,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let path = self.tcx.def_path(found.did()).data; let name = path.last().unwrap().data.get_opt_name(); if name == Some(primitive) { - return Some(Similar::PrimitiveExpected { expected, found: *found }); + return Some(Similar::PrimitiveExpected { expected, found }); } } else if let ty::Adt(expected, _) = expected.kind() && let ty::Adt(found, _) = found.kind() @@ -1390,7 +1390,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { if let (Some(e_last), Some(f_last)) = (e_path.last(), f_path.last()) && e_last == f_last { - return Some(Similar::Adts { expected: *expected, found: *found }); + return Some(Similar::Adts { expected, found }); } } None @@ -1467,7 +1467,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let sort_string = |ty: Ty<'tcx>| match (extra, ty.kind()) { (true, ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) => { let sm = self.tcx.sess.source_map(); - let pos = sm.lookup_char_pos(self.tcx.def_span(*def_id).lo()); + let pos = sm.lookup_char_pos(self.tcx.def_span(def_id).lo()); format!( " (opaque type at <{}:{}:{}>)", sm.filename_for_diagnostics(&pos.file.name), @@ -1852,7 +1852,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { if exp_found.references_error() { return None; } - let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, &exp_found.found); + let (exp, fnd) = self.cmp_fn_sig(exp_found.expected, exp_found.found); Some((exp, fnd, None)) } ValuePairs::Dummy => { @@ -2183,7 +2183,7 @@ impl fmt::Display for TyCategory { impl TyCategory { pub fn from_ty(tcx: TyCtxt<'_>, ty: Ty<'_>) -> Option<(Self, DefId)> { - match *ty.kind() { + match ty.kind() { ty::Closure(def_id, _) => Some((Self::Closure, def_id)), ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { let kind = diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs index f6dd7898fb28e..9cba0d0d4a39b 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs @@ -282,7 +282,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { ) -> InferenceDiagnosticsData { match arg.unpack() { GenericArgKind::Type(ty) => { - if let ty::Infer(ty::TyVar(ty_vid)) = *ty.kind() { + if let ty::Infer(ty::TyVar(ty_vid)) = ty.kind() { let var_origin = self.infcx.type_var_origin(ty_vid); if let Some(def_id) = var_origin.param_def_id // The `Self` param of a trait has the def-id of the trait, @@ -758,7 +758,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { } } fn ty_cost(self, ty: Ty<'tcx>) -> usize { - match *ty.kind() { + match ty.kind() { ty::Closure(..) => 1000, ty::FnDef(..) => 150, ty::FnPtr(..) => 30, @@ -850,7 +850,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { (GenericArgKind::Type(inner_ty), GenericArgKind::Type(target_ty)) => { use ty::{Infer, TyVar}; match (inner_ty.kind(), target_ty.kind()) { - (&Infer(TyVar(a_vid)), &Infer(TyVar(b_vid))) => { + (Infer(TyVar(a_vid)), Infer(TyVar(b_vid))) => { self.tecx.sub_relations.borrow_mut().unified(self.tecx, a_vid, b_vid) } _ => false, diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs index 05c79170902de..b1b3493a4392f 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs @@ -28,7 +28,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { match err { TypeError::ArgumentSorts(values, _) | TypeError::Sorts(values) => { - match (*values.expected.kind(), *values.found.kind()) { + match (values.expected.kind(), values.found.kind()) { (ty::Closure(..), ty::Closure(..)) => { diag.note("no two closures, even if identical, have the same type"); diag.help("consider boxing your closure and/or using it as a trait object"); @@ -545,7 +545,7 @@ impl Trait for X { }; // Get the `DefId` for the type parameter corresponding to `A` in `::Foo`. // This will also work for `impl Trait`. - let ty::Param(param_ty) = *proj_ty.self_ty().kind() else { + let ty::Param(param_ty) = proj_ty.self_ty().kind() else { return false; }; let generics = tcx.generics_of(body_owner_def_id); @@ -716,7 +716,7 @@ fn foo(&self) -> Self::T { String::new() } let tcx = self.tcx; let assoc = tcx.associated_item(proj_ty.def_id); - if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *proj_ty.self_ty().kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = proj_ty.self_ty().kind() { let opaque_local_def_id = def_id.as_local(); let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id { tcx.hir().expect_item(opaque_local_def_id).expect_opaque_ty() @@ -764,7 +764,7 @@ fn foo(&self) -> Self::T { String::new() } }) .filter_map(|item| { let method = tcx.fn_sig(item.def_id).instantiate_identity(); - match *method.output().skip_binder().kind() { + match method.output().skip_binder().kind() { ty::Alias(ty::Projection, ty::AliasTy { def_id: item_def_id, .. }) if item_def_id == proj_ty_item_def_id => { diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/sub_relations.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/sub_relations.rs index ef26a8ff7b863..a15db36259ffe 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/sub_relations.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/sub_relations.rs @@ -63,7 +63,7 @@ impl SubRelations { }; match (a.kind(), b.kind()) { - (&ty::Infer(ty::TyVar(a_vid)), &ty::Infer(ty::TyVar(b_vid))) => { + (ty::Infer(ty::TyVar(a_vid)), ty::Infer(ty::TyVar(b_vid))) => { let a = self.get_id(infcx, a_vid); let b = self.get_id(infcx, b_vid); self.table.with_log(&mut NoUndo).unify_var_var(a, b).unwrap(); diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs index 35f68a56d2ddc..c6a3a72abd365 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/suggest.rs @@ -483,8 +483,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if let (ty::Adt(exp_def, exp_args), ty::Ref(_, found_ty, _)) = (expected.kind(), found.kind()) { - if let ty::Adt(found_def, found_args) = *found_ty.kind() { - if exp_def == &found_def { + if let ty::Adt(found_def, found_args) = found_ty.kind() { + if exp_def == found_def { let have_as_ref = &[ (sym::Option, SuggestAsRefKind::Option), (sym::Result, SuggestAsRefKind::Result), @@ -496,7 +496,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { for (exp_ty, found_ty) in std::iter::zip(exp_args.types(), found_args.types()) { - match *exp_ty.kind() { + match exp_ty.kind() { ty::Ref(_, exp_ty, _) => { match (exp_ty.kind(), found_ty.kind()) { (_, ty::Param(_)) diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs index 326a0e4e35ce8..94da4c36f2259 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs @@ -436,7 +436,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let is_fn_trait = tcx.is_fn_trait(leaf_trait_ref.def_id()); let is_target_feature_fn = if let ty::FnDef(def_id, _) = - *leaf_trait_ref.skip_binder().self_ty().kind() + leaf_trait_ref.skip_binder().self_ty().kind() { !self.tcx.codegen_fn_attrs(def_id).target_features.is_empty() } else { @@ -725,7 +725,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { obligation.cause.code() && let Some(typeck_results) = &self.typeck_results && let ty::Closure(closure_def_id, _) | ty::CoroutineClosure(closure_def_id, _) = - *typeck_results.node_type(arg_hir_id).kind() + typeck_results.node_type(arg_hir_id).kind() { // Otherwise, extract the closure kind from the obligation. let mut err = self.report_closure_error( @@ -744,7 +744,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let self_ty = trait_ref.self_ty().skip_binder(); if let Some(expected_kind) = self.tcx.fn_trait_kind_from_def_id(trait_ref.def_id()) { - let (closure_def_id, found_args, by_ref_captures) = match *self_ty.kind() { + let (closure_def_id, found_args, by_ref_captures) = match self_ty.kind() { ty::Closure(def_id, args) => { (def_id, args.as_closure().sig().map_bound(|sig| sig.inputs()[0]), None) } @@ -1428,7 +1428,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { if self.tcx.is_lang_item(projection_term.def_id, LangItem::FnOnceOutput) { let fn_kind = self_ty.prefix_string(self.tcx); let item = match self_ty.kind() { - ty::FnDef(def, _) => self.tcx.item_name(*def).to_string(), + ty::FnDef(def, _) => self.tcx.item_name(def).to_string(), _ => self_ty.to_string(), }; Some(format!( @@ -1494,7 +1494,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let strip_references = |mut t: Ty<'tcx>| -> Ty<'tcx> { loop { match t.kind() { - ty::Ref(_, inner, _) | ty::RawPtr(inner, _) => t = *inner, + ty::Ref(_, inner, _) | ty::RawPtr(inner, _) => t = inner, _ => break t, } } @@ -2091,7 +2091,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Param(_) = *ty.kind() { + if let ty::Param(_) = ty.kind() { let infcx = self.infcx; *self.var_map.entry(ty).or_insert_with(|| infcx.next_ty_var(DUMMY_SP)) } else { @@ -2600,7 +2600,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { expected_trait_ref.self_ty().error_reported()?; let found_trait_ty = found_trait_ref.self_ty(); - let found_did = match *found_trait_ty.kind() { + let found_did = match found_trait_ty.kind() { ty::Closure(did, _) | ty::FnDef(did, _) | ty::Coroutine(did, ..) => Some(did), _ => None, }; diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index d0f76f0d50ea6..853fb2c6ea46c 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -141,7 +141,7 @@ pub fn suggest_restriction<'tcx, G: EmissionGuarantee>( let generics = tcx.generics_of(item_id); // Given `fn foo(t: impl Trait)` where `Trait` requires assoc type `A`... if let Some((param, bound_str, fn_sig)) = - fn_sig.zip(projection).and_then(|(sig, p)| match *p.self_ty().kind() { + fn_sig.zip(projection).and_then(|(sig, p)| match p.self_ty().kind() { // Shenanigans to get the `Trait` from the `impl Trait`. ty::Param(param) => { let param_def = generics.type_param(param, tcx); @@ -250,7 +250,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let trait_pred = self.resolve_numeric_literals_with_default(trait_pred); let self_ty = trait_pred.skip_binder().self_ty(); - let (param_ty, projection) = match *self_ty.kind() { + let (param_ty, projection) = match self_ty.kind() { ty::Param(_) => (true, None), ty::Alias(ty::Projection, projection) => (false, Some(projection)), _ => (false, None), @@ -472,7 +472,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { self.tcx.instantiate_bound_regions_with_erased(real_trait_pred.self_ty()); if self.can_eq(obligation.param_env, real_ty, arg_ty) - && let ty::Ref(region, base_ty, mutbl) = *real_ty.kind() + && let ty::Ref(region, base_ty, mutbl) = real_ty.kind() { let autoderef = (self.autoderef_steps)(base_ty); if let Some(steps) = @@ -1008,7 +1008,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { .. }) if ident.name == sym::clone && !call_span.from_expansion() - && !has_clone(*inner_ty) => + && !has_clone(inner_ty) => { // We only care about method calls corresponding to the real `Clone` trait. let Some(typeck_results) = self.typeck_results.as_ref() else { return false }; @@ -1026,7 +1026,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let new_obligation = self.mk_trait_obligation_with_new_self_ty( obligation.param_env, - trait_pred.map_bound(|trait_pred| (trait_pred, *inner_ty)), + trait_pred.map_bound(|trait_pred| (trait_pred, inner_ty)), ); if self.predicate_may_hold(&new_obligation) && has_clone(ty) { @@ -1076,7 +1076,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { // Autoderef is useful here because sometimes we box callables, etc. let Some((def_id_or_name, output, inputs)) = (self.autoderef_steps)(found).into_iter().find_map(|(found, _)| { - match *found.kind() { + match found.kind() { ty::FnPtr(sig_tys, _) => Some(( DefIdOrName::Name("function pointer"), sig_tys.output(), @@ -1270,7 +1270,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { && let ty::Ref(_, ty, mutability) = old_pred.self_ty().skip_binder().kind() { ( - mk_result(old_pred.map_bound(|trait_pred| (trait_pred, *ty))), + mk_result(old_pred.map_bound(|trait_pred| (trait_pred, ty))), mutability.is_mut(), ) } else { @@ -1517,7 +1517,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let ty::Ref(_, inner_ty, _) = suggested_ty.kind() else { break; }; - suggested_ty = *inner_ty; + suggested_ty = inner_ty; hir_ty = mut_ty.ty; @@ -1548,7 +1548,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let ty::Ref(_, inner_ty, _) = suggested_ty.kind() else { break 'outer; }; - suggested_ty = *inner_ty; + suggested_ty = inner_ty; expr = borrowed; @@ -1616,7 +1616,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { && let ty = typeck_results.expr_ty_adjusted(base) && let ty::FnDef(def_id, _args) = ty.kind() && let Some(hir::Node::Item(hir::Item { ident, span, vis_span, .. })) = - hir.get_if_local(*def_id) + hir.get_if_local(def_id) { let msg = format!("alternatively, consider making `fn {ident}` asynchronous"); if vis_span.is_empty() { @@ -1666,8 +1666,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } // Skipping binder here, remapping below - if let ty::Ref(region, t_type, mutability) = *trait_pred.skip_binder().self_ty().kind() - { + if let ty::Ref(region, t_type, mutability) = trait_pred.skip_binder().self_ty().kind() { let suggested_ty = match mutability { hir::Mutability::Mut => Ty::new_imm_ref(self.tcx, region, t_type), hir::Mutability::Not => Ty::new_mut_ref(self.tcx, region, t_type), @@ -1912,7 +1911,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let sig = match inputs.kind() { ty::Tuple(inputs) if infcx.tcx.is_fn_trait(trait_ref.def_id) => { infcx.tcx.mk_fn_sig( - *inputs, + inputs, infcx.next_ty_var(DUMMY_SP), false, hir::Safety::Safe, @@ -1980,11 +1979,11 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { let ty::FnPtr(sig_tys, hdr) = expected.kind() else { return; }; - let expected = sig_tys.with(*hdr); + let expected = sig_tys.with(hdr); let ty::FnPtr(sig_tys, hdr) = found.kind() else { return; }; - let found = sig_tys.with(*hdr); + let found = sig_tys.with(hdr); let Node::Expr(arg) = self.tcx.hir_node(*arg_hir_id) else { return; }; @@ -2295,7 +2294,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { "ImplDerived", ); - match *ty.kind() { + match ty.kind() { ty::Coroutine(did, ..) | ty::CoroutineWitness(did, _) => { coroutine = coroutine.or(Some(did)); outer_coroutine = Some(did); @@ -2324,7 +2323,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { self_ty.kind = ?ty.kind(), ); - match *ty.kind() { + match ty.kind() { ty::Coroutine(did, ..) | ty::CoroutineWitness(did, ..) => { coroutine = coroutine.or(Some(did)); outer_coroutine = Some(did); @@ -3239,7 +3238,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { if is_future && obligated_types.last().is_some_and(|ty| match ty.kind() { ty::Coroutine(last_def_id, ..) => { - tcx.coroutine_is_async(*last_def_id) + tcx.coroutine_is_async(last_def_id) } _ => false, }) @@ -3945,7 +3944,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } = fn_ty.fn_sig(tcx).skip_binder() // Extract first param of fn sig with peeled refs, e.g. `fn(&T)` -> `T` - && let Some(&ty::Ref(_, target_ty, needs_mut)) = fn_sig.inputs().first().map(|t| t.kind()) + && let Some(ty::Ref(_, target_ty, needs_mut)) = fn_sig.inputs().first().map(|t| t.kind()) && !target_ty.has_escaping_bound_vars() // Extract first tuple element out of fn trait, e.g. `FnOnce<(U,)>` -> `U` @@ -4060,7 +4059,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { trait_ref: ty::TraitRef::new( tcx, tcx.require_lang_item(LangItem::Clone, Some(span)), - [*ty], + [ty], ), polarity: ty::PredicatePolarity::Positive, }); @@ -4342,10 +4341,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { // 1. `[T; _]` (array of T) // 2. `&[T; _]` (reference to array of T) // 3. `&mut [T; _]` (mutable reference to array of T) - let (element_ty, mut mutability) = match *trait_ref.skip_binder().self_ty().kind() { + let (element_ty, mut mutability) = match trait_ref.skip_binder().self_ty().kind() { ty::Array(element_ty, _) => (element_ty, None), - ty::Ref(_, pointee_ty, mutability) => match *pointee_ty.kind() { + ty::Ref(_, pointee_ty, mutability) => match pointee_ty.kind() { ty::Array(element_ty, _) => (element_ty, Some(mutability)), _ => return, }, @@ -4355,9 +4354,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { // Go through all the candidate impls to see if any of them is for // slices of `element_ty` with `mutability`. - let mut is_slice = |candidate: Ty<'tcx>| match *candidate.kind() { + let mut is_slice = |candidate: Ty<'tcx>| match candidate.kind() { ty::RawPtr(t, m) | ty::Ref(_, t, m) => { - if matches!(*t.kind(), ty::Slice(e) if e == element_ty) + if matches!(t.kind(), ty::Slice(e) if e == element_ty) && m == mutability.unwrap_or(m) { // Use the candidate's mutability going forward. @@ -4557,7 +4556,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { self.type_implements_trait(default_trait, [ty], param_env).must_apply_modulo_regions() }; - Some(match *ty.kind() { + Some(match ty.kind() { ty::Never | ty::Error(_) => return None, ty::Bool => "false".to_string(), ty::Char => "\'x\'".to_string(), @@ -4792,13 +4791,13 @@ fn hint_missing_borrow<'tcx>( } let found_args = match found.kind() { - ty::FnPtr(sig_tys, _) => infcx.enter_forall(*sig_tys, |sig_tys| sig_tys.inputs().iter()), + ty::FnPtr(sig_tys, _) => infcx.enter_forall(sig_tys, |sig_tys| sig_tys.inputs().iter()), kind => { span_bug!(span, "found was converted to a FnPtr above but is now {:?}", kind) } }; let expected_args = match expected.kind() { - ty::FnPtr(sig_tys, _) => infcx.enter_forall(*sig_tys, |sig_tys| sig_tys.inputs().iter()), + ty::FnPtr(sig_tys, _) => infcx.enter_forall(sig_tys, |sig_tys| sig_tys.inputs().iter()), kind => { span_bug!(span, "expected was converted to a FnPtr above but is now {:?}", kind) } @@ -5059,7 +5058,7 @@ struct ReplaceImplTraitFolder<'tcx> { impl<'tcx> TypeFolder> for ReplaceImplTraitFolder<'tcx> { fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { if let ty::Param(ty::ParamTy { index, .. }) = t.kind() { - if self.param.index == *index { + if self.param.index == index { return self.replace_ty; } } @@ -5272,8 +5271,8 @@ fn get_deref_type_and_refs(mut ty: Ty<'_>) -> (Ty<'_>, Vec) { let mut refs = vec![]; while let ty::Ref(_, new_ty, mutbl) = ty.kind() { - ty = *new_ty; - refs.push(*mutbl); + ty = new_ty; + refs.push(mutbl); } (ty, refs) diff --git a/compiler/rustc_trait_selection/src/solve/normalize.rs b/compiler/rustc_trait_selection/src/solve/normalize.rs index c93c40b482680..195435015ac44 100644 --- a/compiler/rustc_trait_selection/src/solve/normalize.rs +++ b/compiler/rustc_trait_selection/src/solve/normalize.rs @@ -70,7 +70,7 @@ where let tcx = infcx.tcx; let recursion_limit = tcx.recursion_limit(); if !recursion_limit.value_within_limit(self.depth) { - let ty::Alias(_, data) = *alias_ty.kind() else { + let ty::Alias(_, data) = alias_ty.kind() else { unreachable!(); }; @@ -181,7 +181,7 @@ where return Ok(ty); } - let ty::Alias(..) = *ty.kind() else { return ty.try_super_fold_with(self) }; + let ty::Alias(..) = ty.kind() else { return ty.try_super_fold_with(self) }; if ty.has_escaping_bound_vars() { let (ty, mapped_regions, mapped_types, mapped_consts) = diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 29f78f9d5f0a1..d309e91612c8e 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -553,7 +553,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { fn is_self_referential_projection(&self, p: ty::PolyProjectionPredicate<'tcx>) -> bool { if let Some(ty) = p.term().skip_binder().as_type() { - matches!(ty.kind(), ty::Alias(ty::Projection, proj) if proj == &p.skip_binder().projection_term.expect_ty(self.tcx)) + matches!(ty.kind(), ty::Alias(ty::Projection, proj) if proj == p.skip_binder().projection_term.expect_ty(self.tcx)) } else { false } diff --git a/compiler/rustc_trait_selection/src/traits/misc.rs b/compiler/rustc_trait_selection/src/traits/misc.rs index 3e65194577e0d..b1cb11b25b90e 100644 --- a/compiler/rustc_trait_selection/src/traits/misc.rs +++ b/compiler/rustc_trait_selection/src/traits/misc.rs @@ -58,7 +58,7 @@ pub fn type_allowed_to_implement_copy<'tcx>( | ty::Ref(_, _, hir::Mutability::Not) | ty::Array(..) => return Ok(()), - &ty::Adt(adt, args) => (adt, args), + ty::Adt(adt, args) => (adt, args), _ => return Err(CopyImplementationError::NotAnAdt), }; @@ -96,7 +96,7 @@ pub fn type_allowed_to_implement_const_param_ty<'tcx>( ) -> Result<(), ConstParamTyImplementationError<'tcx>> { assert_matches!(lang_item, LangItem::ConstParamTy | LangItem::UnsizedConstParamTy); - let inner_tys: Vec<_> = match *self_type.kind() { + let inner_tys: Vec<_> = match self_type.kind() { // Trivially okay as these types are all: // - Sized // - Contain no nested types diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index a350b76a7049a..e1324e716bb30 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -528,7 +528,7 @@ fn is_impossible_associated_item( type Result = ControlFlow<()>; fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result { // If this is a parameter from the trait item's own generics, then bail - if let ty::Param(param) = *t.kind() + if let ty::Param(param) = t.kind() && let param_def_id = self.generics.type_param(param, self.tcx).def_id && self.tcx.parent(param_def_id) == self.trait_item_def_id { diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index 81f8633ba955f..f017482782e4e 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -181,7 +181,7 @@ impl<'a, 'b, 'tcx> TypeFolder> for AssocTypeNormalizer<'a, 'b, 'tcx return ty; } - let (kind, data) = match *ty.kind() { + let (kind, data) = match ty.kind() { ty::Alias(kind, data) => (kind, data), _ => return ty.super_fold_with(self), }; diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 568214fe02298..507bd8b385fdc 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -1524,10 +1524,10 @@ fn confirm_async_iterator_candidate<'cx, 'tcx>( debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Item); - let ty::Adt(_poll_adt, args) = *yield_ty.kind() else { + let ty::Adt(_poll_adt, args) = yield_ty.kind() else { bug!(); }; - let ty::Adt(_option_adt, args) = *args.type_at(0).kind() else { + let ty::Adt(_option_adt, args) = args.type_at(0).kind() else { bug!(); }; let item_ty = args.type_at(0); @@ -1631,7 +1631,7 @@ fn confirm_fn_pointer_candidate<'cx, 'tcx>( sig, ); - let host_effect_param = match *fn_type.kind() { + let host_effect_param = match fn_type.kind() { ty::FnDef(def_id, args) => tcx .generics_of(def_id) .host_effect_index @@ -1658,7 +1658,7 @@ fn confirm_closure_candidate<'cx, 'tcx>( ) -> Progress<'tcx> { let tcx = selcx.tcx(); let self_ty = selcx.infcx.shallow_resolve(obligation.predicate.self_ty()); - let closure_sig = match *self_ty.kind() { + let closure_sig = match self_ty.kind() { ty::Closure(_, args) => args.as_closure().sig(), // Construct a "normal" `FnOnce` signature for coroutine-closure. This is @@ -1790,7 +1790,7 @@ fn confirm_async_closure_candidate<'cx, 'tcx>( }; let item_name = tcx.item_name(obligation.predicate.def_id); - let poly_cache_entry = match *self_ty.kind() { + let poly_cache_entry = match self_ty.kind() { ty::CoroutineClosure(def_id, args) => { let args = args.as_coroutine_closure(); let kind_ty = args.kind_ty(); diff --git a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs index 7d30e6524490c..14bd6c6cfec9f 100644 --- a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs +++ b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs @@ -43,12 +43,12 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { | ty::Error(_) => true, // `T is PAT` and `[T]` have same properties as T. - ty::Pat(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, *ty), + ty::Pat(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, ty), ty::Array(ty, size) => { // Empty array never has a dtor. See issue #110288. match size.try_to_target_usize(tcx) { Some(0) => true, - _ => trivial_dropck_outlives(tcx, *ty), + _ => trivial_dropck_outlives(tcx, ty), } } @@ -232,7 +232,7 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>( ty::Pat(ety, _) | ty::Array(ety, _) | ty::Slice(ety) => { // single-element containers, behave like their element rustc_data_structures::stack::ensure_sufficient_stack(|| { - dtorck_constraint_for_ty_inner(tcx, param_env, span, depth + 1, *ety, constraints) + dtorck_constraint_for_ty_inner(tcx, param_env, span, depth + 1, ety, constraints) })?; } diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 247b6e4823c4b..9bc98d06d9f1c 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -196,7 +196,7 @@ impl<'cx, 'tcx> FallibleTypeFolder> for QueryNormalizer<'cx, 'tcx> return Ok(*ty); } - let (kind, data) = match *ty.kind() { + let (kind, data) = match ty.kind() { ty::Alias(kind, data) => (kind, data), _ => { let res = ty.try_super_fold_with(self)?; diff --git a/compiler/rustc_trait_selection/src/traits/select/_match.rs b/compiler/rustc_trait_selection/src/traits/select/_match.rs index 7ead65721f9bb..3a850b8c3f4ff 100644 --- a/compiler/rustc_trait_selection/src/traits/select/_match.rs +++ b/compiler/rustc_trait_selection/src/traits/select/_match.rs @@ -64,16 +64,16 @@ impl<'tcx> TypeRelation> for MatchAgainstFreshVars<'tcx> { match (a.kind(), b.kind()) { ( _, - &ty::Infer(ty::FreshTy(_)) - | &ty::Infer(ty::FreshIntTy(_)) - | &ty::Infer(ty::FreshFloatTy(_)), + ty::Infer(ty::FreshTy(_)) + | ty::Infer(ty::FreshIntTy(_)) + | ty::Infer(ty::FreshFloatTy(_)), ) => Ok(a), - (&ty::Infer(_), _) | (_, &ty::Infer(_)) => { + (ty::Infer(_), _) | (_, ty::Infer(_)) => { Err(TypeError::Sorts(ExpectedFound::new(true, a, b))) } - (&ty::Error(guar), _) | (_, &ty::Error(guar)) => Ok(Ty::new_error(self.cx(), guar)), + (ty::Error(guar), _) | (_, ty::Error(guar)) => Ok(Ty::new_error(self.cx(), guar)), _ => structurally_relate_tys(self, a, b), } diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index cb8deeaedb66f..e9512d717de0d 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -272,7 +272,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { match self_ty.kind() { // `async`/`gen` constructs get lowered to a special kind of coroutine that // should *not* `impl Coroutine`. - ty::Coroutine(did, ..) if self.tcx().is_general_coroutine(*did) => { + ty::Coroutine(did, ..) if self.tcx().is_general_coroutine(did) => { debug!(?self_ty, ?obligation, "assemble_coroutine_candidates",); candidates.vec.push(CoroutineCandidate); @@ -294,7 +294,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { if let ty::Coroutine(did, ..) = self_ty.kind() { // async constructs get lowered to a special kind of coroutine that // should directly `impl Future`. - if self.tcx().coroutine_is_async(*did) { + if self.tcx().coroutine_is_async(did) { debug!(?self_ty, ?obligation, "assemble_future_candidates",); candidates.vec.push(FutureCandidate); @@ -311,7 +311,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // gen constructs get lowered to a special kind of coroutine that // should directly `impl Iterator`. if let ty::Coroutine(did, ..) = self_ty.kind() - && self.tcx().coroutine_is_gen(*did) + && self.tcx().coroutine_is_gen(did) { debug!(?self_ty, ?obligation, "assemble_iterator_candidates",); @@ -328,7 +328,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // gen constructs get lowered to a special kind of coroutine that // should directly `impl FusedIterator`. if let ty::Coroutine(did, ..) = self_ty.kind() - && self.tcx().coroutine_is_gen(*did) + && self.tcx().coroutine_is_gen(did) { debug!(?self_ty, ?obligation, "assemble_fused_iterator_candidates",); @@ -342,7 +342,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { candidates: &mut SelectionCandidateSet<'tcx>, ) { let self_ty = obligation.self_ty().skip_binder(); - if let ty::Coroutine(did, args) = *self_ty.kind() { + if let ty::Coroutine(did, args) = self_ty.kind() { // gen constructs get lowered to a special kind of coroutine that // should directly `impl AsyncIterator`. if self.tcx().coroutine_is_async_gen(did) { @@ -350,11 +350,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Can only confirm this candidate if we have constrained // the `Yield` type to at least `Poll>`.. - let ty::Adt(_poll_def, args) = *args.as_coroutine().yield_ty().kind() else { + let ty::Adt(_poll_def, args) = args.as_coroutine().yield_ty().kind() else { candidates.ambiguous = true; return; }; - let ty::Adt(_option_def, _) = *args.type_at(0).kind() else { + let ty::Adt(_option_def, _) = args.type_at(0).kind() else { candidates.ambiguous = true; return; }; @@ -383,7 +383,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // touch bound regions, they just capture the in-scope // type/region parameters let self_ty = obligation.self_ty().skip_binder(); - match *self_ty.kind() { + match self_ty.kind() { ty::Closure(def_id, _) => { let is_const = self.tcx().is_const_fn_raw(def_id); debug!(?kind, ?obligation, "assemble_unboxed_candidates"); @@ -447,7 +447,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { return; }; - match *obligation.self_ty().skip_binder().kind() { + match obligation.self_ty().skip_binder().kind() { ty::CoroutineClosure(_, args) => { if let Some(closure_kind) = args.as_coroutine_closure().kind_ty().to_opt_closure_kind() @@ -529,7 +529,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Okay to skip binder because what we are inspecting doesn't involve bound regions. let self_ty = obligation.self_ty().skip_binder(); - match *self_ty.kind() { + match self_ty.kind() { ty::Infer(ty::TyVar(_)) => { debug!("assemble_fn_pointer_candidates: ambiguous self-type"); candidates.ambiguous = true; // Could wind up being a fn() type. @@ -723,7 +723,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let def_id = obligation.predicate.def_id(); if self.tcx().trait_is_auto(def_id) { - match *self_ty.kind() { + match self_ty.kind() { ty::Dynamic(..) => { // For object types, we don't know what the closed // over types are. This means we conservatively @@ -998,7 +998,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { match (source.kind(), target.kind()) { // Trait+Kx+'a -> Trait+Ky+'b (upcasts). - (&ty::Dynamic(a_data, a_region, ty::Dyn), &ty::Dynamic(b_data, b_region, ty::Dyn)) => { + (ty::Dynamic(a_data, a_region, ty::Dyn), ty::Dynamic(b_data, b_region, ty::Dyn)) => { // Upcast coercions permit several things: // // 1. Dropping auto traits, e.g., `Foo + Send` to `Foo` @@ -1071,32 +1071,32 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } // `T` -> `Trait` - (_, &ty::Dynamic(_, _, ty::Dyn)) => { + (_, ty::Dynamic(_, _, ty::Dyn)) => { candidates.vec.push(BuiltinUnsizeCandidate); } // Ambiguous handling is below `T` -> `Trait`, because inference // variables can still implement `Unsize` and nested // obligations will have the final say (likely deferred). - (&ty::Infer(ty::TyVar(_)), _) | (_, &ty::Infer(ty::TyVar(_))) => { + (ty::Infer(ty::TyVar(_)), _) | (_, ty::Infer(ty::TyVar(_))) => { debug!("assemble_candidates_for_unsizing: ambiguous"); candidates.ambiguous = true; } // `[T; n]` -> `[T]` - (&ty::Array(..), &ty::Slice(_)) => { + (ty::Array(..), ty::Slice(_)) => { candidates.vec.push(BuiltinUnsizeCandidate); } // `Struct` -> `Struct` - (&ty::Adt(def_id_a, _), &ty::Adt(def_id_b, _)) if def_id_a.is_struct() => { + (ty::Adt(def_id_a, _), ty::Adt(def_id_b, _)) if def_id_a.is_struct() => { if def_id_a == def_id_b { candidates.vec.push(BuiltinUnsizeCandidate); } } // `(.., T)` -> `(.., U)` - (&ty::Tuple(tys_a), &ty::Tuple(tys_b)) => { + (ty::Tuple(tys_a), ty::Tuple(tys_b)) => { if tys_a.len() == tys_b.len() { candidates.vec.push(BuiltinUnsizeCandidate); } diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 0d7ceca430174..5731cfe11993f 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -526,7 +526,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let trait_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate); let self_ty = self.infcx.shallow_resolve(trait_predicate.self_ty()); - let ty::Dynamic(data, ..) = *self_ty.kind() else { + let ty::Dynamic(data, ..) = self_ty.kind() else { span_bug!(obligation.cause.span, "object candidate with non-object"); }; @@ -762,7 +762,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ) -> Result>, SelectionError<'tcx>> { let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate); let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty()); - let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else { + let ty::Coroutine(coroutine_def_id, args) = self_ty.kind() else { bug!("closure candidate for non-closure {:?}", obligation); }; @@ -792,7 +792,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ) -> Result>, SelectionError<'tcx>> { let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate); let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty()); - let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else { + let ty::Coroutine(coroutine_def_id, args) = self_ty.kind() else { bug!("closure candidate for non-closure {:?}", obligation); }; @@ -822,7 +822,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ) -> Result>, SelectionError<'tcx>> { let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate); let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty()); - let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else { + let ty::Coroutine(coroutine_def_id, args) = self_ty.kind() else { bug!("closure candidate for non-closure {:?}", obligation); }; @@ -852,7 +852,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { ) -> Result>, SelectionError<'tcx>> { let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate); let self_ty = self.infcx.shallow_resolve(placeholder_predicate.self_ty()); - let ty::Coroutine(coroutine_def_id, args) = *self_ty.kind() else { + let ty::Coroutine(coroutine_def_id, args) = self_ty.kind() else { bug!("closure candidate for non-closure {:?}", obligation); }; @@ -884,7 +884,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let placeholder_predicate = self.infcx.enter_forall_and_leak_universe(obligation.predicate); let self_ty: Ty<'_> = self.infcx.shallow_resolve(placeholder_predicate.self_ty()); - let trait_ref = match *self_ty.kind() { + let trait_ref = match self_ty.kind() { ty::Closure(..) => self.closure_trait_ref_unnormalized( self_ty, obligation.predicate.def_id(), @@ -918,7 +918,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let tcx = self.tcx(); let mut nested = vec![]; - let (trait_ref, kind_ty) = match *self_ty.kind() { + let (trait_ref, kind_ty) = match self_ty.kind() { ty::CoroutineClosure(_, args) => { let args = args.as_coroutine_closure(); let trait_ref = args.coroutine_closure_sig().map_bound(|sig| { @@ -1091,10 +1091,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let a_ty = self.infcx.shallow_resolve(predicate.self_ty()); let b_ty = self.infcx.shallow_resolve(predicate.trait_ref.args.type_at(1)); - let ty::Dynamic(a_data, a_region, ty::Dyn) = *a_ty.kind() else { + let ty::Dynamic(a_data, a_region, ty::Dyn) = a_ty.kind() else { bug!("expected `dyn` type in `confirm_trait_upcasting_unsize_candidate`") }; - let ty::Dynamic(b_data, b_region, ty::Dyn) = *b_ty.kind() else { + let ty::Dynamic(b_data, b_region, ty::Dyn) = b_ty.kind() else { bug!("expected `dyn` type in `confirm_trait_upcasting_unsize_candidate`") }; @@ -1131,7 +1131,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { Ok(match (source.kind(), target.kind()) { // Trait+Kx+'a -> Trait+Ky+'b (auto traits and lifetime subtyping). - (&ty::Dynamic(data_a, r_a, dyn_a), &ty::Dynamic(data_b, r_b, dyn_b)) + (ty::Dynamic(data_a, r_a, dyn_a), ty::Dynamic(data_b, r_b, dyn_b)) if dyn_a == dyn_b => { // See `assemble_candidates_for_unsizing` for more info. @@ -1176,7 +1176,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } // `T` -> `Trait` - (_, &ty::Dynamic(data, r, ty::Dyn)) => { + (_, ty::Dynamic(data, r, ty::Dyn)) => { let mut object_dids = data.auto_traits().chain(data.principal_def_id()); if let Some(did) = object_dids.find(|did| !tcx.is_object_safe(*did)) { return Err(TraitNotObjectSafe(did)); @@ -1222,7 +1222,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } // `[T; n]` -> `[T]` - (&ty::Array(a, _), &ty::Slice(b)) => { + (ty::Array(a, _), ty::Slice(b)) => { let InferOk { obligations, .. } = self .infcx .at(&obligation.cause, obligation.param_env) @@ -1233,7 +1233,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } // `Struct` -> `Struct` - (&ty::Adt(def, args_a), &ty::Adt(_, args_b)) => { + (ty::Adt(def, args_a), ty::Adt(_, args_b)) => { let unsizing_params = tcx.unsizing_params_for_adt(def.did()); if unsizing_params.is_empty() { return Err(Unimplemented); @@ -1293,7 +1293,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } // `(.., T)` -> `(.., U)` - (&ty::Tuple(tys_a), &ty::Tuple(tys_b)) => { + (ty::Tuple(tys_a), ty::Tuple(tys_b)) => { assert_eq!(tys_a.len(), tys_b.len()); // The last field of the tuple has to exist. @@ -1379,13 +1379,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } // We want to confirm the ADT's fields if we have an ADT - let mut stack = match *self_ty.skip_binder().kind() { + let mut stack = match self_ty.skip_binder().kind() { ty::Adt(def, args) => def.all_fields().map(|f| f.ty(tcx, args)).collect(), _ => vec![self_ty.skip_binder()], }; while let Some(nested_ty) = stack.pop() { - match *nested_ty.kind() { + match nested_ty.kind() { // We know these types are trivially drop ty::Bool | ty::Char diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index f002fa27db27f..3be98b14cd8c3 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1612,7 +1612,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let mut in_parent_alias_type = false; loop { - let (kind, alias_ty) = match *self_ty.kind() { + let (kind, alias_ty) = match self_ty.kind() { ty::Alias(kind @ (ty::Projection | ty::Opaque), alias_ty) => (kind, alias_ty), ty::Infer(ty::TyVar(_)) => { on_ambiguity(); @@ -2135,7 +2135,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { obligation.predicate.rebind(tys.last().map_or_else(Vec::new, |&last| vec![last])), ), - ty::Pat(ty, _) => Where(obligation.predicate.rebind(vec![*ty])), + ty::Pat(ty, _) => Where(obligation.predicate.rebind(vec![ty])), ty::Adt(def, args) => { if let Some(sized_crit) = def.sized_constraint(self.tcx()) { @@ -2169,7 +2169,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { use self::BuiltinImplConditions::{Ambiguous, None, Where}; - match *self_ty.kind() { + match self_ty.kind() { ty::FnDef(..) | ty::FnPtr(..) | ty::Error(_) => Where(ty::Binder::dummy(Vec::new())), ty::Uint(_) @@ -2301,7 +2301,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { obligation: &PolyTraitObligation<'tcx>, ) -> BuiltinImplConditions<'tcx> { let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder()); - if let ty::Coroutine(did, ..) = *self_ty.kind() + if let ty::Coroutine(did, ..) = self_ty.kind() && self.tcx().coroutine_is_gen(did) { BuiltinImplConditions::Where(ty::Binder::dummy(Vec::new())) @@ -2326,7 +2326,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { &self, t: ty::Binder<'tcx, Ty<'tcx>>, ) -> Result>>, SelectionError<'tcx>> { - Ok(match *t.skip_binder().kind() { + Ok(match t.skip_binder().kind() { ty::Uint(_) | ty::Int(_) | ty::Bool @@ -2720,7 +2720,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> { fn_trait_def_id: DefId, fn_host_effect: ty::Const<'tcx>, ) -> ty::PolyTraitRef<'tcx> { - let ty::Closure(_, args) = *self_ty.kind() else { + let ty::Closure(_, args) = self_ty.kind() else { bug!("expected closure, found {self_ty}"); }; let closure_sig = args.as_closure().sig(); diff --git a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs index 9d657ade86bfe..3f9ac21743b5c 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_normalize.rs @@ -15,7 +15,7 @@ impl<'tcx> At<'_, 'tcx> { assert!(!ty.is_ty_var(), "should have resolved vars before calling"); if self.infcx.next_trait_solver() { - let ty::Alias(..) = *ty.kind() else { + let ty::Alias(..) = ty.kind() else { return Ok(ty); }; diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index 52f87699b164f..7e5713709e77c 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -430,7 +430,7 @@ impl<'tcx> TypeFolder> for BoundVarReplacer<'_, 'tcx> { } fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - match *t.kind() { + match t.kind() { ty::Bound(debruijn, _) if debruijn.as_usize() + 1 > self.current_index.as_usize() + self.universe_indices.len() => @@ -565,7 +565,7 @@ impl<'tcx> TypeFolder> for PlaceholderReplacer<'_, 'tcx> { fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { let ty = self.infcx.shallow_resolve(ty); - match *ty.kind() { + match ty.kind() { ty::Placeholder(p) => { let replace_var = self.mapped_types.get(&p); match replace_var { diff --git a/compiler/rustc_trait_selection/src/traits/vtable.rs b/compiler/rustc_trait_selection/src/traits/vtable.rs index 1729d8d307a51..9ca3ff19775c3 100644 --- a/compiler/rustc_trait_selection/src/traits/vtable.rs +++ b/compiler/rustc_trait_selection/src/traits/vtable.rs @@ -324,7 +324,7 @@ fn vtable_entries<'tcx>( pub(crate) fn first_method_vtable_slot<'tcx>(tcx: TyCtxt<'tcx>, key: ty::TraitRef<'tcx>) -> usize { debug_assert!(!key.has_non_region_infer() && !key.has_non_region_param()); - let ty::Dynamic(source, _, _) = *key.self_ty().kind() else { + let ty::Dynamic(source, _, _) = key.self_ty().kind() else { bug!(); }; let source_principal = tcx @@ -380,7 +380,7 @@ pub(crate) fn supertrait_vtable_slot<'tcx>( let (source, target) = key; // If the target principal is `None`, we can just return `None`. - let ty::Dynamic(target, _, _) = *target.kind() else { + let ty::Dynamic(target, _, _) = target.kind() else { bug!(); }; let target_principal = tcx @@ -388,7 +388,7 @@ pub(crate) fn supertrait_vtable_slot<'tcx>( .with_self_ty(tcx, tcx.types.trait_object_dummy_self); // Given that we have a target principal, it is a bug for there not to be a source principal. - let ty::Dynamic(source, _, _) = *source.kind() else { + let ty::Dynamic(source, _, _) = source.kind() else { bug!(); }; let source_principal = tcx diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index a3982c3d987ef..f0613a198bb20 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -646,7 +646,7 @@ impl<'a, 'tcx> TypeVisitor> for WfPredicates<'a, 'tcx> { let tcx = self.tcx(); - match *t.kind() { + match t.kind() { ty::Bool | ty::Char | ty::Int(..) diff --git a/compiler/rustc_transmute/src/layout/tree.rs b/compiler/rustc_transmute/src/layout/tree.rs index 5c25f913ffe38..286f7e6624c82 100644 --- a/compiler/rustc_transmute/src/layout/tree.rs +++ b/compiler/rustc_transmute/src/layout/tree.rs @@ -239,7 +239,7 @@ pub(crate) mod rustc { let FieldsShape::Array { stride, count } = &ty_and_layout.fields else { return Err(Err::NotYetSupported); }; - let inner_ty_and_layout = cx.layout_of(*inner_ty)?; + let inner_ty_and_layout = cx.layout_of(inner_ty)?; assert_eq!(*stride, inner_ty_and_layout.size); let elt = Tree::from_ty(inner_ty_and_layout, cx)?; Ok(std::iter::repeat(elt) @@ -249,23 +249,17 @@ pub(crate) mod rustc { ty::Adt(adt_def, _args_ref) if !ty_and_layout.ty.is_box() => { match adt_def.adt_kind() { - AdtKind::Struct => Self::from_struct(ty_and_layout, *adt_def, cx), - AdtKind::Enum => Self::from_enum(ty_and_layout, *adt_def, cx), - AdtKind::Union => Self::from_union(ty_and_layout, *adt_def, cx), + AdtKind::Struct => Self::from_struct(ty_and_layout, adt_def, cx), + AdtKind::Enum => Self::from_enum(ty_and_layout, adt_def, cx), + AdtKind::Union => Self::from_union(ty_and_layout, adt_def, cx), } } ty::Ref(lifetime, ty, mutability) => { - let ty_and_layout = cx.layout_of(*ty)?; + let ty_and_layout = cx.layout_of(ty)?; let align = ty_and_layout.align.abi.bytes_usize(); let size = ty_and_layout.size.bytes_usize(); - Ok(Tree::Ref(Ref { - lifetime: *lifetime, - ty: *ty, - mutability: *mutability, - align, - size, - })) + Ok(Tree::Ref(Ref { lifetime, ty, mutability, align, size })) } _ => Err(Err::NotYetSupported), diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index 34c426f2aa6df..19d4fe65ff338 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -44,7 +44,7 @@ fn fn_sig_for_fn_abi<'tcx>( } let ty = instance.ty(tcx, param_env); - match *ty.kind() { + match ty.kind() { ty::FnDef(..) => { // HACK(davidtwco,eddyb): This is a workaround for polymorphization considering // parameters unused if they show up in the signature, but not in the `mir::Body` @@ -53,7 +53,7 @@ fn fn_sig_for_fn_abi<'tcx>( // track of a polymorphization `ParamEnv` to allow normalizing later. // // We normalize the `fn_sig` again after instantiating at a later point. - let mut sig = match *ty.kind() { + let mut sig = match ty.kind() { ty::FnDef(def_id, args) => tcx .fn_sig(def_id) .map_bound(|fn_sig| { @@ -177,7 +177,7 @@ fn fn_sig_for_fn_abi<'tcx>( if let InstanceKind::CoroutineKindShim { .. } = instance.def { // Grab the parent coroutine-closure. It has the same args for the purposes // of instantiation, so this will be okay to do. - let ty::CoroutineClosure(_, coroutine_closure_args) = *tcx + let ty::CoroutineClosure(_, coroutine_closure_args) = tcx .instantiate_and_normalize_erasing_regions( args, param_env, @@ -241,7 +241,7 @@ fn fn_sig_for_fn_abi<'tcx>( if let ty::Adt(resume_ty_adt, _) = sig.resume_ty.kind() { let expected_adt = tcx.adt_def(tcx.require_lang_item(LangItem::ResumeTy, None)); - assert_eq!(*resume_ty_adt, expected_adt); + assert_eq!(resume_ty_adt, expected_adt); } else { panic!("expected `ResumeTy`, found `{:?}`", sig.resume_ty); }; @@ -277,7 +277,7 @@ fn fn_sig_for_fn_abi<'tcx>( if let ty::Adt(resume_ty_adt, _) = sig.resume_ty.kind() { let expected_adt = tcx.adt_def(tcx.require_lang_item(LangItem::ResumeTy, None)); - assert_eq!(*resume_ty_adt, expected_adt); + assert_eq!(resume_ty_adt, expected_adt); } else { panic!("expected `ResumeTy`, found `{:?}`", sig.resume_ty); }; @@ -629,7 +629,7 @@ fn fn_abi_new_uncached<'tcx>( let is_return = arg_idx.is_none(); let is_drop_target = is_drop_in_place && arg_idx == Some(0); let drop_target_pointee = is_drop_target.then(|| match ty.kind() { - ty::RawPtr(ty, _) => *ty, + ty::RawPtr(ty, _) => ty, _ => bug!("argument to drop_in_place is not a raw ptr: {:?}", ty), }); diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index 2492688352342..cc5f14103fecd 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -36,7 +36,7 @@ fn destructure_const<'tcx>( // construct the consts for the elements of the array/slice let field_consts = branches .iter() - .map(|b| ty::Const::new_value(tcx, *b, *inner_ty)) + .map(|b| ty::Const::new_value(tcx, *b, inner_ty)) .collect::>(); debug!(?field_consts); @@ -63,7 +63,7 @@ fn destructure_const<'tcx>( (field_consts, Some(variant_idx)) } ty::Tuple(elem_tys) => { - let fields = iter::zip(*elem_tys, branches) + let fields = iter::zip(elem_tys, branches) .map(|(elem_ty, elem_valtree)| ty::Const::new_value(tcx, *elem_valtree, elem_ty)) .collect::>(); diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index c7ed6e6110fab..2ba68e4a0133f 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -39,7 +39,7 @@ fn resolve_instance_raw<'tcx>( if ty.needs_drop(tcx, param_env) { debug!(" => nontrivial drop glue"); - match *ty.kind() { + match ty.kind() { ty::Closure(..) | ty::CoroutineClosure(..) | ty::Coroutine(..) @@ -61,7 +61,7 @@ fn resolve_instance_raw<'tcx>( let ty = args.type_at(0); if ty.async_drop_glue_morphology(tcx) != AsyncDropGlueMorphology::Noop { - match *ty.kind() { + match ty.kind() { ty::Closure(..) | ty::CoroutineClosure(..) | ty::Coroutine(..) @@ -300,7 +300,7 @@ fn resolve_associated_item<'tcx>( tcx.item_name(trait_item_id) ) } - match *rcvr_args.type_at(0).kind() { + match rcvr_args.type_at(0).kind() { ty::Closure(closure_def_id, args) => { Some(Instance::resolve_closure(tcx, closure_def_id, args, target_kind)) } @@ -333,7 +333,7 @@ fn resolve_associated_item<'tcx>( } } else if let Some(target_kind) = tcx.async_fn_trait_kind_from_def_id(trait_ref.def_id) { - match *rcvr_args.type_at(0).kind() { + match rcvr_args.type_at(0).kind() { ty::CoroutineClosure(coroutine_closure_def_id, args) => { if target_kind == ClosureKind::FnOnce && args.as_coroutine_closure().kind() != ClosureKind::FnOnce diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 234e1a6d55e65..822e9039f2939 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -128,7 +128,7 @@ fn layout_of_uncached<'tcx>( }; debug_assert!(!ty.has_non_region_infer()); - Ok(match *ty.kind() { + Ok(match ty.kind() { ty::Pat(ty, pat) => { let layout = cx.layout_of(ty)?.layout; let mut layout = LayoutS::clone(&layout.0); @@ -452,7 +452,7 @@ fn layout_of_uncached<'tcx>( return Err(error(cx, LayoutError::Unknown(ty))); }; - (*e_ty, *count, true) + (e_ty, *count, true) } else { // First ADT field is not an array: (f0_ty, def.non_enum_variant().fields.len() as _, false) @@ -1033,7 +1033,7 @@ fn record_layout_for_printing<'tcx>(cx: &LayoutCx<'tcx, TyCtxt<'tcx>>, layout: T ); }; - match *layout.ty.kind() { + match layout.ty.kind() { ty::Adt(adt_def, _) => { debug!("print-type-size t: `{:?}` process adt", layout.ty); let adt_kind = adt_def.adt_kind(); diff --git a/compiler/rustc_ty_utils/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs index d274a934d5297..d06ed9f4b9891 100644 --- a/compiler/rustc_ty_utils/src/needs_drop.rs +++ b/compiler/rustc_ty_utils/src/needs_drop.rs @@ -53,7 +53,7 @@ fn filter_array_elements<'tcx>( param_env: ty::ParamEnv<'tcx>, ) -> impl Fn(&Result, AlwaysRequiresDrop>) -> bool { move |ty| match ty { - Ok(ty) => match *ty.kind() { + Ok(ty) => match ty.kind() { ty::Array(elem, _) => tcx.needs_drop_raw(param_env.and(elem)), _ => true, }, @@ -149,7 +149,7 @@ where }; for component in components { - match *component.kind() { + match component.kind() { // The information required to determine whether a coroutine has drop is // computed on MIR, while this very method is used to build MIR. // To avoid cycles, we consider that coroutines always require drop. diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 6680b451b7cc7..2e3617c0ebf59 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -205,7 +205,7 @@ impl<'tcx> TypeVisitor> for OpaqueTypeCollector<'tcx> { #[instrument(skip(self), ret, level = "trace")] fn visit_ty(&mut self, t: Ty<'tcx>) { t.super_visit_with(self); - match *t.kind() { + match t.kind() { ty::Alias(ty::Opaque, alias_ty) if alias_ty.def_id.is_local() => { self.visit_opaque_ty(alias_ty); } @@ -279,7 +279,7 @@ impl<'tcx> TypeVisitor> for OpaqueTypeCollector<'tcx> { // assumption to the `param_env` of the default method. We also separately // rely on that assumption here. let ty = self.tcx.type_of(alias_ty.def_id).instantiate(self.tcx, alias_ty.args); - let ty::Alias(ty::Opaque, alias_ty) = *ty.kind() else { bug!("{ty:?}") }; + let ty::Alias(ty::Opaque, alias_ty) = ty.kind() else { bug!("{ty:?}") }; self.visit_opaque_ty(alias_ty); } } diff --git a/compiler/rustc_ty_utils/src/representability.rs b/compiler/rustc_ty_utils/src/representability.rs index 0ffb7f624965e..18143ef9c8b8d 100644 --- a/compiler/rustc_ty_utils/src/representability.rs +++ b/compiler/rustc_ty_utils/src/representability.rs @@ -35,7 +35,7 @@ fn representability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Representability { } fn representability_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Representability { - match *ty.kind() { + match ty.kind() { ty::Adt(..) => tcx.representability_adt_ty(ty), // FIXME(#11924) allow zero-length arrays? ty::Array(ty, _) => representability_ty(tcx, ty), @@ -100,7 +100,7 @@ fn params_in_repr(tcx: TyCtxt<'_>, def_id: LocalDefId) -> BitSet { } fn params_in_repr_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, params_in_repr: &mut BitSet) { - match *ty.kind() { + match ty.kind() { ty::Adt(adt, args) => { let inner_params_in_repr = tcx.params_in_repr(adt.did()); for (i, arg) in args.iter().enumerate() { diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index aba2acd1842f1..ab7497b5781fa 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -40,7 +40,7 @@ fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option Some(ty), - Pat(ty, _) => sized_constraint_for_ty(tcx, *ty), + Pat(ty, _) => sized_constraint_for_ty(tcx, ty), Tuple(tys) => tys.last().and_then(|&ty| sized_constraint_for_ty(tcx, ty)), @@ -181,7 +181,7 @@ impl<'tcx> TypeVisitor> for ImplTraitInTraitFinder<'_, 'tcx> { } fn visit_ty(&mut self, ty: Ty<'tcx>) { - if let ty::Alias(ty::Projection, unshifted_alias_ty) = *ty.kind() + if let ty::Alias(ty::Projection, unshifted_alias_ty) = ty.kind() && let Some( ty::ImplTraitInTraitData::Trait { fn_def_id, .. } | ty::ImplTraitInTraitData::Impl { fn_def_id, .. }, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 53757349a9b2c..f09b4f1d6b1ea 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1352,7 +1352,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>( tcx.fn_sig(assoc_item.def_id).instantiate_identity().input(0).skip_binder(); if self_arg_ty == self_ty { item.decl.inputs.values[0].type_ = SelfTy; - } else if let ty::Ref(_, ty, _) = *self_arg_ty.kind() { + } else if let ty::Ref(_, ty, _) = self_arg_ty.kind() { if ty == self_ty { match item.decl.inputs.values[0].type_ { BorrowedRef { ref mut type_, .. } => **type_ = SelfTy, @@ -2038,7 +2038,7 @@ pub(crate) fn clean_middle_ty<'tcx>( container: Option>, ) -> Type { let bound_ty = normalize(cx, bound_ty).unwrap_or(bound_ty); - match *bound_ty.skip_binder().kind() { + match bound_ty.skip_binder().kind() { ty::Never => Primitive(PrimitiveType::Never), ty::Bool => Primitive(PrimitiveType::Bool), ty::Char => Primitive(PrimitiveType::Char), @@ -2404,7 +2404,7 @@ pub(crate) fn clean_variant_def<'tcx>(variant: &ty::VariantDef, cx: &mut DocCont pub(crate) fn clean_variant_def_with_args<'tcx>( variant: &ty::VariantDef, - args: &GenericArgsRef<'tcx>, + args: GenericArgsRef<'tcx>, // njn: removed `&` cx: &mut DocContext<'tcx>, ) -> Item { let discriminant = match variant.discr { diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 68266f3506a01..bd1162867211a 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -353,7 +353,7 @@ pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String { } // array lengths are obviously usize ty::ConstKind::Value(ty, ty::ValTree::Leaf(scalar)) - if *ty.kind() == ty::Uint(ty::UintTy::Usize) => + if ty.kind() == ty::Uint(ty::UintTy::Usize) => { scalar.to_string() } @@ -370,8 +370,8 @@ pub(crate) fn print_evaluated_const( tcx.const_eval_poly(def_id).ok().and_then(|val| { let ty = tcx.type_of(def_id).instantiate_identity(); match (val, ty.kind()) { - (_, &ty::Ref(..)) => None, - (mir::ConstValue::Scalar(_), &ty::Adt(_, _)) => None, + (_, ty::Ref(..)) => None, + (mir::ConstValue::Scalar(_), ty::Adt(_, _)) => None, (mir::ConstValue::Scalar(_), _) => { let const_ = mir::Const::from_value(val, ty); Some(print_const_with_custom_print_scalar(tcx, const_, with_underscores, with_type)) diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 5b96529fed70d..3ee2b4c5b525e 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -480,7 +480,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { /// This is used for resolving type aliases. fn def_id_to_res(&self, ty_id: DefId) -> Option { use PrimitiveType::*; - Some(match *self.cx.tcx.type_of(ty_id).instantiate_identity().kind() { + Some(match self.cx.tcx.type_of(ty_id).instantiate_identity().kind() { ty::Bool => Res::Primitive(Bool), ty::Char => Res::Primitive(Char), ty::Int(ity) => Res::Primitive(ity.into()), diff --git a/src/librustdoc/scrape_examples.rs b/src/librustdoc/scrape_examples.rs index f001fb26b81d3..08b794c812126 100644 --- a/src/librustdoc/scrape_examples.rs +++ b/src/librustdoc/scrape_examples.rs @@ -240,7 +240,7 @@ where CallData { locations: Vec::new(), url, display_name, edition, is_bin } }; - let fn_key = tcx.def_path_hash(*def_id); + let fn_key = tcx.def_path_hash(def_id); let fn_entries = self.calls.entry(fn_key).or_default(); trace!("Including expr: {call_span:?}"); diff --git a/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs b/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs index bd123a725a736..c5594bebb5b66 100644 --- a/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs +++ b/src/tools/clippy/clippy_lints/src/borrow_deref_ref.rs @@ -90,7 +90,7 @@ impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef { // has deref trait -> give 2 help // doesn't have deref trait -> give 1 help if let Some(deref_trait_id) = cx.tcx.lang_items().deref_trait() { - if !implements_trait(cx, *inner_ty, deref_trait_id, &[]) { + if !implements_trait(cx, inner_ty, deref_trait_id, &[]) { return; } } diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs b/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs index 102fe25fc67b0..c215fb43fec90 100644 --- a/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs +++ b/src/tools/clippy/clippy_lints/src/casts/cast_possible_truncation.rs @@ -127,10 +127,10 @@ pub(super) fn check( { let i = def.variant_index_with_ctor_id(id); let variant = def.variant(i); - let nbits = utils::enum_value_nbits(get_discriminant_value(cx.tcx, *def, i)); + let nbits = utils::enum_value_nbits(get_discriminant_value(cx.tcx, def, i)); (nbits, Some(variant)) } else { - (utils::enum_ty_to_nbits(*def, cx.tcx), None) + (utils::enum_ty_to_nbits(def, cx.tcx), None) }; let to_nbits = utils::int_ty_to_nbits(cast_to, cx.tcx); @@ -161,7 +161,7 @@ pub(super) fn check( format!("casting `{cast_from}` to `{cast_to}` may truncate the value") }, - (ty::Float(FloatTy::F64), false) if matches!(cast_to.kind(), &ty::Float(FloatTy::F32)) => { + (ty::Float(FloatTy::F64), false) if matches!(cast_to.kind(), ty::Float(FloatTy::F32)) => { "casting `f64` to `f32` may truncate the value".to_string() }, diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_precision_loss.rs b/src/tools/clippy/clippy_lints/src/casts/cast_precision_loss.rs index 035666e4d4c92..25047acc378db 100644 --- a/src/tools/clippy/clippy_lints/src/casts/cast_precision_loss.rs +++ b/src/tools/clippy/clippy_lints/src/casts/cast_precision_loss.rs @@ -12,7 +12,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_from: Ty<'_>, ca } let from_nbits = utils::int_ty_to_nbits(cast_from, cx.tcx); - let to_nbits = if cast_to.kind() == &ty::Float(FloatTy::F32) { + let to_nbits = if cast_to.kind() == ty::Float(FloatTy::F32) { 32 } else { 64 diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_ptr_alignment.rs b/src/tools/clippy/clippy_lints/src/casts/cast_ptr_alignment.rs index 960c81045e36f..8da93afbdccaf 100644 --- a/src/tools/clippy/clippy_lints/src/casts/cast_ptr_alignment.rs +++ b/src/tools/clippy/clippy_lints/src/casts/cast_ptr_alignment.rs @@ -33,8 +33,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { } fn lint_cast_ptr_alignment<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>, cast_from: Ty<'tcx>, cast_to: Ty<'tcx>) { - if let ty::RawPtr(from_ptr_ty, _) = *cast_from.kind() - && let ty::RawPtr(to_ptr_ty, _) = *cast_to.kind() + if let ty::RawPtr(from_ptr_ty, _) = cast_from.kind() + && let ty::RawPtr(to_ptr_ty, _) = cast_to.kind() && let Ok(from_layout) = cx.layout_of(from_ptr_ty) && let Ok(to_layout) = cx.layout_of(to_ptr_ty) && from_layout.align.abi < to_layout.align.abi diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_sign_loss.rs b/src/tools/clippy/clippy_lints/src/casts/cast_sign_loss.rs index 9daf237344a4b..08ce50f7f1d06 100644 --- a/src/tools/clippy/clippy_lints/src/casts/cast_sign_loss.rs +++ b/src/tools/clippy/clippy_lints/src/casts/cast_sign_loss.rs @@ -89,7 +89,7 @@ fn get_const_signed_int_eval<'cx>( let ty = ty.into().unwrap_or_else(|| cx.typeck_results().expr_ty(expr)); if let Constant::Int(n) = ConstEvalCtxt::new(cx).eval(expr)? - && let ty::Int(ity) = *ty.kind() + && let ty::Int(ity) = ty.kind() { return Some(sext(cx.tcx, n, ity)); } @@ -104,7 +104,7 @@ fn get_const_unsigned_int_eval<'cx>( let ty = ty.into().unwrap_or_else(|| cx.typeck_results().expr_ty(expr)); if let Constant::Int(n) = ConstEvalCtxt::new(cx).eval(expr)? - && let ty::Uint(_ity) = *ty.kind() + && let ty::Uint(_ity) = ty.kind() { return Some(n); } diff --git a/src/tools/clippy/clippy_lints/src/casts/cast_slice_different_sizes.rs b/src/tools/clippy/clippy_lints/src/casts/cast_slice_different_sizes.rs index 285f0357112ba..31501505e34ce 100644 --- a/src/tools/clippy/clippy_lints/src/casts/cast_slice_different_sizes.rs +++ b/src/tools/clippy/clippy_lints/src/casts/cast_slice_different_sizes.rs @@ -88,7 +88,7 @@ fn is_child_of_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { fn get_raw_slice_ty_mut(ty: Ty<'_>) -> Option> { match ty.kind() { ty::RawPtr(slice_ty, mutbl) => match slice_ty.kind() { - ty::Slice(ty) => Some(TypeAndMut { ty: *ty, mutbl: *mutbl }), + ty::Slice(ty) => Some(TypeAndMut { ty, mutbl }), _ => None, }, _ => None, diff --git a/src/tools/clippy/clippy_lints/src/casts/char_lit_as_u8.rs b/src/tools/clippy/clippy_lints/src/casts/char_lit_as_u8.rs index a7d3868f76c60..22e7e4c216fc8 100644 --- a/src/tools/clippy/clippy_lints/src/casts/char_lit_as_u8.rs +++ b/src/tools/clippy/clippy_lints/src/casts/char_lit_as_u8.rs @@ -12,7 +12,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) { if let ExprKind::Cast(e, _) = &expr.kind && let ExprKind::Lit(l) = &e.kind && let LitKind::Char(c) = l.node - && ty::Uint(UintTy::U8) == *cx.typeck_results().expr_ty(expr).kind() + && ty::Uint(UintTy::U8) == cx.typeck_results().expr_ty(expr).kind() { let mut applicability = Applicability::MachineApplicable; let snippet = snippet_with_applicability(cx, e.span, "'x'", &mut applicability); diff --git a/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast.rs b/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast.rs index dbe03e4ae8095..c42ee928163cf 100644 --- a/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast.rs +++ b/src/tools/clippy/clippy_lints/src/casts/fn_to_numeric_cast.rs @@ -20,7 +20,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>, let from_snippet = snippet_with_applicability(cx, cast_expr.span, "x", &mut applicability); let to_nbits = utils::int_ty_to_nbits(cast_to, cx.tcx); - if (to_nbits >= cx.tcx.data_layout.pointer_size.bits()) && (*cast_to.kind() != ty::Uint(UintTy::Usize)) { + if (to_nbits >= cx.tcx.data_layout.pointer_size.bits()) && (cast_to.kind() != ty::Uint(UintTy::Usize)) { span_lint_and_sugg( cx, FN_TO_NUMERIC_CAST, diff --git a/src/tools/clippy/clippy_lints/src/casts/ptr_cast_constness.rs b/src/tools/clippy/clippy_lints/src/casts/ptr_cast_constness.rs index 7513e18d408b1..d3346961b8aa7 100644 --- a/src/tools/clippy/clippy_lints/src/casts/ptr_cast_constness.rs +++ b/src/tools/clippy/clippy_lints/src/casts/ptr_cast_constness.rs @@ -27,7 +27,7 @@ pub(super) fn check<'tcx>( && !from_ty.has_erased_regions() { let sugg = Sugg::hir(cx, cast_expr, "_"); - let constness = match *to_mutbl { + let constness = match to_mutbl { Mutability::Not => "const", Mutability::Mut => "mut", }; diff --git a/src/tools/clippy/clippy_lints/src/default.rs b/src/tools/clippy/clippy_lints/src/default.rs index 0b7279f2b360d..71dec3c97624d 100644 --- a/src/tools/clippy/clippy_lints/src/default.rs +++ b/src/tools/clippy/clippy_lints/src/default.rs @@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for Default { // only when assigning `... = Default::default()` && is_expr_default(expr, cx) && let binding_type = cx.typeck_results().node_type(binding_id) - && let ty::Adt(adt, args) = *binding_type.kind() + && let ty::Adt(adt, args) = binding_type.kind() && adt.is_struct() && let variant = adt.non_enum_variant() && (adt.did().is_local() || !variant.is_field_list_non_exhaustive()) diff --git a/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs b/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs index 05c3cd3c81407..a96c4dd3501fe 100644 --- a/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs +++ b/src/tools/clippy/clippy_lints/src/default_numeric_fallback.rs @@ -235,8 +235,8 @@ fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option Some(cx.tcx.fn_sig(*def_id).instantiate_identity()), - ty::FnPtr(sig_tys, hdr) => Some(sig_tys.with(*hdr)), + ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(def_id).instantiate_identity()), + ty::FnPtr(sig_tys, hdr) => Some(sig_tys.with(hdr)), _ => None, } } diff --git a/src/tools/clippy/clippy_lints/src/dereference.rs b/src/tools/clippy/clippy_lints/src/dereference.rs index 0e55d3db469ae..4f29f36f21dc2 100644 --- a/src/tools/clippy/clippy_lints/src/dereference.rs +++ b/src/tools/clippy/clippy_lints/src/dereference.rs @@ -363,7 +363,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> { if let Some(fn_id) = typeck.type_dependent_def_id(hir_id) && let Some(trait_id) = cx.tcx.trait_of_item(fn_id) && let arg_ty = cx.tcx.erase_regions(adjusted_ty) - && let ty::Ref(_, sub_ty, _) = *arg_ty.kind() + && let ty::Ref(_, sub_ty, _) = arg_ty.kind() && let args = typeck.node_args_opt(hir_id).map(|args| &args[1..]).unwrap_or_default() && let impl_ty = @@ -619,9 +619,9 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> { } if !pat.span.from_expansion() - && let ty::Ref(_, tam, _) = *cx.typeck_results().pat_ty(pat).kind() + && let ty::Ref(_, tam, _) = cx.typeck_results().pat_ty(pat).kind() // only lint immutable refs, because borrowed `&mut T` cannot be moved out - && let ty::Ref(_, _, Mutability::Not) = *tam.kind() + && let ty::Ref(_, _, Mutability::Not) = tam.kind() { let mut app = Applicability::MachineApplicable; let snip = snippet_with_context(cx, name.span, pat.span.ctxt(), "..", &mut app).0; @@ -836,13 +836,13 @@ impl TyCoercionStability { } fn for_mir_ty<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, for_return: bool) -> Self { - let ty::Ref(_, mut ty, _) = *ty.kind() else { + let ty::Ref(_, mut ty, _) = ty.kind() else { return Self::None; }; ty = tcx.try_normalize_erasing_regions(param_env, ty).unwrap_or(ty); loop { - break match *ty.kind() { + break match ty.kind() { ty::Ref(_, ref_ty, _) => { ty = ref_ty; continue; @@ -922,7 +922,7 @@ fn ty_contains_infer(ty: &hir::Ty<'_>) -> bool { } fn ty_contains_field(ty: Ty<'_>, name: Symbol) -> bool { - if let ty::Adt(adt, _) = *ty.kind() { + if let ty::Adt(adt, _) = ty.kind() { adt.is_struct() && adt.all_fields().any(|f| f.name == name) } else { false diff --git a/src/tools/clippy/clippy_lints/src/derivable_impls.rs b/src/tools/clippy/clippy_lints/src/derivable_impls.rs index f27f68e2cbc5f..951f791e870bb 100644 --- a/src/tools/clippy/clippy_lints/src/derivable_impls.rs +++ b/src/tools/clippy/clippy_lints/src/derivable_impls.rs @@ -80,7 +80,7 @@ fn is_path_self(e: &Expr<'_>) -> bool { fn contains_trait_object(ty: Ty<'_>) -> bool { match ty.kind() { - ty::Ref(_, ty, _) => contains_trait_object(*ty), + ty::Ref(_, ty, _) => contains_trait_object(ty), ty::Adt(def, args) => def.is_box() && args[0].as_type().map_or(false, contains_trait_object), ty::Dynamic(..) => true, _ => false, @@ -200,7 +200,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls { && let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir) && let ImplItemKind::Fn(_, b) = &impl_item.kind && let Body { value: func_expr, .. } = cx.tcx.hir().body(*b) - && let &ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() + && let ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() && let attrs = cx.tcx.hir().attrs(item.hir_id()) && !attrs.iter().any(|attr| attr.doc_str().is_some()) && cx.tcx.hir().attrs(impl_item_hir).is_empty() diff --git a/src/tools/clippy/clippy_lints/src/derive.rs b/src/tools/clippy/clippy_lints/src/derive.rs index 636698e96f6d1..0d9f90a222b48 100644 --- a/src/tools/clippy/clippy_lints/src/derive.rs +++ b/src/tools/clippy/clippy_lints/src/derive.rs @@ -316,7 +316,7 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &h let Some(copy_id) = cx.tcx.lang_items().copy_trait() else { return; }; - let (ty_adt, ty_subs) = match *ty.kind() { + let (ty_adt, ty_subs) = match ty.kind() { // Unions can't derive clone. ty::Adt(adt, subs) if !adt.is_union() => (adt, subs), _ => return, @@ -453,7 +453,7 @@ fn check_partial_eq_without_eq<'tcx>(cx: &LateContext<'tcx>, span: Span, trait_r && let Some(eq_trait_def_id) = cx.tcx.get_diagnostic_item(sym::Eq) && let Some(def_id) = trait_ref.trait_def_id() && cx.tcx.is_diagnostic_item(sym::PartialEq, def_id) - && !has_non_exhaustive_attr(cx.tcx, *adt) + && !has_non_exhaustive_attr(cx.tcx, adt) && !ty_implements_eq_trait(cx.tcx, ty, eq_trait_def_id) && let param_env = param_env_for_derived_eq(cx.tcx, adt.did(), eq_trait_def_id) && let Some(local_def_id) = adt.did().as_local() diff --git a/src/tools/clippy/clippy_lints/src/eta_reduction.rs b/src/tools/clippy/clippy_lints/src/eta_reduction.rs index a7e831fdc42a8..50f505f98e0f4 100644 --- a/src/tools/clippy/clippy_lints/src/eta_reduction.rs +++ b/src/tools/clippy/clippy_lints/src/eta_reduction.rs @@ -152,13 +152,13 @@ fn check_clousure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tc let sig = match callee_ty_adjusted.kind() { ty::FnDef(def, _) => { // Rewriting `x(|| f())` to `x(f)` where f is marked `#[track_caller]` moves the `Location` - if cx.tcx.has_attr(*def, sym::track_caller) { + if cx.tcx.has_attr(def, sym::track_caller) { return; } cx.tcx.fn_sig(def).skip_binder().skip_binder() }, - ty::FnPtr(sig_tys, hdr) => sig_tys.with(*hdr).skip_binder(), + ty::FnPtr(sig_tys, hdr) => sig_tys.with(hdr).skip_binder(), ty::Closure(_, subs) => cx .tcx .signature_unclosure(subs.as_closure().sig(), Safety::Safe) @@ -167,7 +167,7 @@ fn check_clousure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tc if typeck.type_dependent_def_id(body.value.hir_id).is_some() && let subs = typeck.node_args(body.value.hir_id) && let output = typeck.expr_ty(body.value) - && let ty::Tuple(tys) = *subs.type_at(1).kind() + && let ty::Tuple(tys) = subs.type_at(1).kind() { cx.tcx.mk_fn_sig(tys, output, false, Safety::Safe, Abi::Rust) } else { @@ -313,14 +313,14 @@ fn has_late_bound_to_non_late_bound_regions(from_sig: FnSig<'_>, to_sig: FnSig<' fn check_ty(from_ty: Ty<'_>, to_ty: Ty<'_>) -> bool { match (from_ty.kind(), to_ty.kind()) { - (&ty::Adt(_, from_subs), &ty::Adt(_, to_subs)) => check_subs(from_subs, to_subs), - (&ty::Array(from_ty, _), &ty::Array(to_ty, _)) | (&ty::Slice(from_ty), &ty::Slice(to_ty)) => { + (ty::Adt(_, from_subs), ty::Adt(_, to_subs)) => check_subs(from_subs, to_subs), + (ty::Array(from_ty, _), ty::Array(to_ty, _)) | (ty::Slice(from_ty), ty::Slice(to_ty)) => { check_ty(from_ty, to_ty) }, - (&ty::Ref(from_region, from_ty, _), &ty::Ref(to_region, to_ty, _)) => { + (ty::Ref(from_region, from_ty, _), ty::Ref(to_region, to_ty, _)) => { check_region(from_region, to_region) || check_ty(from_ty, to_ty) }, - (&ty::Tuple(from_tys), &ty::Tuple(to_tys)) => { + (ty::Tuple(from_tys), ty::Tuple(to_tys)) => { from_tys.len() != to_tys.len() || from_tys .iter() diff --git a/src/tools/clippy/clippy_lints/src/float_literal.rs b/src/tools/clippy/clippy_lints/src/float_literal.rs index f095c1add91f8..7bd8a7bc4dc1d 100644 --- a/src/tools/clippy/clippy_lints/src/float_literal.rs +++ b/src/tools/clippy/clippy_lints/src/float_literal.rs @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx hir::Expr<'_>) { if let hir::ExprKind::Lit(lit) = expr.kind && let LitKind::Float(sym, lit_float_ty) = lit.node - && let ty::Float(fty) = *cx.typeck_results().expr_ty(expr).kind() + && let ty::Float(fty) = cx.typeck_results().expr_ty(expr).kind() { let sym_str = sym.as_str(); let formatter = FloatFormat::new(sym_str); diff --git a/src/tools/clippy/clippy_lints/src/from_raw_with_void_ptr.rs b/src/tools/clippy/clippy_lints/src/from_raw_with_void_ptr.rs index d62d008d480f7..c08683a5848ef 100644 --- a/src/tools/clippy/clippy_lints/src/from_raw_with_void_ptr.rs +++ b/src/tools/clippy/clippy_lints/src/from_raw_with_void_ptr.rs @@ -45,7 +45,7 @@ impl LateLintPass<'_> for FromRawWithVoidPtr { && let Some(type_str) = path_def_id(cx, ty).and_then(|id| def_id_matches_type(cx, id)) && let arg_kind = cx.typeck_results().expr_ty(arg).kind() && let ty::RawPtr(ty, _) = arg_kind - && is_c_void(cx, *ty) + && is_c_void(cx, ty) { let msg = format!("creating a `{type_str}` from a void raw pointer"); span_lint_and_help( diff --git a/src/tools/clippy/clippy_lints/src/functions/must_use.rs b/src/tools/clippy/clippy_lints/src/functions/must_use.rs index b179d7b52492c..32da92fbcc61a 100644 --- a/src/tools/clippy/clippy_lints/src/functions/must_use.rs +++ b/src/tools/clippy/clippy_lints/src/functions/must_use.rs @@ -196,7 +196,7 @@ fn is_mutable_pat(cx: &LateContext<'_>, pat: &hir::Pat<'_>, tys: &mut DefIdSet) static KNOWN_WRAPPER_TYS: &[Symbol] = &[sym::Rc, sym::Arc]; fn is_mutable_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, tys: &mut DefIdSet) -> bool { - match *ty.kind() { + match ty.kind() { // primitive types are never mutable ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => false, ty::Adt(adt, args) => { diff --git a/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs b/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs index 1aeefe73cf68f..30b8c208c8390 100644 --- a/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs +++ b/src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs @@ -75,7 +75,7 @@ fn check_raw_ptr<'tcx>( } fn raw_ptr_arg(cx: &LateContext<'_>, arg: &hir::Param<'_>) -> Option { - if let (&hir::PatKind::Binding(_, id, _, _), Some(&ty::RawPtr(_, _))) = ( + if let (&hir::PatKind::Binding(_, id, _, _), Some(ty::RawPtr(_, _))) = ( &arg.pat.kind, cx.maybe_typeck_results() .map(|typeck_results| typeck_results.pat_ty(arg.pat).kind()), diff --git a/src/tools/clippy/clippy_lints/src/functions/result.rs b/src/tools/clippy/clippy_lints/src/functions/result.rs index c3a0b40a677aa..464c17b0b1e90 100644 --- a/src/tools/clippy/clippy_lints/src/functions/result.rs +++ b/src/tools/clippy/clippy_lints/src/functions/result.rs @@ -95,7 +95,7 @@ fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty && let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(local_def_id) && let hir::ItemKind::Enum(ref def, _) = item.kind { - let variants_size = AdtVariantInfo::new(cx, *adt, subst); + let variants_size = AdtVariantInfo::new(cx, adt, subst); if let Some((first_variant, variants)) = variants_size.split_first() && first_variant.size >= large_err_threshold { diff --git a/src/tools/clippy/clippy_lints/src/future_not_send.rs b/src/tools/clippy/clippy_lints/src/future_not_send.rs index 9488ba7568656..11949af21be2a 100644 --- a/src/tools/clippy/clippy_lints/src/future_not_send.rs +++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { return; } let ret_ty = return_ty(cx, cx.tcx.local_def_id_to_hir_id(fn_def_id).expect_owner()); - if let ty::Alias(ty::Opaque, AliasTy { def_id, args, .. }) = *ret_ty.kind() { + if let ty::Alias(ty::Opaque, AliasTy { def_id, args, .. }) = ret_ty.kind() { let preds = cx.tcx.explicit_item_super_predicates(def_id); let is_future = preds.iter_instantiated_copied(cx.tcx, args).any(|(p, _)| { p.as_trait_clause().is_some_and(|trait_pred| { diff --git a/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs b/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs index 67b48878ca513..5153401b3b694 100644 --- a/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs +++ b/src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs @@ -200,7 +200,7 @@ fn is_same_generics<'tcx>( return true; } if let Some(ty) = arg.as_type() { - if let &ty::Param(ty::ParamTy { index, .. }) = ty.kind() + if let ty::Param(ty::ParamTy { index, .. }) = ty.kind() // `index == 0` means that it's referring to `Self`, // in which case we don't try to substitute it && index != 0 diff --git a/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs b/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs index 2f9661c9ea385..417858864f666 100644 --- a/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs +++ b/src/tools/clippy/clippy_lints/src/index_refutable_slice.rs @@ -115,7 +115,7 @@ fn find_slice_values(cx: &LateContext<'_>, pat: &hir::Pat<'_>) -> FxIndexMap LateLintPass<'tcx> for IndexingSlicing { if let Constant::Int(off) = constant && off <= usize::MAX as u128 && let ty::Uint(utype) = cx.typeck_results().expr_ty(index).kind() - && *utype == ty::UintTy::Usize + && utype == ty::UintTy::Usize && let ty::Array(_, s) = ty.kind() && let Some(size) = s.try_eval_target_usize(cx.tcx, cx.param_env) { diff --git a/src/tools/clippy/clippy_lints/src/iter_without_into_iter.rs b/src/tools/clippy/clippy_lints/src/iter_without_into_iter.rs index 1e6404190d3cf..5b15222c0cc3c 100644 --- a/src/tools/clippy/clippy_lints/src/iter_without_into_iter.rs +++ b/src/tools/clippy/clippy_lints/src/iter_without_into_iter.rs @@ -132,7 +132,7 @@ impl LateLintPass<'_> for IterWithoutIntoIter { .trait_def_id() .is_some_and(|did| cx.tcx.is_diagnostic_item(sym::IntoIterator, did)) && !in_external_macro(cx.sess(), item.span) - && let &ty::Ref(_, ty, mtbl) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() + && let ty::Ref(_, ty, mtbl) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind() && let expected_method_name = match mtbl { Mutability::Mut => sym::iter_mut, Mutability::Not => sym::iter, diff --git a/src/tools/clippy/clippy_lints/src/large_const_arrays.rs b/src/tools/clippy/clippy_lints/src/large_const_arrays.rs index 5d2b521b25055..115d97a797ff4 100644 --- a/src/tools/clippy/clippy_lints/src/large_const_arrays.rs +++ b/src/tools/clippy/clippy_lints/src/large_const_arrays.rs @@ -58,7 +58,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays { && let ty::Array(element_type, cst) = ty.kind() && let ConstKind::Value(_, ty::ValTree::Leaf(element_count)) = cst.kind() && let element_count = element_count.to_target_usize(cx.tcx) - && let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()) + && let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes()) && u128::from(self.maximum_allowed_size) < u128::from(element_count) * u128::from(element_size) { let hi_pos = item.ident.span.lo() - BytePos::from_usize(1); diff --git a/src/tools/clippy/clippy_lints/src/large_enum_variant.rs b/src/tools/clippy/clippy_lints/src/large_enum_variant.rs index 225d79aa71d68..4af8b4aec4028 100644 --- a/src/tools/clippy/clippy_lints/src/large_enum_variant.rs +++ b/src/tools/clippy/clippy_lints/src/large_enum_variant.rs @@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant { && adt.variants().len() > 1 && !in_external_macro(cx.tcx.sess, item.span) { - let variants_size = AdtVariantInfo::new(cx, *adt, subst); + let variants_size = AdtVariantInfo::new(cx, adt, subst); let mut difference = variants_size[0].size - variants_size[1].size; if difference > self.maximum_size_difference_allowed { diff --git a/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs b/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs index 15a75b0608965..ffd5a76f995c4 100644 --- a/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs +++ b/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs @@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays { && let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind() && let ConstKind::Value(_, ty::ValTree::Leaf(element_count)) = cst.kind() && let element_count = element_count.to_target_usize(cx.tcx) - && let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()) + && let Ok(element_size) = cx.layout_of(element_type).map(|l| l.size.bytes()) && !cx.tcx.hir().parent_iter(expr.hir_id).any(|(_, node)| { matches!( node, diff --git a/src/tools/clippy/clippy_lints/src/len_zero.rs b/src/tools/clippy/clippy_lints/src/len_zero.rs index 4c737371bd238..5d5085cf40458 100644 --- a/src/tools/clippy/clippy_lints/src/len_zero.rs +++ b/src/tools/clippy/clippy_lints/src/len_zero.rs @@ -357,7 +357,7 @@ fn parse_len_output<'tcx>(cx: &LateContext<'tcx>, sig: FnSig<'tcx>) -> Option Some(LenOutput::Integral), ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Option, adt.did()) => { subs.type_at(0).is_integral().then(|| LenOutput::Option(adt.did())) @@ -381,9 +381,9 @@ impl LenOutput { } match (self, ty.kind()) { - (_, &ty::Bool) => true, - (Self::Option(id), &ty::Adt(adt, subs)) if id == adt.did() => subs.type_at(0).is_bool(), - (Self::Result(id), &ty::Adt(adt, subs)) if id == adt.did() => subs.type_at(0).is_bool(), + (_, ty::Bool) => true, + (Self::Option(id), ty::Adt(adt, subs)) if id == adt.did() => subs.type_at(0).is_bool(), + (Self::Result(id), ty::Adt(adt, subs)) if id == adt.did() => subs.type_at(0).is_bool(), _ => false, } } diff --git a/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs b/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs index eea5f2a94ea60..1338a9f9d575b 100644 --- a/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs @@ -23,7 +23,7 @@ pub(super) fn check( let Some((adjust, ty)) = is_ref_iterable(cx, self_arg, call_expr, enforce_iter_loop_reborrow) else { return; }; - if let ty::Array(_, count) = *ty.peel_refs().kind() { + if let ty::Array(_, count) = ty.peel_refs().kind() { if !ty.is_ref() { if !msrv.meets(msrvs::ARRAY_INTO_ITERATOR) { return; @@ -136,7 +136,7 @@ fn is_ref_iterable<'tcx>( let res_ty = cx .tcx .erase_regions(EarlyBinder::bind(req_res_ty).instantiate(cx.tcx, typeck.node_args(call_expr.hir_id))); - let mutbl = if let ty::Ref(_, _, mutbl) = *req_self_ty.kind() { + let mutbl = if let ty::Ref(_, _, mutbl) = req_self_ty.kind() { Some(mutbl) } else { None @@ -153,7 +153,7 @@ fn is_ref_iterable<'tcx>( return Some((AdjustKind::None, self_ty)); } } else if enforce_iter_loop_reborrow - && let ty::Ref(region, ty, Mutability::Mut) = *self_ty.kind() + && let ty::Ref(region, ty, Mutability::Mut) = self_ty.kind() && let Some(mutbl) = mutbl { // Attempt to reborrow the mutable reference diff --git a/src/tools/clippy/clippy_lints/src/loops/for_kv_map.rs b/src/tools/clippy/clippy_lints/src/loops/for_kv_map.rs index 185d834becafc..c40ed9e9a76cf 100644 --- a/src/tools/clippy/clippy_lints/src/loops/for_kv_map.rs +++ b/src/tools/clippy/clippy_lints/src/loops/for_kv_map.rs @@ -16,7 +16,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &'tcx Pat<'_>, arg: &'tcx if let PatKind::Tuple(pat, _) = pat.kind { if pat.len() == 2 { let arg_span = arg.span; - let (new_pat_span, kind, ty, mutbl) = match *cx.typeck_results().expr_ty(arg).kind() { + let (new_pat_span, kind, ty, mutbl) = match cx.typeck_results().expr_ty(arg).kind() { ty::Ref(_, ty, mutbl) => match (&pat[0].kind, &pat[1].kind) { (key, _) if pat_is_wild(cx, key, body) => (pat[1].span, "value", ty, mutbl), (_, value) if pat_is_wild(cx, value, body) => (pat[0].span, "key", ty, Mutability::Not), diff --git a/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs b/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs index a7c1d1bd6cd36..1658937da1f98 100644 --- a/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs +++ b/src/tools/clippy/clippy_lints/src/loops/manual_memcpy.rs @@ -333,8 +333,8 @@ struct Start<'hir> { fn get_slice_like_element_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option> { match ty.kind() { ty::Adt(adt, subs) if cx.tcx.is_diagnostic_item(sym::Vec, adt.did()) => Some(subs.type_at(0)), - ty::Ref(_, subty, _) => get_slice_like_element_ty(cx, *subty), - ty::Slice(ty) | ty::Array(ty, _) => Some(*ty), + ty::Ref(_, subty, _) => get_slice_like_element_ty(cx, subty), + ty::Slice(ty) | ty::Array(ty, _) => Some(ty), _ => None, } } diff --git a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs index e18e4374667de..f11c423b4cf79 100644 --- a/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs +++ b/src/tools/clippy/clippy_lints/src/loops/needless_range_loop.rs @@ -346,7 +346,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { for expr in args { let ty = self.cx.typeck_results().expr_ty_adjusted(expr); self.prefer_mutable = false; - if let ty::Ref(_, _, mutbl) = *ty.kind() { + if let ty::Ref(_, _, mutbl) = ty.kind() { if mutbl == Mutability::Mut { self.prefer_mutable = true; } @@ -361,7 +361,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> { iter::once(receiver).chain(args.iter()), ) { self.prefer_mutable = false; - if let ty::Ref(_, _, mutbl) = *ty.kind() { + if let ty::Ref(_, _, mutbl) = ty.kind() { if mutbl == Mutability::Mut { self.prefer_mutable = true; } diff --git a/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs b/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs index 51e21aa9734ed..aed99770b0a1b 100644 --- a/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs +++ b/src/tools/clippy/clippy_lints/src/loops/unused_enumerate_index.rs @@ -17,7 +17,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'tcx>, arg: &Expr<'_ && let ExprKind::MethodCall(_method, self_arg, [], _) = arg.kind && let ty = cx.typeck_results().expr_ty(arg) && pat_is_wild(cx, &index.kind, body) - && let ty::Adt(base, _) = *ty.kind() + && let ty::Adt(base, _) = ty.kind() && cx.tcx.is_diagnostic_item(sym::Enumerate, base.did()) && let Some((DefKind::AssocFn, call_id)) = cx.typeck_results().type_dependent_def(arg.hir_id) && cx.tcx.is_diagnostic_item(sym::enumerate_method, call_id) diff --git a/src/tools/clippy/clippy_lints/src/manual_slice_size_calculation.rs b/src/tools/clippy/clippy_lints/src/manual_slice_size_calculation.rs index b24a0f4695a6c..06d1dfca60479 100644 --- a/src/tools/clippy/clippy_lints/src/manual_slice_size_calculation.rs +++ b/src/tools/clippy/clippy_lints/src/manual_slice_size_calculation.rs @@ -94,7 +94,7 @@ fn simplify_half<'tcx>( && cx.tcx.is_diagnostic_item(sym::mem_size_of, def_id) && let Some(ty2) = cx.typeck_results().node_args(func.hir_id).types().next() // T1 == T2? - && *ty1 == ty2 + && ty1 == ty2 { Some(receiver) } else { diff --git a/src/tools/clippy/clippy_lints/src/map_unit_fn.rs b/src/tools/clippy/clippy_lints/src/map_unit_fn.rs index 2db71b1f7a388..81ab0e69ea414 100644 --- a/src/tools/clippy/clippy_lints/src/map_unit_fn.rs +++ b/src/tools/clippy/clippy_lints/src/map_unit_fn.rs @@ -101,7 +101,7 @@ fn is_unit_type(ty: Ty<'_>) -> bool { fn is_unit_function(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool { let ty = cx.typeck_results().expr_ty(expr); - if let ty::FnDef(id, _) = *ty.kind() { + if let ty::FnDef(id, _) = ty.kind() { if let Some(fn_type) = cx.tcx.fn_sig(id).instantiate_identity().no_bound_vars() { return is_unit_type(fn_type.output()); } diff --git a/src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs b/src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs index 6c123649afc2f..1ed8886c8b726 100644 --- a/src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs +++ b/src/tools/clippy/clippy_lints/src/matches/match_as_ref.rs @@ -30,7 +30,7 @@ pub(crate) fn check(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: && let input_ty = args.type_at(0) && let ty::Adt(_, args) = output_ty.kind() && let output_ty = args.type_at(0) - && let ty::Ref(_, output_ty, _) = *output_ty.kind() + && let ty::Ref(_, output_ty, _) = output_ty.kind() && input_ty != output_ty { ".map(|x| x as _)" diff --git a/src/tools/clippy/clippy_lints/src/matches/match_bool.rs b/src/tools/clippy/clippy_lints/src/matches/match_bool.rs index 69105ff0d5c7a..667c21016e63e 100644 --- a/src/tools/clippy/clippy_lints/src/matches/match_bool.rs +++ b/src/tools/clippy/clippy_lints/src/matches/match_bool.rs @@ -12,7 +12,7 @@ use super::MATCH_BOOL; pub(crate) fn check(cx: &LateContext<'_>, scrutinee: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) { // Type of expression is `bool`. - if *cx.typeck_results().expr_ty(scrutinee).kind() == ty::Bool { + if cx.typeck_results().expr_ty(scrutinee).kind() == ty::Bool { span_lint_and_then( cx, MATCH_BOOL, diff --git a/src/tools/clippy/clippy_lints/src/matches/match_str_case_mismatch.rs b/src/tools/clippy/clippy_lints/src/matches/match_str_case_mismatch.rs index 322e9c3ebe5b3..96a7b785be0ea 100644 --- a/src/tools/clippy/clippy_lints/src/matches/match_str_case_mismatch.rs +++ b/src/tools/clippy/clippy_lints/src/matches/match_str_case_mismatch.rs @@ -54,7 +54,7 @@ impl<'a, 'tcx> MatchExprVisitor<'a, 'tcx> { if let Some(case_method) = get_case_method(segment_ident) { let ty = self.cx.typeck_results().expr_ty(receiver).peel_refs(); - if is_type_lang_item(self.cx, ty, LangItem::String) || ty.kind() == &ty::Str { + if is_type_lang_item(self.cx, ty, LangItem::String) || ty.kind() == ty::Str { self.case_method = Some(case_method); return true; } diff --git a/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs b/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs index 9c2f42d218702..8b1db80a7967b 100644 --- a/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs +++ b/src/tools/clippy/clippy_lints/src/matches/significant_drop_in_scrutinee.rs @@ -220,7 +220,7 @@ impl<'a, 'tcx> SigDropChecker<'a, 'tcx> { .any(|ty| self.has_sig_drop_attr_impl(ty))) }, rustc_middle::ty::Tuple(tys) => tys.iter().any(|ty| self.has_sig_drop_attr_impl(ty)), - rustc_middle::ty::Array(ty, _) | rustc_middle::ty::Slice(ty) => self.has_sig_drop_attr_impl(*ty), + rustc_middle::ty::Array(ty, _) | rustc_middle::ty::Slice(ty) => self.has_sig_drop_attr_impl(ty), _ => false, }; @@ -380,7 +380,7 @@ impl<'a, 'tcx> SigDropHelper<'a, 'tcx> { let output_ty = fn_sig.skip_binder().output(); if let rustc_middle::ty::Ref(output_re, peel_ref_ty, _) = output_ty.kind() && input_re == output_re - && for_each_top_level_late_bound_region(*peel_ref_ty, contains_input_re).is_continue() + && for_each_top_level_late_bound_region(peel_ref_ty, contains_input_re).is_continue() { // We're lucky! The output type is still a direct reference to the value with significant drop. self.sig_drop_holder = SigDropHolder::DirectRef; @@ -400,7 +400,7 @@ impl<'a, 'tcx> SigDropHelper<'a, 'tcx> { fn ty_peel_refs(mut ty: Ty<'_>) -> (Ty<'_>, usize) { let mut n = 0; while let rustc_middle::ty::Ref(_, new_ty, Mutability::Not) = ty.kind() { - ty = *new_ty; + ty = new_ty; n += 1; } (ty, n) diff --git a/src/tools/clippy/clippy_lints/src/matches/single_match.rs b/src/tools/clippy/clippy_lints/src/matches/single_match.rs index 24dea03601c5f..e785cf24c24ce 100644 --- a/src/tools/clippy/clippy_lints/src/matches/single_match.rs +++ b/src/tools/clippy/clippy_lints/src/matches/single_match.rs @@ -56,7 +56,7 @@ pub(crate) fn check<'tcx>(cx: &LateContext<'tcx>, ex: &'tcx Expr<'_>, arms: &'tc }; let typeck = cx.typeck_results(); - if *typeck.expr_ty(ex).peel_refs().kind() != ty::Bool || is_lint_allowed(cx, MATCH_BOOL, ex.hir_id) { + if typeck.expr_ty(ex).peel_refs().kind() != ty::Bool || is_lint_allowed(cx, MATCH_BOOL, ex.hir_id) { let mut v = PatVisitor { typeck, has_enum: false, @@ -262,7 +262,7 @@ impl<'a> PatState<'a> { single_pat: Option<&'tcx Pat<'tcx>>, pats: impl IntoIterator>, ) -> bool { - let ty::Adt(adt, _) = *cx.typeck.pat_ty(pat).kind() else { + let ty::Adt(adt, _) = cx.typeck.pat_ty(pat).kind() else { // Should never happen *self = Self::Wild; return true; @@ -308,7 +308,7 @@ impl<'a> PatState<'a> { fn add_pat<'tcx>(&mut self, cx: &'a PatCtxt<'tcx>, pat: &'tcx Pat<'_>) -> bool { match pat.kind { PatKind::Path(_) - if match *cx.typeck.pat_ty(pat).peel_refs().kind() { + if match cx.typeck.pat_ty(pat).peel_refs().kind() { ty::Adt(adt, _) => adt.is_enum() || (adt.is_struct() && !adt.non_enum_variant().fields.is_empty()), ty::Tuple(tys) => !tys.is_empty(), ty::Array(_, len) => len.try_eval_target_usize(cx.tcx, cx.param_env) != Some(1), @@ -329,7 +329,7 @@ impl<'a> PatState<'a> { self.add_pat(cx, sub_pat) }, PatKind::Slice([sub_pat], _, []) | PatKind::Slice([], _, [sub_pat]) - if let ty::Array(_, len) = *cx.typeck.pat_ty(pat).kind() + if let ty::Array(_, len) = cx.typeck.pat_ty(pat).kind() && len.try_eval_target_usize(cx.tcx, cx.param_env) == Some(1) => { self.add_pat(cx, sub_pat) diff --git a/src/tools/clippy/clippy_lints/src/methods/bytecount.rs b/src/tools/clippy/clippy_lints/src/methods/bytecount.rs index 4a2124c74a882..4e636e9d52072 100644 --- a/src/tools/clippy/clippy_lints/src/methods/bytecount.rs +++ b/src/tools/clippy/clippy_lints/src/methods/bytecount.rs @@ -35,7 +35,7 @@ pub(super) fn check<'tcx>( } else { return; } - && ty::Uint(UintTy::U8) == *cx.typeck_results().expr_ty(needle).peel_refs().kind() + && ty::Uint(UintTy::U8) == cx.typeck_results().expr_ty(needle).peel_refs().kind() && !is_local_used(cx, needle, arg_id) { let haystack = if let ExprKind::MethodCall(path, receiver, [], _) = filter_recv.kind { diff --git a/src/tools/clippy/clippy_lints/src/methods/chars_cmp.rs b/src/tools/clippy/clippy_lints/src/methods/chars_cmp.rs index 4ae0aeea2d1c5..e6ca897969c17 100644 --- a/src/tools/clippy/clippy_lints/src/methods/chars_cmp.rs +++ b/src/tools/clippy/clippy_lints/src/methods/chars_cmp.rs @@ -22,7 +22,7 @@ pub(super) fn check( let mut applicability = Applicability::MachineApplicable; let self_ty = cx.typeck_results().expr_ty_adjusted(args[0].0).peel_refs(); - if *self_ty.kind() != ty::Str { + if self_ty.kind() != ty::Str { return false; } diff --git a/src/tools/clippy/clippy_lints/src/methods/cloned_instead_of_copied.rs b/src/tools/clippy/clippy_lints/src/methods/cloned_instead_of_copied.rs index fcafa16223658..11a34072c5cc3 100644 --- a/src/tools/clippy/clippy_lints/src/methods/cloned_instead_of_copied.rs +++ b/src/tools/clippy/clippy_lints/src/methods/cloned_instead_of_copied.rs @@ -30,7 +30,7 @@ pub fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, span: Span, }; match inner_ty.kind() { // &T where T: Copy - ty::Ref(_, ty, _) if is_copy(cx, *ty) => {}, + ty::Ref(_, ty, _) if is_copy(cx, ty) => {}, _ => return, }; span_lint_and_sugg( diff --git a/src/tools/clippy/clippy_lints/src/methods/iter_overeager_cloned.rs b/src/tools/clippy/clippy_lints/src/methods/iter_overeager_cloned.rs index 5ccb5243e903c..6a61ac398119a 100644 --- a/src/tools/clippy/clippy_lints/src/methods/iter_overeager_cloned.rs +++ b/src/tools/clippy/clippy_lints/src/methods/iter_overeager_cloned.rs @@ -49,7 +49,7 @@ pub(super) fn check<'tcx>( && cx.tcx.trait_of_item(method_id) == Some(iter_id) && let cloned_recv_ty = typeck.expr_ty_adjusted(cloned_recv) && let Some(iter_assoc_ty) = cx.get_associated_type(cloned_recv_ty, iter_id, "Item") - && matches!(*iter_assoc_ty.kind(), ty::Ref(_, ty, _) if !is_copy(cx, ty)) + && matches!(iter_assoc_ty.kind(), ty::Ref(_, ty, _) if !is_copy(cx, ty)) { if needs_into_iter && let Some(into_iter_id) = cx.tcx.get_diagnostic_item(sym::IntoIterator) diff --git a/src/tools/clippy/clippy_lints/src/methods/map_clone.rs b/src/tools/clippy/clippy_lints/src/methods/map_clone.rs index 08ce7e204dd27..900cb06680470 100644 --- a/src/tools/clippy/clippy_lints/src/methods/map_clone.rs +++ b/src/tools/clippy/clippy_lints/src/methods/map_clone.rs @@ -78,7 +78,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_ let obj_ty = cx.typeck_results().expr_ty(obj); if let ty::Ref(_, ty, mutability) = obj_ty.kind() { if matches!(mutability, Mutability::Not) { - let copy = is_copy(cx, *ty); + let copy = is_copy(cx, ty); lint_explicit_closure(cx, e.span, recv.span, copy, msrv); } } else { @@ -123,8 +123,8 @@ fn handle_path( && let Some(ty) = args.iter().find_map(|generic_arg| generic_arg.as_type()) && let ty::Ref(_, ty, Mutability::Not) = ty.kind() && let ty::FnDef(_, lst) = cx.typeck_results().expr_ty(arg).kind() - && lst.iter().all(|l| l.as_type() == Some(*ty)) - && !should_call_clone_as_function(cx, *ty) + && lst.iter().all(|l| l.as_type() == Some(ty)) + && !should_call_clone_as_function(cx, ty) { lint_path(cx, e.span, recv.span, is_copy(cx, ty.peel_refs())); } diff --git a/src/tools/clippy/clippy_lints/src/methods/mod.rs b/src/tools/clippy/clippy_lints/src/methods/mod.rs index 1d7b10fe8f045..9d5d90990b906 100644 --- a/src/tools/clippy/clippy_lints/src/methods/mod.rs +++ b/src/tools/clippy/clippy_lints/src/methods/mod.rs @@ -5201,7 +5201,7 @@ impl SelfKind { } fn matches_ref<'a>(cx: &LateContext<'a>, mutability: hir::Mutability, parent_ty: Ty<'a>, ty: Ty<'a>) -> bool { - if let ty::Ref(_, t, m) = *ty.kind() { + if let ty::Ref(_, t, m) = ty.kind() { return m == mutability && t == parent_ty; } diff --git a/src/tools/clippy/clippy_lints/src/methods/needless_character_iteration.rs b/src/tools/clippy/clippy_lints/src/methods/needless_character_iteration.rs index e3d7820771547..ac95ac8acefb5 100644 --- a/src/tools/clippy/clippy_lints/src/methods/needless_character_iteration.rs +++ b/src/tools/clippy/clippy_lints/src/methods/needless_character_iteration.rs @@ -34,7 +34,7 @@ fn handle_expr( && method.ident.name.as_str() == "is_ascii" && path_to_local_id(receiver, first_param) && let char_arg_ty = cx.typeck_results().expr_ty_adjusted(receiver).peel_refs() - && *char_arg_ty.kind() == ty::Char + && char_arg_ty.kind() == ty::Char && let Some(snippet) = snippet_opt(cx, before_chars) { span_lint_and_sugg( @@ -103,7 +103,7 @@ pub(super) fn check(cx: &LateContext<'_>, call_expr: &Expr<'_>, recv: &Expr<'_>, && let ExprKind::MethodCall(method, mut recv, [], _) = recv.kind && method.ident.name.as_str() == "chars" && let str_ty = cx.typeck_results().expr_ty_adjusted(recv).peel_refs() - && *str_ty.kind() == ty::Str + && str_ty.kind() == ty::Str { let expr_start = recv.span; while let ExprKind::MethodCall(_, new_recv, _, _) = recv.kind { diff --git a/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs b/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs index 46b457daf7074..6a2e3056385bb 100644 --- a/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs +++ b/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs @@ -223,7 +223,7 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) - && let sig = cx.tcx.fn_sig(id).instantiate_identity() && sig.skip_binder().output().is_bool() && let [_, search_ty] = *sig.skip_binder().inputs() - && let ty::Ref(_, search_ty, Mutability::Not) = *cx + && let ty::Ref(_, search_ty, Mutability::Not) = cx .tcx .instantiate_bound_regions_with_erased(sig.rebind(search_ty)) .kind() @@ -486,14 +486,14 @@ fn get_captured_ids(cx: &LateContext<'_>, ty: Ty<'_>) -> HirIdSet { fn get_captured_ids_recursive(cx: &LateContext<'_>, ty: Ty<'_>, set: &mut HirIdSet) { match ty.kind() { ty::Adt(_, generics) => { - for generic in *generics { + for generic in generics { if let GenericArgKind::Type(ty) = generic.unpack() { get_captured_ids_recursive(cx, ty, set); } } }, ty::Closure(def_id, _) => { - let closure_hir_node = cx.tcx.hir().get_if_local(*def_id).unwrap(); + let closure_hir_node = cx.tcx.hir().get_if_local(def_id).unwrap(); if let Node::Expr(closure_expr) = closure_hir_node { can_move_expr_to_closure(cx, closure_expr) .unwrap() diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_join.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_join.rs index efd1a718504ce..7296dc61ee310 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_join.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_join.rs @@ -21,7 +21,7 @@ pub(super) fn check<'tcx>( if let ty::Ref(_, ref_type, _) = collect_output_adjusted_type.kind() // the turbofish for collect is ::> && let ty::Slice(slice) = ref_type.kind() - && is_type_lang_item(cx, *slice, LangItem::String) + && is_type_lang_item(cx, slice, LangItem::String) // the argument for join is "" && let ExprKind::Lit(spanned) = &join_arg.kind && let LitKind::Str(symbol, _) = spanned.node diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_min_or_max.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_min_or_max.rs index 86c0a6322b666..4d2fe1da0fa1a 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_min_or_max.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_min_or_max.rs @@ -80,10 +80,10 @@ fn detect_extrema<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option< let cv = ConstEvalCtxt::new(cx).eval(expr)?; match (cv.int_value(cx.tcx, ty)?, ty.kind()) { - (FullInt::S(i), &ty::Int(ity)) if i == i128::MIN >> (128 - ity.bit_width()?) => Some(Extrema::Minimum), - (FullInt::S(i), &ty::Int(ity)) if i == i128::MAX >> (128 - ity.bit_width()?) => Some(Extrema::Maximum), - (FullInt::U(i), &ty::Uint(uty)) if i == u128::MAX >> (128 - uty.bit_width()?) => Some(Extrema::Maximum), - (FullInt::U(0), &ty::Uint(_)) => Some(Extrema::Minimum), + (FullInt::S(i), ty::Int(ity)) if i == i128::MIN >> (128 - ity.bit_width()?) => Some(Extrema::Minimum), + (FullInt::S(i), ty::Int(ity)) if i == i128::MAX >> (128 - ity.bit_width()?) => Some(Extrema::Maximum), + (FullInt::U(i), ty::Uint(uty)) if i == u128::MAX >> (128 - uty.bit_width()?) => Some(Extrema::Maximum), + (FullInt::U(0), ty::Uint(_)) => Some(Extrema::Minimum), _ => None, } } diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs index fed2b128dcf30..0334854e24d58 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -453,7 +453,7 @@ fn get_callee_generic_args_and_args<'tcx>( && let ty::FnDef(callee_def_id, _) = callee_ty.kind() { let generic_args = cx.typeck_results().node_args(callee.hir_id); - return Some((*callee_def_id, generic_args, None, args)); + return Some((callee_def_id, generic_args, None, args)); } if let ExprKind::MethodCall(_, recv, args, _) = expr.kind && let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id) @@ -524,7 +524,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< .chain(call_args) .position(|arg| arg.hir_id == expr.hir_id) && let param_ty = fn_sig.input(arg_index).skip_binder() - && let ty::Param(ParamTy { index: param_index , ..}) = *param_ty.kind() + && let ty::Param(ParamTy { index: param_index , ..}) = param_ty.kind() // https://github.com/rust-lang/rust-clippy/issues/9504 and https://github.com/rust-lang/rust-clippy/issues/10021 && (param_index as usize) < call_generic_args.len() { diff --git a/src/tools/clippy/clippy_lints/src/methods/utils.rs b/src/tools/clippy/clippy_lints/src/methods/utils.rs index 0d2b0a3131763..d2d07624809c5 100644 --- a/src/tools/clippy/clippy_lints/src/methods/utils.rs +++ b/src/tools/clippy/clippy_lints/src/methods/utils.rs @@ -19,7 +19,7 @@ pub(super) fn derefs_to_slice<'tcx>( ty::Adt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()), ty::Adt(..) => is_type_diagnostic_item(cx, ty, sym::Vec), ty::Array(_, size) => size.try_eval_target_usize(cx.tcx, cx.param_env).is_some(), - ty::Ref(_, inner, _) => may_slice(cx, *inner), + ty::Ref(_, inner, _) => may_slice(cx, inner), _ => false, } } @@ -35,7 +35,7 @@ pub(super) fn derefs_to_slice<'tcx>( ty::Slice(_) => Some(expr), ty::Adt(def, _) if def.is_box() && may_slice(cx, ty.boxed_ty()) => Some(expr), ty::Ref(_, inner, _) => { - if may_slice(cx, *inner) { + if may_slice(cx, inner) { Some(expr) } else { None diff --git a/src/tools/clippy/clippy_lints/src/methods/zst_offset.rs b/src/tools/clippy/clippy_lints/src/methods/zst_offset.rs index d33021c2a7bf8..091788e7f0eca 100644 --- a/src/tools/clippy/clippy_lints/src/methods/zst_offset.rs +++ b/src/tools/clippy/clippy_lints/src/methods/zst_offset.rs @@ -7,7 +7,7 @@ use super::ZST_OFFSET; pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) { if let ty::RawPtr(ty, _) = cx.typeck_results().expr_ty(recv).kind() - && let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(*ty)) + && let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty)) && layout.is_zst() { span_lint(cx, ZST_OFFSET, expr.span, "offset calculation on zero-sized value"); diff --git a/src/tools/clippy/clippy_lints/src/mixed_read_write_in_expression.rs b/src/tools/clippy/clippy_lints/src/mixed_read_write_in_expression.rs index 0b3769ecb7cc4..22188e41a4e07 100644 --- a/src/tools/clippy/clippy_lints/src/mixed_read_write_in_expression.rs +++ b/src/tools/clippy/clippy_lints/src/mixed_read_write_in_expression.rs @@ -168,7 +168,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> { match typ.kind() { ty::FnDef(..) | ty::FnPtr(..) => { let sig = typ.fn_sig(self.cx.tcx); - if self.cx.tcx.instantiate_bound_regions_with_erased(sig).output().kind() == &ty::Never { + if self.cx.tcx.instantiate_bound_regions_with_erased(sig).output().kind() == ty::Never { self.report_diverging_sub_expr(e); } }, diff --git a/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs b/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs index 0bde0da3cd814..495bec593dc33 100644 --- a/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs +++ b/src/tools/clippy/clippy_lints/src/multiple_unsafe_ops_per_block.rs @@ -128,7 +128,7 @@ fn collect_unsafe_exprs<'tcx>( }, ExprKind::Call(path_expr, _) => { - let sig = match *cx.typeck_results().expr_ty(path_expr).kind() { + let sig = match cx.typeck_results().expr_ty(path_expr).kind() { ty::FnDef(id, _) => cx.tcx.fn_sig(id).skip_binder(), ty::FnPtr(sig_tys, hdr) => sig_tys.with(hdr), _ => return Continue(Descend::Yes), diff --git a/src/tools/clippy/clippy_lints/src/mutex_atomic.rs b/src/tools/clippy/clippy_lints/src/mutex_atomic.rs index 853e476a006c6..f9e80e8cc04d7 100644 --- a/src/tools/clippy/clippy_lints/src/mutex_atomic.rs +++ b/src/tools/clippy/clippy_lints/src/mutex_atomic.rs @@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for Mutex { "consider using an `{atomic_name}` instead of a `Mutex` here; if you just want the locking \ behavior and not the internal type, consider using `Mutex<()>`" ); - match *mutex_param.kind() { + match mutex_param.kind() { ty::Uint(t) if t != UintTy::Usize => span_lint(cx, MUTEX_INTEGER, expr.span, msg), ty::Int(t) if t != IntTy::Isize => span_lint(cx, MUTEX_INTEGER, expr.span, msg), _ => span_lint(cx, MUTEX_ATOMIC, expr.span, msg), diff --git a/src/tools/clippy/clippy_lints/src/needless_borrows_for_generic_args.rs b/src/tools/clippy/clippy_lints/src/needless_borrows_for_generic_args.rs index 32e7fde03b2c8..5c4b06ee400f1 100644 --- a/src/tools/clippy/clippy_lints/src/needless_borrows_for_generic_args.rs +++ b/src/tools/clippy/clippy_lints/src/needless_borrows_for_generic_args.rs @@ -86,7 +86,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowsForGenericArgs<'tcx> { && !use_cx.is_ty_unified && let use_node = use_cx.use_node(cx) && let Some(DefinedTy::Mir(ty)) = use_node.defined_ty(cx) - && let ty::Param(ty) = *ty.value.skip_binder().kind() + && let ty::Param(ty) = ty.value.skip_binder().kind() && let Some((hir_id, fn_id, i)) = match use_node { ExprUseNode::MethodArg(_, _, 0) => None, ExprUseNode::MethodArg(hir_id, None, i) => cx @@ -327,7 +327,7 @@ fn is_mixed_projection_predicate<'tcx>( // The inner-most self type is a type parameter from the current function. let mut projection_term = projection_predicate.projection_term; loop { - match *projection_term.self_ty().kind() { + match projection_term.self_ty().kind() { ty::Alias(ty::Projection, inner_projection_ty) => { projection_term = inner_projection_ty.into(); }, @@ -422,7 +422,7 @@ fn replace_types<'tcx>( if let Ok(projected_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, projection) && args[term_param_ty.index as usize] != GenericArg::from(projected_ty) { - deque.push_back((*term_param_ty, projected_ty)); + deque.push_back((term_param_ty, projected_ty)); } } } diff --git a/src/tools/clippy/clippy_lints/src/non_copy_const.rs b/src/tools/clippy/clippy_lints/src/non_copy_const.rs index 6915cd4061551..38934f9394dbc 100644 --- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs +++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs @@ -193,7 +193,7 @@ impl<'tcx> NonCopyConst<'tcx> { } fn is_value_unfrozen_raw_inner(cx: &LateContext<'tcx>, val: ty::ValTree<'tcx>, ty: Ty<'tcx>) -> bool { - match *ty.kind() { + match ty.kind() { // the fact that we have to dig into every structs to search enums // leads us to the point checking `UnsafeCell` directly is the only option. ty::Adt(ty_def, ..) if ty_def.is_unsafe_cell() => true, diff --git a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs index a60988ac5dbc2..a0775f6d592e3 100644 --- a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -205,7 +205,7 @@ fn ty_allowed_with_raw_pointer_heuristic<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'t ty::Tuple(fields) => fields .iter() .all(|ty| ty_allowed_with_raw_pointer_heuristic(cx, ty, send_trait)), - ty::Array(ty, _) | ty::Slice(ty) => ty_allowed_with_raw_pointer_heuristic(cx, *ty, send_trait), + ty::Array(ty, _) | ty::Slice(ty) => ty_allowed_with_raw_pointer_heuristic(cx, ty, send_trait), ty::Adt(_, args) => { if contains_pointer_like(cx, ty) { // descends only if ADT contains any raw pointers diff --git a/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs b/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs index aadd729f32a45..736f8326efa3a 100644 --- a/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs +++ b/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs @@ -387,7 +387,7 @@ fn has_matching_args(kind: FnKind, args: GenericArgsRef<'_>) -> bool { FnKind::Fn => true, FnKind::TraitFn => args.iter().enumerate().all(|(idx, subst)| match subst.unpack() { GenericArgKind::Lifetime(_) => true, - GenericArgKind::Type(ty) => matches!(*ty.kind(), ty::Param(ty) if ty.index as usize == idx), + GenericArgKind::Type(ty) => matches!(ty.kind(), ty::Param(ty) if ty.index as usize == idx), GenericArgKind::Const(c) => matches!(c.kind(), ConstKind::Param(c) if c.index as usize == idx), }), FnKind::ImplTraitFn(expected_args) => std::ptr::from_ref(args) as usize == expected_args, diff --git a/src/tools/clippy/clippy_lints/src/operators/absurd_extreme_comparisons.rs b/src/tools/clippy/clippy_lints/src/operators/absurd_extreme_comparisons.rs index a0de5ea711ca0..f5105da5dfb1e 100644 --- a/src/tools/clippy/clippy_lints/src/operators/absurd_extreme_comparisons.rs +++ b/src/tools/clippy/clippy_lints/src/operators/absurd_extreme_comparisons.rs @@ -124,16 +124,16 @@ fn detect_extreme_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Op let cv = ConstEvalCtxt::new(cx).eval(expr)?; let which = match (ty.kind(), cv) { - (&ty::Bool, Constant::Bool(false)) | (&ty::Uint(_), Constant::Int(0)) => ExtremeType::Minimum, - (&ty::Int(ity), Constant::Int(i)) if i == unsext(cx.tcx, i128::MIN >> (128 - int_bits(cx.tcx, ity)), ity) => { + (ty::Bool, Constant::Bool(false)) | (ty::Uint(_), Constant::Int(0)) => ExtremeType::Minimum, + (ty::Int(ity), Constant::Int(i)) if i == unsext(cx.tcx, i128::MIN >> (128 - int_bits(cx.tcx, ity)), ity) => { ExtremeType::Minimum }, - (&ty::Bool, Constant::Bool(true)) => ExtremeType::Maximum, - (&ty::Int(ity), Constant::Int(i)) if i == unsext(cx.tcx, i128::MAX >> (128 - int_bits(cx.tcx, ity)), ity) => { + (ty::Bool, Constant::Bool(true)) => ExtremeType::Maximum, + (ty::Int(ity), Constant::Int(i)) if i == unsext(cx.tcx, i128::MAX >> (128 - int_bits(cx.tcx, ity)), ity) => { ExtremeType::Maximum }, - (&ty::Uint(uty), Constant::Int(i)) if clip(cx.tcx, u128::MAX, uty) == i => ExtremeType::Maximum, + (ty::Uint(uty), Constant::Int(i)) if clip(cx.tcx, u128::MAX, uty) == i => ExtremeType::Maximum, _ => return None, }; diff --git a/src/tools/clippy/clippy_lints/src/operators/identity_op.rs b/src/tools/clippy/clippy_lints/src/operators/identity_op.rs index 830be50c8ba4f..19d906d92b712 100644 --- a/src/tools/clippy/clippy_lints/src/operators/identity_op.rs +++ b/src/tools/clippy/clippy_lints/src/operators/identity_op.rs @@ -201,7 +201,7 @@ fn check_remainder(cx: &LateContext<'_>, left: &Expr<'_>, right: &Expr<'_>, span fn check_op(cx: &LateContext<'_>, e: &Expr<'_>, m: i8, span: Span, arg: Span, parens: Parens, is_erased: bool) -> bool { if let Some(Constant::Int(v)) = ConstEvalCtxt::new(cx).eval_simple(e).map(Constant::peel_refs) { - let check = match *cx.typeck_results().expr_ty(e).peel_refs().kind() { + let check = match cx.typeck_results().expr_ty(e).peel_refs().kind() { ty::Int(ity) => unsext(cx.tcx, -1_i128, ity), ty::Uint(uty) => clip(cx.tcx, !0, uty), _ => return false, diff --git a/src/tools/clippy/clippy_lints/src/operators/modulo_arithmetic.rs b/src/tools/clippy/clippy_lints/src/operators/modulo_arithmetic.rs index c83bdda347a66..a8d735c3294fa 100644 --- a/src/tools/clippy/clippy_lints/src/operators/modulo_arithmetic.rs +++ b/src/tools/clippy/clippy_lints/src/operators/modulo_arithmetic.rs @@ -57,7 +57,7 @@ struct OperandInfo { fn analyze_operand(operand: &Expr<'_>, cx: &LateContext<'_>, expr: &Expr<'_>) -> Option { match ConstEvalCtxt::new(cx).eval(operand) { - Some(Constant::Int(v)) => match *cx.typeck_results().expr_ty(expr).kind() { + Some(Constant::Int(v)) => match cx.typeck_results().expr_ty(expr).kind() { ty::Int(ity) => { let value = sext(cx.tcx, v, ity); return Some(OperandInfo { diff --git a/src/tools/clippy/clippy_lints/src/operators/modulo_one.rs b/src/tools/clippy/clippy_lints/src/operators/modulo_one.rs index 54eea14833ffe..6ceae71a3ca2a 100644 --- a/src/tools/clippy/clippy_lints/src/operators/modulo_one.rs +++ b/src/tools/clippy/clippy_lints/src/operators/modulo_one.rs @@ -13,7 +13,7 @@ pub(crate) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, op: BinOpKind, right: } if let ty::Int(ity) = cx.typeck_results().expr_ty(right).kind() { - if is_integer_const(cx, right, unsext(cx.tcx, -1, *ity)) { + if is_integer_const(cx, right, unsext(cx.tcx, -1, ity)) { span_lint( cx, MODULO_ONE, diff --git a/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs b/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs index 5ca244f0141cb..6b5ce79784098 100644 --- a/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs +++ b/src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs @@ -158,7 +158,7 @@ impl<'tcx> PassByRefOrValue { _ => (), } - match *ty.skip_binder().kind() { + match ty.skip_binder().kind() { ty::Ref(lt, ty, Mutability::Not) => { match lt.kind() { RegionKind::ReBound(index, region) diff --git a/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs b/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs index c1296b04387a0..621c9deea3d6b 100644 --- a/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs +++ b/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs @@ -180,7 +180,7 @@ fn find_first_mismatch(cx: &LateContext<'_>, pat: &Pat<'_>) -> Option<(Span, Mut }; if let Some(adjustments) = cx.typeck_results().pat_adjustments().get(adjust_pat.hir_id) { if let [first, ..] = **adjustments { - if let ty::Ref(.., mutability) = *first.kind() { + if let ty::Ref(.., mutability) = first.kind() { let level = if p.hir_id == pat.hir_id { Level::Top } else { diff --git a/src/tools/clippy/clippy_lints/src/ptr.rs b/src/tools/clippy/clippy_lints/src/ptr.rs index 02c05e0aaf9ce..1de984211a6a6 100644 --- a/src/tools/clippy/clippy_lints/src/ptr.rs +++ b/src/tools/clippy/clippy_lints/src/ptr.rs @@ -425,8 +425,8 @@ fn check_fn_args<'cx, 'tcx: 'cx>( .zip(hir_tys.iter()) .enumerate() .filter_map(move |(i, (ty, hir_ty))| { - if let ty::Ref(_, ty, mutability) = *ty.kind() - && let ty::Adt(adt, args) = *ty.kind() + if let ty::Ref(_, ty, mutability) = ty.kind() + && let ty::Adt(adt, args) = ty.kind() && let TyKind::Ref(lt, ref ty) = hir_ty.kind && let TyKind::Path(QPath::Resolved(None, path)) = ty.ty.kind // Check that the name as typed matches the actual name of the type. @@ -614,7 +614,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &Body<'tcx>, args: &[ ExprKind::Call(f, expr_args) => { let i = expr_args.iter().position(|arg| arg.hir_id == child_id).unwrap_or(0); if expr_sig(self.cx, f).and_then(|sig| sig.input(i)).map_or(true, |ty| { - match *ty.skip_binder().peel_refs().kind() { + match ty.skip_binder().peel_refs().kind() { ty::Dynamic(preds, _, _) => !matches_preds(self.cx, args.deref_ty.ty(self.cx), preds), ty::Param(_) => true, ty::Adt(def, _) => def.did() == args.ty_did, @@ -648,7 +648,7 @@ fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &Body<'tcx>, args: &[ return; }; - match *self.cx.tcx.fn_sig(id).instantiate_identity().skip_binder().inputs()[i] + match self.cx.tcx.fn_sig(id).instantiate_identity().skip_binder().inputs()[i] .peel_refs() .kind() { diff --git a/src/tools/clippy/clippy_lints/src/rc_clone_in_vec_init.rs b/src/tools/clippy/clippy_lints/src/rc_clone_in_vec_init.rs index d0b45b59526fc..953edc230fc44 100644 --- a/src/tools/clippy/clippy_lints/src/rc_clone_in_vec_init.rs +++ b/src/tools/clippy/clippy_lints/src/rc_clone_in_vec_init.rs @@ -132,7 +132,7 @@ fn ref_init(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<(Symbol, Span)> { return Some((symbol, func.span)); } - if let ty::Adt(adt, _) = *cx.typeck_results().expr_ty(expr).kind() + if let ty::Adt(adt, _) = cx.typeck_results().expr_ty(expr).kind() && matches!(cx.tcx.get_diagnostic_name(adt.did()), Some(sym::RcWeak | sym::ArcWeak)) { return Some((Symbol::intern("Weak"), func.span)); diff --git a/src/tools/clippy/clippy_lints/src/redundant_clone.rs b/src/tools/clippy/clippy_lints/src/redundant_clone.rs index a1231c082e68a..380f93b760524 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_clone.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_clone.rs @@ -258,7 +258,7 @@ fn is_call_with_ref_arg<'tcx>( } = kind && args.len() == 1 && let mir::Operand::Move(mir::Place { local, .. }) = &args[0].node - && let ty::FnDef(def_id, _) = *func.ty(mir, cx.tcx).kind() + && let ty::FnDef(def_id, _) = func.ty(mir, cx.tcx).kind() && let (inner_ty, 1) = walk_ptrs_ty_depth(args[0].node.ty(mir, cx.tcx)) && !is_copy(cx, inner_ty) { diff --git a/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs b/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs index 979d6dc77aede..7919adc777309 100644 --- a/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs +++ b/src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs @@ -186,7 +186,7 @@ impl<'cx, 'others, 'tcx> AttrChecker<'cx, 'others, 'tcx> { return true; } } - for generic_arg in *b { + for generic_arg in b { if let GenericArgKind::Type(ty) = generic_arg.unpack() { if self.has_sig_drop_attr(ty) { return true; @@ -198,7 +198,7 @@ impl<'cx, 'others, 'tcx> AttrChecker<'cx, 'others, 'tcx> { rustc_middle::ty::Array(ty, _) | rustc_middle::ty::RawPtr(ty, _) | rustc_middle::ty::Ref(_, ty, _) - | rustc_middle::ty::Slice(ty) => self.has_sig_drop_attr(*ty), + | rustc_middle::ty::Slice(ty) => self.has_sig_drop_attr(ty), _ => false, } } diff --git a/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs b/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs index 01f0e3cfadbd4..51ed91007f41d 100644 --- a/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs +++ b/src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs @@ -110,7 +110,7 @@ fn get_pointee_ty_and_count_expr<'tcx>( && let ty::RawPtr(pointee_ty, _) = cx.typeck_results().expr_ty(ptr_self).kind() { - return Some((*pointee_ty, count)); + return Some((pointee_ty, count)); }; None } diff --git a/src/tools/clippy/clippy_lints/src/to_digit_is_some.rs b/src/tools/clippy/clippy_lints/src/to_digit_is_some.rs index dafe9e38818f5..743eb82ce7006 100644 --- a/src/tools/clippy/clippy_lints/src/to_digit_is_some.rs +++ b/src/tools/clippy/clippy_lints/src/to_digit_is_some.rs @@ -44,7 +44,7 @@ impl<'tcx> LateLintPass<'tcx> for ToDigitIsSome { hir::ExprKind::MethodCall(to_digits_path, char_arg, [radix_arg], _) => { if to_digits_path.ident.name.as_str() == "to_digit" && let char_arg_ty = cx.typeck_results().expr_ty_adjusted(char_arg) - && *char_arg_ty.kind() == ty::Char + && char_arg_ty.kind() == ty::Char { Some((true, *char_arg, radix_arg)) } else { diff --git a/src/tools/clippy/clippy_lints/src/transmute/crosspointer_transmute.rs b/src/tools/clippy/clippy_lints/src/transmute/crosspointer_transmute.rs index c8f959a9854b4..c650f6b3f075b 100644 --- a/src/tools/clippy/clippy_lints/src/transmute/crosspointer_transmute.rs +++ b/src/tools/clippy/clippy_lints/src/transmute/crosspointer_transmute.rs @@ -7,7 +7,7 @@ use rustc_middle::ty::{self, Ty}; /// Checks for `crosspointer_transmute` lint. /// Returns `true` if it's triggered, otherwise returns `false`. pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> bool { - match (*from_ty.kind(), *to_ty.kind()) { + match (from_ty.kind(), to_ty.kind()) { (ty::RawPtr(from_ptr_ty, _), _) if from_ptr_ty == to_ty => { span_lint( cx, diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmute_ref_to_ref.rs b/src/tools/clippy/clippy_lints/src/transmute/transmute_ref_to_ref.rs index 3842c4eb60e82..54c068158ad5f 100644 --- a/src/tools/clippy/clippy_lints/src/transmute/transmute_ref_to_ref.rs +++ b/src/tools/clippy/clippy_lints/src/transmute/transmute_ref_to_ref.rs @@ -19,8 +19,8 @@ pub(super) fn check<'tcx>( ) -> bool { let mut triggered = false; - if let (ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) = (*from_ty.kind(), *to_ty.kind()) { - if let ty::Slice(slice_ty) = *ty_from.kind() + if let (ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) = (from_ty.kind(), to_ty.kind()) { + if let ty::Slice(slice_ty) = ty_from.kind() && ty_to.is_str() && let ty::Uint(ty::UintTy::U8) = slice_ty.kind() && from_mutbl == to_mutbl diff --git a/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs b/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs index 3b32e4396b9f1..4129befe9c276 100644 --- a/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs +++ b/src/tools/clippy/clippy_lints/src/transmute/transmute_undefined_repr.rs @@ -196,21 +196,21 @@ fn reduce_refs<'tcx>(cx: &LateContext<'tcx>, mut from_ty: Ty<'tcx>, mut to_ty: T let (from_fat_ptr, to_fat_ptr) = loop { break match (from_ty.kind(), to_ty.kind()) { ( - &(ty::Ref(_, from_sub_ty, _) | ty::RawPtr(from_sub_ty, _)), - &(ty::Ref(_, to_sub_ty, _) | ty::RawPtr(to_sub_ty, _)), + ty::Ref(_, from_sub_ty, _) | ty::RawPtr(from_sub_ty, _), + ty::Ref(_, to_sub_ty, _) | ty::RawPtr(to_sub_ty, _), ) => { - from_raw_ptr = matches!(*from_ty.kind(), ty::RawPtr(_, _)); + from_raw_ptr = matches!(from_ty.kind(), ty::RawPtr(_, _)); from_ty = from_sub_ty; - to_raw_ptr = matches!(*to_ty.kind(), ty::RawPtr(_, _)); + to_raw_ptr = matches!(to_ty.kind(), ty::RawPtr(_, _)); to_ty = to_sub_ty; continue; }, - (&(ty::Ref(_, unsized_ty, _) | ty::RawPtr(unsized_ty, _)), _) + (ty::Ref(_, unsized_ty, _) | ty::RawPtr(unsized_ty, _), _) if !unsized_ty.is_sized(cx.tcx, cx.param_env) => { (true, false) }, - (_, &(ty::Ref(_, unsized_ty, _) | ty::RawPtr(unsized_ty, _))) + (_, ty::Ref(_, unsized_ty, _) | ty::RawPtr(unsized_ty, _)) if !unsized_ty.is_sized(cx.tcx, cx.param_env) => { (false, true) @@ -245,7 +245,7 @@ enum ReducedTy<'tcx> { fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx> { loop { ty = cx.tcx.try_normalize_erasing_regions(cx.param_env, ty).unwrap_or(ty); - return match *ty.kind() { + return match ty.kind() { ty::Array(sub_ty, _) if matches!(sub_ty.kind(), ty::Int(_) | ty::Uint(_)) => { ReducedTy::TypeErasure { raw_ptr_only: false } }, @@ -307,7 +307,7 @@ fn is_zero_sized_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { } fn is_size_pair(ty: Ty<'_>) -> bool { - if let ty::Tuple(tys) = *ty.kind() + if let ty::Tuple(tys) = ty.kind() && let [ty1, ty2] = &**tys { matches!(ty1.kind(), ty::Int(IntTy::Isize) | ty::Uint(UintTy::Usize)) diff --git a/src/tools/clippy/clippy_lints/src/transmute/useless_transmute.rs b/src/tools/clippy/clippy_lints/src/transmute/useless_transmute.rs index ec5fb2793f976..58acee8d5a4b6 100644 --- a/src/tools/clippy/clippy_lints/src/transmute/useless_transmute.rs +++ b/src/tools/clippy/clippy_lints/src/transmute/useless_transmute.rs @@ -15,7 +15,7 @@ pub(super) fn check<'tcx>( to_ty: Ty<'tcx>, arg: &'tcx Expr<'_>, ) -> bool { - match (*from_ty.kind(), *to_ty.kind()) { + match (from_ty.kind(), to_ty.kind()) { _ if from_ty == to_ty && !from_ty.has_erased_regions() => { span_lint( cx, diff --git a/src/tools/clippy/clippy_lints/src/tuple_array_conversions.rs b/src/tools/clippy/clippy_lints/src/tuple_array_conversions.rs index 1d0de9327546f..3f032703372b9 100644 --- a/src/tools/clippy/clippy_lints/src/tuple_array_conversions.rs +++ b/src/tools/clippy/clippy_lints/src/tuple_array_conversions.rs @@ -90,7 +90,7 @@ fn check_array<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>, elements: & ExprKind::Path(_) => Some(elements.iter().collect()), _ => None, }) - && all_bindings_are_for_conv(cx, &[*ty], expr, elements, &locals, ToType::Array) + && all_bindings_are_for_conv(cx, &[ty], expr, elements, &locals, ToType::Array) && !is_from_proc_macro(cx, expr) { span_lint_and_help( @@ -191,7 +191,8 @@ fn all_bindings_are_for_conv<'tcx>( }, (ToType::Tuple, ty::Array(ty, len)) => { let Some(len) = len.try_eval_target_usize(cx.tcx, cx.param_env) else { return false }; - len as usize == elements.len() && final_tys.iter().chain(once(ty)).all_equal() + // njn: added `&` + len as usize == elements.len() && final_tys.iter().chain(once(&ty)).all_equal() }, _ => false, } diff --git a/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs b/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs index 42100e1d755c7..e533816fae292 100644 --- a/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs +++ b/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs @@ -140,7 +140,7 @@ fn matches_ty<'tcx>( expected_left: Ty<'tcx>, expected_right: Ty<'tcx>, ) -> bool { - while let (&ty::Ref(_, lty, _), &ty::Ref(_, rty, _)) = (left.kind(), right.kind()) { + while let (ty::Ref(_, lty, _), ty::Ref(_, rty, _)) = (left.kind(), right.kind()) { if lty == expected_left && rty == expected_right { return true; } @@ -161,8 +161,8 @@ fn check_partial_eq(cx: &LateContext<'_>, method_span: Span, method_def_id: Loca // That has two arguments. if let [self_arg, other_arg] = sig.inputs() - && let &ty::Ref(_, self_arg, _) = self_arg.kind() - && let &ty::Ref(_, other_arg, _) = other_arg.kind() + && let ty::Ref(_, self_arg, _) = self_arg.kind() + && let ty::Ref(_, other_arg, _) = other_arg.kind() // The two arguments are of the same type. && let Some(trait_def_id) = get_impl_trait_def_id(cx, method_def_id) // The trait is `PartialEq`. diff --git a/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs b/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs index 80b661a757c21..12e32f3f712d4 100644 --- a/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs +++ b/src/tools/clippy/clippy_lints/src/unit_types/let_unit_value.rs @@ -218,7 +218,7 @@ fn needs_inferred_result_ty( _ => return false, }; let sig = cx.tcx.fn_sig(id).instantiate_identity().skip_binder(); - if let ty::Param(output_ty) = *sig.output().kind() { + if let ty::Param(output_ty) = sig.output().kind() { let args: Vec<&Expr<'_>> = if let Some(receiver) = receiver { std::iter::once(receiver).chain(args.iter()).collect() } else { diff --git a/src/tools/clippy/clippy_lints/src/use_self.rs b/src/tools/clippy/clippy_lints/src/use_self.rs index 93785b45c27d4..f962a86a7dbc9 100644 --- a/src/tools/clippy/clippy_lints/src/use_self.rs +++ b/src/tools/clippy/clippy_lints/src/use_self.rs @@ -350,7 +350,7 @@ fn same_lifetimes<'tcx>(a: MiddleTy<'tcx>, b: MiddleTy<'tcx>) -> bool { fn has_no_lifetime(ty: MiddleTy<'_>) -> bool { use rustc_middle::ty::{Adt, GenericArgKind}; match ty.kind() { - &Adt(_, args) => !args + Adt(_, args) => !args .iter() // TODO: Handle inferred lifetimes .any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(..))), diff --git a/src/tools/clippy/clippy_utils/src/consts.rs b/src/tools/clippy/clippy_utils/src/consts.rs index e907e4058e5a2..cb436f97dbb12 100644 --- a/src/tools/clippy/clippy_utils/src/consts.rs +++ b/src/tools/clippy/clippy_utils/src/consts.rs @@ -208,7 +208,7 @@ impl<'tcx> Constant<'tcx> { match (left, right) { (Self::Str(ls), Self::Str(rs)) => Some(ls.cmp(rs)), (Self::Char(l), Self::Char(r)) => Some(l.cmp(r)), - (&Self::Int(l), &Self::Int(r)) => match *cmp_type.kind() { + (&Self::Int(l), &Self::Int(r)) => match cmp_type.kind() { ty::Int(int_ty) => Some(sext(tcx, l, int_ty).cmp(&sext(tcx, r, int_ty))), ty::Uint(_) => Some(l.cmp(&r)), _ => bug!("Not an int type"), @@ -216,7 +216,7 @@ impl<'tcx> Constant<'tcx> { (&Self::F64(l), &Self::F64(r)) => l.partial_cmp(&r), (&Self::F32(l), &Self::F32(r)) => l.partial_cmp(&r), (Self::Bool(l), Self::Bool(r)) => Some(l.cmp(r)), - (Self::Tuple(l), Self::Tuple(r)) if l.len() == r.len() => match *cmp_type.kind() { + (Self::Tuple(l), Self::Tuple(r)) if l.len() == r.len() => match cmp_type.kind() { ty::Tuple(tys) if tys.len() == l.len() => l .iter() .zip(r) @@ -227,7 +227,7 @@ impl<'tcx> Constant<'tcx> { _ => None, }, (Self::Vec(l), Self::Vec(r)) => { - let (ty::Array(cmp_type, _) | ty::Slice(cmp_type)) = *cmp_type.kind() else { + let (ty::Array(cmp_type, _) | ty::Slice(cmp_type)) = cmp_type.kind() else { return None; }; iter::zip(l, r) @@ -238,7 +238,7 @@ impl<'tcx> Constant<'tcx> { (Self::Repeat(lv, ls), Self::Repeat(rv, rs)) => { match Self::partial_cmp( tcx, - match *cmp_type.kind() { + match cmp_type.kind() { ty::Array(ty, _) => ty, _ => return None, }, @@ -251,7 +251,7 @@ impl<'tcx> Constant<'tcx> { }, (Self::Ref(lb), Self::Ref(rb)) => Self::partial_cmp( tcx, - match *cmp_type.kind() { + match cmp_type.kind() { ty::Ref(_, ty, _) => ty, _ => return None, }, @@ -266,7 +266,7 @@ impl<'tcx> Constant<'tcx> { /// Returns the integer value or `None` if `self` or `val_type` is not integer type. pub fn int_value(&self, tcx: TyCtxt<'_>, val_type: Ty<'_>) -> Option { if let Constant::Int(const_int) = *self { - match *val_type.kind() { + match val_type.kind() { ty::Int(ity) => Some(FullInt::S(sext(tcx, const_int, ity))), ty::Uint(_) => Some(FullInt::U(const_int)), _ => None, @@ -509,7 +509,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { if let Some(Constant::Adt(constant)) = &self.expr(local_expr) && let ty::Adt(adt_def, _) = constant.ty().kind() && adt_def.is_struct() - && let Some(desired_field) = field_of_struct(*adt_def, self.tcx, *constant, field) + && let Some(desired_field) = field_of_struct(adt_def, self.tcx, *constant, field) { mir_to_const(self.tcx, desired_field) } else { @@ -570,7 +570,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { Bool(b) => Some(Bool(!b)), Int(value) => { let value = !value; - match *ty.kind() { + match ty.kind() { ty::Int(ity) => Some(Int(unsext(self.tcx, value as i128, ity))), ty::Uint(ity) => Some(Int(clip(self.tcx, value, ity))), _ => None, @@ -584,7 +584,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { use self::Constant::{Int, F32, F64}; match *o { Int(value) => { - let ty::Int(ity) = *ty.kind() else { return None }; + let ty::Int(ity) = ty.kind() else { return None }; let (min, _) = ity.min_max()?; // sign extend let value = sext(self.tcx, value, ity); @@ -726,7 +726,7 @@ impl<'tcx> ConstEvalCtxt<'tcx> { let l = self.expr(left)?; let r = self.expr(right); match (l, r) { - (Constant::Int(l), Some(Constant::Int(r))) => match *self.typeck.expr_ty_opt(left)?.kind() { + (Constant::Int(l), Some(Constant::Int(r))) => match self.typeck.expr_ty_opt(left)?.kind() { ty::Int(ity) => { let (ty_min_value, _) = ity.min_max()?; let bits = ity.bits(); diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 28755ae0710ca..8757375e431cb 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -1107,7 +1107,7 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind { .map_or(&[][..], |x| &**x) { if let rustc_ty::RawPtr(_, mutability) | rustc_ty::Ref(_, _, mutability) = - *adjust.last().map_or(target, |a| a.target).kind() + adjust.last().map_or(target, |a| a.target).kind() { return CaptureKind::Ref(mutability); } @@ -2371,10 +2371,10 @@ pub fn is_slice_of_primitives(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option is_recursively_primitive_type(*element_type), - rustc_ty::Ref(_, inner_ty, _) if matches!(inner_ty.kind(), &rustc_ty::Slice(_)) => { + rustc_ty::Slice(element_type) => is_recursively_primitive_type(element_type), + rustc_ty::Ref(_, inner_ty, _) if matches!(inner_ty.kind(), rustc_ty::Slice(_)) => { if let rustc_ty::Slice(element_type) = inner_ty.kind() { - is_recursively_primitive_type(*element_type) + is_recursively_primitive_type(element_type) } else { unreachable!() } @@ -2525,7 +2525,7 @@ pub fn peel_hir_ty_refs<'a>(mut ty: &'a hir::Ty<'a>) -> (&'a hir::Ty<'a>, usize) pub fn peel_middle_ty_refs(mut ty: Ty<'_>) -> (Ty<'_>, usize) { let mut count = 0; while let rustc_ty::Ref(_, dest_ty, _) = ty.kind() { - ty = *dest_ty; + ty = dest_ty; count += 1; } (ty, count) diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index 553af913ef9df..36048130c8168 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -71,7 +71,7 @@ fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult { return Err((span, "function pointers in const fn are unstable".into())); }, ty::Dynamic(preds, _, _) => { - for pred in *preds { + for pred in preds { match pred.skip_binder() { ty::ExistentialPredicate::AutoTrait(_) | ty::ExistentialPredicate::Projection(_) => { return Err(( @@ -333,7 +333,7 @@ fn check_terminator<'tcx>( } | TerminatorKind::TailCall { func, args, fn_span: _ } => { let fn_ty = func.ty(body, tcx); - if let ty::FnDef(fn_def_id, _) = *fn_ty.kind() { + if let ty::FnDef(fn_def_id, _) = fn_ty.kind() { if !is_const_fn(tcx, fn_def_id, msrv) { return Err(( span, diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index 2f6faba073e95..46810151ef02f 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -91,7 +91,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' return true; } - if let ty::Alias(ty::Opaque, AliasTy { def_id, .. }) = *inner_ty.kind() { + if let ty::Alias(ty::Opaque, AliasTy { def_id, .. }) = inner_ty.kind() { if !seen.insert(def_id) { return false; } @@ -191,7 +191,7 @@ pub fn has_iter_method(cx: &LateContext<'_>, probably_ref_ty: Ty<'_>) -> Option< ]; let ty_to_check = match probably_ref_ty.kind() { - ty::Ref(_, ty_to_check, _) => *ty_to_check, + ty::Ref(_, ty_to_check, _) => ty_to_check, _ => probably_ref_ty, }; @@ -322,11 +322,11 @@ pub fn has_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { match ty.kind() { ty::Adt(adt, _) => cx.tcx.has_attr(adt.did(), sym::must_use), - ty::Foreign(did) => cx.tcx.has_attr(*did, sym::must_use), + ty::Foreign(did) => cx.tcx.has_attr(did, sym::must_use), ty::Slice(ty) | ty::Array(ty, _) | ty::RawPtr(ty, _) | ty::Ref(_, ty, _) => { // for the Array case we don't need to care for the len == 0 case // because we don't want to lint functions returning empty arrays - is_must_use_ty(cx, *ty) + is_must_use_ty(cx, ty) }, ty::Tuple(args) => args.iter().any(|ty| is_must_use_ty(cx, ty)), ty::Alias(ty::Opaque, AliasTy { def_id, .. }) => { @@ -340,7 +340,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { false }, ty::Dynamic(binder, _, _) => { - for predicate in *binder { + for predicate in binder { if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder() { if cx.tcx.has_attr(trait_ref.def_id, sym::must_use) { return true; @@ -407,7 +407,7 @@ pub fn is_non_aggregate_primitive_type(ty: Ty<'_>) -> bool { /// Returns `true` if the given type is a primitive (a `bool` or `char`, any integer or /// floating-point number type, a `str`, or an array, slice, or tuple of those types). pub fn is_recursively_primitive_type(ty: Ty<'_>) -> bool { - match *ty.kind() { + match ty.kind() { ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) | ty::Str => true, ty::Ref(_, inner, _) if inner.is_str() => true, ty::Array(inner_type, _) | ty::Slice(inner_type) => is_recursively_primitive_type(inner_type), @@ -510,7 +510,7 @@ pub fn needs_ordered_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { // Check if any component type has any. match ty.kind() { ty::Tuple(fields) => fields.iter().any(|ty| needs_ordered_drop_inner(cx, ty, seen)), - ty::Array(ty, _) => needs_ordered_drop_inner(cx, *ty, seen), + ty::Array(ty, _) => needs_ordered_drop_inner(cx, ty, seen), ty::Adt(adt, subs) => adt .all_fields() .map(|f| f.ty(cx.tcx, subs)) @@ -530,8 +530,8 @@ pub fn needs_ordered_drop<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { pub fn peel_mid_ty_refs_is_mutable(ty: Ty<'_>) -> (Ty<'_>, usize, Mutability) { fn f(ty: Ty<'_>, count: usize, mutability: Mutability) -> (Ty<'_>, usize, Mutability) { match ty.kind() { - ty::Ref(_, ty, Mutability::Mut) => f(*ty, count + 1, mutability), - ty::Ref(_, ty, Mutability::Not) => f(*ty, count + 1, Mutability::Not), + ty::Ref(_, ty, Mutability::Mut) => f(ty, count + 1, mutability), + ty::Ref(_, ty, Mutability::Not) => f(ty, count + 1, Mutability::Not), _ => (ty, count, mutability), } } @@ -559,7 +559,7 @@ pub fn walk_ptrs_hir_ty<'tcx>(ty: &'tcx hir::Ty<'tcx>) -> &'tcx hir::Ty<'tcx> { pub fn walk_ptrs_ty_depth(ty: Ty<'_>) -> (Ty<'_>, usize) { fn inner(ty: Ty<'_>, depth: usize) -> (Ty<'_>, usize) { match ty.kind() { - ty::Ref(_, ty, _) => inner(*ty, depth + 1), + ty::Ref(_, ty, _) => inner(ty, depth + 1), _ => (ty, depth), } } @@ -599,7 +599,7 @@ pub fn is_uninit_value_valid_for_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) /// A fallback for polymorphic types, which are not supported by `check_validity_requirement`. fn is_uninit_value_valid_for_ty_fallback<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { - match *ty.kind() { + match ty.kind() { // The array length may be polymorphic, let's try the inner type. ty::Array(component, _) => is_uninit_value_valid_for_ty(cx, component), // Peek through tuples and try their fallbacks. @@ -707,7 +707,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option { let decl = id .as_local() @@ -986,7 +986,7 @@ pub fn approx_ty_size<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> u64 { (Ok(size), _) => size, (Err(_), ty::Tuple(list)) => list.iter().map(|t| approx_ty_size(cx, t)).sum(), (Err(_), ty::Array(t, n)) => { - n.try_eval_target_usize(cx.tcx, cx.param_env).unwrap_or_default() * approx_ty_size(cx, *t) + n.try_eval_target_usize(cx.tcx, cx.param_env).unwrap_or_default() * approx_ty_size(cx, t) }, (Err(_), ty::Adt(def, subst)) if def.is_struct() => def .variants() @@ -1200,7 +1200,7 @@ impl<'tcx> InteriorMut<'tcx> { Entry::Vacant(v) => v.insert(None), }; - let interior_mut = match *ty.kind() { + let interior_mut = match ty.kind() { ty::RawPtr(inner_ty, _) if !self.ignore_pointers => self.is_interior_mut_ty(cx, inner_ty), ty::Ref(_, inner_ty, _) | ty::Slice(inner_ty) => self.is_interior_mut_ty(cx, inner_ty), ty::Array(inner_ty, size) => { @@ -1329,7 +1329,7 @@ pub fn get_adt_inherent_method<'a>(cx: &'a LateContext<'_>, ty: Ty<'_>, method_n /// Get's the type of a field by name. pub fn get_field_by_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, name: Symbol) -> Option> { - match *ty.kind() { + match ty.kind() { ty::Adt(def, args) if def.is_union() || def.is_struct() => def .non_enum_variant() .fields diff --git a/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs b/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs index 875ddec259ee8..a07c1d1ebb107 100644 --- a/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ty/type_certainty/mod.rs @@ -294,7 +294,7 @@ fn type_is_inferable_from_arguments(cx: &LateContext<'_>, expr: &Expr<'_>) -> bo ExprKind::Call(callee, _) => { let callee_ty = cx.typeck_results().expr_ty(callee); if let ty::FnDef(callee_def_id, _) = callee_ty.kind() { - Some(*callee_def_id) + Some(callee_def_id) } else { None } diff --git a/src/tools/clippy/clippy_utils/src/visitors.rs b/src/tools/clippy/clippy_utils/src/visitors.rs index e5b6d3965e930..87d72dae65b88 100644 --- a/src/tools/clippy/clippy_utils/src/visitors.rs +++ b/src/tools/clippy/clippy_utils/src/visitors.rs @@ -437,7 +437,7 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { { self.is_unsafe = true; }, - ExprKind::Call(func, _) => match *self.cx.typeck_results().expr_ty(func).peel_refs().kind() { + ExprKind::Call(func, _) => match self.cx.typeck_results().expr_ty(func).peel_refs().kind() { ty::FnDef(id, _) if self.cx.tcx.fn_sig(id).skip_binder().safety() == Safety::Unsafe => { self.is_unsafe = true; }, diff --git a/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs b/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs index 44f42d5fb9cd9..971de2efd189d 100644 --- a/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs +++ b/src/tools/miri/src/borrow_tracker/tree_borrows/mod.rs @@ -383,7 +383,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { ) -> InterpResult<'tcx, ImmTy<'tcx>> { let this = self.eval_context_mut(); let new_perm = match val.layout.ty.kind() { - &ty::Ref(_, pointee, mutability) => + ty::Ref(_, pointee, mutability) => NewPermission::from_ref_ty(pointee, mutability, kind, this), _ => None, }; @@ -466,7 +466,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { // Check the type of this value to see what to do with it (retag, or recurse). match place.layout.ty.kind() { - &ty::Ref(_, pointee, mutability) => { + ty::Ref(_, pointee, mutability) => { let new_perm = NewPermission::from_ref_ty(pointee, mutability, self.kind, self.ecx); self.retag_ptr_inplace(place, new_perm)?; diff --git a/src/tools/miri/src/intrinsics/simd.rs b/src/tools/miri/src/intrinsics/simd.rs index a5afd029b6519..a78a828825487 100644 --- a/src/tools/miri/src/intrinsics/simd.rs +++ b/src/tools/miri/src/intrinsics/simd.rs @@ -468,7 +468,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { assert!(mask.layout.size.bits() >= bitmask_len); this.read_scalar(mask)?.to_bits(mask.layout.size)?.try_into().unwrap() } - ty::Array(elem, _len) if elem == &this.tcx.types.u8 => { + ty::Array(elem, _len) if elem == this.tcx.types.u8 => { // The array must have exactly the right size. assert_eq!(mask.layout.size.bits(), bitmask_len); // Read the raw bytes. @@ -547,7 +547,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { assert!(dest.layout.size.bits() >= bitmask_len); this.write_int(res, dest)?; } - ty::Array(elem, _len) if elem == &this.tcx.types.u8 => { + ty::Array(elem, _len) if elem == this.tcx.types.u8 => { // The array must have exactly the right size. assert_eq!(dest.layout.size.bits(), bitmask_len); // We have to write the result byte-for-byte.