8
8
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
9
9
10
10
use crate :: rustc_internal:: { self , opaque} ;
11
- use crate :: stable_mir:: mir:: { CopyNonOverlapping , UserTypeProjection } ;
11
+ use crate :: stable_mir:: mir:: { CopyNonOverlapping , UserTypeProjection , VariantIdx } ;
12
12
use crate :: stable_mir:: ty:: { FloatTy , IntTy , Movability , RigidTy , TyKind , UintTy } ;
13
13
use crate :: stable_mir:: { self , Context } ;
14
14
use rustc_hir as hir;
@@ -130,16 +130,11 @@ impl<'tcx> Stable<'tcx> for mir::Statement<'tcx> {
130
130
}
131
131
PlaceMention ( place) => stable_mir:: mir:: Statement :: PlaceMention ( place. stable ( tables) ) ,
132
132
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
+ }
143
138
}
144
139
Coverage ( coverage) => stable_mir:: mir:: Statement :: Coverage ( stable_mir:: mir:: Coverage {
145
140
kind : coverage. kind . stable ( tables) ,
@@ -398,13 +393,11 @@ impl<'tcx> Stable<'tcx> for mir::FakeReadCause {
398
393
use mir:: FakeReadCause :: * ;
399
394
match self {
400
395
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
+ }
404
399
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) ) ,
408
401
ForIndex => stable_mir:: mir:: FakeReadCause :: ForIndex ,
409
402
}
410
403
}
@@ -447,22 +440,30 @@ impl<'tcx> Stable<'tcx> for mir::coverage::CoverageKind {
447
440
CoverageKind :: Counter { function_source_hash, id } => {
448
441
stable_mir:: mir:: CoverageKind :: Counter {
449
442
function_source_hash : * function_source_hash as usize ,
450
- id : id . as_usize ( ) ,
443
+ id : opaque ( id ) ,
451
444
}
452
445
}
453
446
CoverageKind :: Expression { id, lhs, op, rhs } => {
454
447
stable_mir:: mir:: CoverageKind :: Expression {
455
- id : id . as_usize ( ) ,
456
- lhs : lhs . as_usize ( ) ,
448
+ id : opaque ( id ) ,
449
+ lhs : opaque ( lhs ) ,
457
450
op : op. stable ( tables) ,
458
- rhs : rhs . as_usize ( ) ,
451
+ rhs : opaque ( rhs ) ,
459
452
}
460
453
}
461
454
CoverageKind :: Unreachable => stable_mir:: mir:: CoverageKind :: Unreachable ,
462
455
}
463
456
}
464
457
}
465
458
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
+
466
467
impl < ' tcx > Stable < ' tcx > for mir:: coverage:: Op {
467
468
type T = stable_mir:: mir:: Op ;
468
469
@@ -476,14 +477,14 @@ impl<'tcx> Stable<'tcx> for mir::coverage::Op {
476
477
}
477
478
478
479
impl < ' tcx > Stable < ' tcx > for mir:: Local {
479
- type T = usize ;
480
+ type T = stable_mir :: mir :: Local ;
480
481
fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
481
482
self . as_usize ( )
482
483
}
483
484
}
484
485
485
486
impl < ' tcx > Stable < ' tcx > for rustc_target:: abi:: VariantIdx {
486
- type T = usize ;
487
+ type T = VariantIdx ;
487
488
fn stable ( & self , _: & mut Tables < ' tcx > ) -> Self :: T {
488
489
self . as_usize ( )
489
490
}
@@ -525,14 +526,12 @@ impl<'tcx> Stable<'tcx> for CodeRegion {
525
526
type T = stable_mir:: mir:: CodeRegion ;
526
527
527
528
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 ,
536
535
}
537
536
}
538
537
}
0 commit comments