Skip to content

Commit c34e3f0

Browse files
matthewjaspercamelid
authored andcommitted
Update clippy for associated item changes
1 parent d7a6033 commit c34e3f0

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

clippy_lints/src/len_zero.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
214214
{
215215
let mut current_and_super_traits = DefIdSet::default();
216216
fill_trait_set(visited_trait.def_id.to_def_id(), &mut current_and_super_traits, cx);
217+
let is_empty = sym!(is_empty);
217218

218219
let is_empty_method_found = current_and_super_traits
219220
.iter()
220-
.flat_map(|&i| cx.tcx.associated_items(i).in_definition_order())
221+
.flat_map(|&i| cx.tcx.associated_items(i).filter_by_name_unhygienic(is_empty))
221222
.any(|i| {
222223
i.kind == ty::AssocKind::Fn
223224
&& i.fn_has_self_parameter
224-
&& i.ident.name == sym!(is_empty)
225225
&& cx.tcx.fn_sig(i.def_id).inputs().skip_binder().len() == 1
226226
});
227227

@@ -458,7 +458,7 @@ fn is_empty_array(expr: &Expr<'_>) -> bool {
458458
fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
459459
/// Gets an `AssocItem` and return true if it matches `is_empty(self)`.
460460
fn is_is_empty(cx: &LateContext<'_>, item: &ty::AssocItem) -> bool {
461-
if item.kind == ty::AssocKind::Fn && item.ident.name.as_str() == "is_empty" {
461+
if item.kind == ty::AssocKind::Fn {
462462
let sig = cx.tcx.fn_sig(item.def_id);
463463
let ty = sig.skip_binder();
464464
ty.inputs().len() == 1
@@ -469,20 +469,22 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
469469

470470
/// Checks the inherent impl's items for an `is_empty(self)` method.
471471
fn has_is_empty_impl(cx: &LateContext<'_>, id: DefId) -> bool {
472+
let is_empty = sym!(is_empty);
472473
cx.tcx.inherent_impls(id).iter().any(|imp| {
473474
cx.tcx
474475
.associated_items(*imp)
475-
.in_definition_order()
476+
.filter_by_name_unhygienic(is_empty)
476477
.any(|item| is_is_empty(cx, item))
477478
})
478479
}
479480

480481
let ty = &cx.typeck_results().expr_ty(expr).peel_refs();
481482
match ty.kind() {
482483
ty::Dynamic(tt, ..) => tt.principal().map_or(false, |principal| {
484+
let is_empty = sym!(is_empty);
483485
cx.tcx
484486
.associated_items(principal.def_id())
485-
.in_definition_order()
487+
.filter_by_name_unhygienic(is_empty)
486488
.any(|item| is_is_empty(cx, item))
487489
}),
488490
ty::Projection(ref proj) => has_is_empty_impl(cx, proj.item_def_id),

clippy_lints/src/non_copy_const.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ use rustc_hir::def_id::DefId;
1212
use rustc_hir::{
1313
BodyId, Expr, ExprKind, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, Node, TraitItem, TraitItemKind, UnOp,
1414
};
15-
use rustc_infer::traits::specialization_graph;
1615
use rustc_lint::{LateContext, LateLintPass, Lint};
1716
use rustc_middle::mir::interpret::{ConstValue, ErrorHandled};
1817
use rustc_middle::ty::adjustment::Adjust;
19-
use rustc_middle::ty::{self, AssocKind, Const, Ty};
18+
use rustc_middle::ty::{self, Const, Ty};
2019
use rustc_session::{declare_lint_pass, declare_tool_lint};
2120
use rustc_span::{InnerSpan, Span, DUMMY_SP};
2221
use rustc_typeck::hir_ty_to_ty;
@@ -293,8 +292,10 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
293292
// Lint a trait impl item only when the definition is a generic type,
294293
// assuming an assoc const is not meant to be an interior mutable type.
295294
if let Some(of_trait_def_id) = of_trait_ref.trait_def_id();
296-
if let Some(of_assoc_item) = specialization_graph::Node::Trait(of_trait_def_id)
297-
.item(cx.tcx, impl_item.ident, AssocKind::Const, of_trait_def_id);
295+
if let Some(of_assoc_item) = cx
296+
.tcx
297+
.associated_item(impl_item.def_id)
298+
.trait_item_def_id;
298299
if cx
299300
.tcx
300301
.layout_of(cx.tcx.param_env(of_trait_def_id).and(
@@ -303,7 +304,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
303304
// and, in that case, the definition is *not* generic.
304305
cx.tcx.normalize_erasing_regions(
305306
cx.tcx.param_env(of_trait_def_id),
306-
cx.tcx.type_of(of_assoc_item.def_id),
307+
cx.tcx.type_of(of_assoc_item),
307308
),
308309
))
309310
.is_err();

clippy_lints/src/use_self.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_hir::{
1313
};
1414
use rustc_lint::{LateContext, LateLintPass, LintContext};
1515
use rustc_middle::hir::map::Map;
16-
use rustc_middle::ty::AssocKind;
1716
use rustc_semver::RustcVersion;
1817
use rustc_session::{declare_tool_lint, impl_lint_pass};
1918
use rustc_span::Span;
@@ -143,10 +142,10 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
143142
// trait, not in the impl of the trait.
144143
let trait_method = cx
145144
.tcx
146-
.associated_items(impl_trait_ref.def_id)
147-
.find_by_name_and_kind(cx.tcx, impl_item.ident, AssocKind::Fn, impl_trait_ref.def_id)
145+
.associated_item(impl_item.def_id)
146+
.trait_item_def_id
148147
.expect("impl method matches a trait method");
149-
let trait_method_sig = cx.tcx.fn_sig(trait_method.def_id);
148+
let trait_method_sig = cx.tcx.fn_sig(trait_method);
150149
let trait_method_sig = cx.tcx.erase_late_bound_regions(trait_method_sig);
151150

152151
// `impl_inputs_outputs` is an iterator over the types (`hir::Ty`) declared in the

0 commit comments

Comments
 (0)