Skip to content

Commit ac8d8d7

Browse files
committed
Add test for doctest edition support
1 parent c996c4d commit ac8d8d7

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

src/doc/unstable-book/src/language-features/try-blocks.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ The tracking issue for this feature is: [#31436]
99
The `try_blocks` feature adds support for `try` blocks. A `try`
1010
block creates a new scope one can use the `?` operator in.
1111

12-
```rust,ignore
13-
// This code needs the 2018 edition
14-
12+
```rust,edition2018
1513
#![feature(try_blocks)]
1614
1715
use std::num::ParseIntError;

src/test/rustdoc/edition-doctest.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags:--test
12+
13+
/// ```rust,edition2018
14+
/// #![feature(try_blocks)]
15+
///
16+
/// use std::num::ParseIntError;
17+
///
18+
/// let result: Result<i32, ParseIntError> = try {
19+
/// "1".parse::<i32>()?
20+
/// + "2".parse::<i32>()?
21+
/// + "3".parse::<i32>()?
22+
/// };
23+
/// assert_eq!(result, Ok(6));
24+
///
25+
/// let result: Result<i32, ParseIntError> = try {
26+
/// "1".parse::<i32>()?
27+
/// + "foo".parse::<i32>()?
28+
/// + "3".parse::<i32>()?
29+
/// };
30+
/// assert!(result.is_err());
31+
/// ```
32+
33+
34+
/// ```rust,edition2015,compile_fail,E0574
35+
/// #![feature(try_blocks)]
36+
///
37+
/// use std::num::ParseIntError;
38+
///
39+
/// let result: Result<i32, ParseIntError> = try {
40+
/// "1".parse::<i32>()?
41+
/// + "2".parse::<i32>()?
42+
/// + "3".parse::<i32>()?
43+
/// };
44+
/// assert_eq!(result, Ok(6));
45+
///
46+
/// let result: Result<i32, ParseIntError> = try {
47+
/// "1".parse::<i32>()?
48+
/// + "foo".parse::<i32>()?
49+
/// + "3".parse::<i32>()?
50+
/// };
51+
/// assert!(result.is_err());
52+
/// ```
53+
54+
pub fn foo() {}

0 commit comments

Comments
 (0)