mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Employ early return pattern more
This commit is contained in:
parent
4034ea9e4e
commit
d610adfc2b
2 changed files with 27 additions and 25 deletions
|
@ -428,20 +428,18 @@ impl SourceAnalyzer {
|
||||||
let std_future_trait =
|
let std_future_trait =
|
||||||
match self.resolver.resolve_path_segments(db, &std_future_path).into_fully_resolved() {
|
match self.resolver.resolve_path_segments(db, &std_future_path).into_fully_resolved() {
|
||||||
PerNs { types: Some(Resolution::Def(ModuleDef::Trait(trait_))), .. } => {
|
PerNs { types: Some(Resolution::Def(ModuleDef::Trait(trait_))), .. } => {
|
||||||
Some(trait_)
|
trait_
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => return false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let krate = self.resolver.krate();
|
let krate = match self.resolver.krate() {
|
||||||
if let Some(krate) = krate {
|
Some(krate) => krate,
|
||||||
if let Some(trait_) = std_future_trait {
|
_ => return false,
|
||||||
let canonical_ty = crate::ty::Canonical { value: ty, num_vars: 0 };
|
};
|
||||||
return implements_trait(&canonical_ty, db, &self.resolver, krate, trait_);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -9,23 +9,27 @@ use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
/// Complete dot accesses, i.e. fields or methods (and .await syntax).
|
/// Complete dot accesses, i.e. fields or methods (and .await syntax).
|
||||||
pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
|
pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
|
||||||
if let Some(dot_receiver) = &ctx.dot_receiver {
|
let dot_receiver = match &ctx.dot_receiver {
|
||||||
let receiver_ty = ctx.analyzer.type_of(ctx.db, &dot_receiver);
|
Some(expr) => expr,
|
||||||
|
_ => return,
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(receiver_ty) = receiver_ty {
|
let receiver_ty = match ctx.analyzer.type_of(ctx.db, &dot_receiver) {
|
||||||
if !ctx.is_call {
|
Some(ty) => ty,
|
||||||
complete_fields(acc, ctx, receiver_ty.clone());
|
_ => return,
|
||||||
}
|
};
|
||||||
complete_methods(acc, ctx, receiver_ty.clone());
|
|
||||||
|
|
||||||
// Suggest .await syntax for types that implement Future trait
|
if !ctx.is_call {
|
||||||
if ctx.analyzer.impls_future(ctx.db, receiver_ty) {
|
complete_fields(acc, ctx, receiver_ty.clone());
|
||||||
CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await")
|
}
|
||||||
.detail("expr.await")
|
complete_methods(acc, ctx, receiver_ty.clone());
|
||||||
.insert_text("await")
|
|
||||||
.add_to(acc);
|
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue