Skip to content

Commit

Permalink
Auto merge of rust-lang#6518 - ThibsG:CopyException, r=ebroto
Browse files Browse the repository at this point in the history
Ensure `Copy` exception in trait definition for `wrong_self_conventio…

Add a test case to ensure `Copy` exception is preserved also in trait definition, when passing `self` by value.

Follow up of rust-lang#6316

changelog: none
  • Loading branch information
bors committed Jan 2, 2021
2 parents 592f7eb + af480a6 commit a02806e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 16 deletions.
30 changes: 28 additions & 2 deletions tests/ui/wrong_self_convention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ mod issue6307 {
trait T: Sized {
fn as_i32(self) {}
fn as_u32(&self) {}
fn into_i32(&self) {}
fn into_i32(self) {}
fn into_i32_ref(&self) {}
fn into_u32(self) {}
fn is_i32(self) {}
fn is_u32(&self) {}
Expand All @@ -117,7 +118,32 @@ mod issue6307 {
trait U {
fn as_i32(self);
fn as_u32(&self);
fn into_i32(&self);
fn into_i32(self);
fn into_i32_ref(&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);
}

trait C: Copy {
fn as_i32(self);
fn as_u32(&self);
fn into_i32(self);
fn into_i32_ref(&self);
fn into_u32(self);
fn is_i32(self);
fn is_u32(&self);
Expand Down
40 changes: 26 additions & 14 deletions tests/ui/wrong_self_convention.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -79,58 +79,70 @@ 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:97:21
--> $DIR/wrong_self_convention.rs:98:25
|
LL | fn into_i32(&self) {}
| ^^^^^
LL | fn into_i32_ref(&self) {}
| ^^^^^

error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:99:19
--> $DIR/wrong_self_convention.rs:100: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:101:19
--> $DIR/wrong_self_convention.rs:102: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:103:21
--> $DIR/wrong_self_convention.rs:104:21
|
LL | fn from_i32(self) {}
| ^^^^

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
--> $DIR/wrong_self_convention.rs:119: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
--> $DIR/wrong_self_convention.rs:122:25
|
LL | fn into_i32(&self);
| ^^^^^
LL | fn into_i32_ref(&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
--> $DIR/wrong_self_convention.rs:124: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
--> $DIR/wrong_self_convention.rs:126: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
--> $DIR/wrong_self_convention.rs:128:21
|
LL | fn from_i32(self);
| ^^^^

error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:146:25
|
LL | fn into_i32_ref(&self);
| ^^^^^

error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
--> $DIR/wrong_self_convention.rs:152:21
|
LL | fn from_i32(self);
| ^^^^

error: aborting due to 22 previous errors
error: aborting due to 24 previous errors

0 comments on commit a02806e

Please sign in to comment.