Skip to content

Commit

Permalink
Merge pull request #100 from dtolnay/closurebailout
Browse files Browse the repository at this point in the history
Disregard bailouts inside of closure bodies
  • Loading branch information
dtolnay authored Jan 12, 2025
2 parents ee1a762 + 490d479 commit f191a5b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 20 deletions.
21 changes: 1 addition & 20 deletions src/fixup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::classify;
use crate::precedence::Precedence;
use syn::{
Expr, ExprBreak, ExprRange, ExprRawAddr, ExprReference, ExprReturn, ExprUnary, ExprYield,
ReturnType,
};

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -595,25 +594,7 @@ fn scan_right(
_ => Scan::Consume,
},
},
// false positive: https://github.com/rust-lang/rust/issues/117304
#[cfg_attr(all(test, exhaustive), allow(non_exhaustive_omitted_patterns))]
Expr::Closure(e) => {
if matches!(e.output, ReturnType::Default)
|| matches!(&*e.body, Expr::Block(body) if body.attrs.is_empty() && body.label.is_none())
{
if bailout_offset >= 1 {
return Scan::Consume;
}
let right_fixup =
fixup.rightmost_subexpression_fixup(false, false, Precedence::Jump);
match scan_right(&e.body, right_fixup, Precedence::Jump, 1, 1) {
Scan::Fail => Scan::Bailout,
Scan::Bailout | Scan::Consume => Scan::Consume,
}
} else {
Scan::Consume
}
}
Expr::Closure(_) => Scan::Consume,
Expr::Let(e) => {
if bailout_offset >= 1 {
return Scan::Consume;
Expand Down
4 changes: 4 additions & 0 deletions tests/test_precedence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,10 @@ fn test_permutations() -> ExitCode {
parsed,
);
}
if pretty.contains("(||") {
// https://github.com/dtolnay/prettyplease/issues/99
return;
}
let no_paren = pretty.replace(['(', ')'], "");
if pretty != no_paren {
if let Ok(mut parsed2) = syn::parse_file(&no_paren) {
Expand Down

0 comments on commit f191a5b

Please sign in to comment.