Skip to content

Commit f32a666

Browse files
nikomatsakiscramertj
authored andcommitted
Improve debugging output of impl trait
1 parent 1152abd commit f32a666

File tree

5 files changed

+36
-3
lines changed

5 files changed

+36
-3
lines changed

src/librustc/middle/resolve_lifetime.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ impl Region {
5252
let i = *index;
5353
*index += 1;
5454
let def_id = hir_map.local_def_id(def.lifetime.id);
55+
debug!("Region::early: index={} def_id={:?}", i, def_id);
5556
(def.lifetime.name, Region::EarlyBound(i, def_id))
5657
}
5758

@@ -379,6 +380,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
379380
}
380381

381382
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
383+
debug!("visit_ty: ty={:?}", ty);
382384
match ty.node {
383385
hir::TyBareFn(ref c) => {
384386
let next_early_index = self.next_early_index();
@@ -421,6 +423,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
421423

422424
let hir::ExistTy { ref generics, ref bounds } = *exist_ty;
423425
let mut index = self.next_early_index();
426+
debug!("visit_ty: index = {}", index);
424427
let lifetimes = generics.lifetimes.iter()
425428
.map(|lt_def| Region::early(self.hir_map, &mut index, lt_def))
426429
.collect();
@@ -927,6 +930,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
927930
}
928931

929932
fn resolve_lifetime_ref(&mut self, lifetime_ref: &hir::Lifetime) {
933+
debug!("resolve_lifetime_ref(lifetime_ref={:?})", lifetime_ref);
934+
930935
// Walk up the scope chain, tracking the number of fn scopes
931936
// that we pass through, until we find a lifetime with the
932937
// given name or we run out of scopes.
@@ -1605,7 +1610,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
16051610
probably a bug in syntax::fold");
16061611
}
16071612

1608-
debug!("{} resolved to {:?} span={:?}",
1613+
debug!("insert_lifetime: {} resolved to {:?} span={:?}",
16091614
self.hir_map.node_to_string(lifetime_ref.id),
16101615
def,
16111616
self.sess.codemap().span_to_string(lifetime_ref.span));

src/librustc/util/ppaux.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,10 @@ define_print! {
10151015
TyForeign(def_id) => parameterized(f, subst::Substs::empty(), def_id, &[]),
10161016
TyProjection(ref data) => data.print(f, cx),
10171017
TyAnon(def_id, substs) => {
1018+
if cx.is_verbose {
1019+
return write!(f, "TyAnon({:?}, {:?})", def_id, substs);
1020+
}
1021+
10181022
ty::tls::with(|tcx| {
10191023
// Grab the "TraitA + TraitB" from `impl TraitA + TraitB`,
10201024
// by looking up the projections associated with the def_id.

src/librustc_typeck/astconv.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,10 +1134,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
11341134
}
11351135

11361136
pub fn impl_trait_ty_to_ty(&self, def_id: DefId, lifetimes: &[hir::Lifetime]) -> Ty<'tcx> {
1137+
debug!("impl_trait_ty_to_ty(def_id={:?}, lifetimes={:?})", def_id, lifetimes);
11371138
let tcx = self.tcx();
11381139
let generics = tcx.generics_of(def_id);
11391140

11401141
// Fill in the substs of the parent generics
1142+
debug!("impl_trait_ty_to_ty: generics={:?}", generics);
11411143
let mut substs = Vec::with_capacity(generics.count());
11421144
if let Some(parent_id) = generics.parent {
11431145
let parent_generics = tcx.generics_of(parent_id);
@@ -1154,6 +1156,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
11541156
*subst = Kind::from(&RegionKind::ReStatic);
11551157
}
11561158
}
1159+
debug!("impl_trait_ty_to_ty: substs from parent = {:?}", substs);
11571160
}
11581161
assert_eq!(substs.len(), generics.parent_count());
11591162

@@ -1162,6 +1165,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
11621165
substs.extend(lifetimes.iter().map(|lt|
11631166
Kind::from(self.ast_region_to_region(lt, None))));
11641167

1168+
debug!("impl_trait_ty_to_ty: final substs = {:?}", substs);
1169+
11651170
tcx.mk_anon(def_id, tcx.intern_substs(&substs))
11661171
}
11671172

src/librustc_typeck/check/mod.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1936,8 +1936,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
19361936
/// Replace all anonymized types with fresh inference variables
19371937
/// and record them for writeback.
19381938
fn instantiate_anon_types<T: TypeFoldable<'tcx>>(&self, value: &T) -> T {
1939+
debug!("instantiate_anon_types(value={:?})", value);
19391940
value.fold_with(&mut BottomUpFolder { tcx: self.tcx, fldop: |ty| {
19401941
if let ty::TyAnon(def_id, substs) = ty.sty {
1942+
debug!("instantiate_anon_types: TyAnon(def_id={:?}, substs={:?})", def_id, substs);
1943+
19411944
// Use the same type variable if the exact same TyAnon appears more
19421945
// than once in the return type (e.g. if it's passed to a type alias).
19431946
let id = self.tcx.hir.as_local_node_id(def_id).unwrap();
@@ -1947,8 +1950,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
19471950
let span = self.tcx.def_span(def_id);
19481951
let ty_var = self.next_ty_var(TypeVariableOrigin::TypeInference(span));
19491952
self.anon_types.borrow_mut().insert(id, ty_var);
1953+
debug!("instantiate_anon_types: ty_var={:?}", ty_var);
19501954

19511955
let predicates_of = self.tcx.predicates_of(def_id);
1956+
debug!("instantiate_anon_types: predicates_of={:?}", predicates_of);
19521957
let bounds = predicates_of.instantiate(self.tcx, substs);
19531958

19541959
for predicate in bounds.predicates {
@@ -1958,8 +1963,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
19581963
let predicate = self.instantiate_anon_types(&predicate);
19591964

19601965
// Require that the predicate holds for the concrete type.
1961-
let cause = traits::ObligationCause::new(span, self.body_id,
1966+
let cause = traits::ObligationCause::new(span,
1967+
self.body_id,
19621968
traits::SizedReturnType);
1969+
1970+
debug!("instantiate_anon_types: predicate={:?}", predicate);
19631971
self.register_predicate(traits::Obligation::new(cause,
19641972
self.param_env,
19651973
predicate));

src/librustc_typeck/collect.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,6 +1334,8 @@ fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
13341334
use rustc::hir::map::*;
13351335
use rustc::hir::*;
13361336

1337+
debug!("explicit_predicates_of(def_id={:?})", def_id);
1338+
13371339
let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
13381340
let node = tcx.hir.get(node_id);
13391341

@@ -1381,15 +1383,24 @@ fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
13811383
let substs = Substs::identity_for_item(tcx, def_id);
13821384
let anon_ty = tcx.mk_anon(def_id, substs);
13831385

1386+
debug!("explicit_predicates_of: anon_ty={:?}", anon_ty);
1387+
13841388
// Collect the bounds, i.e. the `A+B+'c` in `impl A+B+'c`.
13851389
let bounds = compute_bounds(&icx,
13861390
anon_ty,
13871391
&exist_ty.bounds,
13881392
SizedByDefault::Yes,
13891393
span);
1394+
1395+
debug!("explicit_predicates_of: bounds={:?}", bounds);
1396+
1397+
let predicates = bounds.predicates(tcx, anon_ty);
1398+
1399+
debug!("explicit_predicates_of: predicates={:?}", predicates);
1400+
13901401
return ty::GenericPredicates {
13911402
parent: None,
1392-
predicates: bounds.predicates(tcx, anon_ty)
1403+
predicates: predicates
13931404
};
13941405
}
13951406

0 commit comments

Comments
 (0)