Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 38899d0

Browse files
committed
replace usages of fn_sig query with bound_fn_sig
1 parent a64940f commit 38899d0

28 files changed

+48
-47
lines changed

clippy_lints/src/casts/as_ptr_cast_mut.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,
1717
&& let ExprKind::MethodCall(method_name, receiver, [], _) = cast_expr.peel_blocks().kind
1818
&& method_name.ident.name == rustc_span::sym::as_ptr
1919
&& let Some(as_ptr_did) = cx.typeck_results().type_dependent_def_id(cast_expr.peel_blocks().hir_id)
20-
&& let as_ptr_sig = cx.tcx.fn_sig(as_ptr_did)
20+
&& let as_ptr_sig = cx.tcx.bound_fn_sig(as_ptr_did).subst_identity()
2121
&& let Some(first_param_ty) = as_ptr_sig.skip_binder().inputs().iter().next()
2222
&& let ty::Ref(_, _, Mutability::Not) = first_param_ty.kind()
2323
&& let Some(recv) = snippet_opt(cx, receiver.span)

clippy_lints/src/default_numeric_fallback.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NumericFallbackVisitor<'a, 'tcx> {
141141

142142
ExprKind::MethodCall(_, receiver, args, _) => {
143143
if let Some(def_id) = self.cx.typeck_results().type_dependent_def_id(expr.hir_id) {
144-
let fn_sig = self.cx.tcx.fn_sig(def_id).skip_binder();
144+
let fn_sig = self.cx.tcx.bound_fn_sig(def_id).subst_identity().skip_binder();
145145
for (expr, bound) in iter::zip(std::iter::once(*receiver).chain(args.iter()), fn_sig.inputs()) {
146146
self.ty_bounds.push((*bound).into());
147147
self.visit_expr(expr);
@@ -215,7 +215,7 @@ fn fn_sig_opt<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<PolyFnSig<'
215215
let node_ty = cx.typeck_results().node_type_opt(hir_id)?;
216216
// We can't use `Ty::fn_sig` because it automatically performs substs, this may result in FNs.
217217
match node_ty.kind() {
218-
ty::FnDef(def_id, _) => Some(cx.tcx.fn_sig(*def_id)),
218+
ty::FnDef(def_id, _) => Some(cx.tcx.bound_fn_sig(*def_id).subst_identity()),
219219
ty::FnPtr(fn_sig) => Some(*fn_sig),
220220
_ => None,
221221
}

clippy_lints/src/dereference.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ fn walk_parents<'tcx>(
759759
}) if span.ctxt() == ctxt => {
760760
let output = cx
761761
.tcx
762-
.erase_late_bound_regions(cx.tcx.fn_sig(owner_id.to_def_id()).output());
762+
.erase_late_bound_regions(cx.tcx.bound_fn_sig(owner_id.to_def_id()).subst_identity().output());
763763
Some(ty_auto_deref_stability(cx, output, precedence).position_for_result(cx))
764764
},
765765

@@ -791,7 +791,7 @@ fn walk_parents<'tcx>(
791791
} else {
792792
let output = cx
793793
.tcx
794-
.erase_late_bound_regions(cx.tcx.fn_sig(cx.tcx.hir().local_def_id(owner_id)).output());
794+
.erase_late_bound_regions(cx.tcx.bound_fn_sig(cx.tcx.hir().local_def_id(owner_id).into()).subst_identity().output());
795795
ty_auto_deref_stability(cx, output, precedence).position_for_result(cx)
796796
},
797797
)
@@ -858,7 +858,7 @@ fn walk_parents<'tcx>(
858858
&& let subs = cx
859859
.typeck_results()
860860
.node_substs_opt(parent.hir_id).map(|subs| &subs[1..]).unwrap_or_default()
861-
&& let impl_ty = if cx.tcx.fn_sig(id).skip_binder().inputs()[0].is_ref() {
861+
&& let impl_ty = if cx.tcx.bound_fn_sig(id).subst_identity().skip_binder().inputs()[0].is_ref() {
862862
// Trait methods taking `&self`
863863
sub_ty
864864
} else {
@@ -879,7 +879,7 @@ fn walk_parents<'tcx>(
879879
return Some(Position::MethodReceiver);
880880
}
881881
args.iter().position(|arg| arg.hir_id == child_id).map(|i| {
882-
let ty = cx.tcx.fn_sig(id).skip_binder().inputs()[i + 1];
882+
let ty = cx.tcx.bound_fn_sig(id).subst_identity().skip_binder().inputs()[i + 1];
883883
// `e.hir_id == child_id` for https://github.com/rust-lang/rust-clippy/issues/9739
884884
// `method.args.is_none()` for https://github.com/rust-lang/rust-clippy/issues/9782
885885
if e.hir_id == child_id && method.args.is_none() && let ty::Param(param_ty) = ty.kind() {
@@ -896,7 +896,7 @@ fn walk_parents<'tcx>(
896896
} else {
897897
ty_auto_deref_stability(
898898
cx,
899-
cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).input(i + 1)),
899+
cx.tcx.erase_late_bound_regions(cx.tcx.bound_fn_sig(id).subst_identity().input(i + 1)),
900900
precedence,
901901
)
902902
.position_for_arg()
@@ -1093,7 +1093,7 @@ fn needless_borrow_impl_arg_position<'tcx>(
10931093
let sized_trait_def_id = cx.tcx.lang_items().sized_trait();
10941094

10951095
let Some(callee_def_id) = fn_def_id(cx, parent) else { return Position::Other(precedence) };
1096-
let fn_sig = cx.tcx.fn_sig(callee_def_id).skip_binder();
1096+
let fn_sig = cx.tcx.bound_fn_sig(callee_def_id).subst_identity().skip_binder();
10971097
let substs_with_expr_ty = cx
10981098
.typeck_results()
10991099
.node_substs(if let ExprKind::Call(callee, _) = parent.kind {
@@ -1221,7 +1221,7 @@ fn has_ref_mut_self_method(cx: &LateContext<'_>, trait_def_id: DefId) -> bool {
12211221
.in_definition_order()
12221222
.any(|assoc_item| {
12231223
if assoc_item.fn_has_self_parameter {
1224-
let self_ty = cx.tcx.fn_sig(assoc_item.def_id).skip_binder().inputs()[0];
1224+
let self_ty = cx.tcx.bound_fn_sig(assoc_item.def_id).subst_identity().skip_binder().inputs()[0];
12251225
matches!(self_ty.kind(), ty::Ref(_, _, Mutability::Mut))
12261226
} else {
12271227
false

clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn check_raw_ptr<'tcx>(
5858
},
5959
hir::ExprKind::MethodCall(_, recv, args, _) => {
6060
let def_id = typeck.type_dependent_def_id(e.hir_id).unwrap();
61-
if cx.tcx.fn_sig(def_id).skip_binder().unsafety == hir::Unsafety::Unsafe {
61+
if cx.tcx.bound_fn_sig(def_id).skip_binder().skip_binder().unsafety == hir::Unsafety::Unsafe {
6262
check_arg(cx, &raw_ptrs, recv);
6363
for arg in args {
6464
check_arg(cx, &raw_ptrs, arg);

clippy_lints/src/functions/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn result_err_ty<'tcx>(
2121
) -> Option<(&'tcx hir::Ty<'tcx>, Ty<'tcx>)> {
2222
if !in_external_macro(cx.sess(), item_span)
2323
&& let hir::FnRetTy::Return(hir_ty) = decl.output
24-
&& let ty = cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(id).output())
24+
&& let ty = cx.tcx.erase_late_bound_regions(cx.tcx.bound_fn_sig(id.into()).subst_identity().output())
2525
&& is_type_diagnostic_item(cx, ty, sym::Result)
2626
&& let ty::Adt(_, substs) = ty.kind()
2727
{

clippy_lints/src/inherent_to_string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ fn show_lint(cx: &LateContext<'_>, item: &ImplItem<'_>) {
124124
.expect("Failed to get trait ID of `Display`!");
125125

126126
// Get the real type of 'self'
127-
let self_type = cx.tcx.fn_sig(item.owner_id).input(0);
127+
let self_type = cx.tcx.bound_fn_sig(item.owner_id.to_def_id()).skip_binder().input(0);
128128
let self_type = self_type.skip_binder().peel_refs();
129129

130130
// Emit either a warning or an error

clippy_lints/src/iter_not_returning_iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for IterNotReturningIterator {
6666

6767
fn check_sig(cx: &LateContext<'_>, name: &str, sig: &FnSig<'_>, fn_id: LocalDefId) {
6868
if sig.decl.implicit_self.has_implicit_self() {
69-
let ret_ty = cx.tcx.erase_late_bound_regions(cx.tcx.fn_sig(fn_id).output());
69+
let ret_ty = cx.tcx.erase_late_bound_regions(cx.tcx.bound_fn_sig(fn_id.into()).subst_identity().output());
7070
let ret_ty = cx
7171
.tcx
7272
.try_normalize_erasing_regions(cx.param_env, ret_ty)

clippy_lints/src/len_zero.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
144144
if let Some(local_id) = ty_id.as_local();
145145
let ty_hir_id = cx.tcx.hir().local_def_id_to_hir_id(local_id);
146146
if !is_lint_allowed(cx, LEN_WITHOUT_IS_EMPTY, ty_hir_id);
147-
if let Some(output) = parse_len_output(cx, cx.tcx.fn_sig(item.owner_id).skip_binder());
147+
if let Some(output) = parse_len_output(cx, cx.tcx.bound_fn_sig(item.owner_id.to_def_id()).subst_identity().skip_binder());
148148
then {
149149
let (name, kind) = match cx.tcx.hir().find(ty_hir_id) {
150150
Some(Node::ForeignItem(x)) => (x.ident.name, "extern type"),
@@ -196,7 +196,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
196196
fn is_named_self(cx: &LateContext<'_>, item: &TraitItemRef, name: Symbol) -> bool {
197197
item.ident.name == name
198198
&& if let AssocItemKind::Fn { has_self } = item.kind {
199-
has_self && { cx.tcx.fn_sig(item.id.owner_id).inputs().skip_binder().len() == 1 }
199+
has_self && { cx.tcx.bound_fn_sig(item.id.owner_id.to_def_id()).skip_binder().inputs().skip_binder().len() == 1 }
200200
} else {
201201
false
202202
}
@@ -224,7 +224,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
224224
.any(|i| {
225225
i.kind == ty::AssocKind::Fn
226226
&& i.fn_has_self_parameter
227-
&& cx.tcx.fn_sig(i.def_id).inputs().skip_binder().len() == 1
227+
&& cx.tcx.bound_fn_sig(i.def_id).skip_binder().inputs().skip_binder().len() == 1
228228
});
229229

230230
if !is_empty_method_found {
@@ -342,7 +342,7 @@ fn check_for_is_empty<'tcx>(
342342
),
343343
Some(is_empty)
344344
if !(is_empty.fn_has_self_parameter
345-
&& check_is_empty_sig(cx.tcx.fn_sig(is_empty.def_id).skip_binder(), self_kind, output)) =>
345+
&& check_is_empty_sig(cx.tcx.bound_fn_sig(is_empty.def_id).subst_identity().skip_binder(), self_kind, output)) =>
346346
{
347347
(
348348
format!(
@@ -473,7 +473,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
473473
/// Gets an `AssocItem` and return true if it matches `is_empty(self)`.
474474
fn is_is_empty(cx: &LateContext<'_>, item: &ty::AssocItem) -> bool {
475475
if item.kind == ty::AssocKind::Fn {
476-
let sig = cx.tcx.fn_sig(item.def_id);
476+
let sig = cx.tcx.bound_fn_sig(item.def_id).skip_binder();
477477
let ty = sig.skip_binder();
478478
ty.inputs().len() == 1
479479
} else {

clippy_lints/src/loops/needless_range_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
370370
ExprKind::MethodCall(_, receiver, args, _) => {
371371
let def_id = self.cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();
372372
for (ty, expr) in iter::zip(
373-
self.cx.tcx.fn_sig(def_id).inputs().skip_binder(),
373+
self.cx.tcx.bound_fn_sig(def_id).subst_identity().inputs().skip_binder(),
374374
std::iter::once(receiver).chain(args.iter()),
375375
) {
376376
self.prefer_mutable = false;

clippy_lints/src/map_unit_fn.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ fn is_unit_function(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
104104
let ty = cx.typeck_results().expr_ty(expr);
105105

106106
if let ty::FnDef(id, _) = *ty.kind() {
107-
if let Some(fn_type) = cx.tcx.fn_sig(id).no_bound_vars() {
107+
if let Some(fn_type) = cx.tcx.bound_fn_sig(id).subst_identity().no_bound_vars() {
108108
return is_unit_type(fn_type.output());
109109
}
110110
}

0 commit comments

Comments
 (0)