Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong_self_convention possibly too strict for Copy types #6727

Closed
martin-t opened this issue Feb 12, 2021 · 2 comments · Fixed by #6924
Closed

wrong_self_convention possibly too strict for Copy types #6727

martin-t opened this issue Feb 12, 2021 · 2 comments · Fixed by #6924
Assignees
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy

Comments

@martin-t
Copy link
Contributor

martin-t commented Feb 12, 2021

Lint name: wrong_self_convention

I tried this code:

trait F32Ext {
    fn to_something_else(self) -> f32;
}

I get this:

warning: methods called `to_*` usually take self by reference; consider choosing a less ambiguous name
  --> src/main.rs:66:21
   |
66 |     fn to_some_unit(self) -> f32;
   |                     ^^^^
   |

If this trait is implemented for types such as f32, then i think the to_ prefix makes complete sense - f32 already has methods with that prefix and it makes no sense to take such a small type by reference.

I think this lint should allow to_ on Copy types to take self without reference.

Meta

cargo clippy -V: clippy 0.1.52 (e9920ef 2021-02-11)
rustc -Vv:

rustc 1.52.0-nightly (e9920ef77 2021-02-11)
binary: rustc
commit-hash: e9920ef7749d11fc71cc32ca4ba055bcfeaab945
commit-date: 2021-02-11
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1
@giraffate giraffate added C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy labels Feb 16, 2021
@baumanj
Copy link

baumanj commented Mar 15, 2021

I agree this is a false positive per https://rust-lang.github.io/api-guidelines/naming.html#ad-hoc-conversions-follow-as_-to_-into_-conventions-c-conv. A owned -> owned conversion for Copy should use to, rather than into as the prefix.

@mgacek8
Copy link
Contributor

mgacek8 commented Mar 17, 2021

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: Enhancement of lints, like adding more cases or adding help messages good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants