@@ -113,9 +113,9 @@ pub struct ItemCtxt<'tcx> {
113113///////////////////////////////////////////////////////////////////////////
114114
115115#[ derive( Default ) ]
116- crate struct PlaceholderHirTyCollector ( crate Vec < Span > ) ;
116+ crate struct HirPlaceholderCollector ( crate Vec < Span > ) ;
117117
118- impl < ' v > Visitor < ' v > for PlaceholderHirTyCollector {
118+ impl < ' v > Visitor < ' v > for HirPlaceholderCollector {
119119 type Map = intravisit:: ErasedMap < ' v > ;
120120
121121 fn nested_visit_map ( & mut self ) -> NestedVisitorMap < Self :: Map > {
@@ -137,6 +137,12 @@ impl<'v> Visitor<'v> for PlaceholderHirTyCollector {
137137 _ => { }
138138 }
139139 }
140+ fn visit_array_length ( & mut self , length : & ' v hir:: ArrayLen ) {
141+ if let & hir:: ArrayLen :: Infer ( _, span) = length {
142+ self . 0 . push ( span) ;
143+ }
144+ intravisit:: walk_array_len ( self , length)
145+ }
140146}
141147
142148struct CollectItemTypesVisitor < ' tcx > {
@@ -181,7 +187,7 @@ crate fn placeholder_type_error<'tcx>(
181187 sugg. push ( ( span, format ! ( ", {}" , type_name) ) ) ;
182188 }
183189
184- let mut err = bad_placeholder ( tcx, "type" , placeholder_types, kind) ;
190+ let mut err = bad_placeholder ( tcx, placeholder_types, kind) ;
185191
186192 // Suggest, but only if it is not a function in const or static
187193 if suggest {
@@ -239,7 +245,7 @@ fn reject_placeholder_type_signatures_in_item<'tcx>(
239245 _ => return ,
240246 } ;
241247
242- let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
248+ let mut visitor = HirPlaceholderCollector :: default ( ) ;
243249 visitor. visit_item ( item) ;
244250
245251 placeholder_type_error (
@@ -317,7 +323,6 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
317323
318324fn bad_placeholder < ' tcx > (
319325 tcx : TyCtxt < ' tcx > ,
320- placeholder_kind : & ' static str ,
321326 mut spans : Vec < Span > ,
322327 kind : & ' static str ,
323328) -> rustc_errors:: DiagnosticBuilder < ' tcx > {
@@ -328,8 +333,7 @@ fn bad_placeholder<'tcx>(
328333 tcx. sess,
329334 spans. clone( ) ,
330335 E0121 ,
331- "the {} placeholder `_` is not allowed within types on item signatures for {}" ,
332- placeholder_kind,
336+ "the placeholder `_` is not allowed within types on item signatures for {}" ,
333337 kind
334338 ) ;
335339 for span in spans {
@@ -387,7 +391,7 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
387391 }
388392
389393 fn ty_infer ( & self , _: Option < & ty:: GenericParamDef > , span : Span ) -> Ty < ' tcx > {
390- self . tcx ( ) . ty_error_with_message ( span, "bad_placeholder_type " )
394+ self . tcx ( ) . ty_error_with_message ( span, "bad placeholder type " )
391395 }
392396
393397 fn ct_infer (
@@ -396,13 +400,11 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
396400 _: Option < & ty:: GenericParamDef > ,
397401 span : Span ,
398402 ) -> & ' tcx Const < ' tcx > {
399- bad_placeholder ( self . tcx ( ) , "const" , vec ! [ span] , "generic" ) . emit ( ) ;
400- // Typeck doesn't expect erased regions to be returned from `type_of`.
401403 let ty = self . tcx . fold_regions ( ty, & mut false , |r, _| match r {
402404 ty:: ReErased => self . tcx . lifetimes . re_static ,
403405 _ => r,
404406 } ) ;
405- self . tcx ( ) . const_error ( ty)
407+ self . tcx ( ) . const_error_with_message ( ty, span , "bad placeholder constant" )
406408 }
407409
408410 fn projected_ty_from_poly_trait_ref (
@@ -746,7 +748,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
746748 match item. kind {
747749 hir:: ForeignItemKind :: Fn ( ..) => tcx. ensure ( ) . fn_sig ( item. def_id ) ,
748750 hir:: ForeignItemKind :: Static ( ..) => {
749- let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
751+ let mut visitor = HirPlaceholderCollector :: default ( ) ;
750752 visitor. visit_foreign_item ( item) ;
751753 placeholder_type_error (
752754 tcx,
@@ -829,7 +831,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
829831 hir:: ItemKind :: Const ( ty, ..) | hir:: ItemKind :: Static ( ty, ..) => {
830832 // (#75889): Account for `const C: dyn Fn() -> _ = "";`
831833 if let hir:: TyKind :: TraitObject ( ..) = ty. kind {
832- let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
834+ let mut visitor = HirPlaceholderCollector :: default ( ) ;
833835 visitor. visit_item ( it) ;
834836 placeholder_type_error (
835837 tcx,
@@ -865,7 +867,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
865867 hir:: TraitItemKind :: Const ( ..) => {
866868 tcx. ensure ( ) . type_of ( trait_item_id. def_id ) ;
867869 // Account for `const C: _;`.
868- let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
870+ let mut visitor = HirPlaceholderCollector :: default ( ) ;
869871 visitor. visit_trait_item ( trait_item) ;
870872 placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , None , "constant" ) ;
871873 }
@@ -874,7 +876,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
874876 tcx. ensure ( ) . item_bounds ( trait_item_id. def_id ) ;
875877 tcx. ensure ( ) . type_of ( trait_item_id. def_id ) ;
876878 // Account for `type T = _;`.
877- let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
879+ let mut visitor = HirPlaceholderCollector :: default ( ) ;
878880 visitor. visit_trait_item ( trait_item) ;
879881 placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , None , "associated type" ) ;
880882 }
@@ -883,7 +885,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
883885 tcx. ensure ( ) . item_bounds ( trait_item_id. def_id ) ;
884886 // #74612: Visit and try to find bad placeholders
885887 // even if there is no concrete type.
886- let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
888+ let mut visitor = HirPlaceholderCollector :: default ( ) ;
887889 visitor. visit_trait_item ( trait_item) ;
888890
889891 placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , None , "associated type" ) ;
@@ -905,7 +907,7 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
905907 }
906908 hir:: ImplItemKind :: TyAlias ( _) => {
907909 // Account for `type T = _;`
908- let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
910+ let mut visitor = HirPlaceholderCollector :: default ( ) ;
909911 visitor. visit_impl_item ( impl_item) ;
910912
911913 placeholder_type_error ( tcx, None , & [ ] , visitor. 0 , false , None , "associated type" ) ;
@@ -1738,10 +1740,14 @@ fn are_suggestable_generic_args(generic_args: &[hir::GenericArg<'_>]) -> bool {
17381740/// Whether `ty` is a type with `_` placeholders that can be inferred. Used in diagnostics only to
17391741/// use inference to provide suggestions for the appropriate type if possible.
17401742fn is_suggestable_infer_ty ( ty : & hir:: Ty < ' _ > ) -> bool {
1743+ debug ! ( ?ty) ;
17411744 use hir:: TyKind :: * ;
17421745 match & ty. kind {
17431746 Infer => true ,
1744- Slice ( ty) | Array ( ty, _) => is_suggestable_infer_ty ( ty) ,
1747+ Slice ( ty) => is_suggestable_infer_ty ( ty) ,
1748+ Array ( ty, length) => {
1749+ is_suggestable_infer_ty ( ty) || matches ! ( length, hir:: ArrayLen :: Infer ( _, _) )
1750+ }
17451751 Tup ( tys) => tys. iter ( ) . any ( is_suggestable_infer_ty) ,
17461752 Ptr ( mut_ty) | Rptr ( _, mut_ty) => is_suggestable_infer_ty ( mut_ty. ty ) ,
17471753 OpaqueDef ( _, generic_args) => are_suggestable_generic_args ( generic_args) ,
@@ -1793,9 +1799,9 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
17931799 } ) ;
17941800 let fn_sig = ty:: Binder :: dummy ( fn_sig) ;
17951801
1796- let mut visitor = PlaceholderHirTyCollector :: default ( ) ;
1802+ let mut visitor = HirPlaceholderCollector :: default ( ) ;
17971803 visitor. visit_ty ( ty) ;
1798- let mut diag = bad_placeholder ( tcx, "type" , visitor. 0 , "return type" ) ;
1804+ let mut diag = bad_placeholder ( tcx, visitor. 0 , "return type" ) ;
17991805 let ret_ty = fn_sig. skip_binder ( ) . output ( ) ;
18001806 if !ret_ty. references_error ( ) {
18011807 if !ret_ty. is_closure ( ) {
0 commit comments