@@ -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
@@ -586,7 +557,30 @@ impl<P: PrettyPrinter> PrintCx<'a, 'gcx, 'tcx, P> {
586
557
& mut self ,
587
558
self_ty : Ty < ' tcx > ,
588
559
trait_ref : Option < ty:: TraitRef < ' tcx > > ,
560
+ ns : Namespace ,
589
561
) -> P :: Path {
562
+ if trait_ref. is_none ( ) {
563
+ // Inherent impls. Try to print `Foo::bar` for an inherent
564
+ // impl on `Foo`, but fallback to `<Foo>::bar` if self-type is
565
+ // anything other than a simple path.
566
+ match self_ty. sty {
567
+ ty:: Adt ( adt_def, substs) => {
568
+ return self . print_def_path ( adt_def. did , Some ( substs) , ns, iter:: empty ( ) ) ;
569
+ }
570
+ ty:: Foreign ( did) => {
571
+ return self . print_def_path ( did, None , ns, iter:: empty ( ) ) ;
572
+ }
573
+
574
+ ty:: Bool | ty:: Char | ty:: Str |
575
+ ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) => {
576
+ self_ty. print_display ( self ) ?;
577
+ return Ok ( PrettyPath { empty : false } ) ;
578
+ }
579
+
580
+ _ => { }
581
+ }
582
+ }
583
+
590
584
write ! ( self . printer, "<" ) ?;
591
585
self_ty. print_display ( self ) ?;
592
586
if let Some ( trait_ref) = trait_ref {
@@ -775,12 +769,9 @@ impl<F: fmt::Write> Printer for FmtPrinter<F> {
775
769
self : & mut PrintCx < ' _ , ' _ , ' tcx , Self > ,
776
770
self_ty : Ty < ' tcx > ,
777
771
trait_ref : Option < ty:: TraitRef < ' tcx > > ,
772
+ ns : Namespace ,
778
773
) -> Self :: Path {
779
- self . pretty_path_qualified ( self_ty, trait_ref)
780
- }
781
- fn path_impl ( self : & mut PrintCx < ' _ , ' _ , ' _ , Self > , text : & str ) -> Self :: Path {
782
- write ! ( self . printer, "{}" , text) ?;
783
- Ok ( PrettyPath { empty : false } )
774
+ self . pretty_path_qualified ( self_ty, trait_ref, ns)
784
775
}
785
776
fn path_append (
786
777
self : & mut PrintCx < ' _ , ' _ , ' _ , Self > ,
0 commit comments