【发布时间】:2018-07-28 19:57:03
【问题描述】:
如何传递对Arc<A> 的引用以使以下代码编译成功?
use std::sync::Arc;
trait A {
fn send(&self);
}
struct B;
impl A for B {
fn send(&self) {
println!("SENT");
}
}
fn ss(a: &Arc<A>) {
let aa = a.clone();
aa.send();
}
fn main() {
let a = Arc::new(B);
ss(&a);
}
如果我省略了引用,它可以编译,但 Clippy 警告我在这种情况下没有任何意义。
code without reference 上的 Clippy 错误:
Compiling playground v0.0.1 (file:///playground)
warning: this argument is passed by value, but not consumed in the function body
--> src/main.rs:13:10
|
13 | fn ss(a: Arc<A>) {
| ^^^^^^ help: consider taking a reference instead: `&Arc<A>`
|
= note: #[warn(needless_pass_by_value)] on by default
= help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.186/index.html#needless_pass_by_value
【问题讨论】:
标签: rust rust-clippy