Skip to content

Commit 724ce37

Browse files
authored
Rollup merge of rust-lang#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 rust-lang#93148 (comment)
2 parents eb01fe8 + 7ebd48d commit 724ce37

22 files changed

+30
-50
lines changed

compiler/rustc_lint/src/builtin.rs

+1-1
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

-13
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

+2-2
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

+1-1
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

+1-1
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

+2-2
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

+2-2
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

+2-2
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

+1-2
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

+2-2
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
};

src/tools/clippy/clippy_lints/src/matches.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_hir::{
2626
};
2727
use rustc_hir::{HirIdMap, HirIdSet};
2828
use rustc_lint::{LateContext, LateLintPass};
29-
use rustc_middle::ty::{self, Ty, TyS, VariantDef};
29+
use rustc_middle::ty::{self, Ty, VariantDef};
3030
use rustc_semver::RustcVersion;
3131
use rustc_session::{declare_tool_lint, impl_lint_pass};
3232
use rustc_span::source_map::{Span, Spanned};
@@ -2262,7 +2262,7 @@ fn lint_match_arms<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) {
22622262
};
22632263
// the names technically don't have to match; this makes the lint more conservative
22642264
if cx.tcx.hir().name(a_id) == cx.tcx.hir().name(b_id);
2265-
if TyS::same_type(cx.typeck_results().expr_ty(a), cx.typeck_results().expr_ty(b));
2265+
if cx.typeck_results().expr_ty(a) == cx.typeck_results().expr_ty(b);
22662266
if pat_contains_local(lhs.pat, a_id);
22672267
if pat_contains_local(rhs.pat, b_id);
22682268
then {

src/tools/clippy/clippy_lints/src/methods/filter_map.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_hir as hir;
88
use rustc_hir::def::Res;
99
use rustc_hir::{Expr, ExprKind, PatKind, QPath, UnOp};
1010
use rustc_lint::LateContext;
11-
use rustc_middle::ty::TyS;
1211
use rustc_span::source_map::Span;
1312
use rustc_span::symbol::{sym, Symbol};
1413
use std::borrow::Cow;
@@ -149,7 +148,7 @@ pub(super) fn check<'tcx>(
149148
if_chain! {
150149
if path_to_local_id(a_path, filter_param_id);
151150
if path_to_local_id(b, map_param_id);
152-
if TyS::same_type(cx.typeck_results().expr_ty_adjusted(a), cx.typeck_results().expr_ty_adjusted(b));
151+
if cx.typeck_results().expr_ty_adjusted(a) == cx.typeck_results().expr_ty_adjusted(b);
153152
then {
154153
return true;
155154
}

src/tools/clippy/clippy_lints/src/methods/implicit_clone.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir as hir;
88
use rustc_lint::LateContext;
9-
use rustc_middle::ty::TyS;
109
use rustc_span::sym;
1110

1211
use super::IMPLICIT_CLONE;
@@ -19,7 +18,7 @@ pub fn check(cx: &LateContext<'_>, method_name: &str, expr: &hir::Expr<'_>, recv
1918
let input_type = cx.typeck_results().expr_ty(recv);
2019
let (input_type, ref_count) = peel_mid_ty_refs(input_type);
2120
if let Some(ty_name) = input_type.ty_adt_def().map(|adt_def| cx.tcx.item_name(adt_def.did));
22-
if TyS::same_type(return_type, input_type);
21+
if return_type == input_type;
2322
then {
2423
let mut app = Applicability::MachineApplicable;
2524
let recv_snip = snippet_with_context(cx, recv.span, expr.span.ctxt(), "..", &mut app).0;

src/tools/clippy/clippy_lints/src/methods/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ use rustc_hir::def::Res;
7878
use rustc_hir::{Expr, ExprKind, PrimTy, QPath, TraitItem, TraitItemKind};
7979
use rustc_lint::{LateContext, LateLintPass, LintContext};
8080
use rustc_middle::lint::in_external_macro;
81-
use rustc_middle::ty::{self, TraitRef, Ty, TyS};
81+
use rustc_middle::ty::{self, TraitRef, Ty};
8282
use rustc_semver::RustcVersion;
8383
use rustc_session::{declare_tool_lint, impl_lint_pass};
8484
use rustc_span::{sym, Span};
@@ -2195,7 +2195,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
21952195
}
21962196
}
21972197

2198-
if name == "new" && !TyS::same_type(ret_ty, self_ty) {
2198+
if name == "new" && ret_ty != self_ty {
21992199
span_lint(
22002200
cx,
22012201
NEW_RET_NO_SELF,

src/tools/clippy/clippy_lints/src/methods/unnecessary_filter_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir as hir;
55
use rustc_hir::intravisit::{walk_expr, Visitor};
66
use rustc_hir::LangItem::{OptionNone, OptionSome};
77
use rustc_lint::LateContext;
8-
use rustc_middle::ty::{self, TyS};
8+
use rustc_middle::ty;
99
use rustc_span::sym;
1010

1111
use super::UNNECESSARY_FILTER_MAP;
@@ -34,7 +34,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, arg: &hir::Expr<
3434
let in_ty = cx.typeck_results().node_type(body.params[0].hir_id);
3535
match cx.typeck_results().expr_ty(&body.value).kind() {
3636
ty::Adt(adt, subst)
37-
if cx.tcx.is_diagnostic_item(sym::Option, adt.did) && TyS::same_type(in_ty, subst.type_at(0)) =>
37+
if cx.tcx.is_diagnostic_item(sym::Option, adt.did) && in_ty == subst.type_at(0) =>
3838
{
3939
"filter"
4040
},

src/tools/clippy/clippy_lints/src/needless_option_as_deref.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use clippy_utils::ty::is_type_diagnostic_item;
44
use rustc_errors::Applicability;
55
use rustc_hir::{Expr, ExprKind};
66
use rustc_lint::{LateContext, LateLintPass};
7-
use rustc_middle::ty::TyS;
87
use rustc_session::{declare_lint_pass, declare_tool_lint};
98
use rustc_span::symbol::sym;
109

@@ -49,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for OptionNeedlessDeref {
4948
if let ExprKind::MethodCall(path, [sub_expr], _) = expr.kind;
5049
let symbol = path.ident.as_str();
5150
if symbol == "as_deref" || symbol == "as_deref_mut";
52-
if TyS::same_type( outer_ty, typeck.expr_ty(sub_expr) );
51+
if outer_ty == typeck.expr_ty(sub_expr);
5352
then{
5453
span_lint_and_sugg(
5554
cx,

src/tools/clippy/clippy_lints/src/needless_question_mark.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_errors::Applicability;
66
use rustc_hir::LangItem::{OptionSome, ResultOk};
77
use rustc_hir::{AsyncGeneratorKind, Block, Body, Expr, ExprKind, GeneratorKind, LangItem, MatchSource, QPath};
88
use rustc_lint::{LateContext, LateLintPass};
9-
use rustc_middle::ty::TyS;
109
use rustc_session::{declare_lint_pass, declare_tool_lint};
1110

1211
declare_clippy_lint! {
@@ -128,7 +127,7 @@ fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
128127
if expr.span.ctxt() == inner_expr.span.ctxt();
129128
let expr_ty = cx.typeck_results().expr_ty(expr);
130129
let inner_ty = cx.typeck_results().expr_ty(inner_expr);
131-
if TyS::same_type(expr_ty, inner_ty);
130+
if expr_ty == inner_ty;
132131
then {
133132
span_lint_and_sugg(
134133
cx,

src/tools/clippy/clippy_lints/src/new_without_default.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_hir as hir;
88
use rustc_hir::HirIdSet;
99
use rustc_lint::{LateContext, LateLintPass, LintContext};
1010
use rustc_middle::lint::in_external_macro;
11-
use rustc_middle::ty::TyS;
1211
use rustc_session::{declare_tool_lint, impl_lint_pass};
1312
use rustc_span::sym;
1413

@@ -103,7 +102,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
103102
if cx.access_levels.is_reachable(impl_item.def_id);
104103
let self_def_id = cx.tcx.hir().get_parent_item(id);
105104
let self_ty = cx.tcx.type_of(self_def_id);
106-
if TyS::same_type(self_ty, return_ty(cx, id));
105+
if self_ty == return_ty(cx, id);
107106
if let Some(default_trait_id) = cx.tcx.get_diagnostic_item(sym::Default);
108107
then {
109108
if self.impling_types.is_none() {

src/tools/clippy/clippy_lints/src/redundant_slicing.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability};
88
use rustc_lint::{LateContext, LateLintPass};
9-
use rustc_middle::ty::TyS;
109
use rustc_session::{declare_lint_pass, declare_tool_lint};
1110

1211
declare_clippy_lint! {
@@ -54,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing {
5453
if addressee.span.ctxt() == ctxt;
5554
if let ExprKind::Index(indexed, range) = addressee.kind;
5655
if is_type_lang_item(cx, cx.typeck_results().expr_ty_adjusted(range), LangItem::RangeFull);
57-
if TyS::same_type(cx.typeck_results().expr_ty(expr), cx.typeck_results().expr_ty(indexed));
56+
if cx.typeck_results().expr_ty(expr) == cx.typeck_results().expr_ty(indexed);
5857
then {
5958
let mut app = Applicability::MachineApplicable;
6059
let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0;

src/tools/clippy/clippy_lints/src/size_of_in_element_count.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use if_chain::if_chain;
77
use rustc_hir::BinOpKind;
88
use rustc_hir::{Expr, ExprKind};
99
use rustc_lint::{LateContext, LateLintPass};
10-
use rustc_middle::ty::{self, Ty, TyS, TypeAndMut};
10+
use rustc_middle::ty::{self, Ty, TypeAndMut};
1111
use rustc_session::{declare_lint_pass, declare_tool_lint};
1212

1313
declare_clippy_lint! {
@@ -138,7 +138,7 @@ impl<'tcx> LateLintPass<'tcx> for SizeOfInElementCount {
138138
// Find a size_of call in the count parameter expression and
139139
// check that it's the same type
140140
if let Some(ty_used_for_size_of) = get_size_of_ty(cx, count_expr, false);
141-
if TyS::same_type(pointee_ty, ty_used_for_size_of);
141+
if pointee_ty == ty_used_for_size_of;
142142
then {
143143
span_lint_and_help(
144144
cx,

src/tools/clippy/clippy_utils/src/hir_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl HirEqInterExpr<'_, '_, '_> {
102102
if let Some(typeck) = self.inner.maybe_typeck_results {
103103
let l_ty = typeck.pat_ty(l.pat);
104104
let r_ty = typeck.pat_ty(r.pat);
105-
if !rustc_middle::ty::TyS::same_type(l_ty, r_ty) {
105+
if l_ty != r_ty {
106106
return false;
107107
}
108108
}

src/tools/clippy/clippy_utils/src/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub fn can_partially_move_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool
4242
/// Walks into `ty` and returns `true` if any inner type is the same as `other_ty`
4343
pub fn contains_ty(ty: Ty<'_>, other_ty: Ty<'_>) -> bool {
4444
ty.walk().any(|inner| match inner.unpack() {
45-
GenericArgKind::Type(inner_ty) => ty::TyS::same_type(other_ty, inner_ty),
45+
GenericArgKind::Type(inner_ty) => other_ty == inner_ty,
4646
GenericArgKind::Lifetime(_) | GenericArgKind::Const(_) => false,
4747
})
4848
}

0 commit comments

Comments
 (0)