@@ -839,19 +839,25 @@ pub trait PrettyPrinter<'tcx>:
839839 p ! ( print( ty) ) ;
840840 }
841841
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 { "" } ) ) ;
843847
844848 first = false ;
845849 }
846850 // If we got here, we can't print as a `impl Fn(A, B) -> C`. Just record the
847851 // trait_refs we collected in the OpaqueFnEntry as normal trait refs.
848852 _ => {
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+ }
855861 if let Some ( trait_ref) = entry. fn_mut_trait_ref {
856862 traits. entry ( trait_ref) . or_default ( ) ;
857863 }
@@ -943,6 +949,7 @@ pub trait PrettyPrinter<'tcx>:
943949 if let Some ( ( _, ty) ) = proj_ty {
944950 entry. return_ty = Some ( ty) ;
945951 }
952+ entry. has_fn_once = true ;
946953 return ;
947954 } else if Some ( trait_def_id) == self . tcx ( ) . lang_items ( ) . fn_mut_trait ( ) {
948955 let super_trait_ref = crate :: traits:: util:: supertraits ( self . tcx ( ) , trait_ref)
@@ -2695,6 +2702,8 @@ pub fn provide(providers: &mut ty::query::Providers) {
26952702
26962703#[ derive( Default ) ]
26972704pub 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 ,
26982707 fn_mut_trait_ref : Option < ty:: PolyTraitRef < ' tcx > > ,
26992708 fn_trait_ref : Option < ty:: PolyTraitRef < ' tcx > > ,
27002709 return_ty : Option < ty:: Binder < ' tcx , Ty < ' tcx > > > ,
0 commit comments