@@ -14,9 +14,10 @@ use ra_syntax::{
1414} ;
1515use test_utils:: tested_by;
1616
17+ use super :: { ExprSource , PatSource } ;
1718use crate :: {
1819 adt:: StructKind ,
19- body:: { Body , BodySourceMap , Expander , PatPtr } ,
20+ body:: { Body , BodySourceMap , Expander , PatPtr , SyntheticSyntax } ,
2021 builtin_type:: { BuiltinFloat , BuiltinInt } ,
2122 db:: DefDatabase ,
2223 expr:: {
@@ -102,44 +103,48 @@ where
102103
103104 fn alloc_expr ( & mut self , expr : Expr , ptr : AstPtr < ast:: Expr > ) -> ExprId {
104105 let ptr = Either :: Left ( ptr) ;
105- let id = self . body . exprs . alloc ( expr) ;
106106 let src = self . expander . to_source ( ptr) ;
107+ let id = self . make_expr ( expr, Ok ( src) ) ;
107108 self . source_map . expr_map . insert ( src, id) ;
108- self . source_map . expr_map_back . insert ( id, src) ;
109109 id
110110 }
111111 // desugared exprs don't have ptr, that's wrong and should be fixed
112112 // somehow.
113113 fn alloc_expr_desugared ( & mut self , expr : Expr ) -> ExprId {
114- self . body . exprs . alloc ( expr)
114+ self . make_expr ( expr, Err ( SyntheticSyntax ) )
115115 }
116116 fn alloc_expr_field_shorthand ( & mut self , expr : Expr , ptr : AstPtr < ast:: RecordField > ) -> ExprId {
117117 let ptr = Either :: Right ( ptr) ;
118- let id = self . body . exprs . alloc ( expr) ;
119118 let src = self . expander . to_source ( ptr) ;
119+ let id = self . make_expr ( expr, Ok ( src) ) ;
120120 self . source_map . expr_map . insert ( src, id) ;
121+ id
122+ }
123+ fn empty_block ( & mut self ) -> ExprId {
124+ self . alloc_expr_desugared ( Expr :: Block { statements : Vec :: new ( ) , tail : None } )
125+ }
126+ fn missing_expr ( & mut self ) -> ExprId {
127+ self . alloc_expr_desugared ( Expr :: Missing )
128+ }
129+ fn make_expr ( & mut self , expr : Expr , src : Result < ExprSource , SyntheticSyntax > ) -> ExprId {
130+ let id = self . body . exprs . alloc ( expr) ;
121131 self . source_map . expr_map_back . insert ( id, src) ;
122132 id
123133 }
134+
124135 fn alloc_pat ( & mut self , pat : Pat , ptr : PatPtr ) -> PatId {
125- let id = self . body . pats . alloc ( pat) ;
126136 let src = self . expander . to_source ( ptr) ;
137+ let id = self . make_pat ( pat, Ok ( src) ) ;
127138 self . source_map . pat_map . insert ( src, id) ;
128- self . source_map . pat_map_back . insert ( id, src) ;
129139 id
130140 }
131-
132- fn empty_block ( & mut self ) -> ExprId {
133- let block = Expr :: Block { statements : Vec :: new ( ) , tail : None } ;
134- self . body . exprs . alloc ( block)
135- }
136-
137- fn missing_expr ( & mut self ) -> ExprId {
138- self . body . exprs . alloc ( Expr :: Missing )
139- }
140-
141141 fn missing_pat ( & mut self ) -> PatId {
142- self . body . pats . alloc ( Pat :: Missing )
142+ self . make_pat ( Pat :: Missing , Err ( SyntheticSyntax ) )
143+ }
144+ fn make_pat ( & mut self , pat : Pat , src : Result < PatSource , SyntheticSyntax > ) -> PatId {
145+ let id = self . body . pats . alloc ( pat) ;
146+ self . source_map . pat_map_back . insert ( id, src) ;
147+ id
143148 }
144149
145150 fn collect_expr ( & mut self , expr : ast:: Expr ) -> ExprId {
0 commit comments