Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit b4b51d6

Browse files
committedMar 29, 2018
Hopefully partially fix debuginfo
1 parent 5ca4094 commit b4b51d6

File tree

1 file changed

+23
-5
lines changed
  • src/librustc_trans/debuginfo

1 file changed

+23
-5
lines changed
 

‎src/librustc_trans/debuginfo/mod.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ use abi::Abi;
3030
use common::CodegenCx;
3131
use builder::Builder;
3232
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;
3435
use rustc::mir;
3536
use rustc::session::config::{self, FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
3637
use 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

Comments
 (0)
Please sign in to comment.