Auto merge of #11452 - y21:issue11165, r=Centri3

[`len_without_is_empty`]: follow type alias to find inherent `is_empty` method

Fixes #11165

When we see an `impl B` and `B` is a type alias to some type `A`, then we need to follow the type alias to look for an `is_empty` method on the aliased type `A`. Before this PR, it'd get the inherent impls of `B`, which there aren't any and so it would warn that there isn't an `is_empty` method even if there was one.
Passing the type alias `DefId` to `TyCtxt::type_of` gives us the aliased `DefId` (or simply return the type itself if it wasn't a type alias) so we can just use that

changelog: [`len_without_is_empty`]: follow type alias to find inherent `is_empty` method
This commit is contained in:
bors 2023-09-13 23:46:27 +00:00
commit 2009b58df2
3 changed files with 38 additions and 1 deletions

View file

@ -424,6 +424,14 @@ fn check_for_is_empty(
item_name: Symbol,
item_kind: &str,
) {
// Implementor may be a type alias, in which case we need to get the `DefId` of the aliased type to
// find the correct inherent impls.
let impl_ty = if let Some(adt) = cx.tcx.type_of(impl_ty).skip_binder().ty_adt_def() {
adt.did()
} else {
return;
};
let is_empty = Symbol::intern("is_empty");
let is_empty = cx
.tcx