2
2
3
3
mod source_to_def;
4
4
5
- use std:: { cell:: RefCell , fmt, iter, ops} ;
5
+ use std:: { cell:: RefCell , fmt, iter, mem , ops} ;
6
6
7
7
use base_db:: { FileId , FileRange } ;
8
8
use hir_def:: {
@@ -29,7 +29,7 @@ use crate::{
29
29
db:: HirDatabase ,
30
30
semantics:: source_to_def:: { ChildContainer , SourceToDefCache , SourceToDefCtx } ,
31
31
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 ,
33
33
DeriveHelper , Field , Function , HasSource , HirFileId , Impl , InFile , Label , LifetimeParam , Local ,
34
34
Macro , Module , ModuleDef , Name , OverloadedDeref , Path , ScopeDef , ToolModule , Trait , Type ,
35
35
TypeAlias , TypeParam , VariantDef ,
@@ -334,7 +334,7 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
334
334
self . imp . resolve_trait ( trait_)
335
335
}
336
336
337
- pub fn expr_adjustments ( & self , expr : & ast:: Expr ) -> Option < Vec < Adjust > > {
337
+ pub fn expr_adjustments ( & self , expr : & ast:: Expr ) -> Option < Vec < Adjustment > > {
338
338
self . imp . expr_adjustments ( expr)
339
339
}
340
340
@@ -1067,26 +1067,42 @@ impl<'db> SemanticsImpl<'db> {
1067
1067
}
1068
1068
}
1069
1069
1070
- fn expr_adjustments ( & self , expr : & ast:: Expr ) -> Option < Vec < Adjust > > {
1070
+ fn expr_adjustments ( & self , expr : & ast:: Expr ) -> Option < Vec < Adjustment > > {
1071
1071
let mutability = |m| match m {
1072
1072
hir_ty:: Mutability :: Not => Mutability :: Shared ,
1073
1073
hir_ty:: Mutability :: Mut => Mutability :: Mut ,
1074
1074
} ;
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| {
1076
1081
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
1090
1106
} )
1091
1107
. collect ( )
1092
1108
} )
0 commit comments