use std::any::Any;
-pub fn test5(foo: &mut Box<Any>) {
+pub fn test5(foo: &mut Box<dyn Any>) {
println!("{:?}", foo)
}
pub fn test6() {
- let foo: &Box<Any>;
+ let foo: &Box<dyn Any>;
}
struct Test7<'a> {
- foo: &'a Box<Any>,
+ foo: &'a Box<dyn Any>,
}
trait Test8 {
- fn test8(a: &Box<Any>);
+ fn test8(a: &Box<dyn Any>);
}
impl<'a> Test8 for Test7<'a> {
- fn test8(a: &Box<Any>) {
+ fn test8(a: &Box<dyn Any>) {
unimplemented!();
}
}
-pub fn test9(foo: &mut Box<Any + Send + Sync>) {
+pub fn test9(foo: &mut Box<dyn Any + Send + Sync>) {
let _ = foo;
}
pub fn test10() {
- let foo: &Box<Any + Send + 'static>;
+ let foo: &Box<dyn Any + Send + 'static>;
}
struct Test11<'a> {
- foo: &'a Box<Any + Send>,
+ foo: &'a Box<dyn Any + Send>,
}
trait Test12 {
- fn test4(a: &Box<Any + 'static>);
+ fn test4(a: &Box<dyn Any + 'static>);
}
impl<'a> Test12 for Test11<'a> {
- fn test4(a: &Box<Any + 'static>) {
+ fn test4(a: &Box<dyn Any + 'static>) {
unimplemented!();
}
}
fn main() {
test1(&mut Box::new(false));
test2();
- test5(&mut (Box::new(false) as Box<Any>));
+ test5(&mut (Box::new(false) as Box<dyn Any>));
test6();
- test9(&mut (Box::new(false) as Box<Any + Send + Sync>));
+ test9(&mut (Box::new(false) as Box<dyn Any + Send + Sync>));
test10();
}
println!("{:?}", foo.get(0))
}
-pub fn test2(foo: Box<Fn(Vec<u32>)>) {
+pub fn test2(foo: Box<dyn Fn(Vec<u32>)>) {
// pass if #31 is fixed
foo(vec![1, 2, 3])
}
fn main() {}
-fn ok_box_trait(boxed_trait: &Box<Z>) {
+fn ok_box_trait(boxed_trait: &Box<dyn Z>) {
let boxed_local = boxed_trait;
// done
}
let e = Some(1u8).map(generic);
let e = Some(1u8).map(generic);
// See #515
- let a: Option<Box<::std::ops::Deref<Target = [i32]>>> =
- Some(vec![1i32, 2]).map(|v| -> Box<::std::ops::Deref<Target = [i32]>> { Box::new(v) });
+ let a: Option<Box<dyn (::std::ops::Deref<Target = [i32]>)>> =
+ Some(vec![1i32, 2]).map(|v| -> Box<dyn (::std::ops::Deref<Target = [i32]>)> { Box::new(v) });
}
trait TestTrait {
let _: Vec<_> = arr.iter().map(|x| x.map_err(some.take().unwrap())).collect();
}
-struct Thunk<T>(Box<FnMut() -> T>);
+struct Thunk<T>(Box<dyn FnMut() -> T>);
impl<T> Thunk<T> {
fn new<F: 'static + FnOnce() -> T>(f: F) -> Thunk<T> {
let e = Some(1u8).map(|a| generic(a));
let e = Some(1u8).map(generic);
// See #515
- let a: Option<Box<::std::ops::Deref<Target = [i32]>>> =
- Some(vec![1i32, 2]).map(|v| -> Box<::std::ops::Deref<Target = [i32]>> { Box::new(v) });
+ let a: Option<Box<dyn (::std::ops::Deref<Target = [i32]>)>> =
+ Some(vec![1i32, 2]).map(|v| -> Box<dyn (::std::ops::Deref<Target = [i32]>)> { Box::new(v) });
}
trait TestTrait {
let _: Vec<_> = arr.iter().map(|x| x.map_err(|e| some.take().unwrap()(e))).collect();
}
-struct Thunk<T>(Box<FnMut() -> T>);
+struct Thunk<T>(Box<dyn FnMut() -> T>);
impl<T> Thunk<T> {
fn new<F: 'static + FnOnce() -> T>(f: F) -> Thunk<T> {
panic!()
}
-fn unused_lt_blergh<'a>(x: Option<Box<Send + 'a>>) {}
+fn unused_lt_blergh<'a>(x: Option<Box<dyn Send + 'a>>) {}
trait Foo<'a> {
fn x(&self, a: &'a u8);
println!("This should not happen either!");
}
- let z: &TraitsToo = &y;
+ let z: &dyn TraitsToo = &y;
if z.len() > 0 {
// No error; `TraitsToo` has no `.is_empty()` method.
println!("Nor should this!");
}
assert!(!has_is_empty.is_empty());
- let with_is_empty: &WithIsEmpty = &Wither;
+ let with_is_empty: &dyn WithIsEmpty = &Wither;
if with_is_empty.is_empty() {
println!("Or this!");
}
println!("This should not happen either!");
}
- let z: &TraitsToo = &y;
+ let z: &dyn TraitsToo = &y;
if z.len() > 0 {
// No error; `TraitsToo` has no `.is_empty()` method.
println!("Nor should this!");
}
assert!(!has_is_empty.is_empty());
- let with_is_empty: &WithIsEmpty = &Wither;
+ let with_is_empty: &dyn WithIsEmpty = &Wither;
if with_is_empty.len() == 0 {
println!("Or this!");
}
impl<'a> Trait for &'a str {}
-fn h(_: &Trait) {}
+fn h(_: &dyn Trait) {}
#[warn(clippy::needless_borrow)]
#[allow(dead_code)]
fn issue_1432() {
trait WithLifetime<'a> {}
-type WithLifetimeAlias<'a> = WithLifetime<'a>;
+type WithLifetimeAlias<'a> = dyn WithLifetime<'a>;
// Should not warn because it won't build without the lifetime.
-fn trait_obj_elided<'a>(_arg: &'a WithLifetime) -> &'a str {
+fn trait_obj_elided<'a>(_arg: &'a dyn WithLifetime) -> &'a str {
unimplemented!()
}
// Should warn because there is no lifetime on `Drop`, so this would be
// unambiguous if we elided the lifetime.
-fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str {
+fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str {
unimplemented!()
}
}
impl Test {
- fn iter<'a>(&'a self) -> Box<Iterator<Item = usize> + 'a> {
+ fn iter<'a>(&'a self) -> Box<dyn Iterator<Item = usize> + 'a> {
unimplemented!()
}
}
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/needless_lifetimes.rs:178:1
|
-LL | / fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str {
+LL | / fn trait_obj_elided2<'a>(_arg: &'a dyn Drop) -> &'a str {
LL | | unimplemented!()
LL | | }
| |_^
const COW: Cow<str> = Cow::Borrowed("abcdef");
//^ note: a const item of Cow is used in the `postgres` package.
-const NO_ANN: &Display = &70;
+const NO_ANN: &dyn Display = &70;
static STATIC_TUPLE: (AtomicUsize, String) = (ATOMIC, STRING);
//^ there should be no lints on this line
sync::Weak::clone(&arc_weak);
let x = Arc::new(SomeImpl);
- let _: Arc<SomeTrait> = x.clone();
+ let _: Arc<dyn SomeTrait> = x.clone();
}
fn clone_on_copy_generic<T: Copy>(t: T) {
| ^^^^^^^^^^^^^^^^ help: try this: `Weak::<bool>::clone(&arc_weak)`
error: using '.clone()' on a ref-counted pointer
- --> $DIR/unnecessary_clone.rs:47:29
+ --> $DIR/unnecessary_clone.rs:47:33
|
-LL | let _: Arc<SomeTrait> = x.clone();
- | ^^^^^^^^^ help: try this: `Arc::<SomeImpl>::clone(&x)`
+LL | let _: Arc<dyn SomeTrait> = x.clone();
+ | ^^^^^^^^^ help: try this: `Arc::<SomeImpl>::clone(&x)`
error: using `clone` on a `Copy` type
--> $DIR/unnecessary_clone.rs:51:5
#[allow(clippy::no_effect)]
pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G)
where G: Fn() -> () {
- let _y: &Fn() -> () = &f;
+ let _y: &dyn Fn() -> () = &f;
(); // this should not lint, as it's not in return type position
}
}
pub fn get_unit<F: Fn() -> (), G>(&self, f: F, _g: G) ->
()
where G: Fn() -> () {
- let _y: &Fn() -> () = &f;
+ let _y: &dyn Fn() -> () = &f;
(); // this should not lint, as it's not in return type position
}
}