Skip to content

Commit ec629cc

Browse files
authored
Rustup (#752)
Rustup
2 parents 9dfbebd + c748323 commit ec629cc

27 files changed

+100
-95
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
81970852e172c04322cbf8ba23effabeb491c83c
1+
c28084ac16af4ab594b6860958df140e7c876a13

tests/run-pass/box_box_trait.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ trait MyTrait { fn dummy(&self) { } }
1414
impl MyTrait for Box<DroppableStruct> {}
1515

1616
#[allow(dead_code)]
17-
struct Whatever { w: Box<MyTrait+'static> }
17+
struct Whatever { w: Box<dyn MyTrait+'static> }
1818

1919
impl Whatever {
20-
fn new(w: Box<MyTrait+'static>) -> Whatever {
20+
fn new(w: Box<dyn MyTrait+'static>) -> Whatever {
2121
Whatever { w: w }
2222
}
2323
}
2424

2525
fn main() {
2626
{
2727
let f: Box<_> = box DroppableStruct;
28-
let _a = Whatever::new(box f as Box<MyTrait>);
28+
let _a = Whatever::new(box f as Box<dyn MyTrait>);
2929
}
3030
assert!(unsafe { DROPPED });
3131
}

tests/run-pass/call_drop_on_fat_ptr_array_elements.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl Drop for Bar {
1313
}
1414

1515
fn main() {
16-
let b: [Box<Foo>; 4] = [Box::new(Bar), Box::new(Bar), Box::new(Bar), Box::new(Bar)];
16+
let b: [Box<dyn Foo>; 4] = [Box::new(Bar), Box::new(Bar), Box::new(Bar), Box::new(Bar)];
1717
assert_eq!(unsafe { DROP_COUNT }, 0);
1818
drop(b);
1919
assert_eq!(unsafe { DROP_COUNT }, 4);

tests/run-pass/call_drop_through_trait_object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl Drop for Bar {
1313
impl Foo for Bar {}
1414

1515
fn main() {
16-
let b: Box<Foo> = Box::new(Bar);
16+
let b: Box<dyn Foo> = Box::new(Bar);
1717
assert!(unsafe { !DROP_CALLED });
1818
drop(b);
1919
assert!(unsafe { DROP_CALLED });

tests/run-pass/call_drop_through_trait_object_rc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl Foo for Bar {}
1515
use std::rc::Rc;
1616

1717
fn main() {
18-
let b: Rc<Foo> = Rc::new(Bar);
18+
let b: Rc<dyn Foo> = Rc::new(Bar);
1919
assert!(unsafe { !DROP_CALLED });
2020
drop(b);
2121
assert!(unsafe { DROP_CALLED });

tests/run-pass/cast-rfc0401-vtable-kinds.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ impl<T> Foo<T> for () {}
1313
impl Foo<u32> for u32 { fn foo(&self, _: u32) -> u32 { self+43 } }
1414
impl Bar for () {}
1515

16-
unsafe fn round_trip_and_call<'a>(t: *const (Foo<u32>+'a)) -> u32 {
17-
let foo_e : *const Foo<u16> = t as *const _;
18-
let r_1 = foo_e as *mut Foo<u32>;
16+
unsafe fn round_trip_and_call<'a>(t: *const (dyn Foo<u32>+'a)) -> u32 {
17+
let foo_e : *const dyn Foo<u16> = t as *const _;
18+
let r_1 = foo_e as *mut dyn Foo<u32>;
1919

2020
(&*r_1).foo(0)
2121
}
@@ -31,8 +31,8 @@ fn foo_to_bar<T:?Sized>(u: *const FooS<T>) -> *const BarS<T> {
3131

3232
fn main() {
3333
let x = 4u32;
34-
let y : &Foo<u32> = &x;
35-
let fl = unsafe { round_trip_and_call(y as *const Foo<u32>) };
34+
let y : &dyn Foo<u32> = &x;
35+
let fl = unsafe { round_trip_and_call(y as *const dyn Foo<u32>) };
3636
assert_eq!(fl, (43+4));
3737

3838
let s = FooS([0,1,2]);

tests/run-pass/closures.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,62 @@ fn boxed(f: Box<dyn FnOnce() -> i32>) -> i32 {
4444
f()
4545
}
4646

47+
fn fn_item_as_closure_trait_object() {
48+
fn foo() {}
49+
let f: &dyn Fn() = &foo;
50+
f();
51+
}
52+
53+
fn fn_item_with_args_as_closure_trait_object() {
54+
fn foo(i: i32) {
55+
assert_eq!(i, 42);
56+
}
57+
let f: &dyn Fn(i32) = &foo;
58+
f(42);
59+
}
60+
61+
fn fn_item_with_multiple_args_as_closure_trait_object() {
62+
fn foo(i: i32, j: i32) {
63+
assert_eq!(i, 42);
64+
assert_eq!(j, 55);
65+
}
66+
67+
fn bar(i: i32, j: i32, k: f32) {
68+
assert_eq!(i, 42);
69+
assert_eq!(j, 55);
70+
assert_eq!(k, 3.14159)
71+
}
72+
let f: &dyn Fn(i32, i32) = &foo;
73+
f(42, 55);
74+
let f: &dyn Fn(i32, i32, f32) = &bar;
75+
f(42, 55, 3.14159);
76+
}
77+
78+
fn fn_ptr_as_closure_trait_object() {
79+
fn foo() {}
80+
fn bar(u: u32) { assert_eq!(u, 42); }
81+
fn baa(u: u32, f: f32) {
82+
assert_eq!(u, 42);
83+
assert_eq!(f, 3.141);
84+
}
85+
let f: &dyn Fn() = &(foo as fn());
86+
f();
87+
let f: &dyn Fn(u32) = &(bar as fn(u32));
88+
f(42);
89+
let f: &dyn Fn(u32, f32) = &(baa as fn(u32, f32));
90+
f(42, 3.141);
91+
}
92+
93+
4794
fn main() {
4895
assert_eq!(simple(), 12);
4996
assert_eq!(crazy_closure(), (84, 10, 10));
5097
assert_eq!(closure_arg_adjustment_problem(), 3);
5198
assert_eq!(fn_once_closure_with_multiple_args(), 6);
5299
assert_eq!(boxed(Box::new({let x = 13; move || x})), 13);
100+
101+
fn_item_as_closure_trait_object();
102+
fn_item_with_args_as_closure_trait_object();
103+
fn_item_with_multiple_args_as_closure_trait_object();
104+
fn_ptr_as_closure_trait_object();
53105
}

tests/run-pass/dst-field-align.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ fn main() {
2626
// Test that zero-offset works properly
2727
let b : Baz<usize> = Baz { a: 7 };
2828
assert_eq!(b.a.get(), 7);
29-
let b : &Baz<Bar> = &b;
29+
let b : &Baz<dyn Bar> = &b;
3030
assert_eq!(b.a.get(), 7);
3131

3232
// Test that the field is aligned properly
3333
let f : Foo<usize> = Foo { a: 0, b: 11 };
3434
assert_eq!(f.b.get(), 11);
3535
let ptr1 : *const u8 = &f.b as *const _ as *const u8;
3636

37-
let f : &Foo<Bar> = &f;
37+
let f : &Foo<dyn Bar> = &f;
3838
let ptr2 : *const u8 = &f.b as *const _ as *const u8;
3939
assert_eq!(f.b.get(), 11);
4040

@@ -44,13 +44,13 @@ fn main() {
4444
// Test that nested DSTs work properly
4545
let f : Foo<Foo<usize>> = Foo { a: 0, b: Foo { a: 1, b: 17 }};
4646
assert_eq!(f.b.b.get(), 17);
47-
let f : &Foo<Foo<Bar>> = &f;
47+
let f : &Foo<Foo<dyn Bar>> = &f;
4848
assert_eq!(f.b.b.get(), 17);
4949

5050
// Test that get the pointer via destructuring works
5151

5252
let f : Foo<usize> = Foo { a: 0, b: 11 };
53-
let f : &Foo<Bar> = &f;
53+
let f : &Foo<dyn Bar> = &f;
5454
let &Foo { a: _, b: ref bar } = f;
5555
assert_eq!(bar.get(), 11);
5656

tests/run-pass/dst-raw.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ struct Foo<T: ?Sized> {
2121
pub fn main() {
2222
// raw trait object
2323
let x = A { f: 42 };
24-
let z: *const Trait = &x;
24+
let z: *const dyn Trait = &x;
2525
let r = unsafe {
2626
(&*z).foo()
2727
};
2828
assert_eq!(r, 42);
2929

3030
// raw DST struct
3131
let p = Foo {f: A { f: 42 }};
32-
let o: *const Foo<Trait> = &p;
32+
let o: *const Foo<dyn Trait> = &p;
3333
let r = unsafe {
3434
(&*o).f.foo()
3535
};
@@ -64,14 +64,14 @@ pub fn main() {
6464

6565
// all of the above with *mut
6666
let mut x = A { f: 42 };
67-
let z: *mut Trait = &mut x;
67+
let z: *mut dyn Trait = &mut x;
6868
let r = unsafe {
6969
(&*z).foo()
7070
};
7171
assert_eq!(r, 42);
7272

7373
let mut p = Foo {f: A { f: 42 }};
74-
let o: *mut Foo<Trait> = &mut p;
74+
let o: *mut Foo<dyn Trait> = &mut p;
7575
let r = unsafe {
7676
(&*o).f.foo()
7777
};

tests/run-pass/fn_item_as_closure_trait_object.rs

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/run-pass/fn_item_with_args_as_closure_trait_object.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/run-pass/fn_item_with_multiple_args_as_closure_trait_object.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/run-pass/fn_ptr_as_closure_trait_object.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

tests/run-pass/issue-20575.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Test that overloaded calls work with zero arity closures
22

33
fn main() {
4-
let functions: [Box<Fn() -> Option<()>>; 1] = [Box::new(|| None)];
4+
let functions: [Box<dyn Fn() -> Option<()>>; 1] = [Box::new(|| None)];
55

66
let _val: Option<Vec<()>> = functions.iter().map(|f| (*f)()).collect();
77
}

tests/run-pass/issue-23261.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn check_both(val: &Foo<[u8]>) {
4040
}
4141
}
4242

43-
fn check_trait_obj(val: &Foo<Get>) {
43+
fn check_trait_obj(val: &Foo<dyn Get>) {
4444
match *val {
4545
Foo { a, ref inner } => {
4646
assert_eq!(a, 32);
@@ -55,6 +55,6 @@ fn main() {
5555
check_dst_val(foo);
5656
check_both(foo);
5757

58-
let foo: &Foo<Get> = &Foo { a: 32, inner: 32 };
58+
let foo: &Foo<dyn Get> = &Foo { a: 32, inner: 32 };
5959
check_trait_obj(foo);
6060
}

tests/run-pass/issue-26709.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010
let mut x = 0;
1111
{
1212
let wrapper = Box::new(Wrapper(&mut x, 123));
13-
let _val: Box<Wrapper<Send>> = wrapper;
13+
let _val: Box<Wrapper<dyn Send>> = wrapper;
1414
}
1515
assert_eq!(432, x)
1616
}

tests/run-pass/issue-30530.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
pub enum Handler {
1818
Default,
1919
#[allow(dead_code)]
20-
Custom(*mut Box<Fn()>),
20+
Custom(*mut Box<dyn Fn()>),
2121
}
2222

2323
fn main() {
2424
take(Handler::Default, Box::new(main));
2525
}
2626

2727
#[inline(never)]
28-
pub fn take(h: Handler, f: Box<Fn()>) -> Box<Fn()> {
28+
pub fn take(h: Handler, f: Box<dyn Fn()>) -> Box<dyn Fn()> {
2929
unsafe {
3030
match h {
3131
Handler::Custom(ptr) => *Box::from_raw(ptr),

tests/run-pass/issue-33387.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ trait Foo {}
55
impl Foo for [u8; 2] {}
66

77
fn main() {
8-
let _val: Arc<Foo + Send> = Arc::new([3, 4]);
8+
let _val: Arc<dyn Foo + Send> = Arc::new([3, 4]);
99
}

tests/run-pass/issue-35815.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ struct Foo<T: ?Sized> {
1010

1111
fn main() {
1212
let foo: &Foo<i32> = &Foo { a: 1, b: false, c: 2i32 };
13-
let foo_unsized: &Foo<Send> = foo;
13+
let foo_unsized: &Foo<dyn Send> = foo;
1414
assert_eq!(mem::size_of_val(foo), mem::size_of_val(foo_unsized));
1515
}

tests/run-pass/issue-3794.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl T for S {
1515
}
1616
}
1717

18-
fn print_t(t: &T) {
18+
fn print_t(t: &dyn T) {
1919
t.print();
2020
}
2121

@@ -26,6 +26,6 @@ fn print_s(s: &S) {
2626
pub fn main() {
2727
let s: Box<S> = box S { s: 5 };
2828
print_s(&*s);
29-
let t: Box<T> = s as Box<T>;
29+
let t: Box<dyn T> = s as Box<dyn T>;
3030
print_t(&*t);
3131
}

tests/run-pass/last-use-in-cap-clause.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#[allow(dead_code)]
44
struct A { a: Box<isize> }
55

6-
fn foo() -> Box<FnMut() -> isize + 'static> {
6+
fn foo() -> Box<dyn FnMut() -> isize + 'static> {
77
let k: Box<_> = Box::new(22);
88
let _u = A {a: k.clone()};
99
let result = || 22;

tests/run-pass/mir_coercions.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
use std::ops::CoerceUnsized;
44
use std::marker::Unsize;
55

6-
fn identity_coercion(x: &(Fn(u32)->u32 + Send)) -> &Fn(u32)->u32 {
6+
fn identity_coercion(x: &(dyn Fn(u32)->u32 + Send)) -> &dyn Fn(u32)->u32 {
77
x
88
}
99
fn fn_coercions(f: &fn(u32) -> u32) ->
1010
(unsafe fn(u32) -> u32,
11-
&(Fn(u32) -> u32+Send))
11+
&(dyn Fn(u32) -> u32 + Send))
1212
{
1313
(*f, f)
1414
}
@@ -34,8 +34,8 @@ fn coerce_triv_ptr_wrapper(p: TrivPtrWrapper<[u8; 3]>) -> TrivPtrWrapper<[u8]> {
3434
p
3535
}
3636

37-
fn coerce_fat_ptr_wrapper(p: PtrWrapper<Fn(u32) -> u32+Send>)
38-
-> PtrWrapper<Fn(u32) -> u32> {
37+
fn coerce_fat_ptr_wrapper(p: PtrWrapper<dyn Fn(u32) -> u32 + Send>)
38+
-> PtrWrapper<dyn Fn(u32) -> u32> {
3939
p
4040
}
4141

@@ -67,7 +67,7 @@ fn main() {
6767
let z = coerce_fat_ptr_wrapper(PtrWrapper(2,3,(),&square_local));
6868
assert_eq!((z.3)(6), 36);
6969

70-
let z: PtrWrapper<Fn(u32) -> u32> =
70+
let z: PtrWrapper<dyn Fn(u32) -> u32> =
7171
coerce_ptr_wrapper_poly(PtrWrapper(2,3,(),&square_local));
7272
assert_eq!((z.3)(6), 36);
7373
}

tests/run-pass/multi_arg_closure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
fn foo(f: &mut FnMut(isize, isize) -> isize) -> isize {
1+
fn foo(f: &mut dyn FnMut(isize, isize) -> isize) -> isize {
22
f(1, 2)
33
}
44

0 commit comments

Comments
 (0)