@@ -839,19 +839,25 @@ pub trait PrettyPrinter<'tcx>:
839
839
p ! ( print( ty) ) ;
840
840
}
841
841
842
- p ! ( ") -> " , print( return_ty) , write( "{}" , if paren_needed { ")" } else { "" } ) ) ;
842
+ p ! ( ")" ) ;
843
+ if !return_ty. skip_binder ( ) . is_unit ( ) {
844
+ p ! ( "-> " , print( return_ty) ) ;
845
+ }
846
+ p ! ( write( "{}" , if paren_needed { ")" } else { "" } ) ) ;
843
847
844
848
first = false ;
845
849
}
846
850
// If we got here, we can't print as a `impl Fn(A, B) -> C`. Just record the
847
851
// trait_refs we collected in the OpaqueFnEntry as normal trait refs.
848
852
_ => {
849
- traits. entry ( fn_once_trait_ref) . or_default ( ) . extend (
850
- // Group the return ty with its def id, if we had one.
851
- entry
852
- . return_ty
853
- . map ( |ty| ( self . tcx ( ) . lang_items ( ) . fn_once_output ( ) . unwrap ( ) , ty) ) ,
854
- ) ;
853
+ if entry. has_fn_once {
854
+ traits. entry ( fn_once_trait_ref) . or_default ( ) . extend (
855
+ // Group the return ty with its def id, if we had one.
856
+ entry
857
+ . return_ty
858
+ . map ( |ty| ( self . tcx ( ) . lang_items ( ) . fn_once_output ( ) . unwrap ( ) , ty) ) ,
859
+ ) ;
860
+ }
855
861
if let Some ( trait_ref) = entry. fn_mut_trait_ref {
856
862
traits. entry ( trait_ref) . or_default ( ) ;
857
863
}
@@ -943,6 +949,7 @@ pub trait PrettyPrinter<'tcx>:
943
949
if let Some ( ( _, ty) ) = proj_ty {
944
950
entry. return_ty = Some ( ty) ;
945
951
}
952
+ entry. has_fn_once = true ;
946
953
return ;
947
954
} else if Some ( trait_def_id) == self . tcx ( ) . lang_items ( ) . fn_mut_trait ( ) {
948
955
let super_trait_ref = crate :: traits:: util:: supertraits ( self . tcx ( ) , trait_ref)
@@ -2695,6 +2702,8 @@ pub fn provide(providers: &mut ty::query::Providers) {
2695
2702
2696
2703
#[ derive( Default ) ]
2697
2704
pub struct OpaqueFnEntry < ' tcx > {
2705
+ // The trait ref is already stored as a key, so just track if we have it as a real predicate
2706
+ has_fn_once : bool ,
2698
2707
fn_mut_trait_ref : Option < ty:: PolyTraitRef < ' tcx > > ,
2699
2708
fn_trait_ref : Option < ty:: PolyTraitRef < ' tcx > > ,
2700
2709
return_ty : Option < ty:: Binder < ' tcx , Ty < ' tcx > > > ,
0 commit comments