@@ -1215,96 +1215,92 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
12151215}
12161216
12171217fn maybe_expand_private_type_alias ( cx : & mut DocContext < ' _ > , path : & hir:: Path < ' _ > ) -> Option < Type > {
1218- let mut alias = None ;
1219- if let Res :: Def ( DefKind :: TyAlias , def_id) = path. res {
1220- // Substitute private type aliases
1221- if let Some ( def_id) = def_id. as_local ( ) {
1222- let hir_id = cx. tcx . hir ( ) . local_def_id_to_hir_id ( def_id) ;
1223- if !cx. cache . access_levels . is_exported ( def_id. to_def_id ( ) ) {
1224- alias = Some ( & cx. tcx . hir ( ) . expect_item ( hir_id) . kind ) ;
1225- }
1226- }
1218+ let Res :: Def ( DefKind :: TyAlias , def_id) = path. res else { return None } ;
1219+ // Substitute private type aliases
1220+ let Some ( def_id) = def_id. as_local ( ) else { return None } ;
1221+ let hir_id = cx. tcx . hir ( ) . local_def_id_to_hir_id ( def_id) ;
1222+ let alias = if !cx. cache . access_levels . is_exported ( def_id. to_def_id ( ) ) {
1223+ & cx. tcx . hir ( ) . expect_item ( hir_id) . kind
1224+ } else {
1225+ return None ;
12271226 } ;
1227+ let hir:: ItemKind :: TyAlias ( ty, generics) = alias else { return None } ;
12281228
1229- if let Some ( & hir:: ItemKind :: TyAlias ( ref ty, ref generics) ) = alias {
1230- let provided_params = & path. segments . last ( ) . expect ( "segments were empty" ) ;
1231- let mut ty_substs = FxHashMap :: default ( ) ;
1232- let mut lt_substs = FxHashMap :: default ( ) ;
1233- let mut ct_substs = FxHashMap :: default ( ) ;
1234- let generic_args = provided_params. args ( ) ;
1235- {
1236- let mut indices: hir:: GenericParamCount = Default :: default ( ) ;
1237- for param in generics. params . iter ( ) {
1238- match param. kind {
1239- hir:: GenericParamKind :: Lifetime { .. } => {
1240- let mut j = 0 ;
1241- let lifetime = generic_args. args . iter ( ) . find_map ( |arg| match arg {
1242- hir:: GenericArg :: Lifetime ( lt) => {
1243- if indices. lifetimes == j {
1244- return Some ( lt) ;
1245- }
1246- j += 1 ;
1247- None
1248- }
1249- _ => None ,
1250- } ) ;
1251- if let Some ( lt) = lifetime. cloned ( ) {
1252- let lt_def_id = cx. tcx . hir ( ) . local_def_id ( param. hir_id ) ;
1253- let cleaned = if !lt. is_elided ( ) {
1254- lt. clean ( cx)
1255- } else {
1256- self :: types:: Lifetime :: elided ( )
1257- } ;
1258- lt_substs. insert ( lt_def_id. to_def_id ( ) , cleaned) ;
1229+ let provided_params = & path. segments . last ( ) . expect ( "segments were empty" ) ;
1230+ let mut ty_substs = FxHashMap :: default ( ) ;
1231+ let mut lt_substs = FxHashMap :: default ( ) ;
1232+ let mut ct_substs = FxHashMap :: default ( ) ;
1233+ let generic_args = provided_params. args ( ) ;
1234+
1235+ let mut indices: hir:: GenericParamCount = Default :: default ( ) ;
1236+ for param in generics. params . iter ( ) {
1237+ match param. kind {
1238+ hir:: GenericParamKind :: Lifetime { .. } => {
1239+ let mut j = 0 ;
1240+ let lifetime = generic_args. args . iter ( ) . find_map ( |arg| match arg {
1241+ hir:: GenericArg :: Lifetime ( lt) => {
1242+ if indices. lifetimes == j {
1243+ return Some ( lt) ;
12591244 }
1260- indices. lifetimes += 1 ;
1245+ j += 1 ;
1246+ None
12611247 }
1262- hir:: GenericParamKind :: Type { ref default, .. } => {
1263- let ty_param_def_id = cx. tcx . hir ( ) . local_def_id ( param. hir_id ) ;
1264- let mut j = 0 ;
1265- let type_ = generic_args. args . iter ( ) . find_map ( |arg| match arg {
1266- hir:: GenericArg :: Type ( ty) => {
1267- if indices. types == j {
1268- return Some ( ty) ;
1269- }
1270- j += 1 ;
1271- None
1272- }
1273- _ => None ,
1274- } ) ;
1275- if let Some ( ty) = type_ {
1276- ty_substs. insert ( ty_param_def_id. to_def_id ( ) , ty. clean ( cx) ) ;
1277- } else if let Some ( default) = * default {
1278- ty_substs. insert ( ty_param_def_id. to_def_id ( ) , default. clean ( cx) ) ;
1248+ _ => None ,
1249+ } ) ;
1250+ if let Some ( lt) = lifetime. cloned ( ) {
1251+ let lt_def_id = cx. tcx . hir ( ) . local_def_id ( param. hir_id ) ;
1252+ let cleaned = if !lt. is_elided ( ) {
1253+ lt. clean ( cx)
1254+ } else {
1255+ self :: types:: Lifetime :: elided ( )
1256+ } ;
1257+ lt_substs. insert ( lt_def_id. to_def_id ( ) , cleaned) ;
1258+ }
1259+ indices. lifetimes += 1 ;
1260+ }
1261+ hir:: GenericParamKind :: Type { ref default, .. } => {
1262+ let ty_param_def_id = cx. tcx . hir ( ) . local_def_id ( param. hir_id ) ;
1263+ let mut j = 0 ;
1264+ let type_ = generic_args. args . iter ( ) . find_map ( |arg| match arg {
1265+ hir:: GenericArg :: Type ( ty) => {
1266+ if indices. types == j {
1267+ return Some ( ty) ;
12791268 }
1280- indices. types += 1 ;
1269+ j += 1 ;
1270+ None
12811271 }
1282- hir:: GenericParamKind :: Const { .. } => {
1283- let const_param_def_id = cx. tcx . hir ( ) . local_def_id ( param. hir_id ) ;
1284- let mut j = 0 ;
1285- let const_ = generic_args. args . iter ( ) . find_map ( |arg| match arg {
1286- hir:: GenericArg :: Const ( ct) => {
1287- if indices. consts == j {
1288- return Some ( ct) ;
1289- }
1290- j += 1 ;
1291- None
1292- }
1293- _ => None ,
1294- } ) ;
1295- if let Some ( ct) = const_ {
1296- ct_substs. insert ( const_param_def_id. to_def_id ( ) , ct. clean ( cx) ) ;
1272+ _ => None ,
1273+ } ) ;
1274+ if let Some ( ty) = type_ {
1275+ ty_substs. insert ( ty_param_def_id. to_def_id ( ) , ty. clean ( cx) ) ;
1276+ } else if let Some ( default) = * default {
1277+ ty_substs. insert ( ty_param_def_id. to_def_id ( ) , default. clean ( cx) ) ;
1278+ }
1279+ indices. types += 1 ;
1280+ }
1281+ hir:: GenericParamKind :: Const { .. } => {
1282+ let const_param_def_id = cx. tcx . hir ( ) . local_def_id ( param. hir_id ) ;
1283+ let mut j = 0 ;
1284+ let const_ = generic_args. args . iter ( ) . find_map ( |arg| match arg {
1285+ hir:: GenericArg :: Const ( ct) => {
1286+ if indices. consts == j {
1287+ return Some ( ct) ;
12971288 }
1298- // FIXME(const_generics_defaults)
1299- indices . consts += 1 ;
1289+ j += 1 ;
1290+ None
13001291 }
1292+ _ => None ,
1293+ } ) ;
1294+ if let Some ( ct) = const_ {
1295+ ct_substs. insert ( const_param_def_id. to_def_id ( ) , ct. clean ( cx) ) ;
13011296 }
1297+ // FIXME(const_generics_defaults)
1298+ indices. consts += 1 ;
13021299 }
13031300 }
1304- Some ( cx. enter_alias ( ty_substs, lt_substs, ct_substs, |cx| ty. clean ( cx) ) )
1305- } else {
1306- None
13071301 }
1302+
1303+ Some ( cx. enter_alias ( ty_substs, lt_substs, ct_substs, |cx| ty. clean ( cx) ) )
13081304}
13091305
13101306impl Clean < Type > for hir:: Ty < ' _ > {
0 commit comments