1
1
use rustc_data_structures:: fx:: FxIndexSet ;
2
2
use rustc_infer:: infer:: InferCtxt ;
3
3
use rustc_middle:: ty;
4
- use rustc_middle:: ty:: { Const , Region , Ty , TyCtxt , TypeFoldable , TypeFolder , TypeSuperFoldable } ;
4
+ use rustc_middle:: ty:: {
5
+ Const , GenericArg , Region , Ty , TyCtxt , TypeFoldable , TypeFolder , TypeSuperFoldable ,
6
+ } ;
5
7
6
8
pub struct DedupWalker < ' me , ' tcx > {
7
9
infcx : & ' me InferCtxt < ' tcx > ,
@@ -11,15 +13,9 @@ pub struct DedupWalker<'me, 'tcx> {
11
13
vars_present : Vec < usize > ,
12
14
}
13
15
pub struct DedupableIndexer < ' tcx > {
14
- vars : FxIndexSet < DedupVar < ' tcx > > ,
16
+ vars : FxIndexSet < GenericArg < ' tcx > > ,
15
17
pub unremovable_vars : FxIndexSet < usize > ,
16
18
}
17
- #[ derive( Hash , PartialEq , Eq ) ]
18
- enum DedupVar < ' tcx > {
19
- Region ( Region < ' tcx > ) ,
20
- Ty ( Ty < ' tcx > ) ,
21
- Const ( Const < ' tcx > ) ,
22
- }
23
19
24
20
impl < ' me , ' tcx > DedupWalker < ' me , ' tcx > {
25
21
pub fn erase_dedupables < T : TypeFoldable < TyCtxt < ' tcx > > > (
@@ -38,7 +34,7 @@ impl<'tcx> DedupableIndexer<'tcx> {
38
34
pub fn new ( ) -> Self {
39
35
Self { vars : FxIndexSet :: default ( ) , unremovable_vars : FxIndexSet :: default ( ) }
40
36
}
41
- fn lookup ( & mut self , var : DedupVar < ' tcx > ) -> usize {
37
+ fn lookup ( & mut self , var : GenericArg < ' tcx > ) -> usize {
42
38
self . vars . get_index_of ( & var) . unwrap_or_else ( || self . vars . insert_full ( var) . 0 )
43
39
}
44
40
fn add_unremovable_var ( & mut self , var : usize ) {
@@ -63,7 +59,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for DedupWalker<'_, 'tcx> {
63
59
ty:: ReVar ( ..) | ty:: RePlaceholder ( ..) => self . infcx . universe_of_region ( region) ,
64
60
_ => return region,
65
61
} ;
66
- let var_id = self . var_indexer . lookup ( DedupVar :: Region ( region) ) ;
62
+ let var_id = self . var_indexer . lookup ( GenericArg :: from ( region) ) ;
67
63
self . vars_present . push ( var_id) ;
68
64
if self . max_nameable_universe . can_name ( universe) {
69
65
self . var_indexer . add_unremovable_var ( var_id) ;
@@ -90,7 +86,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for DedupWalker<'_, 'tcx> {
90
86
}
91
87
_ => return ty,
92
88
} ;
93
- let var_id = self . var_indexer . lookup ( DedupVar :: Ty ( ty) ) ;
89
+ let var_id = self . var_indexer . lookup ( GenericArg :: from ( ty) ) ;
94
90
self . vars_present . push ( var_id) ;
95
91
if self . max_nameable_universe . can_name ( universe) {
96
92
self . var_indexer . add_unremovable_var ( var_id) ;
@@ -112,7 +108,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for DedupWalker<'_, 'tcx> {
112
108
_ => None ,
113
109
} ;
114
110
let new_const_kind = if let Some ( uni) = universe {
115
- let var_id = self . var_indexer . lookup ( DedupVar :: Const ( ct) ) ;
111
+ let var_id = self . var_indexer . lookup ( GenericArg :: from ( ct) ) ;
116
112
self . vars_present . push ( var_id) ;
117
113
if self . max_nameable_universe . can_name ( uni) {
118
114
self . var_indexer . add_unremovable_var ( var_id) ;
0 commit comments