While trying to make clippy
happy I found some problem I don't understand entirely:
#![allow(dead_code)]
use std::sync::Arc;
use std::fmt::Debug;
struct Struct {
field: Arc<()>
}
impl Struct {
// error: expected trait std::fmt::Debug, found ()
//pub fn clone_some_a(&self) -> Arc<dyn Debug> {
// Arc::clone(&self.field)
//}
// warn: clippy::let_and_return
pub fn clone_some_b(&self) -> Arc<dyn Debug> {
let result = Arc::clone(&self.field);
result
}
// warn: trivial_casts
pub fn clone_some_c(&self) -> Arc<dyn Debug> {
Arc::clone(&self.field) as Arc<dyn Debug>
}
// error: cannot move
//pub fn clone_some_d(&self) -> Arc<dyn Debug> {
// Arc::clone(&(self.field as Arc<dyn Debug>))
//}
// error: non-primitive cast
//pub fn clone_some_e(&self) -> Arc<dyn Debug> {
// Arc::clone(&self.field as &Arc<dyn Debug>)
//}
// warn: clippy::clone_on_ref_ptr
pub fn clone_some_f(&self) -> Arc<dyn Debug> {
self.field.clone()
}
// works without a warning but looks crappy
pub fn clone_some_g(&self) -> Arc<dyn Debug> {
(Arc::clone(&self.field), ()).0
}
}
Why does version a
fail, but b
and g
are ok?
Why is a cast necessary (version c
vs. a
), but on the other hand it's marked as trivial
?