Skip to content

Commit 9e5f23e

Browse files
matthewjaspercamelid
authored andcommitted
Update clippy for associated item changes
1 parent 3b7d496 commit 9e5f23e

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

src/test/ui/span/impl-wrong-item-for-trait.stderr

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ error[E0437]: type `bar` is not a member of trait `Foo`
44
LL | type bar = u64;
55
| ^^^^^^^^^^^^^^^ not a member of trait `Foo`
66

7+
error[E0324]: item `MY_CONST` is an associated method, which doesn't match its trait `Foo`
8+
--> $DIR/impl-wrong-item-for-trait.rs:22:5
9+
|
10+
LL | const MY_CONST: u32;
11+
| -------------------- item in trait
12+
...
13+
LL | fn MY_CONST() {}
14+
| ^^^^^^^^^^^^^^^^ does not match trait
15+
716
error[E0323]: item `bar` is an associated const, which doesn't match its trait `Foo`
817
--> $DIR/impl-wrong-item-for-trait.rs:12:5
918
|
@@ -13,6 +22,15 @@ LL | fn bar(&self);
1322
LL | const bar: u64 = 1;
1423
| ^^^^^^^^^^^^^^^^^^^ does not match trait
1524

25+
error[E0325]: item `bar` is an associated type, which doesn't match its trait `Foo`
26+
--> $DIR/impl-wrong-item-for-trait.rs:30:5
27+
|
28+
LL | fn bar(&self);
29+
| -------------- item in trait
30+
...
31+
LL | type bar = u64;
32+
| ^^^^^^^^^^^^^^^ does not match trait
33+
1634
error[E0046]: not all trait items implemented, missing: `bar`
1735
--> $DIR/impl-wrong-item-for-trait.rs:10:1
1836
|
@@ -22,15 +40,6 @@ LL | fn bar(&self);
2240
LL | impl Foo for FooConstForMethod {
2341
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `bar` in implementation
2442

25-
error[E0324]: item `MY_CONST` is an associated method, which doesn't match its trait `Foo`
26-
--> $DIR/impl-wrong-item-for-trait.rs:22:5
27-
|
28-
LL | const MY_CONST: u32;
29-
| -------------------- item in trait
30-
...
31-
LL | fn MY_CONST() {}
32-
| ^^^^^^^^^^^^^^^^ does not match trait
33-
3443
error[E0046]: not all trait items implemented, missing: `MY_CONST`
3544
--> $DIR/impl-wrong-item-for-trait.rs:19:1
3645
|
@@ -40,15 +49,6 @@ LL | const MY_CONST: u32;
4049
LL | impl Foo for FooMethodForConst {
4150
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `MY_CONST` in implementation
4251

43-
error[E0325]: item `bar` is an associated type, which doesn't match its trait `Foo`
44-
--> $DIR/impl-wrong-item-for-trait.rs:30:5
45-
|
46-
LL | fn bar(&self);
47-
| -------------- item in trait
48-
...
49-
LL | type bar = u64;
50-
| ^^^^^^^^^^^^^^^ does not match trait
51-
5252
error[E0046]: not all trait items implemented, missing: `bar`
5353
--> $DIR/impl-wrong-item-for-trait.rs:28:1
5454
|

src/tools/clippy/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),

src/tools/clippy/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();

src/tools/clippy/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)