Skip to content

Commit

Permalink
wrong_self_convention: For to_* variant don't lint in trait impl ta…
Browse files Browse the repository at this point in the history
…king `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.
  • Loading branch information
mgacek8 committed May 6, 2021
1 parent f3a0ac1 commit ab3094b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 13 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/wrong_self_convention.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
];
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/wrong_self_convention2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mod issue6983 {
}

struct FooNoCopy;
// trigger lint
// don't trigger
impl ToU64 for FooNoCopy {
fn to_u64(self) -> u64 {
2
Expand Down
11 changes: 0 additions & 11 deletions tests/ui/wrong_self_convention2.stderr

This file was deleted.

0 comments on commit ab3094b

Please sign in to comment.