-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wrong_self_convention: to_
convention respects Copy
types
#6924
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,13 +75,13 @@ mod lifetimes { | |
|
||
mod issue2894 { | ||
trait IntoBytes { | ||
fn to_bytes(&self) -> Vec<u8>; | ||
fn to_bytes(self) -> Vec<u8>; | ||
} | ||
|
||
// This should not be linted | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this comment is correct, then why the |
||
impl IntoBytes for u8 { | ||
fn to_bytes(&self) -> Vec<u8> { | ||
vec![*self] | ||
fn to_bytes(self) -> Vec<u8> { | ||
vec![self] | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,13 +75,13 @@ mod lifetimes { | |
|
||
mod issue2894 { | ||
trait IntoBytes { | ||
fn to_bytes(&self) -> Vec<u8>; | ||
fn to_bytes(self) -> Vec<u8>; | ||
} | ||
|
||
// This should not be linted | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. I get that it's probably a different lint that should not trigger, but it still feels wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the comment says that |
||
impl IntoBytes for u8 { | ||
fn to_bytes(&self) -> Vec<u8> { | ||
vec![*self] | ||
fn to_bytes(self) -> Vec<u8> { | ||
vec![self] | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ LL | fn is_i32(self) {} | |
| | ||
= help: consider choosing a less ambiguous name | ||
|
||
error: methods called `to_*` usually take self by reference | ||
error: methods with the following characteristics: (`to_*` and `self type is not Copy`) usually take self by reference | ||
--> $DIR/wrong_self_convention.rs:42:15 | ||
| | ||
LL | fn to_i32(self) {} | ||
|
@@ -79,7 +79,7 @@ LL | pub fn is_i64(self) {} | |
| | ||
= help: consider choosing a less ambiguous name | ||
|
||
error: methods called `to_*` usually take self by reference | ||
error: methods with the following characteristics: (`to_*` and `self type is not Copy`) usually take self by reference | ||
--> $DIR/wrong_self_convention.rs:49:19 | ||
| | ||
LL | pub fn to_i64(self) {} | ||
|
@@ -119,14 +119,6 @@ LL | fn is_i32(self) {} | |
| | ||
= help: consider choosing a less ambiguous name | ||
|
||
error: methods called `to_*` usually take self by reference | ||
--> $DIR/wrong_self_convention.rs:102:19 | ||
| | ||
LL | fn to_i32(self) {} | ||
| ^^^^ | ||
| | ||
= help: consider choosing a less ambiguous name | ||
|
||
error: methods called `from_*` usually take no self | ||
--> $DIR/wrong_self_convention.rs:104:21 | ||
| | ||
|
@@ -159,14 +151,6 @@ LL | fn is_i32(self); | |
| | ||
= help: consider choosing a less ambiguous name | ||
|
||
error: methods called `to_*` usually take self by reference | ||
--> $DIR/wrong_self_convention.rs:126:19 | ||
| | ||
LL | fn to_i32(self); | ||
| ^^^^ | ||
| | ||
= help: consider choosing a less ambiguous name | ||
|
||
error: methods called `from_*` usually take no self | ||
--> $DIR/wrong_self_convention.rs:128:21 | ||
| | ||
|
@@ -191,5 +175,21 @@ LL | fn from_i32(self); | |
| | ||
= help: consider choosing a less ambiguous name | ||
|
||
error: methods with the following characteristics: (`to_*` and `self type is Copy`) usually take self by value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking once more at the resulting error message, this gave me pause: "`self type is Copy`" should probably read "`self` type is `Copy`" (note the double space and the backticks). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, thanks! |
||
--> $DIR/wrong_self_convention.rs:181:22 | ||
| | ||
LL | fn to_u64_v2(&self) -> u64 { | ||
| ^^^^^ | ||
| | ||
= help: consider choosing a less ambiguous name | ||
|
||
error: methods with the following characteristics: (`to_*` and `self type is not Copy`) usually take self by reference | ||
--> $DIR/wrong_self_convention.rs:190:19 | ||
| | ||
LL | fn to_u64(self) -> u64 { | ||
| ^^^^ | ||
| | ||
= help: consider choosing a less ambiguous name | ||
|
||
error: aborting due to 24 previous errors | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if it wouldn't be more clear to have
n/a
instead ofnone
where the Postfix doesn't matter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally don't think an abbreviation of "not applicable" is clearer than "none" when there is no suffix, but that may be my dislike of needless abbreviations.