11use crate :: hir:: map:: DefPathData ;
22use crate :: hir:: def_id:: { CrateNum , DefId } ;
33use crate :: ty:: { self , DefIdTree , Ty , TyCtxt } ;
4- use crate :: ty:: subst:: { Subst , SubstsRef } ;
4+ use crate :: ty:: subst:: { Kind , Subst , SubstsRef } ;
55
66use rustc_data_structures:: fx:: FxHashSet ;
77
@@ -129,7 +129,7 @@ pub trait Printer: Sized {
129129 ) -> Result < Self :: Path , Self :: Error > ;
130130}
131131
132- impl < P : Printer > PrintCx < ' a , ' gcx , ' tcx , P > {
132+ impl < P : Printer > PrintCx < ' _ , ' gcx , ' tcx , P > {
133133 pub fn default_print_def_path (
134134 self ,
135135 def_id : DefId ,
@@ -197,8 +197,7 @@ impl<P: Printer> PrintCx<'a, 'gcx, 'tcx, P> {
197197 } ;
198198
199199 if let ( Some ( generics) , Some ( substs) ) = ( generics, substs) {
200- let has_own_self = generics. has_self && generics. parent_count == 0 ;
201- let params = & generics. params [ has_own_self as usize ..] ;
200+ let params = self . generic_params_to_print ( generics, substs) ;
202201 self . path_generic_args ( print_path, params, substs, projections)
203202 } else {
204203 print_path ( self )
@@ -207,6 +206,30 @@ impl<P: Printer> PrintCx<'a, 'gcx, 'tcx, P> {
207206 }
208207 }
209208
209+ pub fn generic_params_to_print (
210+ & self ,
211+ generics : & ' a ty:: Generics ,
212+ substs : SubstsRef < ' tcx > ,
213+ ) -> & ' a [ ty:: GenericParamDef ] {
214+ // Don't print args for `Self` parameters (of traits).
215+ let has_own_self = generics. has_self && generics. parent_count == 0 ;
216+ let params = & generics. params [ has_own_self as usize ..] ;
217+
218+ // Don't print args that are the defaults of their respective parameters.
219+ let num_supplied_defaults = params. iter ( ) . rev ( ) . take_while ( |param| {
220+ match param. kind {
221+ ty:: GenericParamDefKind :: Lifetime => false ,
222+ ty:: GenericParamDefKind :: Type { has_default, .. } => {
223+ has_default && substs[ param. index as usize ] == Kind :: from (
224+ self . tcx . type_of ( param. def_id ) . subst ( self . tcx , substs)
225+ )
226+ }
227+ ty:: GenericParamDefKind :: Const => false , // FIXME(const_generics:defaults)
228+ }
229+ } ) . count ( ) ;
230+ & params[ ..params. len ( ) - num_supplied_defaults]
231+ }
232+
210233 fn default_print_impl_path (
211234 self ,
212235 impl_def_id : DefId ,
0 commit comments