@@ -20,6 +20,7 @@ use rustc_middle::ty::{
20
20
} ;
21
21
use rustc_span:: symbol:: sym;
22
22
use std:: convert:: TryInto ;
23
+ use std:: ops:: ControlFlow ;
23
24
24
25
/// Provide implementations of queries relating to polymorphization analysis.
25
26
pub fn provide ( providers : & mut Providers ) {
@@ -138,7 +139,7 @@ fn mark_used_by_predicates<'tcx>(
138
139
// predicate is used.
139
140
let any_param_used = {
140
141
let mut vis = HasUsedGenericParams { unused_parameters } ;
141
- predicate. visit_with ( & mut vis)
142
+ predicate. visit_with ( & mut vis) == ControlFlow :: BREAK
142
143
} ;
143
144
144
145
if any_param_used {
@@ -249,17 +250,17 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
249
250
}
250
251
251
252
impl < ' a , ' tcx > TypeVisitor < ' tcx > for MarkUsedGenericParams < ' a , ' tcx > {
252
- fn visit_const ( & mut self , c : & ' tcx Const < ' tcx > ) -> bool {
253
+ fn visit_const ( & mut self , c : & ' tcx Const < ' tcx > ) -> ControlFlow < ( ) , ( ) > {
253
254
debug ! ( "visit_const: c={:?}" , c) ;
254
255
if !c. has_param_types_or_consts ( ) {
255
- return false ;
256
+ return ControlFlow :: CONTINUE ;
256
257
}
257
258
258
259
match c. val {
259
260
ty:: ConstKind :: Param ( param) => {
260
261
debug ! ( "visit_const: param={:?}" , param) ;
261
262
self . unused_parameters . clear ( param. index ) ;
262
- false
263
+ ControlFlow :: CONTINUE
263
264
}
264
265
ty:: ConstKind :: Unevaluated ( def, _, Some ( p) )
265
266
// Avoid considering `T` unused when constants are of the form:
@@ -270,41 +271,41 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
270
271
// the generic parameters, instead, traverse the promoted MIR.
271
272
let promoted = self . tcx . promoted_mir ( def. did ) ;
272
273
self . visit_body ( & promoted[ p] ) ;
273
- false
274
+ ControlFlow :: CONTINUE
274
275
}
275
276
ty:: ConstKind :: Unevaluated ( def, unevaluated_substs, None )
276
277
if self . tcx . def_kind ( def. did ) == DefKind :: AnonConst =>
277
278
{
278
279
self . visit_child_body ( def. did , unevaluated_substs) ;
279
- false
280
+ ControlFlow :: CONTINUE
280
281
}
281
282
_ => c. super_visit_with ( self ) ,
282
283
}
283
284
}
284
285
285
- fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> bool {
286
+ fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> ControlFlow < ( ) , ( ) > {
286
287
debug ! ( "visit_ty: ty={:?}" , ty) ;
287
288
if !ty. has_param_types_or_consts ( ) {
288
- return false ;
289
+ return ControlFlow :: CONTINUE ;
289
290
}
290
291
291
292
match * ty. kind ( ) {
292
293
ty:: Closure ( def_id, substs) | ty:: Generator ( def_id, substs, ..) => {
293
294
debug ! ( "visit_ty: def_id={:?}" , def_id) ;
294
295
// Avoid cycle errors with generators.
295
296
if def_id == self . def_id {
296
- return false ;
297
+ return ControlFlow :: CONTINUE ;
297
298
}
298
299
299
300
// Consider any generic parameters used by any closures/generators as used in the
300
301
// parent.
301
302
self . visit_child_body ( def_id, substs) ;
302
- false
303
+ ControlFlow :: CONTINUE
303
304
}
304
305
ty:: Param ( param) => {
305
306
debug ! ( "visit_ty: param={:?}" , param) ;
306
307
self . unused_parameters . clear ( param. index ) ;
307
- false
308
+ ControlFlow :: CONTINUE
308
309
}
309
310
_ => ty. super_visit_with ( self ) ,
310
311
}
@@ -317,28 +318,38 @@ struct HasUsedGenericParams<'a> {
317
318
}
318
319
319
320
impl < ' a , ' tcx > TypeVisitor < ' tcx > for HasUsedGenericParams < ' a > {
320
- fn visit_const ( & mut self , c : & ' tcx Const < ' tcx > ) -> bool {
321
+ fn visit_const ( & mut self , c : & ' tcx Const < ' tcx > ) -> ControlFlow < ( ) , ( ) > {
321
322
debug ! ( "visit_const: c={:?}" , c) ;
322
323
if !c. has_param_types_or_consts ( ) {
323
- return false ;
324
+ return ControlFlow :: CONTINUE ;
324
325
}
325
326
326
327
match c. val {
327
328
ty:: ConstKind :: Param ( param) => {
328
- !self . unused_parameters . contains ( param. index ) . unwrap_or ( false )
329
+ if self . unused_parameters . contains ( param. index ) . unwrap_or ( false ) {
330
+ ControlFlow :: CONTINUE
331
+ } else {
332
+ ControlFlow :: BREAK
333
+ }
329
334
}
330
335
_ => c. super_visit_with ( self ) ,
331
336
}
332
337
}
333
338
334
- fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> bool {
339
+ fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> ControlFlow < ( ) , ( ) > {
335
340
debug ! ( "visit_ty: ty={:?}" , ty) ;
336
341
if !ty. has_param_types_or_consts ( ) {
337
- return false ;
342
+ return ControlFlow :: CONTINUE ;
338
343
}
339
344
340
345
match ty. kind ( ) {
341
- ty:: Param ( param) => !self . unused_parameters . contains ( param. index ) . unwrap_or ( false ) ,
346
+ ty:: Param ( param) => {
347
+ if self . unused_parameters . contains ( param. index ) . unwrap_or ( false ) {
348
+ ControlFlow :: CONTINUE
349
+ } else {
350
+ ControlFlow :: BREAK
351
+ }
352
+ }
342
353
_ => ty. super_visit_with ( self ) ,
343
354
}
344
355
}
0 commit comments