@@ -141,7 +141,7 @@ crate fn placeholder_type_error(
141
141
generics : & [ hir:: GenericParam < ' _ > ] ,
142
142
placeholder_types : Vec < Span > ,
143
143
suggest : bool ,
144
- is_fn : bool ,
144
+ hir_ty : Option < & hir :: Ty < ' _ > > ,
145
145
) {
146
146
if placeholder_types. is_empty ( ) {
147
147
return ;
@@ -173,13 +173,39 @@ crate fn placeholder_type_error(
173
173
174
174
let mut err = bad_placeholder_type ( tcx, placeholder_types) ;
175
175
176
- // Suggest, but only if it is not a function
177
- if suggest && !is_fn {
178
- err. multipart_suggestion (
179
- "use type parameters instead" ,
180
- sugg,
181
- Applicability :: HasPlaceholders ,
182
- ) ;
176
+ // Suggest, but only if it is not a function in const or static
177
+ if suggest {
178
+ let mut is_fn = false ;
179
+ let mut is_const = false ;
180
+ let mut is_static = false ;
181
+
182
+ if let Some ( hir_ty) = hir_ty {
183
+ if let hir:: TyKind :: BareFn ( _) = hir_ty. kind {
184
+ is_fn = true ;
185
+
186
+ // Check if parent is const or static
187
+ let parent_id = tcx. hir ( ) . get_parent_node ( hir_ty. hir_id ) ;
188
+ let parent_node = tcx. hir ( ) . get ( parent_id) ;
189
+
190
+ if let hir:: Node :: Item ( item) = parent_node {
191
+ if let hir:: ItemKind :: Const ( _, _) = item. kind {
192
+ is_const = true ;
193
+ } else if let hir:: ItemKind :: Static ( _, _, _) = item. kind {
194
+ is_static = true ;
195
+ }
196
+ }
197
+ }
198
+ }
199
+
200
+ // if function is wrapped around a const or static,
201
+ // then don't show the suggestion
202
+ if !( is_fn && ( is_const || is_static) ) {
203
+ err. multipart_suggestion (
204
+ "use type parameters instead" ,
205
+ sugg,
206
+ Applicability :: HasPlaceholders ,
207
+ ) ;
208
+ }
183
209
}
184
210
err. emit ( ) ;
185
211
}
@@ -207,7 +233,7 @@ fn reject_placeholder_type_signatures_in_item(tcx: TyCtxt<'tcx>, item: &'tcx hir
207
233
& generics. params [ ..] ,
208
234
visitor. 0 ,
209
235
suggest,
210
- false ,
236
+ None ,
211
237
) ;
212
238
}
213
239
@@ -648,6 +674,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
648
674
let it = tcx. hir ( ) . expect_item ( item_id) ;
649
675
debug ! ( "convert: item {} with id {}" , it. ident, it. hir_id) ;
650
676
let def_id = tcx. hir ( ) . local_def_id ( item_id) ;
677
+
651
678
match it. kind {
652
679
// These don't define types.
653
680
hir:: ItemKind :: ExternCrate ( _)
@@ -753,7 +780,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
753
780
// Account for `const C: _;`.
754
781
let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
755
782
visitor. visit_trait_item ( trait_item) ;
756
- placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , false ) ;
783
+ placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , None ) ;
757
784
}
758
785
759
786
hir:: TraitItemKind :: Type ( _, Some ( _) ) => {
@@ -762,7 +789,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
762
789
// Account for `type T = _;`.
763
790
let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
764
791
visitor. visit_trait_item ( trait_item) ;
765
- placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , false ) ;
792
+ placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , None ) ;
766
793
}
767
794
768
795
hir:: TraitItemKind :: Type ( _, None ) => {
@@ -771,7 +798,8 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
771
798
// even if there is no concrete type.
772
799
let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
773
800
visitor. visit_trait_item ( trait_item) ;
774
- placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , false ) ;
801
+
802
+ placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , None ) ;
775
803
}
776
804
} ;
777
805
@@ -792,7 +820,8 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::HirId) {
792
820
// Account for `type T = _;`
793
821
let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
794
822
visitor. visit_impl_item ( impl_item) ;
795
- placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , false ) ;
823
+
824
+ placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , None ) ;
796
825
}
797
826
hir:: ImplItemKind :: Const ( ..) => { }
798
827
}
@@ -1583,6 +1612,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
1583
1612
& sig. decl ,
1584
1613
& generics,
1585
1614
Some ( ident. span ) ,
1615
+ None ,
1586
1616
) ,
1587
1617
}
1588
1618
}
@@ -1592,9 +1622,15 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
1592
1622
ident,
1593
1623
generics,
1594
1624
..
1595
- } ) => {
1596
- AstConv :: ty_of_fn ( & icx, header. unsafety , header. abi , decl, & generics, Some ( ident. span ) )
1597
- }
1625
+ } ) => AstConv :: ty_of_fn (
1626
+ & icx,
1627
+ header. unsafety ,
1628
+ header. abi ,
1629
+ decl,
1630
+ & generics,
1631
+ Some ( ident. span ) ,
1632
+ None ,
1633
+ ) ,
1598
1634
1599
1635
ForeignItem ( & hir:: ForeignItem {
1600
1636
kind : ForeignItemKind :: Fn ( ref fn_decl, _, _) ,
@@ -2264,6 +2300,7 @@ fn compute_sig_of_foreign_fn_decl<'tcx>(
2264
2300
decl,
2265
2301
& hir:: Generics :: empty ( ) ,
2266
2302
Some ( ident. span ) ,
2303
+ None ,
2267
2304
) ;
2268
2305
2269
2306
// Feature gate SIMD types in FFI, since I am not sure that the
0 commit comments