refactor: migrate let_else_to_match to editor

Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
This commit is contained in:
Prajwal S N 2025-04-08 14:18:09 +05:30
parent 5adee2ad2c
commit 2eb7389b63
No known key found for this signature in database
GPG key ID: 60701A603988FAC2
8 changed files with 335 additions and 142 deletions

View file

@ -709,7 +709,7 @@ pub fn wildcard_pat() -> ast::WildcardPat {
}
pub fn rest_pat() -> ast::RestPat {
ast_from_text("fn f(..)")
ast_from_text("fn f() { let ..; }")
}
pub fn literal_pat(lit: &str) -> ast::LiteralPat {
@ -788,8 +788,8 @@ pub fn record_pat_field(name_ref: ast::NameRef, pat: ast::Pat) -> ast::RecordPat
ast_from_text(&format!("fn f(S {{ {name_ref}: {pat} }}: ()))"))
}
pub fn record_pat_field_shorthand(name_ref: ast::NameRef) -> ast::RecordPatField {
ast_from_text(&format!("fn f(S {{ {name_ref} }}: ()))"))
pub fn record_pat_field_shorthand(pat: ast::Pat) -> ast::RecordPatField {
ast_from_text(&format!("fn f(S {{ {pat} }}: ()))"))
}
/// Returns a `IdentPat` if the path has just one segment, a `PathPat` otherwise.
@ -801,16 +801,38 @@ pub fn path_pat(path: ast::Path) -> ast::Pat {
}
/// Returns a `Pat` if the path has just one segment, an `OrPat` otherwise.
pub fn or_pat(pats: impl IntoIterator<Item = ast::Pat>, leading_pipe: bool) -> ast::Pat {
///
/// Invariant: `pats` must be length > 1.
pub fn or_pat(pats: impl IntoIterator<Item = ast::Pat>, leading_pipe: bool) -> ast::OrPat {
let leading_pipe = if leading_pipe { "| " } else { "" };
let pats = pats.into_iter().join(" | ");
return from_text(&format!("{leading_pipe}{pats}"));
fn from_text(text: &str) -> ast::Pat {
fn from_text(text: &str) -> ast::OrPat {
ast_from_text(&format!("fn f({text}: ())"))
}
}
pub fn box_pat(pat: ast::Pat) -> ast::BoxPat {
ast_from_text(&format!("fn f(box {pat}: ())"))
}
pub fn paren_pat(pat: ast::Pat) -> ast::ParenPat {
ast_from_text(&format!("fn f(({pat}): ())"))
}
pub fn range_pat(start: Option<ast::Pat>, end: Option<ast::Pat>) -> ast::RangePat {
ast_from_text(&format!(
"fn f({}..{}: ())",
start.map(|e| e.to_string()).unwrap_or_default(),
end.map(|e| e.to_string()).unwrap_or_default()
))
}
pub fn ref_pat(pat: ast::Pat) -> ast::RefPat {
ast_from_text(&format!("fn f(&{pat}: ())"))
}
pub fn match_arm(pat: ast::Pat, guard: Option<ast::MatchGuard>, expr: ast::Expr) -> ast::MatchArm {
return match guard {
Some(guard) => from_text(&format!("{pat} {guard} => {expr}")),