Skip to content

Commit 87582dc

Browse files
committed
fix: use fn_arg_idents() instead of fn_arg_names()
The method got renamed, it took me _way_ too long to figure that out. I ended up removing it entirely in `borrowed_reborrowable` since we already have access to the argument names through the function body. (This was before I realized `fn_arg_names()` wasn't just outright deleted.) rust-lang/rust#139510
1 parent 3a08528 commit 87582dc

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

bevy_lint/src/lints/pedantic/borrowed_reborrowable.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ use clippy_utils::{
105105
source::{snippet, snippet_opt},
106106
};
107107
use rustc_errors::Applicability;
108-
use rustc_hir::{Body, FnDecl, MutTy, Mutability, intravisit::FnKind};
108+
use rustc_hir::{Body, FnDecl, MutTy, Mutability, PatKind, intravisit::FnKind};
109109
use rustc_lint::{LateContext, LateLintPass};
110110
use rustc_middle::ty::{Ty, TyKind, TypeVisitable, TypeVisitor};
111-
use rustc_span::{Span, def_id::LocalDefId, symbol::kw};
111+
use rustc_span::{Span, def_id::LocalDefId, kw};
112112
use rustc_type_ir::Interner;
113113

114114
declare_bevy_lint! {
@@ -145,16 +145,9 @@ impl<'tcx> LateLintPass<'tcx> for BorrowedReborrowable {
145145

146146
// A list of argument types, used in the actual lint check.
147147
let arg_types = fn_sig.inputs().skip_binder();
148-
// A list of argument names, used to check and skip `&mut self`.
149-
let arg_names = cx.tcx.fn_arg_names(def_id);
150148
// A list of argument parameters, used to find the span of arguments.
151149
let arg_params = body.params;
152150

153-
debug_assert_eq!(
154-
arg_types.len(),
155-
arg_names.len(),
156-
"there must be the same number of argument types and names"
157-
);
158151
debug_assert_eq!(
159152
arg_types.len(),
160153
arg_params.len(),
@@ -167,14 +160,13 @@ impl<'tcx> LateLintPass<'tcx> for BorrowedReborrowable {
167160
continue;
168161
};
169162

170-
// This lint would emit a warning on `&mut self` if `self` was reborrowable. This isn't
171-
// useful, though, because it would hurt the ergonomics of using methods of
172-
// reborrowable types.
173-
//
174-
// To avoid this, we skip any parameter named `self`. This won't false-positive on
175-
// other function arguments named `self`, since it is a special keyword that is
176-
// disallowed in other positions.
177-
if arg_names[arg_index].is_some_and(|ident| ident.name == kw::SelfLower) {
163+
// If the argument is named `self`, skip it. Without this check the lint would be
164+
// emitted for `&mut self` if `self` was reborrowable, which isn't wanted! That would
165+
// just be annoying for engine developers trying to add useful methods to reborrowable
166+
// types.
167+
if let PatKind::Binding(_, _, ident, _) = body.params[arg_index].pat.kind
168+
&& ident.name == kw::SelfLower
169+
{
178170
continue;
179171
}
180172

bevy_lint/src/utils/hir_parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl<'tcx> MethodCall<'tcx> {
238238
// ```
239239
if let Res::Def(DefKind::AssocFn, def_id) = cx.qpath_res(qpath, path.hir_id) {
240240
// Retrieve the identifiers for all the arguments to this function.
241-
let inputs = cx.tcx.fn_arg_names(def_id);
241+
let inputs = cx.tcx.fn_arg_idents(def_id);
242242

243243
// If the name of the first argument is `self`, then it *must* be a method.
244244
// `self` is a reserved keyword, and cannot be used as a general function

0 commit comments

Comments
 (0)