@@ -180,6 +180,27 @@ impl<'tcx> Mir<'tcx> {
180180 Some ( Local :: new ( idx) )
181181 }
182182
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+
183204 /// Counts the number of locals, such that that local_index
184205 /// will always return an index smaller than this count.
185206 pub fn count_locals ( & self ) -> usize {
@@ -680,13 +701,13 @@ pub enum AssertMessage<'tcx> {
680701///////////////////////////////////////////////////////////////////////////
681702// Statements
682703
683- #[ derive( Clone , RustcEncodable , RustcDecodable ) ]
704+ #[ derive( Clone , RustcEncodable , RustcDecodable , Eq , PartialEq ) ]
684705pub struct Statement < ' tcx > {
685706 pub source_info : SourceInfo ,
686707 pub kind : StatementKind < ' tcx > ,
687708}
688709
689- #[ derive( Clone , Debug , RustcEncodable , RustcDecodable ) ]
710+ #[ derive( Clone , Debug , RustcEncodable , RustcDecodable , Eq , PartialEq ) ]
690711pub enum StatementKind < ' tcx > {
691712 Assign ( Lvalue < ' tcx > , Rvalue < ' tcx > ) ,
692713}
@@ -710,7 +731,7 @@ newtype_index!(Local, "local");
710731
711732/// A path to a value; something that can be evaluated without
712733/// changing or disturbing program state.
713- #[ derive( Clone , PartialEq , RustcEncodable , RustcDecodable ) ]
734+ #[ derive( Clone , PartialEq , RustcEncodable , RustcDecodable , Eq , Hash ) ]
714735pub enum Lvalue < ' tcx > {
715736 /// local variable declared by the user
716737 Var ( Var ) ,
@@ -868,7 +889,7 @@ pub struct VisibilityScopeData {
868889/// These are values that can appear inside an rvalue (or an index
869890/// lvalue). They are intentionally limited to prevent rvalues from
870891/// being nested in one another.
871- #[ derive( Clone , PartialEq , RustcEncodable , RustcDecodable ) ]
892+ #[ derive( Clone , PartialEq , RustcEncodable , RustcDecodable , Eq , Hash ) ]
872893pub enum Operand < ' tcx > {
873894 Consume ( Lvalue < ' tcx > ) ,
874895 Constant ( Constant < ' tcx > ) ,
@@ -887,7 +908,7 @@ impl<'tcx> Debug for Operand<'tcx> {
887908///////////////////////////////////////////////////////////////////////////
888909/// Rvalues
889910
890- #[ derive( Clone , RustcEncodable , RustcDecodable ) ]
911+ #[ derive( Clone , RustcEncodable , RustcDecodable , Eq , PartialEq ) ]
891912pub enum Rvalue < ' tcx > {
892913 /// x (either a move or copy, depending on type of x)
893914 Use ( Operand < ' tcx > ) ,
@@ -1113,7 +1134,7 @@ pub struct Constant<'tcx> {
11131134 pub literal : Literal < ' tcx > ,
11141135}
11151136
1116- #[ derive( Clone , RustcEncodable , RustcDecodable ) ]
1137+ #[ derive( Clone , RustcEncodable , RustcDecodable , Eq , PartialEq ) ]
11171138pub struct TypedConstVal < ' tcx > {
11181139 pub ty : Ty < ' tcx > ,
11191140 pub span : Span ,
0 commit comments