From 7d865ef071a78736866a9e73d0348352f4332754 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 26 May 2021 22:39:47 +0200 Subject: Merge pattern completion related bools into an enum --- crates/ide_completion/src/completions/pattern.rs | 13 +++++++------ crates/ide_completion/src/completions/unqualified_path.rs | 4 ++-- 2 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 8dc9ab73c..3329a4844 100644 --- a/crates/ide_completion/src/completions/pattern.rs +++ b/crates/ide_completion/src/completions/pattern.rs @@ -1,17 +1,18 @@ //! Completes constants and paths in patterns. -use crate::{CompletionContext, Completions}; +use crate::{context::IsPatOrConst, CompletionContext, Completions}; /// Completes constants and paths in patterns. pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { - if !(ctx.is_pat_binding_or_const || ctx.is_irrefutable_pat_binding) { + if ctx.is_pat_or_const == IsPatOrConst::No { return; } if ctx.record_pat_syntax.is_some() { return; } - if !ctx.is_irrefutable_pat_binding { + let refutable = ctx.is_pat_or_const == IsPatOrConst::Refutable; + if refutable { if let Some(hir::Adt::Enum(e)) = ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt()) { @@ -31,14 +32,14 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { acc.add_struct_pat(ctx, *strukt, Some(name.clone())); true } - hir::ModuleDef::Variant(variant) if !ctx.is_irrefutable_pat_binding => { + hir::ModuleDef::Variant(variant) if refutable => { acc.add_variant_pat(ctx, *variant, Some(name.clone())); true } hir::ModuleDef::Adt(hir::Adt::Enum(..)) | hir::ModuleDef::Variant(..) | hir::ModuleDef::Const(..) - | hir::ModuleDef::Module(..) => !ctx.is_irrefutable_pat_binding, + | hir::ModuleDef::Module(..) => refutable, _ => false, }, hir::ScopeDef::MacroDef(_) => true, @@ -47,7 +48,7 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { acc.add_struct_pat(ctx, strukt, Some(name.clone())); true } - Some(hir::Adt::Enum(_)) => !ctx.is_irrefutable_pat_binding, + Some(hir::Adt::Enum(_)) => refutable, _ => true, }, _ => false, diff --git a/crates/ide_completion/src/completions/unqualified_path.rs b/crates/ide_completion/src/completions/unqualified_path.rs index 6ea0efe9f..b8f8ef25f 100644 --- a/crates/ide_completion/src/completions/unqualified_path.rs +++ b/crates/ide_completion/src/completions/unqualified_path.rs @@ -88,7 +88,7 @@ fn quux(x: Option) { } } "#, - expect![[""]], + expect![[r#""#]], ); } @@ -104,7 +104,7 @@ fn quux(x: Option) { } } "#, - expect![[""]], + expect![[r#""#]], ); } -- cgit v1.2.3