Skip to content

Commit ca19c9a

Browse files
zachlutetopecongiro
authored andcommitted
Fix build with rust nightly by updating try block syntax. (#2965)
1 parent 10512a5 commit ca19c9a

File tree

6 files changed

+71
-69
lines changed

6 files changed

+71
-69
lines changed

Cargo.lock

+43-38
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ env_logger = "0.5"
4747
getopts = "0.2"
4848
derive-new = "0.5"
4949
cargo_metadata = "0.6"
50-
rustc-ap-rustc_target = "235.0.0"
51-
rustc-ap-syntax = "235.0.0"
52-
rustc-ap-syntax_pos = "235.0.0"
50+
rustc-ap-rustc_target = "237.0.0"
51+
rustc-ap-syntax = "237.0.0"
52+
rustc-ap-syntax_pos = "237.0.0"
5353
failure = "0.1.1"
5454

5555
[dev-dependencies]

src/closures.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ fn rewrite_closure_expr(
173173
match expr.node {
174174
ast::ExprKind::Match(..)
175175
| ast::ExprKind::Block(..)
176-
| ast::ExprKind::Catch(..)
176+
| ast::ExprKind::TryBlock(..)
177177
| ast::ExprKind::Loop(..)
178178
| ast::ExprKind::Struct(..) => true,
179179

src/expr.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -317,22 +317,17 @@ pub fn format_expr(
317317
// We do not format these expressions yet, but they should still
318318
// satisfy our width restrictions.
319319
ast::ExprKind::InlineAsm(..) => Some(context.snippet(expr.span).to_owned()),
320-
ast::ExprKind::Catch(ref block) => {
321-
if let rw @ Some(_) = rewrite_single_line_block(
322-
context,
323-
"do catch ",
324-
block,
325-
Some(&expr.attrs),
326-
None,
327-
shape,
328-
) {
320+
ast::ExprKind::TryBlock(ref block) => {
321+
if let rw @ Some(_) =
322+
rewrite_single_line_block(context, "try ", block, Some(&expr.attrs), None, shape)
323+
{
329324
rw
330325
} else {
331-
// 9 = `do catch `
326+
// 9 = `try `
332327
let budget = shape.width.saturating_sub(9);
333328
Some(format!(
334329
"{}{}",
335-
"do catch ",
330+
"try ",
336331
rewrite_block(
337332
block,
338333
Some(&expr.attrs),

tests/source/catch.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1-
#![feature(catch_expr)]
1+
// rustfmt-edition: Edition2018
2+
#![feature(try_blocks)]
23

34
fn main() {
4-
let x = do catch {
5+
let x = try {
56
foo()?
67
};
78

8-
let x = do catch /* Invisible comment */ { foo()? };
9+
let x = try /* Invisible comment */ { foo()? };
910

10-
let x = do catch {
11+
let x = try {
1112
unsafe { foo()? }
1213
};
1314

14-
let y = match (do catch {
15+
let y = match (try {
1516
foo()?
1617
}) {
1718
_ => (),
1819
};
1920

20-
do catch {
21+
try {
2122
foo()?;
2223
};
2324

24-
do catch {
25-
// Regular do catch block
25+
try {
26+
// Regular try block
2627
};
2728
}

tests/target/catch.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
#![feature(catch_expr)]
1+
// rustfmt-edition: Edition2018
2+
#![feature(try_blocks)]
23

34
fn main() {
4-
let x = do catch { foo()? };
5+
let x = try { foo()? };
56

6-
let x = do catch /* Invisible comment */ { foo()? };
7+
let x = try /* Invisible comment */ { foo()? };
78

8-
let x = do catch { unsafe { foo()? } };
9+
let x = try { unsafe { foo()? } };
910

10-
let y = match (do catch { foo()? }) {
11+
let y = match (try { foo()? }) {
1112
_ => (),
1213
};
1314

14-
do catch {
15+
try {
1516
foo()?;
1617
};
1718

18-
do catch {
19-
// Regular do catch block
19+
try {
20+
// Regular try block
2021
};
2122
}

0 commit comments

Comments
 (0)