Skip to content

Commit

Permalink
Fix build with rust nightly by updating try block syntax. (#2965)
Browse files Browse the repository at this point in the history
  • Loading branch information
zachlute authored and topecongiro committed Aug 26, 2018
1 parent 10512a5 commit ca19c9a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 69 deletions.
81 changes: 43 additions & 38 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Expand Up @@ -47,9 +47,9 @@ env_logger = "0.5"
getopts = "0.2"
derive-new = "0.5"
cargo_metadata = "0.6"
rustc-ap-rustc_target = "235.0.0"
rustc-ap-syntax = "235.0.0"
rustc-ap-syntax_pos = "235.0.0"
rustc-ap-rustc_target = "237.0.0"
rustc-ap-syntax = "237.0.0"
rustc-ap-syntax_pos = "237.0.0"
failure = "0.1.1"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/closures.rs
Expand Up @@ -173,7 +173,7 @@ fn rewrite_closure_expr(
match expr.node {
ast::ExprKind::Match(..)
| ast::ExprKind::Block(..)
| ast::ExprKind::Catch(..)
| ast::ExprKind::TryBlock(..)
| ast::ExprKind::Loop(..)
| ast::ExprKind::Struct(..) => true,

Expand Down
17 changes: 6 additions & 11 deletions src/expr.rs
Expand Up @@ -317,22 +317,17 @@ pub fn format_expr(
// We do not format these expressions yet, but they should still
// satisfy our width restrictions.
ast::ExprKind::InlineAsm(..) => Some(context.snippet(expr.span).to_owned()),
ast::ExprKind::Catch(ref block) => {
if let rw @ Some(_) = rewrite_single_line_block(
context,
"do catch ",
block,
Some(&expr.attrs),
None,
shape,
) {
ast::ExprKind::TryBlock(ref block) => {
if let rw @ Some(_) =
rewrite_single_line_block(context, "try ", block, Some(&expr.attrs), None, shape)
{
rw
} else {
// 9 = `do catch `
// 9 = `try `
let budget = shape.width.saturating_sub(9);
Some(format!(
"{}{}",
"do catch ",
"try ",
rewrite_block(
block,
Some(&expr.attrs),
Expand Down
17 changes: 9 additions & 8 deletions tests/source/catch.rs
@@ -1,27 +1,28 @@
#![feature(catch_expr)]
// rustfmt-edition: Edition2018
#![feature(try_blocks)]

fn main() {
let x = do catch {
let x = try {
foo()?
};

let x = do catch /* Invisible comment */ { foo()? };
let x = try /* Invisible comment */ { foo()? };

let x = do catch {
let x = try {
unsafe { foo()? }
};

let y = match (do catch {
let y = match (try {
foo()?
}) {
_ => (),
};

do catch {
try {
foo()?;
};

do catch {
// Regular do catch block
try {
// Regular try block
};
}
17 changes: 9 additions & 8 deletions tests/target/catch.rs
@@ -1,21 +1,22 @@
#![feature(catch_expr)]
// rustfmt-edition: Edition2018
#![feature(try_blocks)]

fn main() {
let x = do catch { foo()? };
let x = try { foo()? };

let x = do catch /* Invisible comment */ { foo()? };
let x = try /* Invisible comment */ { foo()? };

let x = do catch { unsafe { foo()? } };
let x = try { unsafe { foo()? } };

let y = match (do catch { foo()? }) {
let y = match (try { foo()? }) {
_ => (),
};

do catch {
try {
foo()?;
};

do catch {
// Regular do catch block
try {
// Regular try block
};
}

0 comments on commit ca19c9a

Please sign in to comment.