88//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
1010use crate :: rustc_internal:: { self , opaque} ;
11- use crate :: stable_mir:: mir:: { CopyNonOverlapping , UserTypeProjection } ;
11+ use crate :: stable_mir:: mir:: { CopyNonOverlapping , UserTypeProjection , VariantIdx } ;
1212use crate :: stable_mir:: ty:: { FloatTy , IntTy , Movability , RigidTy , TyKind , UintTy } ;
1313use crate :: stable_mir:: { self , Context } ;
1414use rustc_hir as hir;
@@ -130,16 +130,11 @@ impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> {
130130 }
131131 PlaceMention ( place) => stable_mir:: mir:: Statement :: PlaceMention ( place. stable ( tables) ) ,
132132 AscribeUserType ( place_projection, variance) => {
133- stable_mir:: mir:: Statement :: AscribeUserType (
134- (
135- place_projection. as_ref ( ) . 0 . stable ( tables) ,
136- UserTypeProjection {
137- base : place_projection. as_ref ( ) . 1 . base . stable ( tables) ,
138- projection : format ! ( "{:?}" , place_projection. as_ref( ) . 1 . projs) ,
139- } ,
140- ) ,
141- variance. stable ( tables) ,
142- )
133+ stable_mir:: mir:: Statement :: AscribeUserType {
134+ place : place_projection. as_ref ( ) . 0 . stable ( tables) ,
135+ projections : place_projection. as_ref ( ) . 1 . stable ( tables) ,
136+ variance : variance. stable ( tables) ,
137+ }
143138 }
144139 Coverage ( coverage) => stable_mir:: mir:: Statement :: Coverage ( stable_mir:: mir:: Coverage {
145140 kind : coverage. kind . stable ( tables) ,
@@ -398,13 +393,11 @@ impl<'tcx> Stable<'tcx> for mir::FakeReadCause {
398393 use mir:: FakeReadCause :: * ;
399394 match self {
400395 ForMatchGuard => stable_mir:: mir:: FakeReadCause :: ForMatchGuard ,
401- ForMatchedPlace ( local_def_id) => stable_mir :: mir :: FakeReadCause :: ForMatchedPlace (
402- local_def_id . map ( |id| id . to_def_id ( ) . index . index ( ) ) ,
403- ) ,
396+ ForMatchedPlace ( local_def_id) => {
397+ stable_mir :: mir :: FakeReadCause :: ForMatchedPlace ( opaque ( local_def_id ) )
398+ }
404399 ForGuardBinding => stable_mir:: mir:: FakeReadCause :: ForGuardBinding ,
405- ForLet ( local_def_id) => stable_mir:: mir:: FakeReadCause :: ForLet (
406- local_def_id. map ( |id| id. to_def_id ( ) . index . index ( ) ) ,
407- ) ,
400+ ForLet ( local_def_id) => stable_mir:: mir:: FakeReadCause :: ForLet ( opaque ( local_def_id) ) ,
408401 ForIndex => stable_mir:: mir:: FakeReadCause :: ForIndex ,
409402 }
410403 }
@@ -447,22 +440,30 @@ impl<'tcx> Stable<'tcx> for mir::coverage::CoverageKind {
447440 CoverageKind :: Counter { function_source_hash, id } => {
448441 stable_mir:: mir:: CoverageKind :: Counter {
449442 function_source_hash : * function_source_hash as usize ,
450- id : id . as_usize ( ) ,
443+ id : opaque ( id ) ,
451444 }
452445 }
453446 CoverageKind :: Expression { id, lhs, op, rhs } => {
454447 stable_mir:: mir:: CoverageKind :: Expression {
455- id : id . as_usize ( ) ,
456- lhs : lhs . as_usize ( ) ,
448+ id : opaque ( id ) ,
449+ lhs : opaque ( lhs ) ,
457450 op : op. stable ( tables) ,
458- rhs : rhs . as_usize ( ) ,
451+ rhs : opaque ( rhs ) ,
459452 }
460453 }
461454 CoverageKind :: Unreachable => stable_mir:: mir:: CoverageKind :: Unreachable ,
462455 }
463456 }
464457}
465458
459+ impl < ' tcx > Stable < ' tcx > for mir:: UserTypeProjection {
460+ type T = stable_mir:: mir:: UserTypeProjection ;
461+
462+ fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
463+ UserTypeProjection { base : self . base . as_usize ( ) , projection : format ! ( "{:?}" , self . projs) }
464+ }
465+ }
466+
466467impl < ' tcx > Stable < ' tcx > for mir:: coverage:: Op {
467468 type T = stable_mir:: mir:: Op ;
468469
@@ -476,14 +477,14 @@ impl<'tcx> Stable<'tcx> for mir::coverage::Op {
476477}
477478
478479impl < ' tcx > Stable < ' tcx > for mir:: Local {
479- type T = usize ;
480+ type T = stable_mir :: mir :: Local ;
480481 fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
481482 self . as_usize ( )
482483 }
483484}
484485
485486impl < ' tcx > Stable < ' tcx > for rustc_target:: abi:: VariantIdx {
486- type T = usize ;
487+ type T = VariantIdx ;
487488 fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
488489 self . as_usize ( )
489490 }
@@ -525,14 +526,12 @@ impl<'tcx> Stable<'tcx> for CodeRegion {
525526 type T = stable_mir:: mir:: CodeRegion ;
526527
527528 fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
528- match self {
529- _ => stable_mir:: mir:: CodeRegion {
530- file_name : self . file_name . as_u32 ( ) as usize ,
531- start_line : self . start_line as usize ,
532- start_col : self . start_col as usize ,
533- end_line : self . end_line as usize ,
534- end_col : self . end_col as usize ,
535- } ,
529+ stable_mir:: mir:: CodeRegion {
530+ file_name : self . file_name . as_str ( ) . to_string ( ) ,
531+ start_line : self . start_line as usize ,
532+ start_col : self . start_col as usize ,
533+ end_line : self . end_line as usize ,
534+ end_col : self . end_col as usize ,
536535 }
537536 }
538537}
0 commit comments