Skip to content

Commit

Permalink
Add tests for unsized trait in wrong_self_convention lint
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibsG committed Dec 10, 2020
1 parent 1e0f85b commit 90a16e4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/ui/use_self.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
}

Expand Down
23 changes: 23 additions & 0 deletions tests/ui/wrong_self_convention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,27 @@ mod issue6307 {
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);
}
}
32 changes: 31 additions & 1 deletion tests/ui/wrong_self_convention.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 90a16e4

Please sign in to comment.