about summary refs log tree commit diff
path: root/src/doc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-08-03 16:58:56 +0000
committerbors <bors@rust-lang.org>2021-08-03 16:58:56 +0000
commitc6bc102fea9f9274202d0bc55a0fef8a3bc92426 (patch)
tree467d0caf4e7b1c0defb58a75a5585eb3f95aecbd /src/doc
parentd5fd37f00f1ec5e4a4b0d87f5af0b93f36aab271 (diff)
parent3cb625e4683c43991de6fc27d6b4e0db5a34011f (diff)
downloadrust-c6bc102fea9f9274202d0bc55a0fef8a3bc92426.tar.gz
rust-c6bc102fea9f9274202d0bc55a0fef8a3bc92426.zip
Auto merge of #87515 - crlf0710:trait_upcasting_part2, r=bjorn3
Trait upcasting coercion (part2)

This is the second part of trait upcasting coercion implementation.

Currently this is blocked on #86264 .

The third part might be implemented using unsafety checking

r? `@bjorn3`
Diffstat (limited to 'src/doc')
-rw-r--r--src/doc/unstable-book/src/language-features/trait-upcasting.md27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/doc/unstable-book/src/language-features/trait-upcasting.md b/src/doc/unstable-book/src/language-features/trait-upcasting.md
new file mode 100644
index 00000000000..3697ae38f9d
--- /dev/null
+++ b/src/doc/unstable-book/src/language-features/trait-upcasting.md
@@ -0,0 +1,27 @@
+# `trait_upcasting`
+
+The tracking issue for this feature is: [#65991]
+
+[#65991]: https://github.com/rust-lang/rust/issues/65991
+
+------------------------
+
+The `trait_upcasting` feature adds support for trait upcasting coercion. This allows a
+trait object of type `dyn Bar` to be cast to a trait object of type `dyn Foo`
+so long as `Bar: Foo`.
+
+```rust,edition2018
+#![feature(trait_upcasting)]
+#![allow(incomplete_features)]
+
+trait Foo {}
+
+trait Bar: Foo {}
+
+impl Foo for i32 {}
+
+impl<T: Foo + ?Sized> Bar for T {}
+
+let bar: &dyn Bar = &123;
+let foo: &dyn Foo = bar;
+```