From 3f796fea9fab0222913f9f895af78b80c4c7660b Mon Sep 17 00:00:00 2001 From: Lukas Tobias Wirth Date: Wed, 5 May 2021 22:55:12 +0200 Subject: simplify --- crates/ide_completion/src/completions/pattern.rs | 6 ++++-- crates/ide_completion/src/completions/postfix.rs | 5 +---- crates/ide_completion/src/completions/unqualified_path.rs | 6 ++++-- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'crates/ide_completion/src/completions') diff --git a/crates/ide_completion/src/completions/pattern.rs b/crates/ide_completion/src/completions/pattern.rs index 808d7ff7e..8dc9ab73c 100644 --- a/crates/ide_completion/src/completions/pattern.rs +++ b/crates/ide_completion/src/completions/pattern.rs @@ -12,8 +12,10 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { } if !ctx.is_irrefutable_pat_binding { - if let Some(ty) = ctx.expected_type.as_ref() { - super::complete_enum_variants(acc, ctx, ty, |acc, ctx, variant, path| { + if let Some(hir::Adt::Enum(e)) = + ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt()) + { + super::complete_enum_variants(acc, ctx, e, |acc, ctx, variant, path| { acc.add_qualified_variant_pat(ctx, variant, path.clone()); acc.add_qualified_enum_variant(ctx, variant, path); }); diff --git a/crates/ide_completion/src/completions/postfix.rs b/crates/ide_completion/src/completions/postfix.rs index ac69b720a..962aaf0df 100644 --- a/crates/ide_completion/src/completions/postfix.rs +++ b/crates/ide_completion/src/completions/postfix.rs @@ -35,14 +35,11 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { None => return, }; - let ref_removed_ty = - std::iter::successors(Some(receiver_ty.clone()), |ty| ty.remove_ref()).last().unwrap(); - let cap = match ctx.config.snippet_cap { Some(it) => it, None => return, }; - let try_enum = TryEnum::from_ty(&ctx.sema, &ref_removed_ty); + let try_enum = TryEnum::from_ty(&ctx.sema, &receiver_ty.strip_references()); if let Some(try_enum) = &try_enum { match try_enum { TryEnum::Result => { diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index 1b8b063e7..7875500c1 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs @@ -17,8 +17,10 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC return; } - if let Some(ty) = &ctx.expected_type { - super::complete_enum_variants(acc, ctx, ty, |acc, ctx, variant, path| { + if let Some(hir::Adt::Enum(e)) = + ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt()) + { + super::complete_enum_variants(acc, ctx, e, |acc, ctx, variant, path| { acc.add_qualified_enum_variant(ctx, variant, path) }); } -- cgit v1.2.3