mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Introduce TypeInfo
This commit is contained in:
parent
29506b5a26
commit
25ff7171c4
32 changed files with 127 additions and 124 deletions
|
@ -14,7 +14,7 @@ pub(crate) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) {
|
|||
};
|
||||
|
||||
let receiver_ty = match ctx.sema.type_of_expr(dot_receiver) {
|
||||
Some(ty) => ty,
|
||||
Some(ty) => ty.ty,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
|
|
|
@ -180,7 +180,7 @@ fn import_assets(ctx: &CompletionContext, fuzzy_name: String) -> Option<ImportAs
|
|||
if let Some(dot_receiver) = ctx.dot_receiver() {
|
||||
ImportAssets::for_fuzzy_method_call(
|
||||
current_module,
|
||||
ctx.sema.type_of_expr(dot_receiver)?,
|
||||
ctx.sema.type_of_expr(dot_receiver)?.ty,
|
||||
fuzzy_name,
|
||||
dot_receiver.syntax().clone(),
|
||||
)
|
||||
|
|
|
@ -38,7 +38,7 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
|
|||
let receiver_text = get_receiver_text(dot_receiver, receiver_is_ambiguous_float_literal);
|
||||
|
||||
let receiver_ty = match ctx.sema.type_of_expr(dot_receiver) {
|
||||
Some(it) => it,
|
||||
Some(it) => it.ty,
|
||||
None => return,
|
||||
};
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) ->
|
|||
let default_trait = FamousDefs(&ctx.sema, ctx.krate).core_default_Default();
|
||||
let impl_default_trait = default_trait
|
||||
.zip(ty)
|
||||
.map_or(false, |(default_trait, ty)| ty.impls_trait(ctx.db, default_trait, &[]));
|
||||
.map_or(false, |(default_trait, ty)| ty.ty.impls_trait(ctx.db, default_trait, &[]));
|
||||
|
||||
let missing_fields = ctx.sema.record_literal_missing_fields(record_expr);
|
||||
if impl_default_trait && !missing_fields.is_empty() {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//! See `CompletionContext` structure.
|
||||
|
||||
use base_db::SourceDatabaseExt;
|
||||
use hir::{Local, Name, ScopeDef, Semantics, SemanticsScope, Type};
|
||||
use hir::{Local, Name, ScopeDef, Semantics, SemanticsScope, Type, TypeInfo};
|
||||
use ide_db::{
|
||||
base_db::{FilePosition, SourceDatabase},
|
||||
call_info::ActiveParameter,
|
||||
|
@ -453,7 +453,8 @@ impl<'a> CompletionContext<'a> {
|
|||
cov_mark::hit!(expected_type_let_without_leading_char);
|
||||
let ty = it.pat()
|
||||
.and_then(|pat| self.sema.type_of_pat(&pat))
|
||||
.or_else(|| it.initializer().and_then(|it| self.sema.type_of_expr(&it)));
|
||||
.or_else(|| it.initializer().and_then(|it| self.sema.type_of_expr(&it)))
|
||||
.map(TypeInfo::ty);
|
||||
let name = if let Some(ast::Pat::IdentPat(ident)) = it.pat() {
|
||||
ident.name().map(NameOrNameRef::Name)
|
||||
} else {
|
||||
|
@ -496,27 +497,27 @@ impl<'a> CompletionContext<'a> {
|
|||
ast::RecordExprField(it) => {
|
||||
cov_mark::hit!(expected_type_struct_field_with_leading_char);
|
||||
(
|
||||
it.expr().as_ref().and_then(|e| self.sema.type_of_expr(e)),
|
||||
it.expr().as_ref().and_then(|e| self.sema.type_of_expr(e)).map(TypeInfo::ty),
|
||||
it.field_name().map(NameOrNameRef::NameRef),
|
||||
)
|
||||
},
|
||||
ast::MatchExpr(it) => {
|
||||
cov_mark::hit!(expected_type_match_arm_without_leading_char);
|
||||
let ty = it.expr()
|
||||
.and_then(|e| self.sema.type_of_expr(&e));
|
||||
let ty = it.expr().and_then(|e| self.sema.type_of_expr(&e)).map(TypeInfo::ty);
|
||||
(ty, None)
|
||||
},
|
||||
ast::IfExpr(it) => {
|
||||
cov_mark::hit!(expected_type_if_let_without_leading_char);
|
||||
let ty = it.condition()
|
||||
.and_then(|cond| cond.expr())
|
||||
.and_then(|e| self.sema.type_of_expr(&e));
|
||||
.and_then(|e| self.sema.type_of_expr(&e))
|
||||
.map(TypeInfo::ty);
|
||||
(ty, None)
|
||||
},
|
||||
ast::IdentPat(it) => {
|
||||
cov_mark::hit!(expected_type_if_let_with_leading_char);
|
||||
cov_mark::hit!(expected_type_match_arm_with_leading_char);
|
||||
let ty = self.sema.type_of_pat(&ast::Pat::from(it));
|
||||
let ty = self.sema.type_of_pat(&ast::Pat::from(it)).map(TypeInfo::ty);
|
||||
(ty, None)
|
||||
},
|
||||
ast::Fn(it) => {
|
||||
|
@ -527,7 +528,7 @@ impl<'a> CompletionContext<'a> {
|
|||
},
|
||||
ast::ClosureExpr(it) => {
|
||||
let ty = self.sema.type_of_expr(&it.into());
|
||||
ty.and_then(|ty| ty.as_callable(self.db))
|
||||
ty.and_then(|ty| ty.ty.as_callable(self.db))
|
||||
.map(|c| (Some(c.return_type()), None))
|
||||
.unwrap_or((None, None))
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue