@@ -20,6 +20,7 @@ use rustc_middle::ty::{
2020} ;
2121use rustc_span:: symbol:: sym;
2222use std:: convert:: TryInto ;
23+ use std:: ops:: ControlFlow ;
2324
2425/// Provide implementations of queries relating to polymorphization analysis.
2526pub fn provide ( providers : & mut Providers ) {
@@ -138,7 +139,7 @@ fn mark_used_by_predicates<'tcx>(
138139 // predicate is used.
139140 let any_param_used = {
140141 let mut vis = HasUsedGenericParams { unused_parameters } ;
141- predicate. visit_with ( & mut vis)
142+ predicate. visit_with ( & mut vis) == ControlFlow :: BREAK
142143 } ;
143144
144145 if any_param_used {
@@ -249,17 +250,17 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
249250}
250251
251252impl < ' 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 < ( ) , ( ) > {
253254 debug ! ( "visit_const: c={:?}" , c) ;
254255 if !c. has_param_types_or_consts ( ) {
255- return false ;
256+ return ControlFlow :: CONTINUE ;
256257 }
257258
258259 match c. val {
259260 ty:: ConstKind :: Param ( param) => {
260261 debug ! ( "visit_const: param={:?}" , param) ;
261262 self . unused_parameters . clear ( param. index ) ;
262- false
263+ ControlFlow :: CONTINUE
263264 }
264265 ty:: ConstKind :: Unevaluated ( def, _, Some ( p) )
265266 // Avoid considering `T` unused when constants are of the form:
@@ -270,41 +271,41 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> {
270271 // the generic parameters, instead, traverse the promoted MIR.
271272 let promoted = self . tcx . promoted_mir ( def. did ) ;
272273 self . visit_body ( & promoted[ p] ) ;
273- false
274+ ControlFlow :: CONTINUE
274275 }
275276 ty:: ConstKind :: Unevaluated ( def, unevaluated_substs, None )
276277 if self . tcx . def_kind ( def. did ) == DefKind :: AnonConst =>
277278 {
278279 self . visit_child_body ( def. did , unevaluated_substs) ;
279- false
280+ ControlFlow :: CONTINUE
280281 }
281282 _ => c. super_visit_with ( self ) ,
282283 }
283284 }
284285
285- fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> bool {
286+ fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> ControlFlow < ( ) , ( ) > {
286287 debug ! ( "visit_ty: ty={:?}" , ty) ;
287288 if !ty. has_param_types_or_consts ( ) {
288- return false ;
289+ return ControlFlow :: CONTINUE ;
289290 }
290291
291292 match * ty. kind ( ) {
292293 ty:: Closure ( def_id, substs) | ty:: Generator ( def_id, substs, ..) => {
293294 debug ! ( "visit_ty: def_id={:?}" , def_id) ;
294295 // Avoid cycle errors with generators.
295296 if def_id == self . def_id {
296- return false ;
297+ return ControlFlow :: CONTINUE ;
297298 }
298299
299300 // Consider any generic parameters used by any closures/generators as used in the
300301 // parent.
301302 self . visit_child_body ( def_id, substs) ;
302- false
303+ ControlFlow :: CONTINUE
303304 }
304305 ty:: Param ( param) => {
305306 debug ! ( "visit_ty: param={:?}" , param) ;
306307 self . unused_parameters . clear ( param. index ) ;
307- false
308+ ControlFlow :: CONTINUE
308309 }
309310 _ => ty. super_visit_with ( self ) ,
310311 }
@@ -317,28 +318,38 @@ struct HasUsedGenericParams<'a> {
317318}
318319
319320impl < ' 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 < ( ) , ( ) > {
321322 debug ! ( "visit_const: c={:?}" , c) ;
322323 if !c. has_param_types_or_consts ( ) {
323- return false ;
324+ return ControlFlow :: CONTINUE ;
324325 }
325326
326327 match c. val {
327328 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+ }
329334 }
330335 _ => c. super_visit_with ( self ) ,
331336 }
332337 }
333338
334- fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> bool {
339+ fn visit_ty ( & mut self , ty : Ty < ' tcx > ) -> ControlFlow < ( ) , ( ) > {
335340 debug ! ( "visit_ty: ty={:?}" , ty) ;
336341 if !ty. has_param_types_or_consts ( ) {
337- return false ;
342+ return ControlFlow :: CONTINUE ;
338343 }
339344
340345 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+ }
342353 _ => ty. super_visit_with ( self ) ,
343354 }
344355 }
0 commit comments