@@ -173,10 +173,9 @@ pub trait Printer: Sized {
173
173
self : & mut PrintCx < ' _ , ' _ , ' tcx , Self > ,
174
174
self_ty : Ty < ' tcx > ,
175
175
trait_ref : Option < ty:: TraitRef < ' tcx > > ,
176
+ ns : Namespace ,
176
177
) -> Self :: Path ;
177
178
#[ must_use]
178
- fn path_impl ( self : & mut PrintCx < ' _ , ' _ , ' _ , Self > , text : & str ) -> Self :: Path ;
179
- #[ must_use]
180
179
fn path_append (
181
180
self : & mut PrintCx < ' _ , ' _ , ' _ , Self > ,
182
181
path : Self :: Path ,
@@ -291,7 +290,7 @@ impl<P: Printer> PrintCx<'a, 'gcx, 'tcx, P> {
291
290
parent_generics. has_self && parent_generics. parent_count == 0 ;
292
291
if let ( Some ( substs) , true ) = ( substs, parent_has_own_self) {
293
292
let trait_ref = ty:: TraitRef :: new ( parent_def_id, substs) ;
294
- self . path_qualified ( trait_ref. self_ty ( ) , Some ( trait_ref) )
293
+ self . path_qualified ( trait_ref. self_ty ( ) , Some ( trait_ref) , ns )
295
294
} else {
296
295
self . print_def_path ( parent_def_id, substs, ns, iter:: empty ( ) )
297
296
}
@@ -367,35 +366,7 @@ impl<P: Printer> PrintCx<'a, 'gcx, 'tcx, P> {
367
366
368
367
// Otherwise, try to give a good form that would be valid language
369
368
// syntax. Preferably using associated item notation.
370
-
371
- if let Some ( trait_ref) = impl_trait_ref {
372
- // Trait impls.
373
- return self . path_qualified ( self_ty, Some ( trait_ref) ) ;
374
- }
375
-
376
- // Inherent impls. Try to print `Foo::bar` for an inherent
377
- // impl on `Foo`, but fallback to `<Foo>::bar` if self-type is
378
- // anything other than a simple path.
379
- match self_ty. sty {
380
- ty:: Adt ( adt_def, substs) => {
381
- self . print_def_path ( adt_def. did , Some ( substs) , ns, iter:: empty ( ) )
382
- }
383
-
384
- ty:: Foreign ( did) => self . print_def_path ( did, None , ns, iter:: empty ( ) ) ,
385
-
386
- ty:: Bool |
387
- ty:: Char |
388
- ty:: Int ( _) |
389
- ty:: Uint ( _) |
390
- ty:: Float ( _) |
391
- ty:: Str => {
392
- self . path_impl ( & self_ty. to_string ( ) )
393
- }
394
-
395
- _ => {
396
- self . path_qualified ( self_ty, None )
397
- }
398
- }
369
+ self . path_qualified ( self_ty, impl_trait_ref, ns)
399
370
}
400
371
}
401
372
@@ -587,7 +558,30 @@ impl<P: PrettyPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
587
558
& mut self ,
588
559
self_ty : Ty < ' tcx > ,
589
560
trait_ref : Option < ty:: TraitRef < ' tcx > > ,
561
+ ns : Namespace ,
590
562
) -> P :: Path {
563
+ if trait_ref. is_none ( ) {
564
+ // Inherent impls. Try to print `Foo::bar` for an inherent
565
+ // impl on `Foo`, but fallback to `<Foo>::bar` if self-type is
566
+ // anything other than a simple path.
567
+ match self_ty. sty {
568
+ ty:: Adt ( adt_def, substs) => {
569
+ return self . print_def_path ( adt_def. did , Some ( substs) , ns, iter:: empty ( ) ) ;
570
+ }
571
+ ty:: Foreign ( did) => {
572
+ return self . print_def_path ( did, None , ns, iter:: empty ( ) ) ;
573
+ }
574
+
575
+ ty:: Bool | ty:: Char | ty:: Str |
576
+ ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) => {
577
+ self_ty. print_display ( self ) ?;
578
+ return Ok ( PrettyPath { empty : false } ) ;
579
+ }
580
+
581
+ _ => { }
582
+ }
583
+ }
584
+
591
585
write ! ( self . printer, "<" ) ?;
592
586
self_ty. print_display ( self ) ?;
593
587
if let Some ( trait_ref) = trait_ref {
@@ -781,12 +775,9 @@ impl<F: fmt::Write> Printer for FmtPrinter<F> {
781
775
self : & mut PrintCx < ' _ , ' _ , ' tcx , Self > ,
782
776
self_ty : Ty < ' tcx > ,
783
777
trait_ref : Option < ty:: TraitRef < ' tcx > > ,
778
+ ns : Namespace ,
784
779
) -> Self :: Path {
785
- self . pretty_path_qualified ( self_ty, trait_ref)
786
- }
787
- fn path_impl ( self : & mut PrintCx < ' _ , ' _ , ' _ , Self > , text : & str ) -> Self :: Path {
788
- write ! ( self . printer, "{}" , text) ?;
789
- Ok ( PrettyPath { empty : false } )
780
+ self . pretty_path_qualified ( self_ty, trait_ref, ns)
790
781
}
791
782
fn path_append (
792
783
self : & mut PrintCx < ' _ , ' _ , ' _ , Self > ,
0 commit comments