@@ -1148,7 +1148,6 @@ impl Clean<Item> for ty::AssocItem {
11481148}
11491149
11501150fn clean_qpath ( hir_ty : & hir:: Ty < ' _ > , cx : & mut DocContext < ' _ > ) -> Type {
1151- use rustc_hir:: GenericParamCount ;
11521151 let hir:: Ty { hir_id : _, span, ref kind } = * hir_ty;
11531152 let qpath = match kind {
11541153 hir:: TyKind :: Path ( qpath) => qpath,
@@ -1166,97 +1165,12 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
11661165 }
11671166 }
11681167
1169- let mut alias = None ;
1170- if let Res :: Def ( DefKind :: TyAlias , def_id) = path. res {
1171- // Substitute private type aliases
1172- if let Some ( def_id) = def_id. as_local ( ) {
1173- let hir_id = cx. tcx . hir ( ) . local_def_id_to_hir_id ( def_id) ;
1174- if !cx. cache . access_levels . is_exported ( def_id. to_def_id ( ) ) {
1175- alias = Some ( & cx. tcx . hir ( ) . expect_item ( hir_id) . kind ) ;
1176- }
1177- }
1178- } ;
1179-
1180- if let Some ( & hir:: ItemKind :: TyAlias ( ref ty, ref generics) ) = alias {
1181- let provided_params = & path. segments . last ( ) . expect ( "segments were empty" ) ;
1182- let mut ty_substs = FxHashMap :: default ( ) ;
1183- let mut lt_substs = FxHashMap :: default ( ) ;
1184- let mut ct_substs = FxHashMap :: default ( ) ;
1185- let generic_args = provided_params. args ( ) ;
1186- {
1187- let mut indices: GenericParamCount = Default :: default ( ) ;
1188- for param in generics. params . iter ( ) {
1189- match param. kind {
1190- hir:: GenericParamKind :: Lifetime { .. } => {
1191- let mut j = 0 ;
1192- let lifetime = generic_args. args . iter ( ) . find_map ( |arg| match arg {
1193- hir:: GenericArg :: Lifetime ( lt) => {
1194- if indices. lifetimes == j {
1195- return Some ( lt) ;
1196- }
1197- j += 1 ;
1198- None
1199- }
1200- _ => None ,
1201- } ) ;
1202- if let Some ( lt) = lifetime. cloned ( ) {
1203- let lt_def_id = cx. tcx . hir ( ) . local_def_id ( param. hir_id ) ;
1204- let cleaned = if !lt. is_elided ( ) {
1205- lt. clean ( cx)
1206- } else {
1207- self :: types:: Lifetime :: elided ( )
1208- } ;
1209- lt_substs. insert ( lt_def_id. to_def_id ( ) , cleaned) ;
1210- }
1211- indices. lifetimes += 1 ;
1212- }
1213- hir:: GenericParamKind :: Type { ref default, .. } => {
1214- let ty_param_def_id = cx. tcx . hir ( ) . local_def_id ( param. hir_id ) ;
1215- let mut j = 0 ;
1216- let type_ = generic_args. args . iter ( ) . find_map ( |arg| match arg {
1217- hir:: GenericArg :: Type ( ty) => {
1218- if indices. types == j {
1219- return Some ( ty) ;
1220- }
1221- j += 1 ;
1222- None
1223- }
1224- _ => None ,
1225- } ) ;
1226- if let Some ( ty) = type_ {
1227- ty_substs. insert ( ty_param_def_id. to_def_id ( ) , ty. clean ( cx) ) ;
1228- } else if let Some ( default) = * default {
1229- ty_substs
1230- . insert ( ty_param_def_id. to_def_id ( ) , default. clean ( cx) ) ;
1231- }
1232- indices. types += 1 ;
1233- }
1234- hir:: GenericParamKind :: Const { .. } => {
1235- let const_param_def_id = cx. tcx . hir ( ) . local_def_id ( param. hir_id ) ;
1236- let mut j = 0 ;
1237- let const_ = generic_args. args . iter ( ) . find_map ( |arg| match arg {
1238- hir:: GenericArg :: Const ( ct) => {
1239- if indices. consts == j {
1240- return Some ( ct) ;
1241- }
1242- j += 1 ;
1243- None
1244- }
1245- _ => None ,
1246- } ) ;
1247- if let Some ( ct) = const_ {
1248- ct_substs. insert ( const_param_def_id. to_def_id ( ) , ct. clean ( cx) ) ;
1249- }
1250- // FIXME(const_generics_defaults)
1251- indices. consts += 1 ;
1252- }
1253- }
1254- }
1255- }
1256- return cx. enter_alias ( ty_substs, lt_substs, ct_substs, |cx| ty. clean ( cx) ) ;
1168+ if let Some ( expanded) = maybe_expand_private_type_alias ( cx, path) {
1169+ expanded
1170+ } else {
1171+ let path = path. clean ( cx) ;
1172+ resolve_type ( cx, path)
12571173 }
1258- let path = path. clean ( cx) ;
1259- resolve_type ( cx, path)
12601174 }
12611175 hir:: QPath :: Resolved ( Some ( ref qself) , p) => {
12621176 // Try to normalize `<X as Y>::T` to a type
@@ -1300,6 +1214,99 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
13001214 }
13011215}
13021216
1217+ fn 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+ }
1227+ } ;
1228+
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) ;
1259+ }
1260+ indices. lifetimes += 1 ;
1261+ }
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) ) ;
1279+ }
1280+ indices. types += 1 ;
1281+ }
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) ) ;
1297+ }
1298+ // FIXME(const_generics_defaults)
1299+ indices. consts += 1 ;
1300+ }
1301+ }
1302+ }
1303+ }
1304+ Some ( cx. enter_alias ( ty_substs, lt_substs, ct_substs, |cx| ty. clean ( cx) ) )
1305+ } else {
1306+ None
1307+ }
1308+ }
1309+
13031310impl Clean < Type > for hir:: Ty < ' _ > {
13041311 fn clean ( & self , cx : & mut DocContext < ' _ > ) -> Type {
13051312 use rustc_hir:: * ;
0 commit comments