22
33mod source_to_def;
44
5- use std:: { cell:: RefCell , fmt, iter, ops} ;
5+ use std:: { cell:: RefCell , fmt, iter, mem , ops} ;
66
77use base_db:: { FileId , FileRange } ;
88use hir_def:: {
@@ -29,7 +29,7 @@ use crate::{
2929 db:: HirDatabase ,
3030 semantics:: source_to_def:: { ChildContainer , SourceToDefCache , SourceToDefCtx } ,
3131 source_analyzer:: { resolve_hir_path, SourceAnalyzer } ,
32- Access , Adjust , AutoBorrow , BindingMode , BuiltinAttr , Callable , ConstParam , Crate ,
32+ Access , Adjust , Adjustment , AutoBorrow , BindingMode , BuiltinAttr , Callable , ConstParam , Crate ,
3333 DeriveHelper , Field , Function , HasSource , HirFileId , Impl , InFile , Label , LifetimeParam , Local ,
3434 Macro , Module , ModuleDef , Name , OverloadedDeref , Path , ScopeDef , ToolModule , Trait , Type ,
3535 TypeAlias , TypeParam , VariantDef ,
@@ -334,7 +334,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
334334 self . imp . resolve_trait ( trait_)
335335 }
336336
337- pub fn expr_adjustments ( & self , expr : & ast:: Expr ) -> Option < Vec < Adjust > > {
337+ pub fn expr_adjustments ( & self , expr : & ast:: Expr ) -> Option < Vec < Adjustment > > {
338338 self . imp . expr_adjustments ( expr)
339339 }
340340
@@ -1067,26 +1067,42 @@ impl<'db> SemanticsImpl<'db> {
10671067 }
10681068 }
10691069
1070- fn expr_adjustments ( & self , expr : & ast:: Expr ) -> Option < Vec < Adjust > > {
1070+ fn expr_adjustments ( & self , expr : & ast:: Expr ) -> Option < Vec < Adjustment > > {
10711071 let mutability = |m| match m {
10721072 hir_ty:: Mutability :: Not => Mutability :: Shared ,
10731073 hir_ty:: Mutability :: Mut => Mutability :: Mut ,
10741074 } ;
1075- self . analyze ( expr. syntax ( ) ) ?. expr_adjustments ( self . db , expr) . map ( |it| {
1075+
1076+ let analyzer = self . analyze ( expr. syntax ( ) ) ?;
1077+
1078+ let ( mut source_ty, _) = analyzer. type_of_expr ( self . db , expr) ?;
1079+
1080+ analyzer. expr_adjustments ( self . db , expr) . map ( |it| {
10761081 it. iter ( )
1077- . map ( |adjust| match adjust. kind {
1078- hir_ty:: Adjust :: NeverToAny => Adjust :: NeverToAny ,
1079- hir_ty:: Adjust :: Deref ( Some ( hir_ty:: OverloadedDeref ( m) ) ) => {
1080- Adjust :: Deref ( Some ( OverloadedDeref ( mutability ( m) ) ) )
1081- }
1082- hir_ty:: Adjust :: Deref ( None ) => Adjust :: Deref ( None ) ,
1083- hir_ty:: Adjust :: Borrow ( hir_ty:: AutoBorrow :: RawPtr ( m) ) => {
1084- Adjust :: Borrow ( AutoBorrow :: RawPtr ( mutability ( m) ) )
1085- }
1086- hir_ty:: Adjust :: Borrow ( hir_ty:: AutoBorrow :: Ref ( m) ) => {
1087- Adjust :: Borrow ( AutoBorrow :: Ref ( mutability ( m) ) )
1088- }
1089- hir_ty:: Adjust :: Pointer ( pc) => Adjust :: Pointer ( pc) ,
1082+ . map ( |adjust| {
1083+ let target =
1084+ Type :: new_with_resolver ( self . db , & analyzer. resolver , adjust. target . clone ( ) ) ;
1085+ let kind = match adjust. kind {
1086+ hir_ty:: Adjust :: NeverToAny => Adjust :: NeverToAny ,
1087+ hir_ty:: Adjust :: Deref ( Some ( hir_ty:: OverloadedDeref ( m) ) ) => {
1088+ Adjust :: Deref ( Some ( OverloadedDeref ( mutability ( m) ) ) )
1089+ }
1090+ hir_ty:: Adjust :: Deref ( None ) => Adjust :: Deref ( None ) ,
1091+ hir_ty:: Adjust :: Borrow ( hir_ty:: AutoBorrow :: RawPtr ( m) ) => {
1092+ Adjust :: Borrow ( AutoBorrow :: RawPtr ( mutability ( m) ) )
1093+ }
1094+ hir_ty:: Adjust :: Borrow ( hir_ty:: AutoBorrow :: Ref ( m) ) => {
1095+ Adjust :: Borrow ( AutoBorrow :: Ref ( mutability ( m) ) )
1096+ }
1097+ hir_ty:: Adjust :: Pointer ( pc) => Adjust :: Pointer ( pc) ,
1098+ } ;
1099+
1100+ // Update `source_ty` for the next adjustment
1101+ let source = mem:: replace ( & mut source_ty, target. clone ( ) ) ;
1102+
1103+ let adjustment = Adjustment { source, target, kind } ;
1104+
1105+ adjustment
10901106 } )
10911107 . collect ( )
10921108 } )
0 commit comments