-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #7002 - mgacek8:issue6983_wrong_self_convention_inside_…
…trait_impls, r=phansch wrong_self_convention: fix FP inside trait impl for `to_*` method taking `&self` fixes #6983 changelog: `wrong_self_convention`: fix FP inside trait impl for `to_*` method taking `&self`
- Loading branch information
Showing
6 changed files
with
81 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// edition:2018 | ||
#![warn(clippy::wrong_self_convention)] | ||
#![warn(clippy::wrong_pub_self_convention)] | ||
#![allow(dead_code)] | ||
|
||
fn main() {} | ||
|
||
mod issue6983 { | ||
pub struct Thing; | ||
pub trait Trait { | ||
fn to_thing(&self) -> Thing; | ||
} | ||
|
||
impl Trait for u8 { | ||
// don't trigger, e.g. `ToString` from `std` requires `&self` | ||
fn to_thing(&self) -> Thing { | ||
Thing | ||
} | ||
} | ||
|
||
trait ToU64 { | ||
fn to_u64(self) -> u64; | ||
} | ||
|
||
struct FooNoCopy; | ||
// trigger lint | ||
impl ToU64 for FooNoCopy { | ||
fn to_u64(self) -> u64 { | ||
2 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error: methods with the following characteristics: (`to_*` and `self` type is not `Copy`) usually take `self` by reference | ||
--> $DIR/wrong_self_convention2.rs:28:19 | ||
| | ||
LL | fn to_u64(self) -> u64 { | ||
| ^^^^ | ||
| | ||
= note: `-D clippy::wrong-self-convention` implied by `-D warnings` | ||
= help: consider choosing a less ambiguous name | ||
|
||
error: aborting due to previous error | ||
|