@@ -15,6 +15,7 @@ use rustc_middle::ty::{
1515 self ,
1616 fold:: { TypeFoldable , TypeVisitor } ,
1717 query:: Providers ,
18+ subst:: SubstsRef ,
1819 Const , Ty , TyCtxt ,
1920} ;
2021use rustc_span:: symbol:: sym;
@@ -205,6 +206,25 @@ struct UsedGenericParametersVisitor<'a, 'tcx> {
205206 unused_parameters : & ' a mut FiniteBitSet < u32 > ,
206207}
207208
209+ impl < ' a , ' tcx > UsedGenericParametersVisitor < ' a , ' tcx > {
210+ /// Invoke `unused_generic_params` on a body contained within the current item (e.g.
211+ /// a closure, generator or constant).
212+ fn visit_child_body ( & mut self , def_id : DefId , substs : SubstsRef < ' tcx > ) {
213+ let unused = self . tcx . unused_generic_params ( def_id) ;
214+ debug ! (
215+ "visit_child_body: unused_parameters={:?} unused={:?}" ,
216+ self . unused_parameters, unused
217+ ) ;
218+ for ( i, arg) in substs. iter ( ) . enumerate ( ) {
219+ let i = i. try_into ( ) . unwrap ( ) ;
220+ if !unused. contains ( i) . unwrap_or ( false ) {
221+ arg. visit_with ( self ) ;
222+ }
223+ }
224+ debug ! ( "visit_child_body: unused_parameters={:?}" , self . unused_parameters) ;
225+ }
226+ }
227+
208228impl < ' a , ' tcx > Visitor < ' tcx > for UsedGenericParametersVisitor < ' a , ' tcx > {
209229 fn visit_local_decl ( & mut self , local : Local , local_decl : & LocalDecl < ' tcx > ) {
210230 debug ! ( "visit_local_decl: local_decl={:?}" , local_decl) ;
@@ -252,6 +272,10 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for UsedGenericParametersVisitor<'a, 'tcx> {
252272 self . visit_body ( & promoted[ p] ) ;
253273 false
254274 }
275+ ty:: ConstKind :: Unevaluated ( def_id, unevaluated_substs, None ) => {
276+ self . visit_child_body ( def_id. did , unevaluated_substs) ;
277+ false
278+ }
255279 _ => c. super_visit_with ( self ) ,
256280 }
257281 }
@@ -272,19 +296,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for UsedGenericParametersVisitor<'a, 'tcx> {
272296
273297 // Consider any generic parameters used by any closures/generators as used in the
274298 // parent.
275- let unused = self . tcx . unused_generic_params ( def_id) ;
276- debug ! (
277- "visit_ty: unused_parameters={:?} unused={:?}" ,
278- self . unused_parameters, unused
279- ) ;
280- for ( i, arg) in substs. iter ( ) . enumerate ( ) {
281- let i = i. try_into ( ) . unwrap ( ) ;
282- if !unused. contains ( i) . unwrap_or ( false ) {
283- arg. visit_with ( self ) ;
284- }
285- }
286- debug ! ( "visit_ty: unused_parameters={:?}" , self . unused_parameters) ;
287-
299+ self . visit_child_body ( def_id, substs) ;
288300 false
289301 }
290302 ty:: Param ( param) => {
0 commit comments