@@ -1075,93 +1075,110 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
10751075 ) -> Option < ( DefIdOrName , Ty < ' tcx > , Vec < Ty < ' tcx > > ) > {
10761076 // Autoderef is useful here because sometimes we box callables, etc.
10771077 let Some ( ( def_id_or_name, output, inputs) ) =
1078- ( self . autoderef_steps ) ( found) . into_iter ( ) . find_map ( |( found, _) | {
1079- match * found. kind ( ) {
1080- ty:: FnPtr ( sig_tys, _) => Some ( (
1081- DefIdOrName :: Name ( "function pointer" ) ,
1082- sig_tys. output ( ) ,
1083- sig_tys. inputs ( ) ,
1084- ) ) ,
1085- ty:: FnDef ( def_id, _) => {
1086- let fn_sig = found. fn_sig ( self . tcx ) ;
1087- Some ( ( DefIdOrName :: DefId ( def_id) , fn_sig. output ( ) , fn_sig. inputs ( ) ) )
1088- }
1089- ty:: Closure ( def_id, args) => {
1090- let fn_sig = args. as_closure ( ) . sig ( ) ;
1091- Some ( (
1092- DefIdOrName :: DefId ( def_id) ,
1093- fn_sig. output ( ) ,
1094- fn_sig. inputs ( ) . map_bound ( |inputs| & inputs[ 1 ..] ) ,
1095- ) )
1096- }
1097- ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, args, .. } ) => {
1098- self . tcx
1099- . item_super_predicates ( def_id)
1100- . instantiate ( self . tcx , args)
1101- . iter ( )
1102- . find_map ( |pred| {
1103- if let ty:: ClauseKind :: Projection ( proj) = pred. kind ( ) . skip_binder ( )
1104- && self . tcx . is_lang_item ( proj. projection_term . def_id , LangItem :: FnOnceOutput )
1105- // args tuple will always be args[1]
1106- && let ty:: Tuple ( args) = proj. projection_term . args . type_at ( 1 ) . kind ( )
1107- {
1108- Some ( (
1109- DefIdOrName :: DefId ( def_id) ,
1110- pred. kind ( ) . rebind ( proj. term . expect_type ( ) ) ,
1111- pred. kind ( ) . rebind ( args. as_slice ( ) ) ,
1112- ) )
1113- } else {
1114- None
1115- }
1116- } )
1117- }
1118- ty:: Dynamic ( data, _, ty:: Dyn ) => {
1119- data. iter ( ) . find_map ( |pred| {
1120- if let ty:: ExistentialPredicate :: Projection ( proj) = pred. skip_binder ( )
1078+ ( self . autoderef_steps ) ( found) . into_iter ( ) . find_map ( |( found, _) | match * found. kind ( ) {
1079+ ty:: FnPtr ( sig_tys, _) => Some ( (
1080+ DefIdOrName :: Name ( "function pointer" ) ,
1081+ sig_tys. output ( ) ,
1082+ sig_tys. inputs ( ) ,
1083+ ) ) ,
1084+ ty:: FnDef ( def_id, _) => {
1085+ let fn_sig = found. fn_sig ( self . tcx ) ;
1086+ Some ( ( DefIdOrName :: DefId ( def_id) , fn_sig. output ( ) , fn_sig. inputs ( ) ) )
1087+ }
1088+ ty:: Closure ( def_id, args) => {
1089+ let fn_sig = args. as_closure ( ) . sig ( ) ;
1090+ Some ( (
1091+ DefIdOrName :: DefId ( def_id) ,
1092+ fn_sig. output ( ) ,
1093+ fn_sig. inputs ( ) . map_bound ( |inputs| inputs[ 0 ] . tuple_fields ( ) . as_slice ( ) ) ,
1094+ ) )
1095+ }
1096+ ty:: CoroutineClosure ( def_id, args) => {
1097+ let sig_parts = args. as_coroutine_closure ( ) . coroutine_closure_sig ( ) ;
1098+ Some ( (
1099+ DefIdOrName :: DefId ( def_id) ,
1100+ sig_parts. map_bound ( |sig| {
1101+ sig. to_coroutine (
1102+ self . tcx ,
1103+ args. as_coroutine_closure ( ) . parent_args ( ) ,
1104+ // Just use infer vars here, since we don't really care
1105+ // what these types are, just that we're returning a coroutine.
1106+ self . next_ty_var ( DUMMY_SP ) ,
1107+ self . tcx . coroutine_for_closure ( def_id) ,
1108+ self . next_ty_var ( DUMMY_SP ) ,
1109+ )
1110+ } ) ,
1111+ sig_parts. map_bound ( |sig| sig. tupled_inputs_ty . tuple_fields ( ) . as_slice ( ) ) ,
1112+ ) )
1113+ }
1114+ ty:: Alias ( ty:: Opaque , ty:: AliasTy { def_id, args, .. } ) => self
1115+ . tcx
1116+ . item_super_predicates ( def_id)
1117+ . instantiate ( self . tcx , args)
1118+ . iter ( )
1119+ . find_map ( |pred| {
1120+ if let ty:: ClauseKind :: Projection ( proj) = pred. kind ( ) . skip_binder ( )
1121+ && self
1122+ . tcx
1123+ . is_lang_item ( proj. projection_term . def_id , LangItem :: FnOnceOutput )
1124+ // args tuple will always be args[1]
1125+ && let ty:: Tuple ( args) = proj. projection_term . args . type_at ( 1 ) . kind ( )
1126+ {
1127+ Some ( (
1128+ DefIdOrName :: DefId ( def_id) ,
1129+ pred. kind ( ) . rebind ( proj. term . expect_type ( ) ) ,
1130+ pred. kind ( ) . rebind ( args. as_slice ( ) ) ,
1131+ ) )
1132+ } else {
1133+ None
1134+ }
1135+ } ) ,
1136+ ty:: Dynamic ( data, _, ty:: Dyn ) => data. iter ( ) . find_map ( |pred| {
1137+ if let ty:: ExistentialPredicate :: Projection ( proj) = pred. skip_binder ( )
11211138 && self . tcx . is_lang_item ( proj. def_id , LangItem :: FnOnceOutput )
11221139 // for existential projection, args are shifted over by 1
11231140 && let ty:: Tuple ( args) = proj. args . type_at ( 0 ) . kind ( )
1124- {
1125- Some ( (
1126- DefIdOrName :: Name ( "trait object" ) ,
1127- pred. rebind ( proj. term . expect_type ( ) ) ,
1128- pred. rebind ( args. as_slice ( ) ) ,
1129- ) )
1130- } else {
1131- None
1132- }
1133- } )
1141+ {
1142+ Some ( (
1143+ DefIdOrName :: Name ( "trait object" ) ,
1144+ pred. rebind ( proj. term . expect_type ( ) ) ,
1145+ pred. rebind ( args. as_slice ( ) ) ,
1146+ ) )
1147+ } else {
1148+ None
11341149 }
1135- ty:: Param ( param) => {
1136- let generics = self . tcx . generics_of ( body_id) ;
1137- let name = if generics. count ( ) > param. index as usize
1138- && let def = generics. param_at ( param. index as usize , self . tcx )
1139- && matches ! ( def. kind, ty:: GenericParamDefKind :: Type { .. } )
1140- && def. name == param. name
1150+ } ) ,
1151+ ty:: Param ( param) => {
1152+ let generics = self . tcx . generics_of ( body_id) ;
1153+ let name = if generics. count ( ) > param. index as usize
1154+ && let def = generics. param_at ( param. index as usize , self . tcx )
1155+ && matches ! ( def. kind, ty:: GenericParamDefKind :: Type { .. } )
1156+ && def. name == param. name
1157+ {
1158+ DefIdOrName :: DefId ( def. def_id )
1159+ } else {
1160+ DefIdOrName :: Name ( "type parameter" )
1161+ } ;
1162+ param_env. caller_bounds ( ) . iter ( ) . find_map ( |pred| {
1163+ if let ty:: ClauseKind :: Projection ( proj) = pred. kind ( ) . skip_binder ( )
1164+ && self
1165+ . tcx
1166+ . is_lang_item ( proj. projection_term . def_id , LangItem :: FnOnceOutput )
1167+ && proj. projection_term . self_ty ( ) == found
1168+ // args tuple will always be args[1]
1169+ && let ty:: Tuple ( args) = proj. projection_term . args . type_at ( 1 ) . kind ( )
11411170 {
1142- DefIdOrName :: DefId ( def. def_id )
1171+ Some ( (
1172+ name,
1173+ pred. kind ( ) . rebind ( proj. term . expect_type ( ) ) ,
1174+ pred. kind ( ) . rebind ( args. as_slice ( ) ) ,
1175+ ) )
11431176 } else {
1144- DefIdOrName :: Name ( "type parameter" )
1145- } ;
1146- param_env. caller_bounds ( ) . iter ( ) . find_map ( |pred| {
1147- if let ty:: ClauseKind :: Projection ( proj) = pred. kind ( ) . skip_binder ( )
1148- && self . tcx . is_lang_item ( proj. projection_term . def_id , LangItem :: FnOnceOutput )
1149- && proj. projection_term . self_ty ( ) == found
1150- // args tuple will always be args[1]
1151- && let ty:: Tuple ( args) = proj. projection_term . args . type_at ( 1 ) . kind ( )
1152- {
1153- Some ( (
1154- name,
1155- pred. kind ( ) . rebind ( proj. term . expect_type ( ) ) ,
1156- pred. kind ( ) . rebind ( args. as_slice ( ) ) ,
1157- ) )
1158- } else {
1159- None
1160- }
1161- } )
1162- }
1163- _ => None ,
1177+ None
1178+ }
1179+ } )
11641180 }
1181+ _ => None ,
11651182 } )
11661183 else {
11671184 return None ;
0 commit comments