Skip to content

Commit d13951f

Browse files
committed
Auto merge of rust-lang#15730 - Alainx277:let-else-postfix, r=Veykril
Add postfix completion for let else Adds a postfix completion for let else syntax, similar to the if let postfix.
2 parents 7219414 + 7ec32d0 commit d13951f

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

crates/ide-completion/src/completions/postfix.rs

+37
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ pub(crate) fn complete_postfix(
8484
)
8585
.add_to(acc, ctx.db);
8686

87+
postfix_snippet(
88+
"lete",
89+
"let Ok else {}",
90+
&format!("let Ok($1) = {receiver_text} else {{\n $2\n}};\n$0"),
91+
)
92+
.add_to(acc, ctx.db);
93+
8794
postfix_snippet(
8895
"while",
8996
"while let Ok {}",
@@ -99,6 +106,13 @@ pub(crate) fn complete_postfix(
99106
)
100107
.add_to(acc, ctx.db);
101108

109+
postfix_snippet(
110+
"lete",
111+
"let Some else {}",
112+
&format!("let Some($1) = {receiver_text} else {{\n $2\n}};\n$0"),
113+
)
114+
.add_to(acc, ctx.db);
115+
102116
postfix_snippet(
103117
"while",
104118
"while let Some {}",
@@ -469,6 +483,29 @@ fn main() {
469483
);
470484
}
471485

486+
#[test]
487+
fn option_letelse() {
488+
check_edit(
489+
"lete",
490+
r#"
491+
//- minicore: option
492+
fn main() {
493+
let bar = Some(true);
494+
bar.$0
495+
}
496+
"#,
497+
r#"
498+
fn main() {
499+
let bar = Some(true);
500+
let Some($1) = bar else {
501+
$2
502+
};
503+
$0
504+
}
505+
"#,
506+
);
507+
}
508+
472509
#[test]
473510
fn result_match() {
474511
check_edit(

0 commit comments

Comments
 (0)