Skip to content

Commit

Permalink
Auto merge of #7182 - mgacek8:wrong_self_convention_to__variant, r=fl…
Browse files Browse the repository at this point in the history
…ip1995

For `to_*` variant don't lint in trait impl taking `self` when non-`Copy` type

Lint name: `wrong_self_convention`.
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.
More information in the discussion with `@flip1995` [here](#7002 (comment))

changelog: `wrong_self_convention`: For `to_*` variant don't lint in trait impl taking `self` when non-`Copy` type
r? `@flip1995`
  • Loading branch information
bors committed May 7, 2021
2 parents 1e582c3 + ab3094b commit 4756667
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 4756667

Please sign in to comment.