From e06c51553ddc202a79f2c0b76822ad56c4a30f80 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 11 Mar 2017 17:10:05 -0500 Subject: [PATCH 1/6] Rust unstable book: basic desc and example for `const_fn`. --- cargo | 2 +- src/doc/unstable-book/src/const-fn.md | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cargo b/cargo index 4a3c0a63b07e9..5f3b9c4c6a7be 160000 --- a/cargo +++ b/cargo @@ -1 +1 @@ -Subproject commit 4a3c0a63b07e9a4feb41cb11de37c92a09db5a60 +Subproject commit 5f3b9c4c6a7be1f177d6024cb83d150b6479148a diff --git a/src/doc/unstable-book/src/const-fn.md b/src/doc/unstable-book/src/const-fn.md index 9b7942c408a24..d5a2243683862 100644 --- a/src/doc/unstable-book/src/const-fn.md +++ b/src/doc/unstable-book/src/const-fn.md @@ -6,5 +6,24 @@ The tracking issue for this feature is: [#24111] ------------------------ +The `const_fn` feature allows marking free functions and inherent methods as +`const`, enabling them to be called in constants contexts, with constant +arguments. +## Examples +```rust +#![feature(const_fn)] + +const fn double(x: i32) -> i32 { + x * 2 +} + +const FIVE: i32 = 5; +const TEN: i32 = double(FIVE); + +fn main() { + assert_eq!(5, FIVE); + assert_eq!(10, TEN); +} +``` From 327e8e9196b638c4ed35ab2d57d550a3138a628b Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 11 Mar 2017 17:34:41 -0500 Subject: [PATCH 2/6] Rust unstable book: basic desc and example for `conservative_impl_trait`. --- .../src/conservative-impl-trait.md | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/doc/unstable-book/src/conservative-impl-trait.md b/src/doc/unstable-book/src/conservative-impl-trait.md index 7d8bda439bd34..62a7f8c16a0a7 100644 --- a/src/doc/unstable-book/src/conservative-impl-trait.md +++ b/src/doc/unstable-book/src/conservative-impl-trait.md @@ -6,5 +6,61 @@ The tracking issue for this feature is: [#34511] ------------------------ +The `conservative_impl_trait` feature allows a conservative form of abstract +return types. +Abstract return types allow a function to hide a concrete return type behind a +trait interface similar to trait objects, while still generating the same +statically dispatched code as with concrete types. +## Examples + +```rust +#![feature(conservative_impl_trait)] + +fn even_iter() -> impl Iterator { + (0..).map(|n| n * 2) +} + +fn main() { + let first_four_even_numbers = even_iter().take(4).collect::>(); + assert_eq!(first_four_even_numbers, vec![0, 2, 4, 6]); +} +``` + +## Background + +In today's Rust, you can write function signatures like: + +````rust,ignore +fn consume_iter_static>(iter: I) { } + +fn consume_iter_dynamic(iter: Box>) { } +```` + +In both cases, the function does not depend on the exact type of the argument. +The type held is "abstract", and is assumed only to satisfy a trait bound. + +* In the `_static` version using generics, each use of the function is + specialized to a concrete, statically-known type, giving static dispatch, + inline layout, and other performance wins. +* In the `_dynamic` version using trait objects, the concrete argument type is + only known at runtime using a vtable. + +On the other hand, while you can write: + +````rust,ignore +fn produce_iter_dynamic() -> Box> { } +```` + +...but you _cannot_ write something like: + +````rust,ignore +fn produce_iter_static() -> Iterator { } +```` + +That is, in today's Rust, abstract return types can only be written using trait +objects, which can be a significant performance penalty. This RFC proposes +"unboxed abstract types" as a way of achieving signatures like +`produce_iter_static`. Like generics, unboxed abstract types guarantee static +dispatch and inline data layout. From 0dd03ffaf72d317d7fed27562fa2c76061cd3aff Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 11 Mar 2017 20:50:18 -0500 Subject: [PATCH 3/6] Rust unstable book: basic desc and example for `const_indexing`. --- src/doc/unstable-book/src/const-indexing.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/doc/unstable-book/src/const-indexing.md b/src/doc/unstable-book/src/const-indexing.md index bd92b0b1b478f..42d46ce15f676 100644 --- a/src/doc/unstable-book/src/const-indexing.md +++ b/src/doc/unstable-book/src/const-indexing.md @@ -6,5 +6,14 @@ The tracking issue for this feature is: [#29947] ------------------------ +The `const_indexing` feature allows the constant evaluation of index operations +on constant arrays and repeat expressions. +## Examples +```rust +#![feature(const_indexing)] + +const ARR: [usize; 5] = [1, 2, 3, 4, 5]; +const ARR2: [usize; ARR[1]] = [42, 99]; +``` \ No newline at end of file From 137c1e8121b0fcaa3a1a1c7e2294e1152a932f46 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 11 Mar 2017 21:07:58 -0500 Subject: [PATCH 4/6] Rust unstable book: basic desc and example for `i128_type`. --- src/doc/unstable-book/src/i128-type.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/doc/unstable-book/src/i128-type.md b/src/doc/unstable-book/src/i128-type.md index ffcf45feb2ad7..a850b7644c3a7 100644 --- a/src/doc/unstable-book/src/i128-type.md +++ b/src/doc/unstable-book/src/i128-type.md @@ -6,5 +6,20 @@ The tracking issue for this feature is: [#35118] ------------------------ +The `i128_type` feature adds support for 128 bit signed and unsigned integer +types. +```rust +#![feature(i128_type)] + +fn main() { + assert_eq!(1u128 + 1u128, 2u128); + assert_eq!(u128::min_value(), 0); + assert_eq!(u128::max_value(), 340282366920938463463374607431768211455); + + assert_eq!(1i128 - 2i128, -1i128); + assert_eq!(i128::min_value(), -170141183460469231731687303715884105728); + assert_eq!(i128::max_value(), 170141183460469231731687303715884105727); +} +``` From e58e3d0bc0495a5103527d4c0317f089684ac0f1 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 12 Mar 2017 01:05:55 -0500 Subject: [PATCH 5/6] Rust unstable book: basic desc and example for `non_ascii_idents`. --- src/doc/unstable-book/src/non-ascii-idents.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/doc/unstable-book/src/non-ascii-idents.md b/src/doc/unstable-book/src/non-ascii-idents.md index f426022ab3a51..d5600c58fd9a6 100644 --- a/src/doc/unstable-book/src/non-ascii-idents.md +++ b/src/doc/unstable-book/src/non-ascii-idents.md @@ -6,5 +6,13 @@ The tracking issue for this feature is: [#28979] ------------------------ +The `non_ascii_idents` feature adds support for non-ASCII identifiers. +## Examples +```rust +#![feature(non_ascii_idents)] + +const ε: f64 = 0.00001f64; +const Π: f64 = 3.14f64; +``` \ No newline at end of file From d3ae2eb58ea2f96aa52b53d9171111b176b611eb Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 12 Mar 2017 01:12:29 -0500 Subject: [PATCH 6/6] Rust unstable book: basic desc and example for `concat_idents`. --- src/doc/unstable-book/src/concat-idents.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/doc/unstable-book/src/concat-idents.md b/src/doc/unstable-book/src/concat-idents.md index c9a48293dba68..ecfd34a22e5cc 100644 --- a/src/doc/unstable-book/src/concat-idents.md +++ b/src/doc/unstable-book/src/concat-idents.md @@ -6,5 +6,17 @@ The tracking issue for this feature is: [#29599] ------------------------ +The `concat_idents` feature adds a macro for concatenating multiple identifiers +into one identifier. +## Examples +```rust +#![feature(concat_idents)] + +fn main() { + fn foobar() -> u32 { 23 } + let f = concat_idents!(foo, bar); + assert_eq!(f(), 23); +} +``` \ No newline at end of file