Fix applicable after l_curly for replace_is_method_with_if_let_method

This commit is contained in:
A4-Tacks 2025-09-18 20:00:31 +08:00
parent 2268a56350
commit d3748517c9
No known key found for this signature in database
GPG Key ID: DBD861323040663B

View File

@ -31,6 +31,9 @@ pub(crate) fn replace_is_method_with_if_let_method(
ast::Expr::MethodCallExpr(call) => call,
_ => return None,
};
if ctx.offset() > if_expr.then_branch()?.stmt_list()?.l_curly_token()?.text_range().end() {
return None;
}
let name_ref = call_expr.name_ref()?;
match name_ref.text().as_str() {
@ -188,6 +191,21 @@ fn main() {
let x = Ok(1);
if x.is_e$0rr() {}
}
"#,
);
}
#[test]
fn replace_is_some_with_if_let_some_not_applicable_after_l_curly() {
check_assist_not_applicable(
replace_is_method_with_if_let_method,
r#"
fn main() {
let x = Some(1);
if x.is_some() {
()$0
}
}
"#,
);
}