Skip to content

Do not suggest Rc::clone(x) over x.clone() when x is trait #2174

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

Closed
topecongiro opened this issue Oct 25, 2017 · 2 comments
Closed

Do not suggest Rc::clone(x) over x.clone() when x is trait #2174

topecongiro opened this issue Oct 25, 2017 · 2 comments

Comments

@topecongiro
Copy link
Contributor

Given the following code:

use std::rc::Rc;

trait Foo {}

struct Bar {}

impl Foo for Bar {}

fn foo(x: Rc<Foo>) {}

fn main() {
    let x = Rc::new(Bar{});
    foo(x.clone()); // foo(Rc::clone(&x)) will not work here.
}

cargo clippy gives a warning against using '.clone()' on a ref-counted pointer and suggests Rc::clone(&x). However the latter will not compile:

   |
13 |     foo(Rc::clone(&x));
   |                   ^^ expected trait Foo, found struct `Bar`
   |
   = note: expected type `&std::rc::Rc<Foo>`
              found type `&std::rc::Rc<Bar>`
@oli-obk
Copy link
Contributor

oli-obk commented Oct 25, 2017

Thanks for the bug report. This bug is already tracked under #2048

@oli-obk oli-obk closed this as completed Oct 25, 2017
@topecongiro
Copy link
Contributor Author

Oops, sorry for the noise.

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

No branches or pull requests

2 participants