10587: fix: Fix `add_missing_match_arm` panicking on failed upmapping r=Veykril a=Veykril

Closes https://github.com/rust-analyzer/rust-analyzer/issues/10580#issuecomment-946170475

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-10-19 12:16:30 +00:00 committed by GitHub
commit e77fc481ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,6 @@
use ide_db::RootDatabase;
use itertools::Itertools;
use syntax::ast::{self, make, AstNode, HasName, MatchArm, MatchArmList, MatchExpr, Pat};
use syntax::TextRange;
use crate::{
utils::{self, render_snippet, Cursor},
@ -40,21 +39,15 @@
pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
let match_expr = ctx.find_node_at_offset_with_descend::<ast::MatchExpr>()?;
let match_arm_list = match_expr.match_arm_list()?;
let target_range: TextRange;
let target_range = ctx.sema.original_range(match_expr.syntax()).range;
if let None = cursor_at_trivial_match_arm_list(&ctx, &match_expr, &match_arm_list) {
target_range = TextRange::new(
ctx.sema.original_range(match_expr.syntax()).range.start(),
ctx.sema.original_range(match_arm_list.syntax()).range.start(),
);
let cursor_in_range = target_range.contains_range(ctx.selection_trimmed());
if !cursor_in_range {
let arm_list_range = ctx.sema.original_range(match_arm_list.syntax()).range;
let cursor_in_range = arm_list_range.contains_range(ctx.selection_trimmed());
if cursor_in_range {
cov_mark::hit!(not_applicable_outside_of_range_right);
return None;
}
} else {
target_range = ctx.sema.original_range(match_expr.syntax()).range;
}
let expr = match_expr.expr()?;
@ -953,7 +946,9 @@ fn main() {
}
}
"#,
"match E::X ",
"match E::X {
E::X => {}
}",
);
}