Add tests for unsized trait in wrong_self_convention lint

This commit is contained in:
ThibsG 2020-12-10 17:00:55 +01:00
parent 1e0f85b264
commit 90a16e4397
3 changed files with 55 additions and 2 deletions

View File

@ -71,7 +71,7 @@ mod lifetimes {
mod issue2894 {
trait IntoBytes {
#[allow(clippy::clippy::wrong_self_convention)]
#[allow(clippy::wrong_self_convention)]
fn into_bytes(&self) -> Vec<u8>;
}

View File

@ -113,4 +113,27 @@ fn to_(self) {}
fn from_(self) {}
fn to_mut(&mut self) {}
}
trait U {
fn as_i32(self);
fn as_u32(&self);
fn into_i32(&self);
fn into_u32(self);
fn is_i32(self);
fn is_u32(&self);
fn to_i32(self);
fn to_u32(&self);
fn from_i32(self);
// check whether the lint can be allowed at the function level
#[allow(clippy::wrong_self_convention)]
fn from_cake(self);
// test for false positives
fn as_(self);
fn into_(&self);
fn is_(self);
fn to_(self);
fn from_(self);
fn to_mut(&mut self);
}
}

View File

@ -102,5 +102,35 @@ error: methods called `from_*` usually take no self; consider choosing a less am
LL | fn from_i32(self) {}
| ^^^^
error: aborting due to 17 previous errors
error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:118:19
|
LL | fn as_i32(self);
| ^^^^
error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:120:21
|
LL | fn into_i32(&self);
| ^^^^^
error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:122:19
|
LL | fn is_i32(self);
| ^^^^
error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:124:19
|
LL | fn to_i32(self);
| ^^^^
error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:126:21
|
LL | fn from_i32(self);
| ^^^^
error: aborting due to 22 previous errors