@@ -6,13 +6,14 @@ pub mod scope;
66#[ cfg( test) ]
77mod tests;
88
9- use std:: ops:: Index ;
9+ use std:: ops:: { Deref , Index } ;
1010
1111use base_db:: CrateId ;
1212use cfg:: { CfgExpr , CfgOptions } ;
1313use hir_expand:: { name:: Name , InFile } ;
1414use la_arena:: { Arena , ArenaMap } ;
1515use rustc_hash:: FxHashMap ;
16+ use smallvec:: SmallVec ;
1617use span:: MacroFileId ;
1718use syntax:: { ast, AstPtr , SyntaxNodePtr } ;
1819use triomphe:: Arc ;
@@ -91,6 +92,7 @@ pub struct BodySourceMap {
9192 label_map_back : ArenaMap < LabelId , LabelSource > ,
9293
9394 self_param : Option < InFile < AstPtr < ast:: SelfParam > > > ,
95+ binding_definitions : FxHashMap < BindingId , SmallVec < [ PatId ; 4 ] > > ,
9496
9597 /// We don't create explicit nodes for record fields (`S { record_field: 92 }`).
9698 /// Instead, we use id of expression (`92`) to identify the field.
@@ -377,6 +379,10 @@ impl BodySourceMap {
377379 self . label_map_back [ label]
378380 }
379381
382+ pub fn patterns_for_binding ( & self , binding : BindingId ) -> & [ PatId ] {
383+ self . binding_definitions . get ( & binding) . map_or ( & [ ] , Deref :: deref)
384+ }
385+
380386 pub fn node_label ( & self , node : InFile < & ast:: Label > ) -> Option < LabelId > {
381387 let src = node. map ( AstPtr :: new) ;
382388 self . label_map . get ( & src) . cloned ( )
@@ -428,6 +434,7 @@ impl BodySourceMap {
428434 expansions,
429435 format_args_template_map,
430436 diagnostics,
437+ binding_definitions,
431438 } = self ;
432439 format_args_template_map. shrink_to_fit ( ) ;
433440 expr_map. shrink_to_fit ( ) ;
@@ -440,5 +447,6 @@ impl BodySourceMap {
440447 pat_field_map_back. shrink_to_fit ( ) ;
441448 expansions. shrink_to_fit ( ) ;
442449 diagnostics. shrink_to_fit ( ) ;
450+ binding_definitions. shrink_to_fit ( ) ;
443451 }
444452}
0 commit comments