Skip to content

Commit 724ce37

Browse files
authored
Rollup merge of #93290 - lcnr:same_type, r=jackh726
remove `TyS::same_type` This function ignored regions and constants in adts, but didn't do so for references or any other types. cc #93148 (comment)
2 parents eb01fe8 + 7ebd48d commit 724ce37

File tree

22 files changed

+30
-50
lines changed

22 files changed

+30
-50
lines changed

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2833,7 +2833,7 @@ impl ClashingExternDeclarations {
28332833
return true;
28342834
}
28352835
let tcx = cx.tcx;
2836-
if a == b || rustc_middle::ty::TyS::same_type(a, b) {
2836+
if a == b {
28372837
// All nominally-same types are structurally same, too.
28382838
true
28392839
} else {

compiler/rustc_middle/src/ty/util.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -893,19 +893,6 @@ impl<'tcx> ty::TyS<'tcx> {
893893
}
894894
}
895895

896-
pub fn same_type(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
897-
match (&a.kind(), &b.kind()) {
898-
(&Adt(did_a, substs_a), &Adt(did_b, substs_b)) => {
899-
if did_a != did_b {
900-
return false;
901-
}
902-
903-
substs_a.types().zip(substs_b.types()).all(|(a, b)| Self::same_type(a, b))
904-
}
905-
_ => a == b,
906-
}
907-
}
908-
909896
/// Peel off all reference types in this type until there are none left.
910897
///
911898
/// This method is idempotent, i.e. `ty.peel_refs().peel_refs() == ty.peel_refs()`.

compiler/rustc_mir_transform/src/function_item_references.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_middle::mir::*;
66
use rustc_middle::ty::{
77
self,
88
subst::{GenericArgKind, Subst, SubstsRef},
9-
PredicateKind, Ty, TyCtxt, TyS,
9+
PredicateKind, Ty, TyCtxt,
1010
};
1111
use rustc_session::lint::builtin::FUNCTION_ITEM_REFERENCES;
1212
use rustc_span::{symbol::sym, Span};
@@ -88,7 +88,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
8888
for generic_inner_ty in arg_def.walk() {
8989
if let GenericArgKind::Type(inner_ty) = generic_inner_ty.unpack() {
9090
// If the inner type matches the type bound by `Pointer`
91-
if TyS::same_type(inner_ty, bound_ty) {
91+
if inner_ty == bound_ty {
9292
// Do a substitution using the parameters from the callsite
9393
let subst_ty = inner_ty.subst(self.tcx, substs_ref);
9494
if let Some((fn_id, fn_substs)) =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1555,7 +1555,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
15551555
// `erase_late_bound_regions`.
15561556
let ty_erased = self.tcx.erase_late_bound_regions(ty);
15571557
let ty_erased = self.tcx.erase_regions(ty_erased);
1558-
let eq = ty::TyS::same_type(ty_erased, target_ty_erased);
1558+
let eq = ty_erased == target_ty_erased;
15591559
debug!(
15601560
"maybe_note_obligation_cause_for_async_await: ty_erased={:?} \
15611561
target_ty_erased={:?} eq={:?}",

compiler/rustc_ty_utils/src/representability.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ fn is_type_structurally_recursive_inner<'tcx>(
322322
// struct Foo { Option<Option<Foo>> }
323323

324324
for &seen_adt in iter {
325-
if ty::TyS::same_type(ty, seen_adt) {
325+
if ty == seen_adt {
326326
debug!("ContainsRecursive: {:?} contains {:?}", seen_adt, ty);
327327
return Representability::ContainsRecursive;
328328
}

src/tools/clippy/clippy_lints/src/dereference.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_hir::{
1212
};
1313
use rustc_lint::{LateContext, LateLintPass};
1414
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
15-
use rustc_middle::ty::{self, Ty, TyCtxt, TyS, TypeckResults};
15+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeckResults};
1616
use rustc_session::{declare_tool_lint, impl_lint_pass};
1717
use rustc_span::{symbol::sym, Span};
1818

@@ -448,7 +448,7 @@ fn try_parse_ref_op<'tcx>(
448448
// the reference.
449449
fn deref_method_same_type(result_ty: Ty<'_>, arg_ty: Ty<'_>) -> bool {
450450
match (result_ty.kind(), arg_ty.kind()) {
451-
(ty::Ref(_, result_ty, _), ty::Ref(_, arg_ty, _)) => TyS::same_type(result_ty, arg_ty),
451+
(ty::Ref(_, result_ty, _), ty::Ref(_, arg_ty, _)) => result_ty == arg_ty,
452452

453453
// The result type for a deref method is always a reference
454454
// Not matching the previous pattern means the argument type is not a reference

src/tools/clippy/clippy_lints/src/implicit_hasher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hir::{Body, Expr, ExprKind, GenericArg, Item, ItemKind, QPath, TyKind}
88
use rustc_lint::{LateContext, LateLintPass, LintContext};
99
use rustc_middle::hir::nested_filter;
1010
use rustc_middle::lint::in_external_macro;
11-
use rustc_middle::ty::{Ty, TyS, TypeckResults};
11+
use rustc_middle::ty::{Ty, TypeckResults};
1212
use rustc_session::{declare_lint_pass, declare_tool_lint};
1313
use rustc_span::source_map::Span;
1414
use rustc_span::symbol::sym;
@@ -346,7 +346,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 't
346346
if let TyKind::Path(QPath::Resolved(None, ty_path)) = ty.kind;
347347
if let Some(ty_did) = ty_path.res.opt_def_id();
348348
then {
349-
if !TyS::same_type(self.target.ty(), self.maybe_typeck_results.unwrap().expr_ty(e)) {
349+
if self.target.ty() != self.maybe_typeck_results.unwrap().expr_ty(e) {
350350
return;
351351
}
352352

src/tools/clippy/clippy_lints/src/len_zero.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_hir::{
1010
ItemKind, Mutability, Node, TraitItemRef, TyKind,
1111
};
1212
use rustc_lint::{LateContext, LateLintPass};
13-
use rustc_middle::ty::{self, AssocKind, FnSig, Ty, TyS};
13+
use rustc_middle::ty::{self, AssocKind, FnSig, Ty};
1414
use rustc_session::{declare_lint_pass, declare_tool_lint};
1515
use rustc_span::{
1616
source_map::{Span, Spanned, Symbol},
@@ -265,7 +265,7 @@ impl LenOutput<'_> {
265265
(_, &ty::Bool) => true,
266266
(Self::Option(id), &ty::Adt(adt, subs)) if id == adt.did => subs.type_at(0).is_bool(),
267267
(Self::Result(id, err_ty), &ty::Adt(adt, subs)) if id == adt.did => {
268-
subs.type_at(0).is_bool() && TyS::same_type(subs.type_at(1), err_ty)
268+
subs.type_at(0).is_bool() && subs.type_at(1) == err_ty
269269
},
270270
_ => false,
271271
}

src/tools/clippy/clippy_lints/src/loops/explicit_into_iter_loop.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ use clippy_utils::source::snippet_with_applicability;
55
use rustc_errors::Applicability;
66
use rustc_hir::Expr;
77
use rustc_lint::LateContext;
8-
use rustc_middle::ty::TyS;
98
use rustc_span::symbol::sym;
109

1110
pub(super) fn check(cx: &LateContext<'_>, self_arg: &Expr<'_>, call_expr: &Expr<'_>) {
1211
let self_ty = cx.typeck_results().expr_ty(self_arg);
1312
let self_ty_adjusted = cx.typeck_results().expr_ty_adjusted(self_arg);
14-
if !(TyS::same_type(self_ty, self_ty_adjusted) && is_trait_method(cx, call_expr, sym::IntoIterator)) {
13+
if !(self_ty == self_ty_adjusted && is_trait_method(cx, call_expr, sym::IntoIterator)) {
1514
return;
1615
}
1716

src/tools/clippy/clippy_lints/src/loops/explicit_iter_loop.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use clippy_utils::ty::is_type_diagnostic_item;
66
use rustc_errors::Applicability;
77
use rustc_hir::{Expr, Mutability};
88
use rustc_lint::LateContext;
9-
use rustc_middle::ty::{self, Ty, TyS};
9+
use rustc_middle::ty::{self, Ty};
1010
use rustc_span::sym;
1111

1212
pub(super) fn check(cx: &LateContext<'_>, self_arg: &Expr<'_>, arg: &Expr<'_>, method_name: &str) {
@@ -22,7 +22,7 @@ pub(super) fn check(cx: &LateContext<'_>, self_arg: &Expr<'_>, arg: &Expr<'_>, m
2222
mutbl: Mutability::Not,
2323
},
2424
);
25-
TyS::same_type(receiver_ty_adjusted, ref_receiver_ty)
25+
receiver_ty_adjusted == ref_receiver_ty
2626
},
2727
_ => false,
2828
};

0 commit comments

Comments
 (0)