@@ -30,7 +30,8 @@ use abi::Abi;
30
30
use common:: CodegenCx ;
31
31
use builder:: Builder ;
32
32
use monomorphize:: Instance ;
33
- use rustc:: ty:: { self , ParamEnv , Ty } ;
33
+ use rustc:: ty:: { self , TyCtxt , ParamEnv , Ty , TypeFoldable } ;
34
+ use rustc:: ty:: fold:: TypeFolder ;
34
35
use rustc:: mir;
35
36
use rustc:: session:: config:: { self , FullDebugInfo , LimitedDebugInfo , NoDebugInfo } ;
36
37
use rustc:: util:: nodemap:: { DefIdMap , FxHashMap , FxHashSet } ;
@@ -201,13 +202,30 @@ pub fn finalize(cx: &CodegenCx) {
201
202
/// for debug info creation. The function may also return another variant of the
202
203
/// FunctionDebugContext enum which indicates why no debuginfo should be created
203
204
/// 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 > ,
205
206
instance : Instance < ' tcx > ,
206
207
sig : ty:: FnSig < ' tcx > ,
207
208
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 {
211
229
return FunctionDebugContext :: DebugInfoDisabled ;
212
230
}
213
231
0 commit comments