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.

0 commit comments

Comments
 (0)