@@ -119,16 +119,6 @@ fn mark_used_by_predicates<'tcx>(
119
119
def_id : DefId ,
120
120
unused_parameters : & mut FiniteBitSet < u32 > ,
121
121
) {
122
- let is_ty_used = |unused_parameters : & FiniteBitSet < u32 > , ty : Ty < ' tcx > | -> bool {
123
- let mut vis = IsUsedGenericParams { unused_parameters } ;
124
- ty. visit_with ( & mut vis)
125
- } ;
126
-
127
- let mark_ty = |unused_parameters : & mut FiniteBitSet < u32 > , ty : Ty < ' tcx > | {
128
- let mut vis = MarkUsedGenericParams { tcx, def_id, unused_parameters } ;
129
- ty. visit_with ( & mut vis) ;
130
- } ;
131
-
132
122
let def_id = tcx. closure_base_def_id ( def_id) ;
133
123
let predicates = tcx. explicit_predicates_of ( def_id) ;
134
124
debug ! ( "mark_used_by_predicates: predicates_of={:?}" , predicates) ;
@@ -144,69 +134,16 @@ fn mark_used_by_predicates<'tcx>(
144
134
current_unused_parameters = * unused_parameters;
145
135
146
136
for ( predicate, _) in predicates. predicates {
147
- match predicate. skip_binders ( ) {
148
- ty:: PredicateAtom :: Trait ( predicate, ..) => {
149
- let trait_ref = predicate. trait_ref ;
150
- debug ! ( "mark_used_by_predicates: (trait) trait_ref={:?}" , trait_ref) ;
151
-
152
- // Consider `T` used if `I` is used in predicates of the form
153
- // `I: Iterator<Item = T>`
154
- debug ! ( "mark_used_by_predicates: checking self" ) ;
155
- if is_ty_used ( unused_parameters, trait_ref. self_ty ( ) ) {
156
- debug ! ( "mark_used_by_predicates: used!" ) ;
157
- for ty in trait_ref. substs . types ( ) {
158
- mark_ty ( unused_parameters, ty) ;
159
- }
160
-
161
- // No need to check for a type being used in the substs if `self_ty` was
162
- // used.
163
- continue ;
164
- }
165
-
166
- // Consider `I` used if `T` is used in predicates of the form
167
- // `I: Iterator<Item = &'a (T, E)>` (see rust-lang/rust#75326)
168
- debug ! ( "mark_used_by_predicates: checking substs" ) ;
169
- for ty in trait_ref. substs . types ( ) {
170
- if is_ty_used ( unused_parameters, ty) {
171
- debug ! ( "mark_used_by_predicates: used!" ) ;
172
- mark_ty ( unused_parameters, trait_ref. self_ty ( ) ) ;
173
- }
174
- }
175
- }
176
- ty:: PredicateAtom :: Projection ( proj, ..) => {
177
- let self_ty = proj. projection_ty . self_ty ( ) ;
178
- debug ! (
179
- "mark_used_by_predicates: (projection) self_ty={:?} proj.ty={:?}" ,
180
- self_ty, proj. ty
181
- ) ;
182
-
183
- // Consider `T` used if `I` is used in predicates of the form
184
- // `<I as Iterator>::Item = T`
185
- debug ! ( "mark_used_by_predicates: checking self" ) ;
186
- if is_ty_used ( unused_parameters, self_ty) {
187
- debug ! ( "mark_used_by_predicates: used!" ) ;
188
- mark_ty ( unused_parameters, proj. ty ) ;
189
-
190
- // No need to check for projection type being used if `self_ty` was used.
191
- continue ;
192
- }
193
-
194
- // Consider `I` used if `T` is used in predicates of the form
195
- // `<I as Iterator>::Item = &'a (T, E)` (see rust-lang/rust#75326)
196
- debug ! ( "mark_used_by_predicates: checking projection ty" ) ;
197
- if is_ty_used ( unused_parameters, proj. ty ) {
198
- debug ! ( "mark_used_by_predicates: used!" ) ;
199
- mark_ty ( unused_parameters, self_ty) ;
200
- }
201
- }
202
- ty:: PredicateAtom :: RegionOutlives ( ..)
203
- | ty:: PredicateAtom :: TypeOutlives ( ..)
204
- | ty:: PredicateAtom :: WellFormed ( ..)
205
- | ty:: PredicateAtom :: ObjectSafe ( ..)
206
- | ty:: PredicateAtom :: ClosureKind ( ..)
207
- | ty:: PredicateAtom :: Subtype ( ..)
208
- | ty:: PredicateAtom :: ConstEvaluatable ( ..)
209
- | ty:: PredicateAtom :: ConstEquate ( ..) => ( ) ,
137
+ // Consider all generic params in a predicate as used if any other parameter in the
138
+ // predicate is used.
139
+ let any_param_used = {
140
+ let mut vis = HasUsedGenericParams { unused_parameters } ;
141
+ predicate. visit_with ( & mut vis)
142
+ } ;
143
+
144
+ if any_param_used {
145
+ let mut vis = MarkUsedGenericParams { tcx, def_id, unused_parameters } ;
146
+ predicate. visit_with ( & mut vis) ;
210
147
}
211
148
}
212
149
}
@@ -375,11 +312,11 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
375
312
}
376
313
377
314
/// Visitor used to check if a generic parameter is used.
378
- struct IsUsedGenericParams < ' a > {
315
+ struct HasUsedGenericParams < ' a > {
379
316
unused_parameters : & ' a FiniteBitSet < u32 > ,
380
317
}
381
318
382
- impl < ' a , ' tcx > TypeVisitor < ' tcx > for IsUsedGenericParams < ' a > {
319
+ impl < ' a , ' tcx > TypeVisitor < ' tcx > for HasUsedGenericParams < ' a > {
383
320
fn visit_const ( & mut self , c : & ' tcx Const < ' tcx > ) -> bool {
384
321
debug ! ( "visit_const: c={:?}" , c) ;
385
322
if !c. has_param_types_or_consts ( ) {
0 commit comments