mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
[len_without_is_empty
]: follow type alias
This commit is contained in:
parent
b9906aca5a
commit
26c0f97579
3 changed files with 38 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -436,4 +436,27 @@ impl DifferingErrors {
|
|||
}
|
||||
}
|
||||
|
||||
// Issue #11165
|
||||
pub struct Aliased1;
|
||||
pub type Alias1 = Aliased1;
|
||||
|
||||
impl Alias1 {
|
||||
pub fn len(&self) -> usize {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Aliased2;
|
||||
pub type Alias2 = Aliased2;
|
||||
impl Alias2 {
|
||||
pub fn len(&self) -> usize {
|
||||
//~^ ERROR: type `Alias2` has a public `len` method, but no `is_empty` method
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -139,5 +139,11 @@ error: struct `AsyncResultLenWithoutIsEmpty` has a public `len` method, but no `
|
|||
LL | pub async fn len(&self) -> Result<usize, ()> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 15 previous errors
|
||||
error: type `Alias2` has a public `len` method, but no `is_empty` method
|
||||
--> $DIR/len_without_is_empty.rs:456:5
|
||||
|
|
||||
LL | pub fn len(&self) -> usize {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 16 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue