about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-05-23 00:15:42 -0400
committerGitHub <noreply@github.com>2017-05-23 00:15:42 -0400
commit7a7e2360765e5ce2eb0ad5da409da24f440dc68f (patch)
tree5b5ce1cbeab505f1f0a2bb4ee0e53a814b418ab0 /src
parente38d5d5039c0d46f4021a176c00501c7c27379fb (diff)
parent2d3438d35f8db4de0326f56232169b0bdbd6051c (diff)
downloadrust-7a7e2360765e5ce2eb0ad5da409da24f440dc68f.tar.gz
rust-7a7e2360765e5ce2eb0ad5da409da24f440dc68f.zip
Rollup merge of #42122 - rust-lang:frewsxcv/unstable-book, r=steveklabnik
Add a few entries to the Unstable Book.
Diffstat (limited to 'src')
-rw-r--r--src/doc/unstable-book/src/language-features/attr-literals.md20
-rw-r--r--src/doc/unstable-book/src/language-features/catch-expr.md23
-rw-r--r--src/doc/unstable-book/src/language-features/on-unimplemented.md37
3 files changed, 80 insertions, 0 deletions
diff --git a/src/doc/unstable-book/src/language-features/attr-literals.md b/src/doc/unstable-book/src/language-features/attr-literals.md
index 67eee214a4f..60741a74400 100644
--- a/src/doc/unstable-book/src/language-features/attr-literals.md
+++ b/src/doc/unstable-book/src/language-features/attr-literals.md
@@ -6,5 +6,25 @@ The tracking issue for this feature is: [#34981]
 
 ------------------------
 
+At present, literals are only accepted as the value of a key-value pair in
+attributes. What's more, only _string_ literals are accepted. This means that
+literals can only appear in forms of `#[attr(name = "value")]` or
+`#[attr = "value"]`.
 
+The `attr_literals` unstable feature allows other types of literals to be used
+in attributes. Here are some examples of attributes that can now be used with
+this feature enabled:
+
++```rust,ignore
++#[attr]
++#[attr(true)]
++#[attr(ident)]
++#[attr(ident, 100, true, "true", ident = 100, ident = "hello", ident(100))]
++#[attr(100)]
++#[attr(enabled = true)]
++#[enabled(true)]
++#[attr("hello")]
++#[repr(C, align = 4)]
++#[repr(C, align(4))]
++```
 
diff --git a/src/doc/unstable-book/src/language-features/catch-expr.md b/src/doc/unstable-book/src/language-features/catch-expr.md
index 44eb2a6dd4f..fbd213dca56 100644
--- a/src/doc/unstable-book/src/language-features/catch-expr.md
+++ b/src/doc/unstable-book/src/language-features/catch-expr.md
@@ -5,3 +5,26 @@ The tracking issue for this feature is: [#31436]
 [#31436]: https://github.com/rust-lang/rust/issues/31436
 
 ------------------------
+
+The `catch_expr` feature adds support for a `catch` expression. The `catch`
+expression creates a new scope one can use the `?` operator in.
+
+```rust
+#![feature(catch_expr)]
+
+use std::num::ParseIntError;
+
+let result: Result<i32, ParseIntError> = do catch {
+    Ok("1".parse::<i32>()?
+        + "2".parse::<i32>()?
+        + "3".parse::<i32>()?)
+};
+assert_eq!(result, Ok(6));
+
+let result: Result<i32, ParseIntError> = do catch {
+    Ok("1".parse::<i32>()?
+        + "foo".parse::<i32>()?
+        + "3".parse::<i32>()?)
+};
+assert!(result.is_err());
+```
diff --git a/src/doc/unstable-book/src/language-features/on-unimplemented.md b/src/doc/unstable-book/src/language-features/on-unimplemented.md
index 81f284d0a6a..9eea3fccbbc 100644
--- a/src/doc/unstable-book/src/language-features/on-unimplemented.md
+++ b/src/doc/unstable-book/src/language-features/on-unimplemented.md
@@ -6,5 +6,42 @@ The tracking issue for this feature is: [#29628]
 
 ------------------------
 
+The `on_unimplemented` feature provides the `#[rustc_on_unimplemented]`
+attribute, which allows trait definitions to add specialized notes to error
+messages when an implementation was expected but not found.
 
+For example:
+
+```rust,compile_fail
+#![feature(on_unimplemented)]
+
+#[rustc_on_unimplemented="a collection of type `{Self}` cannot be built from an \
+                          iterator over elements of type `{A}`"]
+trait MyIterator<A> {
+    fn next(&mut self) -> A;
+}
+
+fn iterate_chars<I: MyIterator<char>>(i: I) {
+    // ...
+}
+
+fn main() {
+    iterate_chars(&[1, 2, 3][..]);
+}
+```
+
+When the user compiles this, they will see the following;
+
+```txt
+error[E0277]: the trait bound `&[{integer}]: MyIterator<char>` is not satisfied
+  --> <anon>:14:5
+   |
+14 |     iterate_chars(&[1, 2, 3][..]);
+   |     ^^^^^^^^^^^^^ the trait `MyIterator<char>` is not implemented for `&[{integer}]`
+   |
+   = note: a collection of type `&[{integer}]` cannot be built from an iterator over elements of type `char`
+   = note: required by `iterate_chars`
+
+error: aborting due to previous error
+```