@@ -180,6 +180,27 @@ impl<'tcx> Mir<'tcx> {
180
180
Some ( Local :: new ( idx) )
181
181
}
182
182
183
+ pub fn from_local_index_to_temp ( & self , local : Local ) -> Option < Temp > {
184
+ let num_args_and_vars = self . arg_decls . len ( ) + self . var_decls . len ( ) ;
185
+ if local. index ( ) < num_args_and_vars {
186
+ None
187
+ } else if local. index ( ) >= num_args_and_vars + self . temp_decls . len ( ) {
188
+ None
189
+ } else {
190
+ Some ( Temp :: new ( local. index ( ) - num_args_and_vars) )
191
+ }
192
+ }
193
+ pub fn from_local_index_to_var ( & self , local : Local ) -> Option < Var > {
194
+ let num_args = self . arg_decls . len ( ) ;
195
+ if local. index ( ) < num_args {
196
+ None
197
+ } else if local. index ( ) >= num_args + self . var_decls . len ( ) {
198
+ None
199
+ } else {
200
+ Some ( Var :: new ( local. index ( ) - num_args) )
201
+ }
202
+ }
203
+
183
204
/// Counts the number of locals, such that that local_index
184
205
/// will always return an index smaller than this count.
185
206
pub fn count_locals ( & self ) -> usize {
@@ -710,7 +731,7 @@ newtype_index!(Local, "local");
710
731
711
732
/// A path to a value; something that can be evaluated without
712
733
/// changing or disturbing program state.
713
- #[ derive( Clone , PartialEq , RustcEncodable , RustcDecodable ) ]
734
+ #[ derive( Clone , PartialEq , RustcEncodable , RustcDecodable , Eq , Hash ) ]
714
735
pub enum Lvalue < ' tcx > {
715
736
/// local variable declared by the user
716
737
Var ( Var ) ,
@@ -868,7 +889,7 @@ pub struct VisibilityScopeData {
868
889
/// These are values that can appear inside an rvalue (or an index
869
890
/// lvalue). They are intentionally limited to prevent rvalues from
870
891
/// being nested in one another.
871
- #[ derive( Clone , PartialEq , RustcEncodable , RustcDecodable ) ]
892
+ #[ derive( Clone , PartialEq , RustcEncodable , RustcDecodable , Eq , Hash ) ]
872
893
pub enum Operand < ' tcx > {
873
894
Consume ( Lvalue < ' tcx > ) ,
874
895
Constant ( Constant < ' tcx > ) ,
0 commit comments