Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
};
}