@@ -28,7 +28,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
28
28
29
29
debug ! ( "get_var_name_and_span_for_region: attempting upvar" ) ;
30
30
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
+ } )
32
35
. or_else ( || {
33
36
debug ! ( "get_var_name_and_span_for_region: attempting argument" ) ;
34
37
self . get_argument_index_for_region ( tcx, fr)
@@ -37,7 +40,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
37
40
. unwrap_or_else ( || span_bug ! ( mir. span, "can't find var name for free region {:?}" , fr) )
38
41
}
39
42
40
- /// Get upvar index for a region .
43
+ /// Search the upvars (if any) to find one that references fr. Return its index .
41
44
crate fn get_upvar_index_for_region (
42
45
& self ,
43
46
tcx : TyCtxt < ' _ , ' _ , ' tcx > ,
@@ -69,13 +72,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
69
72
Some ( upvar_index)
70
73
}
71
74
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.
73
77
crate fn get_upvar_name_and_span_for_region (
74
78
& self ,
75
79
tcx : TyCtxt < ' _ , ' _ , ' tcx > ,
76
80
mir : & Mir < ' tcx > ,
77
81
upvar_index : usize ,
78
- ) -> ( Option < Symbol > , Span ) {
82
+ ) -> ( Symbol , Span ) {
79
83
let upvar_hir_id = mir. upvar_decls [ upvar_index] . var_hir_id . assert_crate_local ( ) ;
80
84
let upvar_node_id = tcx. hir . hir_to_node_id ( upvar_hir_id) ;
81
85
debug ! ( "get_upvar_name_and_span_for_region: upvar_node_id={:?}" , upvar_node_id) ;
@@ -85,10 +89,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
85
89
debug ! ( "get_upvar_name_and_span_for_region: upvar_name={:?} upvar_span={:?}" ,
86
90
upvar_name, upvar_span) ;
87
91
88
- ( Some ( upvar_name) , upvar_span)
92
+ ( upvar_name, upvar_span)
89
93
}
90
94
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.
92
100
crate fn get_argument_index_for_region (
93
101
& self ,
94
102
tcx : TyCtxt < ' _ , ' _ , ' tcx > ,
@@ -116,7 +124,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
116
124
Some ( argument_index)
117
125
}
118
126
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.
120
129
crate fn get_argument_name_and_span_for_region (
121
130
& self ,
122
131
mir : & Mir < ' tcx > ,
0 commit comments