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
5 changes: 4 additions & 1 deletion src/tools/rustfmt/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1553,7 +1553,10 @@ pub(crate) fn can_be_overflowed_expr(
}

// Handle always block-like expressions
ast::ExprKind::Gen(..) | ast::ExprKind::Block(..) | ast::ExprKind::Closure(..) => true,
ast::ExprKind::Gen(..)
| ast::ExprKind::Block(..)
| ast::ExprKind::Closure(..)
| ast::ExprKind::TryBlock(..) => true,

// Handle `[]` and `{}`-like expressions
ast::ExprKind::Array(..) | ast::ExprKind::Struct(..) => {
Expand Down
8 changes: 8 additions & 0 deletions src/tools/rustfmt/tests/source/try_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,13 @@ fn baz() -> Option<i32> {

let x: Option<i32> = try { baz()?; baz()?; baz()?; 7 };

let _ = overflowed_expr(
x,
try {
foo()?;
bar()?;
},
);

return None;
}
10 changes: 10 additions & 0 deletions src/tools/rustfmt/tests/source/try_blocks_heterogeneous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,15 @@ fn baz() -> Option<i32> {

let x = try bikeshed Foo<Bar, Bar, Bar, Bar, Bar, Bar, Bar, Bar, Bar, Bar, Bar, Bar, Bar, Bar> {};

let x = try bikeshed Result<VeryVeryVeryVeryVeryLongTypeForSuccess, VeryVeryVeryVeryVeryLongTypeForFailure> {};

let _ = overflowed_expr(
x,
try bikeshed Option<_> {
foo()?;
bar()?;
},
);

return None;
}
5 changes: 5 additions & 0 deletions src/tools/rustfmt/tests/target/try_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,10 @@ fn baz() -> Option<i32> {
7
};

let _ = overflowed_expr(x, try {
foo()?;
bar()?;
});

return None;
}
11 changes: 11 additions & 0 deletions src/tools/rustfmt/tests/target/try_blocks_heterogeneous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,16 @@ fn baz() -> Option<i32> {
let x =
try bikeshed Foo<Bar, Bar, Bar, Bar, Bar, Bar, Bar, Bar, Bar, Bar, Bar, Bar, Bar, Bar> {};

let x = try bikeshed Result<
VeryVeryVeryVeryVeryLongTypeForSuccess,
VeryVeryVeryVeryVeryLongTypeForFailure,
> {
};
Comment on lines +40 to +44
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not directly related to the PR, but an oversight from #152293 that I realized based on feedback in #152311. I believe it's small enough to be fine to fit in this PR. Otherwise, I'm happy to create a separate PR if needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you elaborate on what the oversight was? I'm a little confused.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I forgot to test the case where the type needs to be broken. That's essentially the last condition of #152311 (comment). The other cases are already covered.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. Yeah, that's fine to include here.


let _ = overflowed_expr(x, try bikeshed Option<_> {
foo()?;
bar()?;
});

return None;
}
Loading