@@ -67,10 +67,8 @@ use rustc_hir::{Item, ItemKind, Node};
6767use rustc_middle:: dep_graph:: DepContext ;
6868use rustc_middle:: ty:: print:: with_no_trimmed_paths;
6969use rustc_middle:: ty:: {
70- self ,
71- error:: TypeError ,
72- subst:: { GenericArgKind , Subst , SubstsRef } ,
73- Binder , EarlyBinder , List , Region , Ty , TyCtxt , TypeFoldable , TypeSuperFoldable ,
70+ self , error:: TypeError , Binder , List , Region , Subst , Ty , TyCtxt , TypeFoldable ,
71+ TypeSuperFoldable ,
7472} ;
7573use rustc_span:: { sym, symbol:: kw, BytePos , DesugaringKind , Pos , Span } ;
7674use rustc_target:: spec:: abi;
@@ -926,10 +924,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
926924 mut t1_out : & mut DiagnosticStyledString ,
927925 mut t2_out : & mut DiagnosticStyledString ,
928926 path : String ,
929- sub : ty:: subst :: SubstsRef < ' tcx > ,
927+ sub : & ' tcx [ ty:: GenericArg < ' tcx > ] ,
930928 other_path : String ,
931929 other_ty : Ty < ' tcx > ,
932930 ) -> Option < ( ) > {
931+ // FIXME/HACK: Go back to `SubstsRef` to use its inherent methods,
932+ // ideally that shouldn't be necessary.
933+ let sub = self . tcx . intern_substs ( sub) ;
933934 for ( i, ta) in sub. types ( ) . enumerate ( ) {
934935 if ta == other_ty {
935936 self . highlight_outer ( & mut t1_out, & mut t2_out, path, sub, i, other_ty) ;
@@ -960,45 +961,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
960961 }
961962 }
962963
963- /// For generic types with parameters with defaults, remove the parameters corresponding to
964- /// the defaults. This repeats a lot of the logic found in `ty::print::pretty`.
965- fn strip_generic_default_params (
966- & self ,
967- def_id : DefId ,
968- substs : ty:: subst:: SubstsRef < ' tcx > ,
969- ) -> SubstsRef < ' tcx > {
970- let generics = self . tcx . generics_of ( def_id) ;
971- let mut num_supplied_defaults = 0 ;
972-
973- let default_params = generics. params . iter ( ) . rev ( ) . filter_map ( |param| match param. kind {
974- ty:: GenericParamDefKind :: Type { has_default : true , .. } => Some ( param. def_id ) ,
975- ty:: GenericParamDefKind :: Const { has_default : true } => Some ( param. def_id ) ,
976- _ => None ,
977- } ) ;
978- for ( def_id, actual) in iter:: zip ( default_params, substs. iter ( ) . rev ( ) ) {
979- match actual. unpack ( ) {
980- GenericArgKind :: Const ( c) => {
981- if EarlyBinder ( self . tcx . const_param_default ( def_id) ) . subst ( self . tcx , substs)
982- != c
983- {
984- break ;
985- }
986- }
987- GenericArgKind :: Type ( ty) => {
988- if self . tcx . bound_type_of ( def_id) . subst ( self . tcx , substs) != ty {
989- break ;
990- }
991- }
992- _ => break ,
993- }
994- num_supplied_defaults += 1 ;
995- }
996- let len = generics. params . len ( ) ;
997- let mut generics = generics. clone ( ) ;
998- generics. params . truncate ( len - num_supplied_defaults) ;
999- substs. truncate_to ( self . tcx , & generics)
1000- }
1001-
1002964 /// Given two `fn` signatures highlight only sub-parts that are different.
1003965 fn cmp_fn_sig (
1004966 & self ,
@@ -1156,8 +1118,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11561118 ( & ty:: Adt ( def1, sub1) , & ty:: Adt ( def2, sub2) ) => {
11571119 let did1 = def1. did ( ) ;
11581120 let did2 = def2. did ( ) ;
1159- let sub_no_defaults_1 = self . strip_generic_default_params ( did1, sub1) ;
1160- let sub_no_defaults_2 = self . strip_generic_default_params ( did2, sub2) ;
1121+ let sub_no_defaults_1 =
1122+ self . tcx . generics_of ( did1) . own_substs_no_defaults ( self . tcx , sub1) ;
1123+ let sub_no_defaults_2 =
1124+ self . tcx . generics_of ( did2) . own_substs_no_defaults ( self . tcx , sub2) ;
11611125 let mut values = ( DiagnosticStyledString :: new ( ) , DiagnosticStyledString :: new ( ) ) ;
11621126 let path1 = self . tcx . def_path_str ( did1) ;
11631127 let path2 = self . tcx . def_path_str ( did2) ;
0 commit comments