Skip to content

Commit c2673b2

Browse files
committed
Add let-else test case with trailing try operator ?
This was a test case I found when testing `let-else` formatting on projects out in the wild. It's a case that I hadn't considered before and thought it was novel enough to add a test case. I have a feeling some users are going to be unhappy that the `?` forces the `else block` onto the next line, while the same code without the trailing `?` does not. I guess we'll have to wait and see!
1 parent 3610c62 commit c2673b2

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

tests/source/let_else.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,12 @@ fn long_patterns() {
151151
return;
152152
};
153153
}
154+
155+
fn with_trailing_try_operator() {
156+
// Currently the trailing ? forces the else on the next line
157+
// This may be revisited in style edition 2024
158+
let Some(next_bucket) = ranking_rules[cur_ranking_rule_index].next_bucket(ctx, logger, &ranking_rule_universes[cur_ranking_rule_index])? else { return };
159+
160+
// Maybe this is a workaround?
161+
let Ok(Some(next_bucket)) = ranking_rules[cur_ranking_rule_index].next_bucket(ctx, logger, &ranking_rule_universes[cur_ranking_rule_index]) else { return };
162+
}

tests/target/let_else.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,25 @@ fn long_patterns() {
230230
return;
231231
};
232232
}
233+
234+
fn with_trailing_try_operator() {
235+
// Currently the trailing ? forces the else on the next line
236+
// This may be revisited in style edition 2024
237+
let Some(next_bucket) = ranking_rules[cur_ranking_rule_index].next_bucket(
238+
ctx,
239+
logger,
240+
&ranking_rule_universes[cur_ranking_rule_index],
241+
)?
242+
else {
243+
return;
244+
};
245+
246+
// Maybe this is a workaround?
247+
let Ok(Some(next_bucket)) = ranking_rules[cur_ranking_rule_index].next_bucket(
248+
ctx,
249+
logger,
250+
&ranking_rule_universes[cur_ranking_rule_index],
251+
) else {
252+
return;
253+
};
254+
}

0 commit comments

Comments
 (0)