@@ -28,7 +28,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
2828
2929 debug ! ( "get_var_name_and_span_for_region: attempting upvar" ) ;
3030 self . get_upvar_index_for_region ( tcx, fr)
31- . map ( |index| self . get_upvar_name_and_span_for_region ( tcx, mir, index) )
31+ . map ( |index| {
32+ let ( name, span) = self . get_upvar_name_and_span_for_region ( tcx, mir, index) ;
33+ ( Some ( name) , span)
34+ } )
3235 . or_else ( || {
3336 debug ! ( "get_var_name_and_span_for_region: attempting argument" ) ;
3437 self . get_argument_index_for_region ( tcx, fr)
@@ -37,7 +40,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
3740 . unwrap_or_else ( || span_bug ! ( mir. span, "can't find var name for free region {:?}" , fr) )
3841 }
3942
40- /// Get upvar index for a region .
43+ /// Search the upvars (if any) to find one that references fr. Return its index .
4144 crate fn get_upvar_index_for_region (
4245 & self ,
4346 tcx : TyCtxt < ' _ , ' _ , ' tcx > ,
@@ -69,13 +72,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
6972 Some ( upvar_index)
7073 }
7174
72- /// Get upvar name and span for a region.
75+ /// Given the index of an upvar, finds its name and the span from where it was
76+ /// declared.
7377 crate fn get_upvar_name_and_span_for_region (
7478 & self ,
7579 tcx : TyCtxt < ' _ , ' _ , ' tcx > ,
7680 mir : & Mir < ' tcx > ,
7781 upvar_index : usize ,
78- ) -> ( Option < Symbol > , Span ) {
82+ ) -> ( Symbol , Span ) {
7983 let upvar_hir_id = mir. upvar_decls [ upvar_index] . var_hir_id . assert_crate_local ( ) ;
8084 let upvar_node_id = tcx. hir . hir_to_node_id ( upvar_hir_id) ;
8185 debug ! ( "get_upvar_name_and_span_for_region: upvar_node_id={:?}" , upvar_node_id) ;
@@ -85,10 +89,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
8589 debug ! ( "get_upvar_name_and_span_for_region: upvar_name={:?} upvar_span={:?}" ,
8690 upvar_name, upvar_span) ;
8791
88- ( Some ( upvar_name) , upvar_span)
92+ ( upvar_name, upvar_span)
8993 }
9094
91- /// Get argument index for a region.
95+ /// Search the argument types for one that references fr (which should be a free region).
96+ /// Returns Some(_) with the index of the input if one is found.
97+ ///
98+ /// NB: In the case of a closure, the index is indexing into the signature as seen by the
99+ /// user - in particular, index 0 is not the implicit self parameter.
92100 crate fn get_argument_index_for_region (
93101 & self ,
94102 tcx : TyCtxt < ' _ , ' _ , ' tcx > ,
@@ -116,7 +124,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
116124 Some ( argument_index)
117125 }
118126
119- /// Get argument name and span for a region.
127+ /// Given the index of an argument, finds its name (if any) and the span from where it was
128+ /// declared.
120129 crate fn get_argument_name_and_span_for_region (
121130 & self ,
122131 mir : & Mir < ' tcx > ,
0 commit comments