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 does not recognize this: Self #3414

Closed
yvt opened this issue Nov 5, 2018 · 0 comments · Fixed by #7678
Closed

wrong_self_convention does not recognize this: Self #3414

yvt opened this issue Nov 5, 2018 · 0 comments · Fixed by #7678

Comments

@yvt
Copy link

yvt commented Nov 5, 2018

The following code triggers wrong_self_convention:

struct CellLikeThing<T>(T);

impl<T> CellLikeThing<T> {
    fn into_inner(this: Self) -> T {     // <------ here
        this.0
    }
}

impl<T> std::ops::Deref for CellLikeThing<T> {
    type Target = T;

    fn deref(&self) -> &T {
        &self.0
    }
}
warning: methods called `into_*` usually take self by value; consider choosing a less ambiguous name
 --> src/main.rs:4:19
  |
4 |     fn into_inner(this: Self) -> T {
  |                   ^^^^
  |
  = note: #[warn(clippy::wrong_self_convention)] on by default
  = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.212/index.html#wrong_self_convention

(Playground)

Receiving Self via a this: Self parameter to avoid method name collisions is an idiomatic pattern for implementing methods on a smart pointer-like type, as exemplified by std::rc::Rc::into_raw.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant