145 lines
2.4 KiB
Rust
145 lines
2.4 KiB
Rust
#![allow(dead_code, clippy::extra_unused_lifetimes)]
|
|
#![warn(clippy::multiple_inherent_impl)]
|
|
|
|
struct MyStruct;
|
|
|
|
impl MyStruct {
|
|
fn first() {}
|
|
}
|
|
|
|
impl MyStruct {
|
|
//~^ multiple_inherent_impl
|
|
|
|
fn second() {}
|
|
}
|
|
|
|
impl<'a> MyStruct {
|
|
//~^ multiple_inherent_impl
|
|
fn lifetimed() {}
|
|
}
|
|
|
|
mod submod {
|
|
struct MyStruct;
|
|
impl MyStruct {
|
|
fn other() {}
|
|
}
|
|
|
|
impl super::MyStruct {
|
|
//~^ multiple_inherent_impl
|
|
|
|
fn third() {}
|
|
}
|
|
}
|
|
|
|
use std::fmt;
|
|
impl fmt::Debug for MyStruct {
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
write!(f, "MyStruct {{ }}")
|
|
}
|
|
}
|
|
|
|
// issue #5772
|
|
struct WithArgs<T>(T);
|
|
impl WithArgs<u32> {
|
|
fn f1() {}
|
|
}
|
|
impl WithArgs<u64> {
|
|
fn f2() {}
|
|
}
|
|
impl WithArgs<u64> {
|
|
//~^ multiple_inherent_impl
|
|
|
|
fn f3() {}
|
|
}
|
|
|
|
// Ok, the struct is allowed to have multiple impls.
|
|
#[allow(clippy::multiple_inherent_impl)]
|
|
struct Allowed;
|
|
impl Allowed {}
|
|
impl Allowed {}
|
|
impl Allowed {}
|
|
|
|
struct AllowedImpl;
|
|
#[allow(clippy::multiple_inherent_impl)]
|
|
impl AllowedImpl {}
|
|
// Ok, the first block is skipped by this lint.
|
|
impl AllowedImpl {}
|
|
|
|
struct OneAllowedImpl;
|
|
impl OneAllowedImpl {}
|
|
#[allow(clippy::multiple_inherent_impl)]
|
|
impl OneAllowedImpl {}
|
|
impl OneAllowedImpl {}
|
|
//~^ multiple_inherent_impl
|
|
|
|
#[expect(clippy::multiple_inherent_impl)]
|
|
struct ExpectedFulfilled;
|
|
|
|
impl ExpectedFulfilled {}
|
|
impl ExpectedFulfilled {}
|
|
|
|
struct OneExpected;
|
|
impl OneExpected {}
|
|
#[expect(clippy::multiple_inherent_impl)]
|
|
impl OneExpected {}
|
|
impl OneExpected {}
|
|
//~^ multiple_inherent_impl
|
|
|
|
// issue #8714
|
|
struct Lifetime<'s> {
|
|
s: &'s str,
|
|
}
|
|
|
|
impl Lifetime<'_> {}
|
|
impl Lifetime<'_> {}
|
|
//~^ multiple_inherent_impl
|
|
|
|
impl<'a> Lifetime<'a> {}
|
|
impl<'a> Lifetime<'a> {}
|
|
//~^ multiple_inherent_impl
|
|
|
|
impl<'b> Lifetime<'b> {} // false negative?
|
|
|
|
impl Lifetime<'static> {}
|
|
|
|
struct Generic<G> {
|
|
g: Vec<G>,
|
|
}
|
|
|
|
impl<G> Generic<G> {}
|
|
impl<G> Generic<G> {}
|
|
//~^ multiple_inherent_impl
|
|
|
|
use std::fmt::Debug;
|
|
|
|
#[derive(Debug)]
|
|
struct GenericWithBounds<T: Debug>(T);
|
|
|
|
impl<T: Debug> GenericWithBounds<T> {
|
|
fn make_one(_one: T) -> Self {
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
impl<T: Debug> GenericWithBounds<T> {
|
|
//~^ multiple_inherent_impl
|
|
fn make_two(_two: T) -> Self {
|
|
todo!()
|
|
}
|
|
}
|
|
|
|
struct MultipleTraitBounds<T>(T);
|
|
|
|
impl<T: Debug> MultipleTraitBounds<T> {
|
|
fn debug_fn() {}
|
|
}
|
|
|
|
impl<T: Clone> MultipleTraitBounds<T> {
|
|
fn clone_fn() {}
|
|
}
|
|
|
|
impl<T: Debug + Clone> MultipleTraitBounds<T> {
|
|
fn debug_clone_fn() {}
|
|
}
|
|
|
|
fn main() {}
|