-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 #45233 - kennytm:rollup, r=kennytm
Rollup of 9 pull requests - Successful merges: #44989, #45005, #45049, #45105, #45121, #45166, #45172, #45190, #45231 - Failed merges: #45138
- Loading branch information
Showing
31 changed files
with
240 additions
and
73 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
47 changes: 47 additions & 0 deletions
47
src/doc/unstable-book/src/language-features/optin-builtin-traits.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,47 @@ | ||
# `optin_builtin_traits` | ||
|
||
The tracking issue for this feature is [#13231] | ||
|
||
[#13231]: https://github.com/rust-lang/rust/issues/13231 | ||
|
||
---- | ||
|
||
The `optin_builtin_traits` feature gate allows you to define auto traits. | ||
|
||
Auto traits, like [`Send`] or [`Sync`] in the standard library, are marker traits | ||
that are automatically implemented for every type, unless the type, or a type it contains, | ||
has explictly opted out via a negative impl. | ||
|
||
[`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html | ||
[`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html | ||
|
||
```rust,ignore | ||
impl !Type for Trait | ||
``` | ||
|
||
Example: | ||
|
||
```rust | ||
#![feature(optin_builtin_traits)] | ||
|
||
trait Valid {} | ||
|
||
impl Valid for .. {} | ||
|
||
struct True; | ||
struct False; | ||
|
||
impl !Valid for False {} | ||
|
||
struct MaybeValid<T>(T); | ||
|
||
fn must_be_valid<T: Valid>(_t: T) { } | ||
|
||
fn main() { | ||
// works | ||
must_be_valid( MaybeValid(True) ); | ||
|
||
// compiler error - trait bound not satisfied | ||
// must_be_valid( MaybeValid(False) ); | ||
} | ||
``` |
25 changes: 25 additions & 0 deletions
25
src/doc/unstable-book/src/language-features/unboxed-closures.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,25 @@ | ||
# `unboxed_closures` | ||
|
||
The tracking issue for this feature is [#29625] | ||
|
||
See Also: [`fn_traits`](library-features/fn-traits.html) | ||
|
||
[#29625]: https://github.com/rust-lang/rust/issues/29625 | ||
|
||
---- | ||
|
||
The `unboxed_closures` feature allows you to write functions using the `"rust-call"` ABI, | ||
required for implmenting the [`Fn*`] family of traits. `"rust-call"` functions must have | ||
exactly one (non self) argument, a tuple representing the argument list. | ||
|
||
[`Fn*`]: https://doc.rust-lang.org/std/ops/trait.Fn.html | ||
|
||
```rust | ||
#![feature(unboxed_closures)] | ||
|
||
extern "rust-call" fn add_args(args: (u32, u32)) -> u32 { | ||
args.0 + args.1 | ||
} | ||
|
||
fn main() {} | ||
``` |
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,35 @@ | ||
# `fn_traits` | ||
|
||
The tracking issue for this feature is [#29625] | ||
|
||
See Also: [`unboxed_closures`](language-features/unboxed-closures.html) | ||
|
||
[#29625]: https://github.com/rust-lang/rust/issues/29625 | ||
|
||
---- | ||
|
||
The `fn_traits` feature allows for implementation of the [`Fn*`] traits | ||
for creating custom closure-like types. | ||
|
||
[`Fn*`]: https://doc.rust-lang.org/std/ops/trait.Fn.html | ||
|
||
```rust | ||
#![feature(unboxed_closures)] | ||
#![feature(fn_traits)] | ||
|
||
struct Adder { | ||
a: u32 | ||
} | ||
|
||
impl FnOnce<(u32, )> for Adder { | ||
type Output = u32; | ||
extern "rust-call" fn call_once(self, b: (u32, )) -> Self::Output { | ||
self.a + b.0 | ||
} | ||
} | ||
|
||
fn main() { | ||
let adder = Adder { a: 3 }; | ||
assert_eq!(adder(2), 5); | ||
} | ||
``` |
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.