wrong_self_convention: For to_* variant don't lint in trait impl taking self when non-Copy type
It relaxes rules for `to_*` variant, so it doesn't lint in trait definitions and implementations anymore. Although, non-`Copy` type implementing trait's `to_*` method taking `self` feels not good (consumes ownership, so should be rather named `into_`), it would be better if this case was a pedantic lint (allow-by-default) instead.
This commit is contained in:
parent
f3a0ac1f4b
commit
ab3094b3db
3 changed files with 2 additions and 13 deletions
|
|
@ -22,7 +22,7 @@ const CONVENTIONS: [(&[Convention], &[SelfKind]); 9] = [
|
|||
// Conversion using `to_` can use borrowed (non-Copy types) or owned (Copy types).
|
||||
// Source: https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv
|
||||
(&[Convention::StartsWith("to_"), Convention::NotEndsWith("_mut"), Convention::IsSelfTypeCopy(false),
|
||||
Convention::IsTraitItem(false)], &[SelfKind::Ref]),
|
||||
Convention::IsTraitItem(false), Convention::ImplementsTrait(false)], &[SelfKind::Ref]),
|
||||
(&[Convention::StartsWith("to_"), Convention::NotEndsWith("_mut"), Convention::IsSelfTypeCopy(true),
|
||||
Convention::IsTraitItem(false), Convention::ImplementsTrait(false)], &[SelfKind::Value]),
|
||||
];
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ mod issue6983 {
|
|||
}
|
||||
|
||||
struct FooNoCopy;
|
||||
// trigger lint
|
||||
// don't trigger
|
||||
impl ToU64 for FooNoCopy {
|
||||
fn to_u64(self) -> u64 {
|
||||
2
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue