@@ -177,9 +177,7 @@ fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir
177
177
| hir:: ItemKind :: Enum ( _, generics)
178
178
| hir:: ItemKind :: Struct ( _, generics) => ( & generics. params [ ..] , true ) ,
179
179
hir:: ItemKind :: TyAlias ( _, generics) => ( & generics. params [ ..] , false ) ,
180
- // hir::ItemKind::Static(ty, ..) => {
181
- // hir::ItemKind::Fn(..) |
182
- // hir::ItemKind::Const(..) => {} // We handle these elsewhere to suggest appropriate type.
180
+ // `static`, `fn` and `const` are handled elsewhere to suggest appropriate type.
183
181
_ => return ,
184
182
} ;
185
183
@@ -1276,7 +1274,7 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
1276
1274
}
1277
1275
TraitItemKind :: Const ( ref ty, body_id) => body_id
1278
1276
. and_then ( |body_id| {
1279
- if is_infer_ty ( ty) {
1277
+ if is_suggestable_infer_ty ( ty) {
1280
1278
Some ( infer_placeholder_type ( tcx, def_id, body_id, ty. span , item. ident ) )
1281
1279
} else {
1282
1280
None
@@ -1295,7 +1293,7 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
1295
1293
tcx. mk_fn_def ( def_id, substs)
1296
1294
}
1297
1295
ImplItemKind :: Const ( ref ty, body_id) => {
1298
- if is_infer_ty ( ty) {
1296
+ if is_suggestable_infer_ty ( ty) {
1299
1297
infer_placeholder_type ( tcx, def_id, body_id, ty. span , item. ident )
1300
1298
} else {
1301
1299
icx. to_ty ( ty)
@@ -1320,7 +1318,7 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
1320
1318
Node :: Item ( item) => {
1321
1319
match item. kind {
1322
1320
ItemKind :: Static ( ref ty, .., body_id) | ItemKind :: Const ( ref ty, body_id) => {
1323
- if is_infer_ty ( ty) {
1321
+ if is_suggestable_infer_ty ( ty) {
1324
1322
infer_placeholder_type ( tcx, def_id, body_id, ty. span , item. ident )
1325
1323
} else {
1326
1324
icx. to_ty ( ty)
@@ -1792,10 +1790,12 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
1792
1790
}
1793
1791
}
1794
1792
1795
- crate fn is_infer_ty ( ty : & hir:: Ty < ' _ > ) -> bool {
1793
+ /// Whether `ty` is a type with `_` placeholders that can be infered. Used in diagnostics only to
1794
+ /// use inference to provide suggestions for the appropriate type if possible.
1795
+ fn is_suggestable_infer_ty ( ty : & hir:: Ty < ' _ > ) -> bool {
1796
1796
match & ty. kind {
1797
1797
hir:: TyKind :: Infer => true ,
1798
- hir:: TyKind :: Slice ( ty) | hir:: TyKind :: Array ( ty, _) => is_infer_ty ( ty) ,
1798
+ hir:: TyKind :: Slice ( ty) | hir:: TyKind :: Array ( ty, _) => is_suggestable_infer_ty ( ty) ,
1799
1799
hir:: TyKind :: Tup ( tys)
1800
1800
if !tys. is_empty ( )
1801
1801
&& tys. iter ( ) . any ( |ty| match ty. kind {
@@ -1811,7 +1811,7 @@ crate fn is_infer_ty(ty: &hir::Ty<'_>) -> bool {
1811
1811
1812
1812
pub fn get_infer_ret_ty ( output : & ' hir hir:: FunctionRetTy < ' hir > ) -> Option < & ' hir hir:: Ty < ' hir > > {
1813
1813
if let hir:: FunctionRetTy :: Return ( ref ty) = output {
1814
- if is_infer_ty ( ty) {
1814
+ if is_suggestable_infer_ty ( ty) {
1815
1815
return Some ( & * * ty) ;
1816
1816
}
1817
1817
}
0 commit comments