prevent useless_asref from suggesting .clone() on types without the Clone trait
This commit is contained in:
parent
a8b17827c6
commit
91548d0fe3
4 changed files with 82 additions and 19 deletions
|
|
@ -8,6 +8,7 @@
|
|||
)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::ops::Deref;
|
||||
use std::rc::{Rc, Weak as RcWeak};
|
||||
use std::sync::{Arc, Weak as ArcWeak};
|
||||
|
||||
|
|
@ -218,6 +219,35 @@ fn issue_14088() {
|
|||
let _: Option<&str> = s.as_ref().map(|x| x.as_ref());
|
||||
}
|
||||
|
||||
pub struct Wrap<T> {
|
||||
inner: T,
|
||||
}
|
||||
|
||||
impl<T> Deref for Wrap<T> {
|
||||
type Target = T;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
struct NonCloneableError;
|
||||
|
||||
pub struct Issue12357 {
|
||||
current: Option<Wrap<Arc<u32>>>,
|
||||
}
|
||||
|
||||
impl Issue12357 {
|
||||
fn f(&self) -> Option<Arc<u32>> {
|
||||
self.current.as_ref().map(|p| Arc::clone(p))
|
||||
}
|
||||
|
||||
fn g(&self) {
|
||||
let result: Result<String, NonCloneableError> = Ok("Hello".to_string());
|
||||
let cloned = result.as_ref().map(|s| s.clone());
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
not_ok();
|
||||
ok();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue