Skip to content

Commit 4756667

Browse files
committed
Auto merge of #7182 - mgacek8:wrong_self_convention_to__variant, r=flip1995
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`
2 parents 1e582c3 + ab3094b commit 4756667

File tree

3 files changed

+2
-13
lines changed

3 files changed

+2
-13
lines changed

clippy_lints/src/methods/wrong_self_convention.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const CONVENTIONS: [(&[Convention], &[SelfKind]); 9] = [
2222
// Conversion using `to_` can use borrowed (non-Copy types) or owned (Copy types).
2323
// Source: https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv
2424
(&[Convention::StartsWith("to_"), Convention::NotEndsWith("_mut"), Convention::IsSelfTypeCopy(false),
25-
Convention::IsTraitItem(false)], &[SelfKind::Ref]),
25+
Convention::IsTraitItem(false), Convention::ImplementsTrait(false)], &[SelfKind::Ref]),
2626
(&[Convention::StartsWith("to_"), Convention::NotEndsWith("_mut"), Convention::IsSelfTypeCopy(true),
2727
Convention::IsTraitItem(false), Convention::ImplementsTrait(false)], &[SelfKind::Value]),
2828
];

tests/ui/wrong_self_convention2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mod issue6983 {
2323
}
2424

2525
struct FooNoCopy;
26-
// trigger lint
26+
// don't trigger
2727
impl ToU64 for FooNoCopy {
2828
fn to_u64(self) -> u64 {
2929
2

tests/ui/wrong_self_convention2.stderr

-11
This file was deleted.

0 commit comments

Comments
 (0)