Skip to content

Commit a02806e

Browse files
committed
Auto merge of rust-lang#6518 - ThibsG:CopyException, r=ebroto
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
2 parents 592f7eb + af480a6 commit a02806e

File tree

2 files changed

+54
-16
lines changed

2 files changed

+54
-16
lines changed

tests/ui/wrong_self_convention.rs

+28-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ mod issue6307 {
9494
trait T: Sized {
9595
fn as_i32(self) {}
9696
fn as_u32(&self) {}
97-
fn into_i32(&self) {}
97+
fn into_i32(self) {}
98+
fn into_i32_ref(&self) {}
9899
fn into_u32(self) {}
99100
fn is_i32(self) {}
100101
fn is_u32(&self) {}
@@ -117,7 +118,32 @@ mod issue6307 {
117118
trait U {
118119
fn as_i32(self);
119120
fn as_u32(&self);
120-
fn into_i32(&self);
121+
fn into_i32(self);
122+
fn into_i32_ref(&self);
123+
fn into_u32(self);
124+
fn is_i32(self);
125+
fn is_u32(&self);
126+
fn to_i32(self);
127+
fn to_u32(&self);
128+
fn from_i32(self);
129+
// check whether the lint can be allowed at the function level
130+
#[allow(clippy::wrong_self_convention)]
131+
fn from_cake(self);
132+
133+
// test for false positives
134+
fn as_(self);
135+
fn into_(&self);
136+
fn is_(self);
137+
fn to_(self);
138+
fn from_(self);
139+
fn to_mut(&mut self);
140+
}
141+
142+
trait C: Copy {
143+
fn as_i32(self);
144+
fn as_u32(&self);
145+
fn into_i32(self);
146+
fn into_i32_ref(&self);
121147
fn into_u32(self);
122148
fn is_i32(self);
123149
fn is_u32(&self);

tests/ui/wrong_self_convention.stderr

+26-14
Original file line numberDiff line numberDiff line change
@@ -79,58 +79,70 @@ LL | fn as_i32(self) {}
7979
| ^^^^
8080

8181
error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
82-
--> $DIR/wrong_self_convention.rs:97:21
82+
--> $DIR/wrong_self_convention.rs:98:25
8383
|
84-
LL | fn into_i32(&self) {}
85-
| ^^^^^
84+
LL | fn into_i32_ref(&self) {}
85+
| ^^^^^
8686

8787
error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name
88-
--> $DIR/wrong_self_convention.rs:99:19
88+
--> $DIR/wrong_self_convention.rs:100:19
8989
|
9090
LL | fn is_i32(self) {}
9191
| ^^^^
9292

9393
error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name
94-
--> $DIR/wrong_self_convention.rs:101:19
94+
--> $DIR/wrong_self_convention.rs:102:19
9595
|
9696
LL | fn to_i32(self) {}
9797
| ^^^^
9898

9999
error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
100-
--> $DIR/wrong_self_convention.rs:103:21
100+
--> $DIR/wrong_self_convention.rs:104:21
101101
|
102102
LL | fn from_i32(self) {}
103103
| ^^^^
104104

105105
error: methods called `as_*` usually take self by reference or self by mutable reference; consider choosing a less ambiguous name
106-
--> $DIR/wrong_self_convention.rs:118:19
106+
--> $DIR/wrong_self_convention.rs:119:19
107107
|
108108
LL | fn as_i32(self);
109109
| ^^^^
110110

111111
error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
112-
--> $DIR/wrong_self_convention.rs:120:21
112+
--> $DIR/wrong_self_convention.rs:122:25
113113
|
114-
LL | fn into_i32(&self);
115-
| ^^^^^
114+
LL | fn into_i32_ref(&self);
115+
| ^^^^^
116116

117117
error: methods called `is_*` usually take self by reference or no self; consider choosing a less ambiguous name
118-
--> $DIR/wrong_self_convention.rs:122:19
118+
--> $DIR/wrong_self_convention.rs:124:19
119119
|
120120
LL | fn is_i32(self);
121121
| ^^^^
122122

123123
error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name
124-
--> $DIR/wrong_self_convention.rs:124:19
124+
--> $DIR/wrong_self_convention.rs:126:19
125125
|
126126
LL | fn to_i32(self);
127127
| ^^^^
128128

129129
error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
130-
--> $DIR/wrong_self_convention.rs:126:21
130+
--> $DIR/wrong_self_convention.rs:128:21
131+
|
132+
LL | fn from_i32(self);
133+
| ^^^^
134+
135+
error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
136+
--> $DIR/wrong_self_convention.rs:146:25
137+
|
138+
LL | fn into_i32_ref(&self);
139+
| ^^^^^
140+
141+
error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
142+
--> $DIR/wrong_self_convention.rs:152:21
131143
|
132144
LL | fn from_i32(self);
133145
| ^^^^
134146

135-
error: aborting due to 22 previous errors
147+
error: aborting due to 24 previous errors
136148

0 commit comments

Comments
 (0)