@@ -143,6 +143,7 @@ crate fn placeholder_type_error(
143143 generics : & [ hir:: GenericParam < ' _ > ] ,
144144 placeholder_types : Vec < Span > ,
145145 suggest : bool ,
146+ hir_ty : Option < & hir:: Ty < ' _ > > ,
146147) {
147148 if placeholder_types. is_empty ( ) {
148149 return ;
@@ -173,12 +174,40 @@ crate fn placeholder_type_error(
173174 }
174175
175176 let mut err = bad_placeholder_type ( tcx, placeholder_types) ;
177+
178+ // Suggest, but only if it is not a function in const or static
176179 if suggest {
177- err. multipart_suggestion (
178- "use type parameters instead" ,
179- sugg,
180- Applicability :: HasPlaceholders ,
181- ) ;
180+ let mut is_fn = false ;
181+ let mut is_const = false ;
182+ let mut is_static = false ;
183+
184+ if let Some ( hir_ty) = hir_ty {
185+ if let hir:: TyKind :: BareFn ( _) = hir_ty. kind {
186+ is_fn = true ;
187+
188+ // Check if parent is const or static
189+ let parent_id = tcx. hir ( ) . get_parent_node ( hir_ty. hir_id ) ;
190+ let parent_node = tcx. hir ( ) . get ( parent_id) ;
191+
192+ if let hir:: Node :: Item ( item) = parent_node {
193+ if let hir:: ItemKind :: Const ( _, _) = item. kind {
194+ is_const = true ;
195+ } else if let hir:: ItemKind :: Static ( _, _, _) = item. kind {
196+ is_static = true ;
197+ }
198+ }
199+ }
200+ }
201+
202+ // if function is wrapped around a const or static,
203+ // then don't show the suggestion
204+ if !( is_fn && ( is_const || is_static) ) {
205+ err. multipart_suggestion (
206+ "use type parameters instead" ,
207+ sugg,
208+ Applicability :: HasPlaceholders ,
209+ ) ;
210+ }
182211 }
183212 err. emit ( ) ;
184213}
@@ -200,7 +229,14 @@ fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir
200229 let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
201230 visitor. visit_item ( item) ;
202231
203- placeholder_type_error ( tcx, Some ( generics. span ) , & generics. params [ ..] , visitor. 0 , suggest) ;
232+ placeholder_type_error (
233+ tcx,
234+ Some ( generics. span ) ,
235+ & generics. params [ ..] ,
236+ visitor. 0 ,
237+ suggest,
238+ None ,
239+ ) ;
204240}
205241
206242impl Visitor < ' tcx > for CollectItemTypesVisitor < ' tcx > {
@@ -682,6 +718,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
682718 let it = tcx. hir ( ) . expect_item ( item_id) ;
683719 debug ! ( "convert: item {} with id {}" , it. ident, it. hir_id) ;
684720 let def_id = tcx. hir ( ) . local_def_id ( item_id) ;
721+
685722 match it. kind {
686723 // These don't define types.
687724 hir:: ItemKind :: ExternCrate ( _)
@@ -787,7 +824,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
787824 // Account for `const C: _;`.
788825 let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
789826 visitor. visit_trait_item ( trait_item) ;
790- placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false ) ;
827+ placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , None ) ;
791828 }
792829
793830 hir:: TraitItemKind :: Type ( _, Some ( _) ) => {
@@ -796,7 +833,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
796833 // Account for `type T = _;`.
797834 let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
798835 visitor. visit_trait_item ( trait_item) ;
799- placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false ) ;
836+ placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , None ) ;
800837 }
801838
802839 hir:: TraitItemKind :: Type ( _, None ) => {
@@ -805,7 +842,8 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
805842 // even if there is no concrete type.
806843 let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
807844 visitor. visit_trait_item ( trait_item) ;
808- placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false ) ;
845+
846+ placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , None ) ;
809847 }
810848 } ;
811849
@@ -826,7 +864,8 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::HirId) {
826864 // Account for `type T = _;`
827865 let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
828866 visitor. visit_impl_item ( impl_item) ;
829- placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false ) ;
867+
868+ placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , None ) ;
830869 }
831870 hir:: ImplItemKind :: Const ( ..) => { }
832871 }
@@ -1654,6 +1693,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
16541693 & sig. decl ,
16551694 & generics,
16561695 Some ( ident. span ) ,
1696+ None ,
16571697 ) ,
16581698 }
16591699 }
@@ -1663,9 +1703,15 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
16631703 ident,
16641704 generics,
16651705 ..
1666- } ) => {
1667- AstConv :: ty_of_fn ( & icx, header. unsafety , header. abi , decl, & generics, Some ( ident. span ) )
1668- }
1706+ } ) => AstConv :: ty_of_fn (
1707+ & icx,
1708+ header. unsafety ,
1709+ header. abi ,
1710+ decl,
1711+ & generics,
1712+ Some ( ident. span ) ,
1713+ None ,
1714+ ) ,
16691715
16701716 ForeignItem ( & hir:: ForeignItem {
16711717 kind : ForeignItemKind :: Fn ( ref fn_decl, _, _) ,
@@ -2335,6 +2381,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
23352381 decl,
23362382 & hir:: Generics :: empty ( ) ,
23372383 Some ( ident. span ) ,
2384+ None ,
23382385 ) ;
23392386
23402387 // Feature gate SIMD types in FFI, since I am not sure that the
0 commit comments