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