-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #55101 - alexreg:trait-aliases, r=nikomatsakis
Implement trait aliases (RFC 1733) Extends groundwork done in #45047, and fully implements rust-lang/rfcs#1733. CC @durka @nikomatsakis
- Loading branch information
Showing
42 changed files
with
633 additions
and
332 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/doc/unstable-book/src/language-features/trait-alias.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# `trait_alias` | ||
|
||
The tracking issue for this feature is: [#41517] | ||
|
||
[#41417]: https://github.com/rust-lang/rust/issues/41517 | ||
|
||
------------------------ | ||
|
||
The `trait_alias` feature adds support for trait aliases. These allow aliases | ||
to be created for one or more traits (currently just a single regular trait plus | ||
any number of auto-traits), and used wherever traits would normally be used as | ||
either bounds or trait objects. | ||
|
||
```rust | ||
#![feature(trait_alias)] | ||
|
||
trait Foo = std::fmt::Debug + Send; | ||
trait Bar = Foo + Sync; | ||
|
||
// Use trait alias as bound on type parameter. | ||
fn foo<T: Foo>(v: &T) { | ||
println!("{:?}", v); | ||
} | ||
|
||
pub fn main() { | ||
foo(&1); | ||
|
||
// Use trait alias for trait objects. | ||
let a: &Bar = &123; | ||
println!("{:?}", a); | ||
let b = Box::new(456) as Box<dyn Foo>; | ||
println!("{:?}", b); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.