mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-31 05:26:23 +03:00
update for rustc warning about missing dyn
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
81970852e172c04322cbf8ba23effabeb491c83c
|
||||
c28084ac16af4ab594b6860958df140e7c876a13
|
||||
|
||||
@@ -14,10 +14,10 @@ trait MyTrait { fn dummy(&self) { } }
|
||||
impl MyTrait for Box<DroppableStruct> {}
|
||||
|
||||
#[allow(dead_code)]
|
||||
struct Whatever { w: Box<MyTrait+'static> }
|
||||
struct Whatever { w: Box<dyn MyTrait+'static> }
|
||||
|
||||
impl Whatever {
|
||||
fn new(w: Box<MyTrait+'static>) -> Whatever {
|
||||
fn new(w: Box<dyn MyTrait+'static>) -> Whatever {
|
||||
Whatever { w: w }
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ fn new(w: Box<MyTrait+'static>) -> Whatever {
|
||||
fn main() {
|
||||
{
|
||||
let f: Box<_> = box DroppableStruct;
|
||||
let _a = Whatever::new(box f as Box<MyTrait>);
|
||||
let _a = Whatever::new(box f as Box<dyn MyTrait>);
|
||||
}
|
||||
assert!(unsafe { DROPPED });
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ fn drop(&mut self) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let b: [Box<Foo>; 4] = [Box::new(Bar), Box::new(Bar), Box::new(Bar), Box::new(Bar)];
|
||||
let b: [Box<dyn Foo>; 4] = [Box::new(Bar), Box::new(Bar), Box::new(Bar), Box::new(Bar)];
|
||||
assert_eq!(unsafe { DROP_COUNT }, 0);
|
||||
drop(b);
|
||||
assert_eq!(unsafe { DROP_COUNT }, 4);
|
||||
|
||||
@@ -13,7 +13,7 @@ fn drop(&mut self) {
|
||||
impl Foo for Bar {}
|
||||
|
||||
fn main() {
|
||||
let b: Box<Foo> = Box::new(Bar);
|
||||
let b: Box<dyn Foo> = Box::new(Bar);
|
||||
assert!(unsafe { !DROP_CALLED });
|
||||
drop(b);
|
||||
assert!(unsafe { DROP_CALLED });
|
||||
|
||||
@@ -15,7 +15,7 @@ impl Foo for Bar {}
|
||||
use std::rc::Rc;
|
||||
|
||||
fn main() {
|
||||
let b: Rc<Foo> = Rc::new(Bar);
|
||||
let b: Rc<dyn Foo> = Rc::new(Bar);
|
||||
assert!(unsafe { !DROP_CALLED });
|
||||
drop(b);
|
||||
assert!(unsafe { DROP_CALLED });
|
||||
|
||||
@@ -13,9 +13,9 @@ impl<T> Foo<T> for () {}
|
||||
impl Foo<u32> for u32 { fn foo(&self, _: u32) -> u32 { self+43 } }
|
||||
impl Bar for () {}
|
||||
|
||||
unsafe fn round_trip_and_call<'a>(t: *const (Foo<u32>+'a)) -> u32 {
|
||||
let foo_e : *const Foo<u16> = t as *const _;
|
||||
let r_1 = foo_e as *mut Foo<u32>;
|
||||
unsafe fn round_trip_and_call<'a>(t: *const (dyn Foo<u32>+'a)) -> u32 {
|
||||
let foo_e : *const dyn Foo<u16> = t as *const _;
|
||||
let r_1 = foo_e as *mut dyn Foo<u32>;
|
||||
|
||||
(&*r_1).foo(0)
|
||||
}
|
||||
@@ -31,8 +31,8 @@ fn foo_to_bar<T:?Sized>(u: *const FooS<T>) -> *const BarS<T> {
|
||||
|
||||
fn main() {
|
||||
let x = 4u32;
|
||||
let y : &Foo<u32> = &x;
|
||||
let fl = unsafe { round_trip_and_call(y as *const Foo<u32>) };
|
||||
let y : &dyn Foo<u32> = &x;
|
||||
let fl = unsafe { round_trip_and_call(y as *const dyn Foo<u32>) };
|
||||
assert_eq!(fl, (43+4));
|
||||
|
||||
let s = FooS([0,1,2]);
|
||||
|
||||
@@ -26,7 +26,7 @@ fn main() {
|
||||
// Test that zero-offset works properly
|
||||
let b : Baz<usize> = Baz { a: 7 };
|
||||
assert_eq!(b.a.get(), 7);
|
||||
let b : &Baz<Bar> = &b;
|
||||
let b : &Baz<dyn Bar> = &b;
|
||||
assert_eq!(b.a.get(), 7);
|
||||
|
||||
// Test that the field is aligned properly
|
||||
@@ -34,7 +34,7 @@ fn main() {
|
||||
assert_eq!(f.b.get(), 11);
|
||||
let ptr1 : *const u8 = &f.b as *const _ as *const u8;
|
||||
|
||||
let f : &Foo<Bar> = &f;
|
||||
let f : &Foo<dyn Bar> = &f;
|
||||
let ptr2 : *const u8 = &f.b as *const _ as *const u8;
|
||||
assert_eq!(f.b.get(), 11);
|
||||
|
||||
@@ -44,13 +44,13 @@ fn main() {
|
||||
// Test that nested DSTs work properly
|
||||
let f : Foo<Foo<usize>> = Foo { a: 0, b: Foo { a: 1, b: 17 }};
|
||||
assert_eq!(f.b.b.get(), 17);
|
||||
let f : &Foo<Foo<Bar>> = &f;
|
||||
let f : &Foo<Foo<dyn Bar>> = &f;
|
||||
assert_eq!(f.b.b.get(), 17);
|
||||
|
||||
// Test that get the pointer via destructuring works
|
||||
|
||||
let f : Foo<usize> = Foo { a: 0, b: 11 };
|
||||
let f : &Foo<Bar> = &f;
|
||||
let f : &Foo<dyn Bar> = &f;
|
||||
let &Foo { a: _, b: ref bar } = f;
|
||||
assert_eq!(bar.get(), 11);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ struct Foo<T: ?Sized> {
|
||||
pub fn main() {
|
||||
// raw trait object
|
||||
let x = A { f: 42 };
|
||||
let z: *const Trait = &x;
|
||||
let z: *const dyn Trait = &x;
|
||||
let r = unsafe {
|
||||
(&*z).foo()
|
||||
};
|
||||
@@ -29,7 +29,7 @@ pub fn main() {
|
||||
|
||||
// raw DST struct
|
||||
let p = Foo {f: A { f: 42 }};
|
||||
let o: *const Foo<Trait> = &p;
|
||||
let o: *const Foo<dyn Trait> = &p;
|
||||
let r = unsafe {
|
||||
(&*o).f.foo()
|
||||
};
|
||||
@@ -64,14 +64,14 @@ pub fn main() {
|
||||
|
||||
// all of the above with *mut
|
||||
let mut x = A { f: 42 };
|
||||
let z: *mut Trait = &mut x;
|
||||
let z: *mut dyn Trait = &mut x;
|
||||
let r = unsafe {
|
||||
(&*z).foo()
|
||||
};
|
||||
assert_eq!(r, 42);
|
||||
|
||||
let mut p = Foo {f: A { f: 42 }};
|
||||
let o: *mut Foo<Trait> = &mut p;
|
||||
let o: *mut Foo<dyn Trait> = &mut p;
|
||||
let r = unsafe {
|
||||
(&*o).f.foo()
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
fn foo() {}
|
||||
|
||||
fn main() {
|
||||
let f: &Fn() = &foo;
|
||||
let f: &dyn Fn() = &foo;
|
||||
f();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ fn foo(i: i32) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let f: &Fn(i32) = &foo;
|
||||
let f: &dyn Fn(i32) = &foo;
|
||||
f(42);
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ fn bar(i: i32, j: i32, k: f32) {
|
||||
|
||||
|
||||
fn main() {
|
||||
let f: &Fn(i32, i32) = &foo;
|
||||
let f: &dyn Fn(i32, i32) = &foo;
|
||||
f(42, 55);
|
||||
let f: &Fn(i32, i32, f32) = &bar;
|
||||
let f: &dyn Fn(i32, i32, f32) = &bar;
|
||||
f(42, 55, 3.14159);
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ fn baa(u: u32, f: f32) {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let f: &Fn() = &(foo as fn());
|
||||
let f: &dyn Fn() = &(foo as fn());
|
||||
f();
|
||||
let f: &Fn(u32) = &(bar as fn(u32));
|
||||
let f: &dyn Fn(u32) = &(bar as fn(u32));
|
||||
f(42);
|
||||
let f: &Fn(u32, f32) = &(baa as fn(u32, f32));
|
||||
let f: &dyn Fn(u32, f32) = &(baa as fn(u32, f32));
|
||||
f(42, 3.141);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Test that overloaded calls work with zero arity closures
|
||||
|
||||
fn main() {
|
||||
let functions: [Box<Fn() -> Option<()>>; 1] = [Box::new(|| None)];
|
||||
let functions: [Box<dyn Fn() -> Option<()>>; 1] = [Box::new(|| None)];
|
||||
|
||||
let _val: Option<Vec<()>> = functions.iter().map(|f| (*f)()).collect();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ fn check_both(val: &Foo<[u8]>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn check_trait_obj(val: &Foo<Get>) {
|
||||
fn check_trait_obj(val: &Foo<dyn Get>) {
|
||||
match *val {
|
||||
Foo { a, ref inner } => {
|
||||
assert_eq!(a, 32);
|
||||
@@ -55,6 +55,6 @@ fn main() {
|
||||
check_dst_val(foo);
|
||||
check_both(foo);
|
||||
|
||||
let foo: &Foo<Get> = &Foo { a: 32, inner: 32 };
|
||||
let foo: &Foo<dyn Get> = &Foo { a: 32, inner: 32 };
|
||||
check_trait_obj(foo);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ fn main() {
|
||||
let mut x = 0;
|
||||
{
|
||||
let wrapper = Box::new(Wrapper(&mut x, 123));
|
||||
let _val: Box<Wrapper<Send>> = wrapper;
|
||||
let _val: Box<Wrapper<dyn Send>> = wrapper;
|
||||
}
|
||||
assert_eq!(432, x)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
pub enum Handler {
|
||||
Default,
|
||||
#[allow(dead_code)]
|
||||
Custom(*mut Box<Fn()>),
|
||||
Custom(*mut Box<dyn Fn()>),
|
||||
}
|
||||
|
||||
fn main() {
|
||||
@@ -25,7 +25,7 @@ fn main() {
|
||||
}
|
||||
|
||||
#[inline(never)]
|
||||
pub fn take(h: Handler, f: Box<Fn()>) -> Box<Fn()> {
|
||||
pub fn take(h: Handler, f: Box<dyn Fn()>) -> Box<dyn Fn()> {
|
||||
unsafe {
|
||||
match h {
|
||||
Handler::Custom(ptr) => *Box::from_raw(ptr),
|
||||
|
||||
@@ -5,5 +5,5 @@ trait Foo {}
|
||||
impl Foo for [u8; 2] {}
|
||||
|
||||
fn main() {
|
||||
let _val: Arc<Foo + Send> = Arc::new([3, 4]);
|
||||
let _val: Arc<dyn Foo + Send> = Arc::new([3, 4]);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,6 @@ struct Foo<T: ?Sized> {
|
||||
|
||||
fn main() {
|
||||
let foo: &Foo<i32> = &Foo { a: 1, b: false, c: 2i32 };
|
||||
let foo_unsized: &Foo<Send> = foo;
|
||||
let foo_unsized: &Foo<dyn Send> = foo;
|
||||
assert_eq!(mem::size_of_val(foo), mem::size_of_val(foo_unsized));
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ fn print(&self) {
|
||||
}
|
||||
}
|
||||
|
||||
fn print_t(t: &T) {
|
||||
fn print_t(t: &dyn T) {
|
||||
t.print();
|
||||
}
|
||||
|
||||
@@ -26,6 +26,6 @@ fn print_s(s: &S) {
|
||||
pub fn main() {
|
||||
let s: Box<S> = box S { s: 5 };
|
||||
print_s(&*s);
|
||||
let t: Box<T> = s as Box<T>;
|
||||
let t: Box<dyn T> = s as Box<dyn T>;
|
||||
print_t(&*t);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#[allow(dead_code)]
|
||||
struct A { a: Box<isize> }
|
||||
|
||||
fn foo() -> Box<FnMut() -> isize + 'static> {
|
||||
fn foo() -> Box<dyn FnMut() -> isize + 'static> {
|
||||
let k: Box<_> = Box::new(22);
|
||||
let _u = A {a: k.clone()};
|
||||
let result = || 22;
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
use std::ops::CoerceUnsized;
|
||||
use std::marker::Unsize;
|
||||
|
||||
fn identity_coercion(x: &(Fn(u32)->u32 + Send)) -> &Fn(u32)->u32 {
|
||||
fn identity_coercion(x: &(dyn Fn(u32)->u32 + Send)) -> &dyn Fn(u32)->u32 {
|
||||
x
|
||||
}
|
||||
fn fn_coercions(f: &fn(u32) -> u32) ->
|
||||
(unsafe fn(u32) -> u32,
|
||||
&(Fn(u32) -> u32+Send))
|
||||
&(dyn Fn(u32) -> u32 + Send))
|
||||
{
|
||||
(*f, f)
|
||||
}
|
||||
@@ -34,8 +34,8 @@ impl<'a, T: ?Sized+Unsize<U>, U: ?Sized>
|
||||
p
|
||||
}
|
||||
|
||||
fn coerce_fat_ptr_wrapper(p: PtrWrapper<Fn(u32) -> u32+Send>)
|
||||
-> PtrWrapper<Fn(u32) -> u32> {
|
||||
fn coerce_fat_ptr_wrapper(p: PtrWrapper<dyn Fn(u32) -> u32 + Send>)
|
||||
-> PtrWrapper<dyn Fn(u32) -> u32> {
|
||||
p
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ fn main() {
|
||||
let z = coerce_fat_ptr_wrapper(PtrWrapper(2,3,(),&square_local));
|
||||
assert_eq!((z.3)(6), 36);
|
||||
|
||||
let z: PtrWrapper<Fn(u32) -> u32> =
|
||||
let z: PtrWrapper<dyn Fn(u32) -> u32> =
|
||||
coerce_ptr_wrapper_poly(PtrWrapper(2,3,(),&square_local));
|
||||
assert_eq!((z.3)(6), 36);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
fn foo(f: &mut FnMut(isize, isize) -> isize) -> isize {
|
||||
fn foo(f: &mut dyn FnMut(isize, isize) -> isize) -> isize {
|
||||
f(1, 2)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ fn main() {
|
||||
BAR(44, 45);
|
||||
let bar: unsafe fn(i32, i32) = BAR;
|
||||
unsafe { bar(46, 47) };
|
||||
let boo: &Fn(i32, i32) = &BAR;
|
||||
let boo: &dyn Fn(i32, i32) = &BAR;
|
||||
boo(48, 49);
|
||||
|
||||
let f = magic(||{}) as fn();
|
||||
|
||||
@@ -64,8 +64,8 @@ fn rc_from() {
|
||||
}
|
||||
|
||||
fn rc_fat_ptr_eq() {
|
||||
let p = Rc::new(1) as Rc<Debug>;
|
||||
let a: *const Debug = &*p;
|
||||
let p = Rc::new(1) as Rc<dyn Debug>;
|
||||
let a: *const dyn Debug = &*p;
|
||||
let r = Rc::into_raw(p);
|
||||
assert!(a == r);
|
||||
drop(unsafe { Rc::from_raw(r) });
|
||||
|
||||
@@ -16,15 +16,15 @@
|
||||
|
||||
pub fn main() {
|
||||
fn explicit() {
|
||||
fn test<F>(_x: Option<Box<F>>) where F: FnMut(Box<for<'a> FnMut(&'a isize)>) {}
|
||||
test(Some(box |_f: Box<for<'a> FnMut(&'a isize)>| {}));
|
||||
fn test<F>(_x: Option<Box<F>>) where F: FnMut(Box<dyn for<'a> FnMut(&'a isize)>) {}
|
||||
test(Some(box |_f: Box<dyn for<'a> FnMut(&'a isize)>| {}));
|
||||
}
|
||||
|
||||
// The code below is shorthand for the code above (and more likely
|
||||
// to represent what one encounters in practice).
|
||||
fn implicit() {
|
||||
fn test<F>(_x: Option<Box<F>>) where F: FnMut(Box< FnMut(& isize)>) {}
|
||||
test(Some(box |_f: Box< FnMut(& isize)>| {}));
|
||||
fn test<F>(_x: Option<Box<F>>) where F: FnMut(Box<dyn FnMut(& isize)>) {}
|
||||
test(Some(box |_f: Box<dyn FnMut(& isize)>| {}));
|
||||
}
|
||||
|
||||
explicit();
|
||||
|
||||
@@ -13,17 +13,17 @@ fn method(&self) {
|
||||
struct Foo<T: ?Sized>(T);
|
||||
|
||||
fn main() {
|
||||
let y: &Trait = &Struct(42);
|
||||
let y: &dyn Trait = &Struct(42);
|
||||
y.method();
|
||||
let x: Foo<Struct> = Foo(Struct(42));
|
||||
let y: &Foo<Trait> = &x;
|
||||
let y: &Foo<dyn Trait> = &x;
|
||||
y.0.method();
|
||||
|
||||
let x: Box<Fn(i32) -> i32> = Box::new(|x| x * 2);
|
||||
let x: Box<dyn Fn(i32) -> i32> = Box::new(|x| x * 2);
|
||||
assert_eq!(x(21), 42);
|
||||
let mut i = 5;
|
||||
{
|
||||
let mut x: Box<FnMut()> = Box::new(|| i *= 2);
|
||||
let mut x: Box<dyn FnMut()> = Box::new(|| i *= 2);
|
||||
x(); x();
|
||||
}
|
||||
assert_eq!(i, 20);
|
||||
|
||||
Reference in New Issue
Block a user