aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src/completions
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-26 21:43:53 +0100
committerGitHub <[email protected]>2021-05-26 21:43:53 +0100
commit666fc1cec10a41f88db56dfb339785eb1e7dd521 (patch)
treeb06cb9f920a95da9289005e8a8b98d15834be439 /crates/ide_completion/src/completions
parent8389510f8d15e67ab112343ef876db1c8b01e36e (diff)
parent7d865ef071a78736866a9e73d0348352f4332754 (diff)
Merge #9015
9015: Merge pattern completion related bools into an enum r=Veykril a=Veykril The two bools can never both be set so this is basically just a tri-state enum. bors r+ Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/ide_completion/src/completions')
-rw-r--r--crates/ide_completion/src/completions/pattern.rs13
-rw-r--r--crates/ide_completion/src/completions/unqualified_path.rs4
2 files changed, 9 insertions, 8 deletions
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 @@
1//! Completes constants and paths in patterns. 1//! Completes constants and paths in patterns.
2 2
3use crate::{CompletionContext, Completions}; 3use crate::{context::IsPatOrConst, CompletionContext, Completions};
4 4
5/// Completes constants and paths in patterns. 5/// Completes constants and paths in patterns.
6pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { 6pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
7 if !(ctx.is_pat_binding_or_const || ctx.is_irrefutable_pat_binding) { 7 if ctx.is_pat_or_const == IsPatOrConst::No {
8 return; 8 return;
9 } 9 }
10 if ctx.record_pat_syntax.is_some() { 10 if ctx.record_pat_syntax.is_some() {
11 return; 11 return;
12 } 12 }
13 13
14 if !ctx.is_irrefutable_pat_binding { 14 let refutable = ctx.is_pat_or_const == IsPatOrConst::Refutable;
15 if refutable {
15 if let Some(hir::Adt::Enum(e)) = 16 if let Some(hir::Adt::Enum(e)) =
16 ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt()) 17 ctx.expected_type.as_ref().and_then(|ty| ty.strip_references().as_adt())
17 { 18 {
@@ -31,14 +32,14 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
31 acc.add_struct_pat(ctx, *strukt, Some(name.clone())); 32 acc.add_struct_pat(ctx, *strukt, Some(name.clone()));
32 true 33 true
33 } 34 }
34 hir::ModuleDef::Variant(variant) if !ctx.is_irrefutable_pat_binding => { 35 hir::ModuleDef::Variant(variant) if refutable => {
35 acc.add_variant_pat(ctx, *variant, Some(name.clone())); 36 acc.add_variant_pat(ctx, *variant, Some(name.clone()));
36 true 37 true
37 } 38 }
38 hir::ModuleDef::Adt(hir::Adt::Enum(..)) 39 hir::ModuleDef::Adt(hir::Adt::Enum(..))
39 | hir::ModuleDef::Variant(..) 40 | hir::ModuleDef::Variant(..)
40 | hir::ModuleDef::Const(..) 41 | hir::ModuleDef::Const(..)
41 | hir::ModuleDef::Module(..) => !ctx.is_irrefutable_pat_binding, 42 | hir::ModuleDef::Module(..) => refutable,
42 _ => false, 43 _ => false,
43 }, 44 },
44 hir::ScopeDef::MacroDef(_) => true, 45 hir::ScopeDef::MacroDef(_) => true,
@@ -47,7 +48,7 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) {
47 acc.add_struct_pat(ctx, strukt, Some(name.clone())); 48 acc.add_struct_pat(ctx, strukt, Some(name.clone()));
48 true 49 true
49 } 50 }
50 Some(hir::Adt::Enum(_)) => !ctx.is_irrefutable_pat_binding, 51 Some(hir::Adt::Enum(_)) => refutable,
51 _ => true, 52 _ => true,
52 }, 53 },
53 _ => false, 54 _ => 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<Enum>) {
88 } 88 }
89} 89}
90"#, 90"#,
91 expect![[""]], 91 expect![[r#""#]],
92 ); 92 );
93 } 93 }
94 94
@@ -104,7 +104,7 @@ fn quux(x: Option<Enum>) {
104 } 104 }
105} 105}
106"#, 106"#,
107 expect![[""]], 107 expect![[r#""#]],
108 ); 108 );
109 } 109 }
110 110