You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::rc::Rc;traitFoo{}structBar{}implFooforBar{}fnfoo(x:Rc<Foo>){}fnmain(){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>`
The text was updated successfully, but these errors were encountered:
Given the following code:
cargo clippy
gives a warning against using '.clone()' on a ref-counted pointer and suggestsRc::clone(&x)
. However the latter will not compile:The text was updated successfully, but these errors were encountered: