From e06c51553ddc202a79f2c0b76822ad56c4a30f80 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sat, 11 Mar 2017 17:10:05 -0500 Subject: [PATCH] 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 4a3c0a63b07..5f3b9c4c6a7 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 9b7942c408a..d5a22436838 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); +} +```