Skip to content

Commit b867376

Browse files
Alexander Regueirocrlf0710
Alexander Regueiro
authored andcommitted
Added page to Unstable Book.
1 parent a1cff1c commit b867376

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# `trait_upcasting`
2+
3+
The tracking issue for this feature is: [#31436]
4+
5+
[#65991]: https://github.com/rust-lang/rust/issues/65991
6+
7+
------------------------
8+
9+
The `trait_upcasting` feature adds support for trait upcasting. This allows a
10+
trait object of type `dyn Foo` to be cast to a trait object of type `dyn Bar`
11+
so long as `Foo: Bar`.
12+
13+
```rust,edition2018
14+
#![feature(trait_upcasting)]
15+
16+
trait Foo {}
17+
18+
trait Bar: Foo {}
19+
20+
impl Foo for i32 {}
21+
22+
impl<T: Foo + ?Sized> Bar for T {}
23+
24+
let foo: &dyn Foo = &123;
25+
let bar: &dyn Bar = foo;
26+
```

0 commit comments

Comments
 (0)