Skip to content

Commit 145a101

Browse files
committed
Deunwrap add_missing_match_arms
1 parent 326f37e commit 145a101

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

crates/ide-assists/src/handlers/add_missing_match_arms.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,10 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
273273
syntax::SyntaxElement::Token(it) => {
274274
// Don't have a way to make tokens mut, so instead make the parent mut
275275
// and find the token again
276-
let parent = edit.make_syntax_mut(it.parent().unwrap());
276+
let parent =
277+
edit.make_syntax_mut(it.parent().expect("Token must have a parent."));
277278
let mut_token =
278-
parent.covering_element(it.text_range()).into_token().unwrap();
279+
parent.covering_element(it.text_range()).into_token().expect("Covering element cannot be found. Range may be beyond the current node's range");
279280

280281
syntax::SyntaxElement::from(mut_token)
281282
}
@@ -446,21 +447,23 @@ fn build_pat(
446447
mod_path_to_ast(&module.find_use_path(db, ModuleDef::from(var), prefer_no_std)?);
447448

448449
// FIXME: use HIR for this; it doesn't currently expose struct vs. tuple vs. unit variants though
449-
let pat: ast::Pat = match var.source(db)?.value.kind() {
450+
Some(match var.source(db)?.value.kind() {
450451
ast::StructKind::Tuple(field_list) => {
451452
let pats =
452453
iter::repeat(make::wildcard_pat().into()).take(field_list.fields().count());
453454
make::tuple_struct_pat(path, pats).into()
454455
}
455456
ast::StructKind::Record(field_list) => {
456-
let pats = field_list
457-
.fields()
458-
.map(|f| make::ext::simple_ident_pat(f.name().unwrap()).into());
457+
let pats = field_list.fields().map(|f| {
458+
make::ext::simple_ident_pat(
459+
f.name().expect("Record field must have a name"),
460+
)
461+
.into()
462+
});
459463
make::record_pat(path, pats).into()
460464
}
461465
ast::StructKind::Unit => make::path_pat(path),
462-
};
463-
Some(pat)
466+
})
464467
}
465468
ExtendedVariant::True => Some(ast::Pat::from(make::literal_pat("true"))),
466469
ExtendedVariant::False => Some(ast::Pat::from(make::literal_pat("false"))),

0 commit comments

Comments
 (0)