From d610adfc2bfe3d4e9fec61b7a5bc02cfea503384 Mon Sep 17 00:00:00 2001 From: Evgenii P Date: Sun, 4 Aug 2019 08:03:17 +0700 Subject: Employ early return pattern more --- crates/ra_hir/src/source_binder.rs | 18 ++++++------- crates/ra_ide_api/src/completion/complete_dot.rs | 34 +++++++++++++----------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index cf9a9e108..2c4cedd8b 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -428,20 +428,18 @@ impl SourceAnalyzer { let std_future_trait = match self.resolver.resolve_path_segments(db, &std_future_path).into_fully_resolved() { PerNs { types: Some(Resolution::Def(ModuleDef::Trait(trait_))), .. } => { - Some(trait_) + trait_ } - _ => None, + _ => return false, }; - let krate = self.resolver.krate(); - if let Some(krate) = krate { - if let Some(trait_) = std_future_trait { - let canonical_ty = crate::ty::Canonical { value: ty, num_vars: 0 }; - return implements_trait(&canonical_ty, db, &self.resolver, krate, trait_); - } - } + let krate = match self.resolver.krate() { + Some(krate) => krate, + _ => return false, + }; - false + let canonical_ty = crate::ty::Canonical { value: ty, num_vars: 0 }; + return implements_trait(&canonical_ty, db, &self.resolver, krate, std_future_trait); } #[cfg(test)] diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 9a3b353a9..d43ff2eec 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -9,23 +9,27 @@ use rustc_hash::FxHashSet; /// Complete dot accesses, i.e. fields or methods (and .await syntax). pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { - if let Some(dot_receiver) = &ctx.dot_receiver { - let receiver_ty = ctx.analyzer.type_of(ctx.db, &dot_receiver); + let dot_receiver = match &ctx.dot_receiver { + Some(expr) => expr, + _ => return, + }; - if let Some(receiver_ty) = receiver_ty { - if !ctx.is_call { - complete_fields(acc, ctx, receiver_ty.clone()); - } - complete_methods(acc, ctx, receiver_ty.clone()); + let receiver_ty = match ctx.analyzer.type_of(ctx.db, &dot_receiver) { + Some(ty) => ty, + _ => return, + }; - // Suggest .await syntax for types that implement Future trait - if ctx.analyzer.impls_future(ctx.db, receiver_ty) { - CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await") - .detail("expr.await") - .insert_text("await") - .add_to(acc); - } - } + if !ctx.is_call { + complete_fields(acc, ctx, receiver_ty.clone()); + } + complete_methods(acc, ctx, receiver_ty.clone()); + + // Suggest .await syntax for types that implement Future trait + if ctx.analyzer.impls_future(ctx.db, receiver_ty) { + CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await") + .detail("expr.await") + .insert_text("await") + .add_to(acc); } } -- cgit v1.2.3