-
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 #53542 - alexreg:impl-trait-in-bindings, r=cramertj
`impl trait` in bindings (feature: impl-trait-existential-types) This PR enables `impl Trait` syntax (opaque types) to be used in bindings, e.g. * `let foo: impl Clone = 1;` * `static foo: impl Clone = 2;` * `const foo: impl Clone = 3;` This is part of [RFC 2071](https://github.com/rust-lang/rfcs/blob/master/text/2071-impl-trait-existential-types.md) ([tracking issue](#34511)), but exists behind the separate feature gate `impl_trait_in_bindings`. CC @cramertj @oli-obk @eddyb @Centril @varkor
- Loading branch information
Showing
25 changed files
with
746 additions
and
370 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/doc/unstable-book/src/language-features/impl-trait-in-bindings.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,28 @@ | ||
# `impl_trait_in_bindings` | ||
|
||
The tracking issue for this feature is: [#34511] | ||
|
||
[#34511]: https://github.com/rust-lang/rust/issues/34511 | ||
|
||
------------------------ | ||
|
||
The `impl_trait_in_bindings` feature gate lets you use `impl Trait` syntax in | ||
`let`, `static`, and `const` bindings. | ||
|
||
A simple example is: | ||
|
||
```rust | ||
#![feature(impl_trait_in_bindings)] | ||
|
||
use std::fmt::Debug; | ||
|
||
fn main() { | ||
let a: impl Debug + Clone = 42; | ||
let b = a.clone(); | ||
println!("{:?}", b); // prints `42` | ||
} | ||
``` | ||
|
||
Note however that because the types of `a` and `b` are opaque in the above | ||
example, calling inherent methods or methods outside of the specified traits | ||
(e.g., `a.abs()` or `b.abs()`) is not allowed, and yields an error. |
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.