@@ -21,46 +21,46 @@ use ty::TypeVariants::*;
21
21
/// Represents a set of DefIds closed under the ancestor relation. That is, if
22
22
/// a DefId is in this set then so are all its descendants.
23
23
#[ derive( Clone ) ]
24
- pub struct DefIdForrest {
24
+ pub struct DefIdForest {
25
25
/// The minimal set of DefIds required to represent the whole set.
26
- /// If A and B are DefIds in the DefIdForrest , and A is a desecendant
26
+ /// If A and B are DefIds in the DefIdForest , and A is a desecendant
27
27
/// of B, then only B will be in root_ids.
28
28
/// We use a SmallVec here because (for its use in this module) its rare
29
29
/// that this will contain even two ids.
30
30
root_ids : SmallVec < [ DefId ; 1 ] > ,
31
31
}
32
32
33
- impl < ' a , ' gcx , ' tcx > DefIdForrest {
34
- /// Create an empty forrest .
35
- pub fn empty ( ) -> DefIdForrest {
36
- DefIdForrest {
33
+ impl < ' a , ' gcx , ' tcx > DefIdForest {
34
+ /// Create an empty forest .
35
+ pub fn empty ( ) -> DefIdForest {
36
+ DefIdForest {
37
37
root_ids : SmallVec :: new ( ) ,
38
38
}
39
39
}
40
40
41
- /// Create a forrest consisting of a single tree representing the entire
41
+ /// Create a forest consisting of a single tree representing the entire
42
42
/// crate.
43
43
#[ inline]
44
- pub fn full ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> DefIdForrest {
44
+ pub fn full ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> DefIdForest {
45
45
let crate_id = tcx. map . local_def_id ( CRATE_NODE_ID ) ;
46
- DefIdForrest :: from_id ( crate_id)
46
+ DefIdForest :: from_id ( crate_id)
47
47
}
48
48
49
- /// Create a forrest containing a DefId and all its descendants.
50
- pub fn from_id ( id : DefId ) -> DefIdForrest {
49
+ /// Create a forest containing a DefId and all its descendants.
50
+ pub fn from_id ( id : DefId ) -> DefIdForest {
51
51
let mut root_ids = SmallVec :: new ( ) ;
52
52
root_ids. push ( id) ;
53
- DefIdForrest {
53
+ DefIdForest {
54
54
root_ids : root_ids,
55
55
}
56
56
}
57
57
58
- /// Test whether the forrest is empty.
58
+ /// Test whether the forest is empty.
59
59
pub fn is_empty ( & self ) -> bool {
60
60
self . root_ids . is_empty ( )
61
61
}
62
62
63
- /// Test whether the forrest conains a given DefId.
63
+ /// Test whether the forest conains a given DefId.
64
64
pub fn contains ( & self ,
65
65
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
66
66
id : DefId ) -> bool
@@ -73,25 +73,25 @@ impl<'a, 'gcx, 'tcx> DefIdForrest {
73
73
false
74
74
}
75
75
76
- /// Calculate the intersection of a collection of forrests .
76
+ /// Calculate the intersection of a collection of forests .
77
77
pub fn intersection < I > ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
78
- iter : I ) -> DefIdForrest
79
- where I : IntoIterator < Item =DefIdForrest >
78
+ iter : I ) -> DefIdForest
79
+ where I : IntoIterator < Item =DefIdForest >
80
80
{
81
- let mut ret = DefIdForrest :: full ( tcx) ;
81
+ let mut ret = DefIdForest :: full ( tcx) ;
82
82
let mut next_ret = SmallVec :: new ( ) ;
83
83
let mut old_ret: SmallVec < [ DefId ; 1 ] > = SmallVec :: new ( ) ;
84
- for next_forrest in iter {
84
+ for next_forest in iter {
85
85
for id in ret. root_ids . drain ( ..) {
86
- if next_forrest . contains ( tcx, id) {
86
+ if next_forest . contains ( tcx, id) {
87
87
next_ret. push ( id) ;
88
88
} else {
89
89
old_ret. push ( id) ;
90
90
}
91
91
}
92
92
ret. root_ids . extend ( old_ret. drain ( ..) ) ;
93
93
94
- for id in next_forrest . root_ids {
94
+ for id in next_forest . root_ids {
95
95
if ret. contains ( tcx, id) {
96
96
next_ret. push ( id) ;
97
97
}
@@ -103,21 +103,21 @@ impl<'a, 'gcx, 'tcx> DefIdForrest {
103
103
ret
104
104
}
105
105
106
- /// Calculate the union of a collection of forrests .
106
+ /// Calculate the union of a collection of forests .
107
107
pub fn union < I > ( tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
108
- iter : I ) -> DefIdForrest
109
- where I : IntoIterator < Item =DefIdForrest >
108
+ iter : I ) -> DefIdForest
109
+ where I : IntoIterator < Item =DefIdForest >
110
110
{
111
- let mut ret = DefIdForrest :: empty ( ) ;
111
+ let mut ret = DefIdForest :: empty ( ) ;
112
112
let mut next_ret = SmallVec :: new ( ) ;
113
- for next_forrest in iter {
113
+ for next_forest in iter {
114
114
for id in ret. root_ids . drain ( ..) {
115
- if !next_forrest . contains ( tcx, id) {
115
+ if !next_forest . contains ( tcx, id) {
116
116
next_ret. push ( id) ;
117
117
}
118
118
}
119
119
120
- for id in next_forrest . root_ids {
120
+ for id in next_forest . root_ids {
121
121
if !next_ret. contains ( & id) {
122
122
next_ret. push ( id) ;
123
123
}
@@ -131,18 +131,18 @@ impl<'a, 'gcx, 'tcx> DefIdForrest {
131
131
}
132
132
133
133
impl < ' a , ' gcx , ' tcx > AdtDef {
134
- /// Calculate the forrest of DefIds from which this adt is visibly uninhabited.
134
+ /// Calculate the forest of DefIds from which this adt is visibly uninhabited.
135
135
pub fn uninhabited_from (
136
136
& self ,
137
137
visited : & mut FxHashSet < ( DefId , & ' tcx Substs < ' tcx > ) > ,
138
138
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
139
- substs : & ' tcx Substs < ' tcx > ) -> DefIdForrest
139
+ substs : & ' tcx Substs < ' tcx > ) -> DefIdForest
140
140
{
141
141
if !visited. insert ( ( self . did , substs) ) {
142
- return DefIdForrest :: empty ( ) ;
142
+ return DefIdForest :: empty ( ) ;
143
143
}
144
144
145
- let ret = DefIdForrest :: intersection ( tcx, self . variants . iter ( ) . map ( |v| {
145
+ let ret = DefIdForest :: intersection ( tcx, self . variants . iter ( ) . map ( |v| {
146
146
v. uninhabited_from ( visited, tcx, substs, self . adt_kind ( ) )
147
147
} ) ) ;
148
148
visited. remove ( & ( self . did , substs) ) ;
@@ -151,27 +151,27 @@ impl<'a, 'gcx, 'tcx> AdtDef {
151
151
}
152
152
153
153
impl < ' a , ' gcx , ' tcx > VariantDef {
154
- /// Calculate the forrest of DefIds from which this variant is visibly uninhabited.
154
+ /// Calculate the forest of DefIds from which this variant is visibly uninhabited.
155
155
pub fn uninhabited_from (
156
156
& self ,
157
157
visited : & mut FxHashSet < ( DefId , & ' tcx Substs < ' tcx > ) > ,
158
158
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
159
159
substs : & ' tcx Substs < ' tcx > ,
160
- adt_kind : AdtKind ) -> DefIdForrest
160
+ adt_kind : AdtKind ) -> DefIdForest
161
161
{
162
162
match adt_kind {
163
163
AdtKind :: Union => {
164
- DefIdForrest :: intersection ( tcx, self . fields . iter ( ) . map ( |f| {
164
+ DefIdForest :: intersection ( tcx, self . fields . iter ( ) . map ( |f| {
165
165
f. uninhabited_from ( visited, tcx, substs, false )
166
166
} ) )
167
167
} ,
168
168
AdtKind :: Struct => {
169
- DefIdForrest :: union ( tcx, self . fields . iter ( ) . map ( |f| {
169
+ DefIdForest :: union ( tcx, self . fields . iter ( ) . map ( |f| {
170
170
f. uninhabited_from ( visited, tcx, substs, false )
171
171
} ) )
172
172
} ,
173
173
AdtKind :: Enum => {
174
- DefIdForrest :: union ( tcx, self . fields . iter ( ) . map ( |f| {
174
+ DefIdForest :: union ( tcx, self . fields . iter ( ) . map ( |f| {
175
175
f. uninhabited_from ( visited, tcx, substs, true )
176
176
} ) )
177
177
} ,
@@ -180,24 +180,24 @@ impl<'a, 'gcx, 'tcx> VariantDef {
180
180
}
181
181
182
182
impl < ' a , ' gcx , ' tcx > FieldDef {
183
- /// Calculate the forrest of DefIds from which this field is visibly uninhabited.
183
+ /// Calculate the forest of DefIds from which this field is visibly uninhabited.
184
184
pub fn uninhabited_from (
185
185
& self ,
186
186
visited : & mut FxHashSet < ( DefId , & ' tcx Substs < ' tcx > ) > ,
187
187
tcx : TyCtxt < ' a , ' gcx , ' tcx > ,
188
188
substs : & ' tcx Substs < ' tcx > ,
189
- is_enum : bool ) -> DefIdForrest
189
+ is_enum : bool ) -> DefIdForest
190
190
{
191
191
let mut data_uninhabitedness = move || self . ty ( tcx, substs) . uninhabited_from ( visited, tcx) ;
192
192
if is_enum {
193
193
data_uninhabitedness ( )
194
194
} else {
195
195
match self . vis {
196
- Visibility :: Invisible => DefIdForrest :: empty ( ) ,
196
+ Visibility :: Invisible => DefIdForest :: empty ( ) ,
197
197
Visibility :: Restricted ( from) => {
198
- let forrest = DefIdForrest :: from_id ( from) ;
199
- let iter = Some ( forrest ) . into_iter ( ) . chain ( Some ( data_uninhabitedness ( ) ) ) ;
200
- DefIdForrest :: intersection ( tcx, iter)
198
+ let forest = DefIdForest :: from_id ( from) ;
199
+ let iter = Some ( forest ) . into_iter ( ) . chain ( Some ( data_uninhabitedness ( ) ) ) ;
200
+ DefIdForest :: intersection ( tcx, iter)
201
201
} ,
202
202
Visibility :: Public => data_uninhabitedness ( ) ,
203
203
}
@@ -206,58 +206,58 @@ impl<'a, 'gcx, 'tcx> FieldDef {
206
206
}
207
207
208
208
impl < ' a , ' gcx , ' tcx > TyS < ' tcx > {
209
- /// Calculate the forrest of DefIds from which this type is visibly uninhabited.
209
+ /// Calculate the forest of DefIds from which this type is visibly uninhabited.
210
210
pub fn uninhabited_from (
211
211
& self ,
212
212
visited : & mut FxHashSet < ( DefId , & ' tcx Substs < ' tcx > ) > ,
213
- tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> DefIdForrest
213
+ tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> DefIdForest
214
214
{
215
215
match tcx. lift_to_global ( & self ) {
216
216
Some ( global_ty) => {
217
217
{
218
218
let cache = tcx. inhabitedness_cache . borrow ( ) ;
219
- if let Some ( forrest ) = cache. get ( & global_ty) {
220
- return forrest . clone ( ) ;
219
+ if let Some ( forest ) = cache. get ( & global_ty) {
220
+ return forest . clone ( ) ;
221
221
}
222
222
}
223
- let forrest = global_ty. uninhabited_from_inner ( visited, tcx) ;
223
+ let forest = global_ty. uninhabited_from_inner ( visited, tcx) ;
224
224
let mut cache = tcx. inhabitedness_cache . borrow_mut ( ) ;
225
- cache. insert ( global_ty, forrest . clone ( ) ) ;
226
- forrest
225
+ cache. insert ( global_ty, forest . clone ( ) ) ;
226
+ forest
227
227
} ,
228
228
None => {
229
- let forrest = self . uninhabited_from_inner ( visited, tcx) ;
230
- forrest
229
+ let forest = self . uninhabited_from_inner ( visited, tcx) ;
230
+ forest
231
231
} ,
232
232
}
233
233
}
234
234
235
235
fn uninhabited_from_inner (
236
236
& self ,
237
237
visited : & mut FxHashSet < ( DefId , & ' tcx Substs < ' tcx > ) > ,
238
- tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> DefIdForrest
238
+ tcx : TyCtxt < ' a , ' gcx , ' tcx > ) -> DefIdForest
239
239
{
240
240
match self . sty {
241
241
TyAdt ( def, substs) => {
242
242
def. uninhabited_from ( visited, tcx, substs)
243
243
} ,
244
244
245
- TyNever => DefIdForrest :: full ( tcx) ,
245
+ TyNever => DefIdForest :: full ( tcx) ,
246
246
TyTuple ( ref tys) => {
247
- DefIdForrest :: union ( tcx, tys. iter ( ) . map ( |ty| {
247
+ DefIdForest :: union ( tcx, tys. iter ( ) . map ( |ty| {
248
248
ty. uninhabited_from ( visited, tcx)
249
249
} ) )
250
250
} ,
251
251
TyArray ( ty, len) => {
252
252
if len == 0 {
253
- DefIdForrest :: empty ( )
253
+ DefIdForest :: empty ( )
254
254
} else {
255
255
ty. uninhabited_from ( visited, tcx)
256
256
}
257
257
}
258
258
TyRef ( _, ref tm) => tm. ty . uninhabited_from ( visited, tcx) ,
259
259
260
- _ => DefIdForrest :: empty ( ) ,
260
+ _ => DefIdForest :: empty ( ) ,
261
261
}
262
262
}
263
263
}
0 commit comments