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