diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index f9cb043a7b..ab3cb10b38 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -90,22 +90,23 @@ impl PathResolution { #[derive(Debug)] pub struct TypeInfo { /// The original type of the expression or pattern. - pub ty: Type, - /// The coerced type, if a coercion happened. - pub coerced: Option, + pub original: Type, + /// The adjusted type, if an adjustment happened. + pub adjusted: Option, } impl TypeInfo { - pub fn ty(self) -> Type { - self.ty + pub fn original(self) -> Type { + self.original } - pub fn has_coercion(&self) -> bool { - self.coerced.is_some() + pub fn has_adjustment(&self) -> bool { + self.adjusted.is_some() } - pub fn coerced(self) -> Type { - self.coerced.unwrap_or(self.ty) + /// The adjusted type, or the original in case no adjustments occurred. + pub fn adjusted(self) -> Type { + self.adjusted.unwrap_or(self.original) } } @@ -581,13 +582,13 @@ impl<'db> SemanticsImpl<'db> { fn type_of_expr(&self, expr: &ast::Expr) -> Option { self.analyze(expr.syntax()) .type_of_expr(self.db, expr) - .map(|(ty, coerced)| TypeInfo { ty, coerced }) + .map(|(ty, coerced)| TypeInfo { original: ty, adjusted: coerced }) } fn type_of_pat(&self, pat: &ast::Pat) -> Option { self.analyze(pat.syntax()) .type_of_pat(self.db, pat) - .map(|(ty, coerced)| TypeInfo { ty, coerced }) + .map(|(ty, coerced)| TypeInfo { original: ty, adjusted: coerced }) } fn type_of_self(&self, param: &ast::SelfParam) -> Option { @@ -766,7 +767,7 @@ impl<'db> SemanticsImpl<'db> { ast::Expr::FieldExpr(field_expr) => field_expr, _ => return None, }; - let ty = self.type_of_expr(&field_expr.expr()?)?.ty; + let ty = self.type_of_expr(&field_expr.expr()?)?.original; if !ty.is_packed(self.db) { return None; } @@ -793,7 +794,7 @@ impl<'db> SemanticsImpl<'db> { self.type_of_expr(&expr) }) // Binding a reference to a packed type is possibly unsafe. - .map(|ty| ty.ty.is_packed(self.db)) + .map(|ty| ty.original.is_packed(self.db)) .unwrap_or(false) // FIXME This needs layout computation to be correct. It will highlight @@ -839,7 +840,7 @@ impl<'db> SemanticsImpl<'db> { } }) // Binding a reference to a packed type is possibly unsafe. - .map(|ty| ty.ty.is_packed(self.db)) + .map(|ty| ty.original.is_packed(self.db)) .unwrap_or(false) } } diff --git a/crates/ide/src/call_hierarchy.rs b/crates/ide/src/call_hierarchy.rs index 428f3f1c6d..f725247ccb 100644 --- a/crates/ide/src/call_hierarchy.rs +++ b/crates/ide/src/call_hierarchy.rs @@ -86,7 +86,7 @@ pub(crate) fn outgoing_calls(db: &RootDatabase, position: FilePosition) -> Optio let name_ref = call_node.name_ref()?; let func_target = match call_node { FnCallNode::CallExpr(expr) => { - let callable = sema.type_of_expr(&expr.expr()?)?.ty.as_callable(db)?; + let callable = sema.type_of_expr(&expr.expr()?)?.original.as_callable(db)?; match callable.kind() { hir::CallableKind::Function(it) => it.try_to_nav(db), _ => None, diff --git a/crates/ide/src/goto_type_definition.rs b/crates/ide/src/goto_type_definition.rs index 3e9dfb8cb6..f8105790f4 100644 --- a/crates/ide/src/goto_type_definition.rs +++ b/crates/ide/src/goto_type_definition.rs @@ -32,8 +32,8 @@ pub(crate) fn goto_type_definition( let (ty, node) = sema.token_ancestors_with_macros(token).find_map(|node| { let ty = match_ast! { match node { - ast::Expr(it) => sema.type_of_expr(&it)?.ty, - ast::Pat(it) => sema.type_of_pat(&it)?.ty, + ast::Expr(it) => sema.type_of_expr(&it)?.original, + ast::Pat(it) => sema.type_of_pat(&it)?.original, ast::SelfParam(it) => sema.type_of_self(&it)?, ast::Type(it) => sema.resolve_type(&it)?, ast::RecordField(it) => sema.to_def(&it).map(|d| d.ty(db.upcast()))?, diff --git a/crates/ide/src/highlight_related.rs b/crates/ide/src/highlight_related.rs index a1c50c6364..b4715b10a0 100644 --- a/crates/ide/src/highlight_related.rs +++ b/crates/ide/src/highlight_related.rs @@ -123,7 +123,7 @@ fn highlight_exit_points( } } ast::Expr::MethodCallExpr(_) | ast::Expr::CallExpr(_) | ast::Expr::MacroCall(_) => { - if sema.type_of_expr(&expr).map_or(false, |ty| ty.ty.is_never()) { + if sema.type_of_expr(&expr).map_or(false, |ty| ty.original.is_never()) { highlights .push(HighlightedRange { access: None, range: expr.syntax().text_range() }); } diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs index 9ca20776b5..6789abfb0a 100644 --- a/crates/ide/src/hover.rs +++ b/crates/ide/src/hover.rs @@ -225,29 +225,29 @@ fn hover_type_info( config: &HoverConfig, expr_or_pat: &Either, ) -> Option { - let TypeInfo { ty, coerced } = match expr_or_pat { + let TypeInfo { original, adjusted } = match expr_or_pat { Either::Left(expr) => sema.type_of_expr(expr)?, Either::Right(pat) => sema.type_of_pat(pat)?, }; let mut res = HoverResult::default(); - res.markup = if let Some(coerced_ty) = coerced { - let uncoerced = ty.display(sema.db).to_string(); - let coerced = coerced_ty.display(sema.db).to_string(); + res.markup = if let Some(adjusted_ty) = adjusted { + let original = original.display(sema.db).to_string(); + let adjusted = adjusted_ty.display(sema.db).to_string(); format!( - "```text\nType: {:>upad$}\nCoerced to: {:>cpad$}\n```\n", - uncoerced = uncoerced, - coerced = coerced, + "```text\nType: {:>apad$}\nCoerced to: {:>opad$}\n```\n", + uncoerced = original, + coerced = adjusted, // 6 base padding for static text prefix of each line - upad = 6 + coerced.len().max(uncoerced.len()), - cpad = uncoerced.len(), + apad = 6 + adjusted.len().max(original.len()), + opad = original.len(), ) .into() } else { if config.markdown() { - Markup::fenced_block(&ty.display(sema.db)) + Markup::fenced_block(&original.display(sema.db)) } else { - ty.display(sema.db).to_string().into() + original.display(sema.db).to_string().into() } }; Some(res) diff --git a/crates/ide/src/inlay_hints.rs b/crates/ide/src/inlay_hints.rs index 48c2f893aa..3dc1bbf7dc 100644 --- a/crates/ide/src/inlay_hints.rs +++ b/crates/ide/src/inlay_hints.rs @@ -117,7 +117,7 @@ fn get_chaining_hints( next_next = tokens.next()?.kind(); } if next_next == T![.] { - let ty = sema.type_of_expr(&expr)?.ty; + let ty = sema.type_of_expr(&expr)?.original; if ty.is_unknown() { return None; } @@ -189,7 +189,7 @@ fn get_bind_pat_hints( let krate = sema.scope(pat.syntax()).module().map(|it| it.krate()); let famous_defs = FamousDefs(sema, krate); - let ty = sema.type_of_pat(&pat.clone().into())?.ty; + let ty = sema.type_of_pat(&pat.clone().into())?.original; if should_not_display_type_hint(sema, &pat, &ty) { return None; @@ -308,7 +308,7 @@ fn should_not_display_type_hint( return it.in_token().is_none() || it.iterable() .and_then(|iterable_expr| sema.type_of_expr(&iterable_expr)) - .map(TypeInfo::ty) + .map(TypeInfo::original) .map_or(true, |iterable_ty| iterable_ty.is_unknown() || iterable_ty.is_unit()) }, _ => (), @@ -394,7 +394,7 @@ fn is_enum_name_similar_to_param_name( argument: &ast::Expr, param_name: &str, ) -> bool { - match sema.type_of_expr(argument).and_then(|t| t.ty.as_adt()) { + match sema.type_of_expr(argument).and_then(|t| t.original.as_adt()) { Some(hir::Adt::Enum(e)) => to_lower_snake_case(&e.name(sema.db).to_string()) == param_name, _ => false, } @@ -431,7 +431,7 @@ fn get_callable( ) -> Option<(hir::Callable, ast::ArgList)> { match expr { ast::Expr::CallExpr(expr) => { - sema.type_of_expr(&expr.expr()?)?.ty.as_callable(sema.db).zip(expr.arg_list()) + sema.type_of_expr(&expr.expr()?)?.original.as_callable(sema.db).zip(expr.arg_list()) } ast::Expr::MethodCallExpr(expr) => { sema.resolve_method_call_as_callable(expr).zip(expr.arg_list()) diff --git a/crates/ide/src/syntax_highlighting/highlight.rs b/crates/ide/src/syntax_highlighting/highlight.rs index 9eab563fff..3f61a856dd 100644 --- a/crates/ide/src/syntax_highlighting/highlight.rs +++ b/crates/ide/src/syntax_highlighting/highlight.rs @@ -123,7 +123,7 @@ pub(super) fn element( let prefix_expr = element.parent().and_then(ast::PrefixExpr::cast)?; let expr = prefix_expr.expr()?; - let ty = sema.type_of_expr(&expr)?.ty; + let ty = sema.type_of_expr(&expr)?.original; if ty.is_raw_ptr() { HlTag::Operator(HlOperator::Other) | HlMod::Unsafe } else if let Some(ast::PrefixOp::Deref) = prefix_expr.op_kind() { @@ -555,7 +555,7 @@ fn highlight_method_call( if let Some(receiver_ty) = method_call.receiver().and_then(|it| sema.type_of_expr(&it)) { - if !receiver_ty.coerced().is_copy(sema.db) { + if !receiver_ty.adjusted().is_copy(sema.db) { h |= HlMod::Consuming } } diff --git a/crates/ide_assists/src/handlers/add_explicit_type.rs b/crates/ide_assists/src/handlers/add_explicit_type.rs index 275ef53861..a48729b45f 100644 --- a/crates/ide_assists/src/handlers/add_explicit_type.rs +++ b/crates/ide_assists/src/handlers/add_explicit_type.rs @@ -57,7 +57,7 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Optio (ast::Pat::IdentPat(_), Some(expr)) => ctx.sema.type_of_expr(&expr)?, (pat, _) => ctx.sema.type_of_pat(&pat)?, } - .coerced(); + .adjusted(); // Unresolved or unnameable types can't be annotated if ty.contains_unknown() || ty.is_closure() { diff --git a/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs b/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs index a24c9359cb..a7344572ba 100644 --- a/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs +++ b/crates/ide_assists/src/handlers/convert_iter_for_each_to_for.rs @@ -86,7 +86,7 @@ fn validate_method_call_expr( let receiver = expr.receiver()?; let expr = ast::Expr::MethodCallExpr(expr); - let it_type = sema.type_of_expr(&receiver)?.coerced(); + let it_type = sema.type_of_expr(&receiver)?.adjusted(); let module = sema.scope(receiver.syntax()).module()?; let krate = module.krate(); diff --git a/crates/ide_assists/src/handlers/extract_function.rs b/crates/ide_assists/src/handlers/extract_function.rs index a861755cbb..25a66029cb 100644 --- a/crates/ide_assists/src/handlers/extract_function.rs +++ b/crates/ide_assists/src/handlers/extract_function.rs @@ -345,7 +345,7 @@ impl FlowKind { FlowKind::Return(Some(expr)) | FlowKind::Break(Some(expr)) | FlowKind::TryReturn { expr, .. } => { - ctx.sema.type_of_expr(expr).map(TypeInfo::coerced) + ctx.sema.type_of_expr(expr).map(TypeInfo::adjusted) } FlowKind::Try { .. } => { stdx::never!("try does not have defined expr_ty"); @@ -852,7 +852,7 @@ fn either_syntax(value: &Either) -> &SyntaxNode { fn body_return_ty(ctx: &AssistContext, body: &FunctionBody) -> Option { match body.tail_expr() { - Some(expr) => ctx.sema.type_of_expr(&expr).map(TypeInfo::ty).map(RetType::Expr), + Some(expr) => ctx.sema.type_of_expr(&expr).map(TypeInfo::original).map(RetType::Expr), None => Some(RetType::Stmt), } } @@ -949,7 +949,7 @@ fn expr_err_kind(expr: &ast::Expr, ctx: &AssistContext) -> Option { let text = func_name.syntax().text(); if text == "Err" { - Some(TryKind::Result { ty: ctx.sema.type_of_expr(expr).map(TypeInfo::ty)? }) + Some(TryKind::Result { ty: ctx.sema.type_of_expr(expr).map(TypeInfo::original)? }) } else if text == "None" { Some(TryKind::Option) } else { diff --git a/crates/ide_assists/src/handlers/extract_variable.rs b/crates/ide_assists/src/handlers/extract_variable.rs index c94fa12712..c72ed32423 100644 --- a/crates/ide_assists/src/handlers/extract_variable.rs +++ b/crates/ide_assists/src/handlers/extract_variable.rs @@ -40,7 +40,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option .take_while(|it| it.text_range().contains_range(ctx.frange.range)) .find_map(valid_target_expr)?; if let Some(ty_info) = ctx.sema.type_of_expr(&to_extract) { - if ty_info.coerced().is_unit() { + if ty_info.adjusted().is_unit() { return None; } } diff --git a/crates/ide_assists/src/handlers/fill_match_arms.rs b/crates/ide_assists/src/handlers/fill_match_arms.rs index 52f0851295..f71b9e3a3c 100644 --- a/crates/ide_assists/src/handlers/fill_match_arms.rs +++ b/crates/ide_assists/src/handlers/fill_match_arms.rs @@ -223,7 +223,7 @@ impl ExtendedEnum { } fn resolve_enum_def(sema: &Semantics, expr: &ast::Expr) -> Option { - sema.type_of_expr(expr)?.coerced().autoderef(sema.db).find_map(|ty| match ty.as_adt() { + sema.type_of_expr(expr)?.adjusted().autoderef(sema.db).find_map(|ty| match ty.as_adt() { Some(Adt::Enum(e)) => Some(ExtendedEnum::Enum(e)), _ => ty.is_bool().then(|| ExtendedEnum::Bool), }) @@ -234,7 +234,7 @@ fn resolve_tuple_of_enum_def( expr: &ast::Expr, ) -> Option> { sema.type_of_expr(expr)? - .coerced() + .adjusted() .tuple_fields(sema.db) .iter() .map(|ty| { diff --git a/crates/ide_assists/src/handlers/generate_function.rs b/crates/ide_assists/src/handlers/generate_function.rs index d22929206b..255f9ae4ec 100644 --- a/crates/ide_assists/src/handlers/generate_function.rs +++ b/crates/ide_assists/src/handlers/generate_function.rs @@ -153,7 +153,8 @@ impl FunctionBuilder { // type, but that the current state of their code doesn't allow that return type // to be accurately inferred. let (ret_ty, should_render_snippet) = { - match ctx.sema.type_of_expr(&ast::Expr::CallExpr(call.clone())).map(TypeInfo::ty) { + match ctx.sema.type_of_expr(&ast::Expr::CallExpr(call.clone())).map(TypeInfo::original) + { Some(ty) if ty.is_unknown() || ty.is_unit() => (make::ty_unit(), true), Some(ty) => { let rendered = ty.display_source_code(ctx.db(), target_module.into()); @@ -331,7 +332,7 @@ fn fn_arg_type( target_module: hir::Module, fn_arg: &ast::Expr, ) -> Option { - let ty = ctx.sema.type_of_expr(fn_arg)?.coerced(); + let ty = ctx.sema.type_of_expr(fn_arg)?.adjusted(); if ty.is_unknown() { return None; } diff --git a/crates/ide_assists/src/handlers/infer_function_return_type.rs b/crates/ide_assists/src/handlers/infer_function_return_type.rs index c4bb716071..778ad21b08 100644 --- a/crates/ide_assists/src/handlers/infer_function_return_type.rs +++ b/crates/ide_assists/src/handlers/infer_function_return_type.rs @@ -18,7 +18,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; pub(crate) fn infer_function_return_type(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let (fn_type, tail_expr, builder_edit_pos) = extract_tail(ctx)?; let module = ctx.sema.scope(tail_expr.syntax()).module()?; - let ty = ctx.sema.type_of_expr(&tail_expr)?.coerced(); + let ty = ctx.sema.type_of_expr(&tail_expr)?.adjusted(); if ty.is_unit() { return None; } diff --git a/crates/ide_assists/src/handlers/inline_call.rs b/crates/ide_assists/src/handlers/inline_call.rs index 8bafae93f9..c60dd81eb0 100644 --- a/crates/ide_assists/src/handlers/inline_call.rs +++ b/crates/ide_assists/src/handlers/inline_call.rs @@ -190,7 +190,7 @@ pub(crate) fn inline_( let ty = ctx .sema .type_of_expr(&expr) - .filter(TypeInfo::has_coercion) + .filter(TypeInfo::has_adjustment) .and_then(|_| param_ty); body.push_front( make::let_stmt(pat, ty, Some(expr)).clone_for_update().into(), diff --git a/crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs b/crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs index 54c3f4a2a2..371223e79d 100644 --- a/crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs +++ b/crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs @@ -80,7 +80,7 @@ fn is_ref_and_impls_iter_method( }; let wanted_method = if ref_expr.mut_token().is_some() { known::iter_mut } else { known::iter }; let expr_behind_ref = ref_expr.expr()?; - let ty = sema.type_of_expr(&expr_behind_ref)?.coerced(); + let ty = sema.type_of_expr(&expr_behind_ref)?.adjusted(); let scope = sema.scope(iterable.syntax()); let krate = scope.module()?.krate(); let traits_in_scope = scope.traits_in_scope(); @@ -110,7 +110,7 @@ fn is_ref_and_impls_iter_method( /// Whether iterable implements core::Iterator fn impls_core_iter(sema: &hir::Semantics, iterable: &ast::Expr) -> bool { let it_typ = match sema.type_of_expr(iterable) { - Some(it) => it.coerced(), + Some(it) => it.adjusted(), None => return false, }; diff --git a/crates/ide_assists/src/handlers/replace_if_let_with_match.rs b/crates/ide_assists/src/handlers/replace_if_let_with_match.rs index 45b3ce2990..323f58acbb 100644 --- a/crates/ide_assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/ide_assists/src/handlers/replace_if_let_with_match.rs @@ -127,7 +127,7 @@ fn make_else_arm( let pattern = if let [(Either::Left(pat), _)] = conditionals { ctx.sema .type_of_pat(&pat) - .and_then(|ty| TryEnum::from_ty(&ctx.sema, &ty.coerced())) + .and_then(|ty| TryEnum::from_ty(&ctx.sema, &ty.adjusted())) .zip(Some(pat)) } else { None @@ -268,7 +268,7 @@ fn binds_name(pat: &ast::Pat) -> bool { fn is_sad_pat(sema: &hir::Semantics, pat: &ast::Pat) -> bool { sema.type_of_pat(pat) - .and_then(|ty| TryEnum::from_ty(sema, &ty.coerced())) + .and_then(|ty| TryEnum::from_ty(sema, &ty.adjusted())) .map_or(false, |it| does_pat_match_variant(pat, &it.sad_pattern())) } diff --git a/crates/ide_assists/src/handlers/replace_let_with_if_let.rs b/crates/ide_assists/src/handlers/replace_let_with_if_let.rs index 190f302d5c..19abb129ef 100644 --- a/crates/ide_assists/src/handlers/replace_let_with_if_let.rs +++ b/crates/ide_assists/src/handlers/replace_let_with_if_let.rs @@ -50,7 +50,7 @@ pub(crate) fn replace_let_with_if_let(acc: &mut Assists, ctx: &AssistContext) -> |edit| { let ty = ctx.sema.type_of_expr(&init); let happy_variant = ty - .and_then(|ty| TryEnum::from_ty(&ctx.sema, &ty.coerced())) + .and_then(|ty| TryEnum::from_ty(&ctx.sema, &ty.adjusted())) .map(|it| it.happy_case()); let pat = match happy_variant { None => original_pat, diff --git a/crates/ide_assists/src/utils.rs b/crates/ide_assists/src/utils.rs index 1efac04db9..0bd89b51f8 100644 --- a/crates/ide_assists/src/utils.rs +++ b/crates/ide_assists/src/utils.rs @@ -270,8 +270,8 @@ fn invert_special_case(sema: &Semantics, expr: &ast::Expr) -> Opti fn bin_impls_ord(sema: &Semantics, bin: &ast::BinExpr) -> bool { match ( - bin.lhs().and_then(|lhs| sema.type_of_expr(&lhs)).map(hir::TypeInfo::coerced), - bin.rhs().and_then(|rhs| sema.type_of_expr(&rhs)).map(hir::TypeInfo::coerced), + bin.lhs().and_then(|lhs| sema.type_of_expr(&lhs)).map(hir::TypeInfo::adjusted), + bin.rhs().and_then(|rhs| sema.type_of_expr(&rhs)).map(hir::TypeInfo::adjusted), ) { (Some(lhs_ty), Some(rhs_ty)) if lhs_ty == rhs_ty => { let krate = sema.scope(bin.syntax()).module().map(|it| it.krate()); diff --git a/crates/ide_assists/src/utils/suggest_name.rs b/crates/ide_assists/src/utils/suggest_name.rs index 6a2f086382..c1513f97da 100644 --- a/crates/ide_assists/src/utils/suggest_name.rs +++ b/crates/ide_assists/src/utils/suggest_name.rs @@ -197,7 +197,7 @@ fn from_param(expr: &ast::Expr, sema: &Semantics<'_, RootDatabase>) -> Option { let func = call.expr()?; - let func_ty = sema.type_of_expr(&func)?.coerced(); + let func_ty = sema.type_of_expr(&func)?.adjusted(); func_ty.as_callable(sema.db)? }, ast::MethodCallExpr(method) => sema.resolve_method_call_as_callable(&method)?, @@ -225,7 +225,7 @@ fn var_name_from_pat(pat: &ast::Pat) -> Option { } fn from_type(expr: &ast::Expr, sema: &Semantics<'_, RootDatabase>) -> Option { - let ty = sema.type_of_expr(expr)?.coerced(); + let ty = sema.type_of_expr(expr)?.adjusted(); let ty = ty.remove_ref().unwrap_or(ty); name_of_type(&ty, sema.db) diff --git a/crates/ide_completion/src/completions/dot.rs b/crates/ide_completion/src/completions/dot.rs index 564f5f2eae..fdd6e59ffe 100644 --- a/crates/ide_completion/src/completions/dot.rs +++ b/crates/ide_completion/src/completions/dot.rs @@ -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.ty, + Some(ty) => ty.original, _ => return, }; diff --git a/crates/ide_completion/src/completions/flyimport.rs b/crates/ide_completion/src/completions/flyimport.rs index e10eb26936..33b9b61a72 100644 --- a/crates/ide_completion/src/completions/flyimport.rs +++ b/crates/ide_completion/src/completions/flyimport.rs @@ -180,7 +180,7 @@ fn import_assets(ctx: &CompletionContext, fuzzy_name: String) -> Option it.ty, + Some(it) => it.original, None => return, }; diff --git a/crates/ide_completion/src/completions/record.rs b/crates/ide_completion/src/completions/record.rs index d15375634d..8ede825a62 100644 --- a/crates/ide_completion/src/completions/record.rs +++ b/crates/ide_completion/src/completions/record.rs @@ -12,9 +12,9 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> Some(ImmediateLocation::RecordExpr(record_expr)) => { let ty = ctx.sema.type_of_expr(&Expr::RecordExpr(record_expr.clone())); 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.ty.impls_trait(ctx.db, default_trait, &[])); + let impl_default_trait = default_trait.zip(ty).map_or(false, |(default_trait, ty)| { + ty.original.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() { diff --git a/crates/ide_completion/src/context.rs b/crates/ide_completion/src/context.rs index 6922c203ce..ac5cd1ce8e 100644 --- a/crates/ide_completion/src/context.rs +++ b/crates/ide_completion/src/context.rs @@ -454,7 +454,7 @@ impl<'a> CompletionContext<'a> { 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))) - .map(TypeInfo::ty); + .map(TypeInfo::original); let name = if let Some(ast::Pat::IdentPat(ident)) = it.pat() { ident.name().map(NameOrNameRef::Name) } else { @@ -497,13 +497,13 @@ 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)).map(TypeInfo::ty), + it.expr().as_ref().and_then(|e| self.sema.type_of_expr(e)).map(TypeInfo::original), 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)).map(TypeInfo::ty); + let ty = it.expr().and_then(|e| self.sema.type_of_expr(&e)).map(TypeInfo::original); (ty, None) }, ast::IfExpr(it) => { @@ -511,13 +511,13 @@ impl<'a> CompletionContext<'a> { let ty = it.condition() .and_then(|cond| cond.expr()) .and_then(|e| self.sema.type_of_expr(&e)) - .map(TypeInfo::ty); + .map(TypeInfo::original); (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)).map(TypeInfo::ty); + let ty = self.sema.type_of_pat(&ast::Pat::from(it)).map(TypeInfo::original); (ty, None) }, ast::Fn(it) => { @@ -528,7 +528,7 @@ impl<'a> CompletionContext<'a> { }, ast::ClosureExpr(it) => { let ty = self.sema.type_of_expr(&it.into()); - ty.and_then(|ty| ty.ty.as_callable(self.db)) + ty.and_then(|ty| ty.original.as_callable(self.db)) .map(|c| (Some(c.return_type()), None)) .unwrap_or((None, None)) }, diff --git a/crates/ide_db/src/call_info.rs b/crates/ide_db/src/call_info.rs index a406e0d6f5..016b001439 100644 --- a/crates/ide_db/src/call_info.rs +++ b/crates/ide_db/src/call_info.rs @@ -119,7 +119,7 @@ fn call_info_impl( let callable = match &calling_node { FnCallNode::CallExpr(call) => { - sema.type_of_expr(&call.expr()?)?.coerced().as_callable(sema.db)? + sema.type_of_expr(&call.expr()?)?.adjusted().as_callable(sema.db)? } FnCallNode::MethodCallExpr(call) => sema.resolve_method_call_as_callable(call)?, }; diff --git a/crates/ide_db/src/helpers/import_assets.rs b/crates/ide_db/src/helpers/import_assets.rs index 52cd99ec91..3433398eba 100644 --- a/crates/ide_db/src/helpers/import_assets.rs +++ b/crates/ide_db/src/helpers/import_assets.rs @@ -543,7 +543,7 @@ impl ImportCandidate { match sema.resolve_method_call(method_call) { Some(_) => None, None => Some(Self::TraitMethod(TraitImportCandidate { - receiver_ty: sema.type_of_expr(&method_call.receiver()?)?.coerced(), + receiver_ty: sema.type_of_expr(&method_call.receiver()?)?.adjusted(), assoc_item_name: NameToImport::Exact(method_call.name_ref()?.to_string()), })), } diff --git a/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs b/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs index 06dc8dcd8b..2e9bd2d3dd 100644 --- a/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs +++ b/crates/ide_diagnostics/src/handlers/missing_ok_or_some_in_tail_expr.rs @@ -35,7 +35,7 @@ fn fixes(ctx: &DiagnosticsContext<'_>, d: &hir::MissingOkOrSomeInTailExpr) -> Op let tail_expr_range = tail_expr.syntax().text_range(); let mut builder = TextEdit::builder(); for_each_tail_expr(&tail_expr, &mut |expr| { - if ctx.sema.type_of_expr(expr).map(TypeInfo::ty).as_ref() != Some(&d.expected) { + if ctx.sema.type_of_expr(expr).map(TypeInfo::original).as_ref() != Some(&d.expected) { builder.insert(expr.syntax().text_range().start(), format!("{}(", d.required)); builder.insert(expr.syntax().text_range().end(), ")".to_string()); } diff --git a/crates/ide_diagnostics/src/handlers/no_such_field.rs b/crates/ide_diagnostics/src/handlers/no_such_field.rs index 2518dd8bb6..667a550d1f 100644 --- a/crates/ide_diagnostics/src/handlers/no_such_field.rs +++ b/crates/ide_diagnostics/src/handlers/no_such_field.rs @@ -62,7 +62,7 @@ fn missing_record_expr_field_fixes( }; let def_file_id = def_file_id.original_file(sema.db); - let new_field_type = sema.type_of_expr(&record_expr_field.expr()?)?.coerced(); + let new_field_type = sema.type_of_expr(&record_expr_field.expr()?)?.adjusted(); if new_field_type.is_unknown() { return None; } diff --git a/crates/ide_ssr/src/matching.rs b/crates/ide_ssr/src/matching.rs index 6699d29f97..55147674d2 100644 --- a/crates/ide_ssr/src/matching.rs +++ b/crates/ide_ssr/src/matching.rs @@ -615,7 +615,7 @@ impl<'db, 'sema> Matcher<'db, 'sema> { .ok_or_else(|| { match_error!("Failed to get receiver type for `{}`", expr.syntax().text()) })? - .ty; + .original; // Temporary needed to make the borrow checker happy. let res = code_type .autoderef(self.sema.db)