@@ -162,8 +162,10 @@ pub trait Printer: Sized {
162
162
impl_def_id : DefId ,
163
163
substs : Option < & ' tcx Substs < ' tcx > > ,
164
164
ns : Namespace ,
165
+ self_ty : Ty < ' tcx > ,
166
+ trait_ref : Option < ty:: TraitRef < ' tcx > > ,
165
167
) -> Self :: Path {
166
- self . default_print_impl_path ( impl_def_id, substs, ns)
168
+ self . default_print_impl_path ( impl_def_id, substs, ns, self_ty , trait_ref )
167
169
}
168
170
169
171
#[ must_use]
@@ -272,7 +274,16 @@ impl<P: Printer> PrintCx<'a, 'gcx, 'tcx, P> {
272
274
}
273
275
274
276
DefPathData :: Impl => {
275
- self . print_impl_path ( def_id, substs, ns)
277
+ let mut self_ty = self . tcx . type_of ( def_id) ;
278
+ if let Some ( substs) = substs {
279
+ self_ty = self_ty. subst ( self . tcx , substs) ;
280
+ }
281
+
282
+ let mut impl_trait_ref = self . tcx . impl_trait_ref ( def_id) ;
283
+ if let Some ( substs) = substs {
284
+ impl_trait_ref = impl_trait_ref. subst ( self . tcx , substs) ;
285
+ }
286
+ self . print_impl_path ( def_id, substs, ns, self_ty, impl_trait_ref)
276
287
}
277
288
278
289
_ => {
@@ -322,30 +333,24 @@ impl<P: Printer> PrintCx<'a, 'gcx, 'tcx, P> {
322
333
fn default_print_impl_path (
323
334
& mut self ,
324
335
impl_def_id : DefId ,
325
- substs : Option < & ' tcx Substs < ' tcx > > ,
336
+ _substs : Option < & ' tcx Substs < ' tcx > > ,
326
337
ns : Namespace ,
338
+ self_ty : Ty < ' tcx > ,
339
+ impl_trait_ref : Option < ty:: TraitRef < ' tcx > > ,
327
340
) -> P :: Path {
328
- debug ! ( "default_print_impl_path: impl_def_id={:?}" , impl_def_id ) ;
329
- let parent_def_id = self . tcx . parent ( impl_def_id) . unwrap ( ) ;
341
+ debug ! ( "default_print_impl_path: impl_def_id={:?}, self_ty={}, impl_trait_ref={:?}" ,
342
+ impl_def_id, self_ty , impl_trait_ref ) ;
330
343
331
344
// Decide whether to print the parent path for the impl.
332
345
// Logically, since impls are global, it's never needed, but
333
346
// users may find it useful. Currently, we omit the parent if
334
347
// the impl is either in the same module as the self-type or
335
348
// as the trait.
336
- let mut self_ty = self . tcx . type_of ( impl_def_id) ;
337
- if let Some ( substs) = substs {
338
- self_ty = self_ty. subst ( self . tcx , substs) ;
339
- }
349
+ let parent_def_id = self . tcx . parent ( impl_def_id) . unwrap ( ) ;
340
350
let in_self_mod = match characteristic_def_id_of_type ( self_ty) {
341
351
None => false ,
342
352
Some ( ty_def_id) => self . tcx . parent ( ty_def_id) == Some ( parent_def_id) ,
343
353
} ;
344
-
345
- let mut impl_trait_ref = self . tcx . impl_trait_ref ( impl_def_id) ;
346
- if let Some ( substs) = substs {
347
- impl_trait_ref = impl_trait_ref. subst ( self . tcx , substs) ;
348
- }
349
354
let in_trait_mod = match impl_trait_ref {
350
355
None => false ,
351
356
Some ( trait_ref) => self . tcx . parent ( trait_ref. def_id ) == Some ( parent_def_id) ,
@@ -696,7 +701,7 @@ impl<F: fmt::Write> Printer for FmtPrinter<F> {
696
701
ns : Namespace ,
697
702
projections : impl Iterator < Item = ty:: ExistentialProjection < ' tcx > > ,
698
703
) -> Self :: Path {
699
- // FIXME(eddyb) avoid querying `tcx.generics_of`
704
+ // FIXME(eddyb) avoid querying `tcx.generics_of` and `tcx.def_key`
700
705
// both here and in `default_print_def_path`.
701
706
let generics = substs. map ( |_| self . tcx . generics_of ( def_id) ) ;
702
707
if // HACK(eddyb) remove the `FORCE_ABSOLUTE` hack by bypassing `FmtPrinter`
@@ -714,35 +719,31 @@ impl<F: fmt::Write> Printer for FmtPrinter<F> {
714
719
}
715
720
}
716
721
717
- self . default_print_def_path ( def_id, substs, ns, projections)
718
- }
719
- fn print_impl_path (
720
- self : & mut PrintCx < ' _ , ' _ , ' tcx , Self > ,
721
- impl_def_id : DefId ,
722
- substs : Option < & ' tcx Substs < ' tcx > > ,
723
- ns : Namespace ,
724
- ) -> Self :: Path {
725
- // Always use types for non-local impls, where types are always
726
- // available, and filename/line-number is mostly uninteresting.
727
- let use_types = // HACK(eddyb) remove the `FORCE_ABSOLUTE` hack by bypassing `FmtPrinter`
728
- FORCE_ABSOLUTE . with ( |force| force. get ( ) ) ||
729
- !impl_def_id. is_local ( ) || {
730
- // Otherwise, use filename/line-number if forced.
731
- let force_no_types = FORCE_IMPL_FILENAME_LINE . with ( |f| f. get ( ) ) ;
732
- !force_no_types
733
- } ;
722
+ let key = self . tcx . def_key ( def_id) ;
723
+ if let DefPathData :: Impl = key. disambiguated_data . data {
724
+ // Always use types for non-local impls, where types are always
725
+ // available, and filename/line-number is mostly uninteresting.
726
+ let use_types =
727
+ // HACK(eddyb) remove the `FORCE_ABSOLUTE` hack by bypassing `FmtPrinter`
728
+ FORCE_ABSOLUTE . with ( |force| force. get ( ) ) ||
729
+ !def_id. is_local ( ) || {
730
+ // Otherwise, use filename/line-number if forced.
731
+ let force_no_types = FORCE_IMPL_FILENAME_LINE . with ( |f| f. get ( ) ) ;
732
+ !force_no_types
733
+ } ;
734
734
735
- if !use_types {
736
- // If no type info is available, fall back to
737
- // pretty printing some span information. This should
738
- // only occur very early in the compiler pipeline.
739
- let parent_def_id = self . tcx . parent ( impl_def_id) . unwrap ( ) ;
740
- let path = self . print_def_path ( parent_def_id, None , ns, iter:: empty ( ) ) ;
741
- let span = self . tcx . def_span ( impl_def_id) ;
742
- return self . path_append ( path, & format ! ( "<impl at {:?}>" , span) ) ;
735
+ if !use_types {
736
+ // If no type info is available, fall back to
737
+ // pretty printing some span information. This should
738
+ // only occur very early in the compiler pipeline.
739
+ let parent_def_id = DefId { index : key. parent . unwrap ( ) , ..def_id } ;
740
+ let path = self . print_def_path ( parent_def_id, None , ns, iter:: empty ( ) ) ;
741
+ let span = self . tcx . def_span ( def_id) ;
742
+ return self . path_append ( path, & format ! ( "<impl at {:?}>" , span) ) ;
743
+ }
743
744
}
744
745
745
- self . default_print_impl_path ( impl_def_id , substs, ns)
746
+ self . default_print_def_path ( def_id , substs, ns, projections )
746
747
}
747
748
748
749
fn path_crate ( self : & mut PrintCx < ' _ , ' _ , ' _ , Self > , cnum : CrateNum ) -> Self :: Path {
0 commit comments