Skip to content

Commit 5d25e1e

Browse files
committed
Rollup merge of rust-lang#45166 - tinaun:more_unstable_docs, r=steveklabnik
Documented a few more unstable feature gates. unboxed closures, fn_traits, and OIBIT. hope these are decent!
2 parents 9655312 + d5ef9f9 commit 5d25e1e

File tree

3 files changed

+107
-0
lines changed

3 files changed

+107
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# `optin_builtin_traits`
2+
3+
The tracking issue for this feature is [#13231]
4+
5+
[#13231]: https://github.com/rust-lang/rust/issues/13231
6+
7+
----
8+
9+
The `optin_builtin_traits` feature gate allows you to define auto traits.
10+
11+
Auto traits, like [`Send`] or [`Sync`] in the standard library, are marker traits
12+
that are automatically implemented for every type, unless the type, or a type it contains,
13+
has explictly opted out via a negative impl.
14+
15+
[`Send`]: https://doc.rust-lang.org/std/marker/trait.Send.html
16+
[`Sync`]: https://doc.rust-lang.org/std/marker/trait.Sync.html
17+
18+
```rust,ignore
19+
impl !Type for Trait
20+
```
21+
22+
Example:
23+
24+
```rust
25+
#![feature(optin_builtin_traits)]
26+
27+
trait Valid {}
28+
29+
impl Valid for .. {}
30+
31+
struct True;
32+
struct False;
33+
34+
impl !Valid for False {}
35+
36+
struct MaybeValid<T>(T);
37+
38+
fn must_be_valid<T: Valid>(_t: T) { }
39+
40+
fn main() {
41+
// works
42+
must_be_valid( MaybeValid(True) );
43+
44+
// compiler error - trait bound not satisfied
45+
// must_be_valid( MaybeValid(False) );
46+
}
47+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# `unboxed_closures`
2+
3+
The tracking issue for this feature is [#29625]
4+
5+
See Also: [`fn_traits`](library-features/fn-traits.html)
6+
7+
[#29625]: https://github.com/rust-lang/rust/issues/29625
8+
9+
----
10+
11+
The `unboxed_closures` feature allows you to write functions using the `"rust-call"` ABI,
12+
required for implmenting the [`Fn*`] family of traits. `"rust-call"` functions must have
13+
exactly one (non self) argument, a tuple representing the argument list.
14+
15+
[`Fn*`]: https://doc.rust-lang.org/std/ops/trait.Fn.html
16+
17+
```rust
18+
#![feature(unboxed_closures)]
19+
20+
extern "rust-call" fn add_args(args: (u32, u32)) -> u32 {
21+
args.0 + args.1
22+
}
23+
24+
fn main() {}
25+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# `fn_traits`
2+
3+
The tracking issue for this feature is [#29625]
4+
5+
See Also: [`unboxed_closures`](language-features/unboxed-closures.html)
6+
7+
[#29625]: https://github.com/rust-lang/rust/issues/29625
8+
9+
----
10+
11+
The `fn_traits` feature allows for implementation of the [`Fn*`] traits
12+
for creating custom closure-like types.
13+
14+
[`Fn*`]: https://doc.rust-lang.org/std/ops/trait.Fn.html
15+
16+
```rust
17+
#![feature(unboxed_closures)]
18+
#![feature(fn_traits)]
19+
20+
struct Adder {
21+
a: u32
22+
}
23+
24+
impl FnOnce<(u32, )> for Adder {
25+
type Output = u32;
26+
extern "rust-call" fn call_once(self, b: (u32, )) -> Self::Output {
27+
self.a + b.0
28+
}
29+
}
30+
31+
fn main() {
32+
let adder = Adder { a: 3 };
33+
assert_eq!(adder(2), 5);
34+
}
35+
```

0 commit comments

Comments
 (0)