Skip to content

Commit 7a7e236

Browse files
authored
Rollup merge of #42122 - rust-lang:frewsxcv/unstable-book, r=steveklabnik
Add a few entries to the Unstable Book.
2 parents e38d5d5 + 2d3438d commit 7a7e236

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

src/doc/unstable-book/src/language-features/attr-literals.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,25 @@ The tracking issue for this feature is: [#34981]
66

77
------------------------
88

9+
At present, literals are only accepted as the value of a key-value pair in
10+
attributes. What's more, only _string_ literals are accepted. This means that
11+
literals can only appear in forms of `#[attr(name = "value")]` or
12+
`#[attr = "value"]`.
913

14+
The `attr_literals` unstable feature allows other types of literals to be used
15+
in attributes. Here are some examples of attributes that can now be used with
16+
this feature enabled:
17+
18+
+```rust,ignore
19+
+#[attr]
20+
+#[attr(true)]
21+
+#[attr(ident)]
22+
+#[attr(ident, 100, true, "true", ident = 100, ident = "hello", ident(100))]
23+
+#[attr(100)]
24+
+#[attr(enabled = true)]
25+
+#[enabled(true)]
26+
+#[attr("hello")]
27+
+#[repr(C, align = 4)]
28+
+#[repr(C, align(4))]
29+
+```
1030

src/doc/unstable-book/src/language-features/catch-expr.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,26 @@ The tracking issue for this feature is: [#31436]
55
[#31436]: https://github.com/rust-lang/rust/issues/31436
66

77
------------------------
8+
9+
The `catch_expr` feature adds support for a `catch` expression. The `catch`
10+
expression creates a new scope one can use the `?` operator in.
11+
12+
```rust
13+
#![feature(catch_expr)]
14+
15+
use std::num::ParseIntError;
16+
17+
let result: Result<i32, ParseIntError> = do catch {
18+
Ok("1".parse::<i32>()?
19+
+ "2".parse::<i32>()?
20+
+ "3".parse::<i32>()?)
21+
};
22+
assert_eq!(result, Ok(6));
23+
24+
let result: Result<i32, ParseIntError> = do catch {
25+
Ok("1".parse::<i32>()?
26+
+ "foo".parse::<i32>()?
27+
+ "3".parse::<i32>()?)
28+
};
29+
assert!(result.is_err());
30+
```

src/doc/unstable-book/src/language-features/on-unimplemented.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,42 @@ The tracking issue for this feature is: [#29628]
66

77
------------------------
88

9+
The `on_unimplemented` feature provides the `#[rustc_on_unimplemented]`
10+
attribute, which allows trait definitions to add specialized notes to error
11+
messages when an implementation was expected but not found.
912

13+
For example:
14+
15+
```rust,compile_fail
16+
#![feature(on_unimplemented)]
17+
18+
#[rustc_on_unimplemented="a collection of type `{Self}` cannot be built from an \
19+
iterator over elements of type `{A}`"]
20+
trait MyIterator<A> {
21+
fn next(&mut self) -> A;
22+
}
23+
24+
fn iterate_chars<I: MyIterator<char>>(i: I) {
25+
// ...
26+
}
27+
28+
fn main() {
29+
iterate_chars(&[1, 2, 3][..]);
30+
}
31+
```
32+
33+
When the user compiles this, they will see the following;
34+
35+
```txt
36+
error[E0277]: the trait bound `&[{integer}]: MyIterator<char>` is not satisfied
37+
--> <anon>:14:5
38+
|
39+
14 | iterate_chars(&[1, 2, 3][..]);
40+
| ^^^^^^^^^^^^^ the trait `MyIterator<char>` is not implemented for `&[{integer}]`
41+
|
42+
= note: a collection of type `&[{integer}]` cannot be built from an iterator over elements of type `char`
43+
= note: required by `iterate_chars`
44+
45+
error: aborting due to previous error
46+
```
1047

0 commit comments

Comments
 (0)