Skip to content

Commit c456b9e

Browse files
committed
Add tests for unsized trait in wrong_self_convention lint
1 parent 1e0f85b commit c456b9e

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

tests/ui/wrong_self_convention.rs

+23
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,27 @@ mod issue6307 {
113113
fn from_(self) {}
114114
fn to_mut(&mut self) {}
115115
}
116+
117+
trait U {
118+
fn as_i32(self);
119+
fn as_u32(&self);
120+
fn into_i32(&self);
121+
fn into_u32(self);
122+
fn is_i32(self);
123+
fn is_u32(&self);
124+
fn to_i32(self);
125+
fn to_u32(&self);
126+
fn from_i32(self);
127+
// check whether the lint can be allowed at the function level
128+
#[allow(clippy::wrong_self_convention)]
129+
fn from_cake(self);
130+
131+
// test for false positives
132+
fn as_(self);
133+
fn into_(&self);
134+
fn is_(self);
135+
fn to_(self);
136+
fn from_(self);
137+
fn to_mut(&mut self);
138+
}
116139
}

tests/ui/wrong_self_convention.stderr

+31-1
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,35 @@ error: methods called `from_*` usually take no self; consider choosing a less am
102102
LL | fn from_i32(self) {}
103103
| ^^^^
104104

105-
error: aborting due to 17 previous errors
105+
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
107+
|
108+
LL | fn as_i32(self);
109+
| ^^^^
110+
111+
error: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
112+
--> $DIR/wrong_self_convention.rs:120:21
113+
|
114+
LL | fn into_i32(&self);
115+
| ^^^^^
116+
117+
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
119+
|
120+
LL | fn is_i32(self);
121+
| ^^^^
122+
123+
error: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name
124+
--> $DIR/wrong_self_convention.rs:124:19
125+
|
126+
LL | fn to_i32(self);
127+
| ^^^^
128+
129+
error: methods called `from_*` usually take no self; consider choosing a less ambiguous name
130+
--> $DIR/wrong_self_convention.rs:126:21
131+
|
132+
LL | fn from_i32(self);
133+
| ^^^^
134+
135+
error: aborting due to 22 previous errors
106136

0 commit comments

Comments
 (0)