@@ -30,7 +30,8 @@ use abi::Abi;
3030use common:: CodegenCx ;
3131use builder:: Builder ;
3232use monomorphize:: Instance ;
33- use rustc:: ty:: { self , ParamEnv , Ty } ;
33+ use rustc:: ty:: { self , TyCtxt , ParamEnv , Ty , TypeFoldable } ;
34+ use rustc:: ty:: fold:: TypeFolder ;
3435use rustc:: mir;
3536use rustc:: session:: config:: { self , FullDebugInfo , LimitedDebugInfo , NoDebugInfo } ;
3637use rustc:: util:: nodemap:: { DefIdMap , FxHashMap , FxHashSet } ;
@@ -201,13 +202,30 @@ pub fn finalize(cx: &CodegenCx) {
201202/// for debug info creation. The function may also return another variant of the
202203/// FunctionDebugContext enum which indicates why no debuginfo should be created
203204/// for the function.
204- pub fn create_function_debug_context < ' a , ' tcx > ( cx : & CodegenCx < ' a , ' tcx > ,
205+ pub fn create_function_debug_context < ' a , ' tcx > ( cx : & ' a CodegenCx < ' a , ' tcx > ,
205206 instance : Instance < ' tcx > ,
206207 sig : ty:: FnSig < ' tcx > ,
207208 llfn : ValueRef ,
208- mir : & mir:: Mir ) -> FunctionDebugContext {
209- let has_unused_subst = true ; // FIXME: make it work with TyUnusedSubst
210- if cx. sess ( ) . opts . debuginfo == NoDebugInfo || has_unused_subst {
209+ mir : & ' a mir:: Mir < ' tcx > ) -> FunctionDebugContext {
210+ struct UnusedParamVisitor < ' a , ' gcx : ' a + ' tcx , ' tcx : ' a > ( TyCtxt < ' a , ' gcx , ' tcx > , bool ) ;
211+ impl < ' a , ' gcx : ' a + ' tcx , ' tcx : ' a > TypeFolder < ' gcx , ' tcx > for UnusedParamVisitor < ' a , ' gcx , ' tcx > {
212+ fn tcx < ' b > ( & ' b self ) -> TyCtxt < ' b , ' gcx , ' tcx > {
213+ self . 0
214+ }
215+ fn fold_ty ( & mut self , ty : Ty < ' tcx > ) -> Ty < ' tcx > {
216+ match ty. sty {
217+ ty:: TyUnusedParam => {
218+ self . 1 = true ;
219+ }
220+ _ => { }
221+ }
222+ ty. super_fold_with ( self )
223+ }
224+ }
225+ let mut has_unused_param_visitor = UnusedParamVisitor ( cx. tcx , false ) ;
226+ mir. fold_with ( & mut has_unused_param_visitor) ;
227+
228+ if cx. sess ( ) . opts . debuginfo == NoDebugInfo || has_unused_param_visitor. 1 {
211229 return FunctionDebugContext :: DebugInfoDisabled ;
212230 }
213231
0 commit comments