@@ -10,9 +10,10 @@ use std::collections::hash_map::Entry;
1010use std:: slice;
1111
1212use rustc_abi:: { Align , ExternAbi , Size } ;
13- use rustc_ast:: { AttrStyle , LitKind , MetaItemKind , ast} ;
13+ use rustc_ast:: { AttrStyle , MetaItemKind , ast} ;
1414use rustc_attr_parsing:: { AttributeParser , Late } ;
1515use rustc_data_structures:: fx:: FxHashMap ;
16+ use rustc_data_structures:: thin_vec:: ThinVec ;
1617use rustc_errors:: { DiagCtxtHandle , IntoDiagArg , MultiSpan , StashKey } ;
1718use rustc_feature:: {
1819 ACCEPTED_LANG_FEATURES , AttributeDuplicates , AttributeType , BUILTIN_ATTRIBUTE_MAP ,
@@ -211,6 +212,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
211212 Attribute :: Parsed ( AttributeKind :: MacroExport { span, .. } ) => {
212213 self . check_macro_export ( hir_id, * span, target)
213214 } ,
215+ Attribute :: Parsed ( AttributeKind :: RustcLegacyConstGenerics { attr_span, fn_indexes} ) => {
216+ self . check_rustc_legacy_const_generics ( hir_id, span, target, item, * attr_span, fn_indexes)
217+ } ,
214218 Attribute :: Parsed ( AttributeKind :: Doc ( attr) ) => self . check_doc_attrs ( attr, hir_id, target) ,
215219 Attribute :: Parsed (
216220 AttributeKind :: BodyStability { .. }
@@ -300,9 +304,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
300304 [ sym:: rustc_never_returns_null_ptr, ..] => {
301305 self . check_applied_to_fn_or_method ( hir_id, attr. span ( ) , span, target)
302306 }
303- [ sym:: rustc_legacy_const_generics, ..] => {
304- self . check_rustc_legacy_const_generics ( hir_id, attr, span, target, item)
305- }
306307 [ sym:: rustc_lint_query_instability, ..] => {
307308 self . check_applied_to_fn_or_method ( hir_id, attr. span ( ) , span, target)
308309 }
@@ -1178,26 +1179,22 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11781179 fn check_rustc_legacy_const_generics (
11791180 & self ,
11801181 hir_id : HirId ,
1181- attr : & Attribute ,
11821182 span : Span ,
11831183 target : Target ,
11841184 item : Option < ItemLike < ' _ > > ,
1185+ attr_span : Span ,
1186+ index_list : & ThinVec < ( u128 , Span ) > ,
11851187 ) {
11861188 let is_function = matches ! ( target, Target :: Fn ) ;
11871189 if !is_function {
11881190 self . dcx ( ) . emit_err ( errors:: AttrShouldBeAppliedToFn {
1189- attr_span : attr . span ( ) ,
1191+ attr_span,
11901192 defn_span : span,
11911193 on_crate : hir_id == CRATE_HIR_ID ,
11921194 } ) ;
11931195 return ;
11941196 }
11951197
1196- let Some ( list) = attr. meta_item_list ( ) else {
1197- // The attribute form is validated on AST.
1198- return ;
1199- } ;
1200-
12011198 let Some ( ItemLike :: Item ( Item {
12021199 kind : ItemKind :: Fn { sig : FnSig { decl, .. } , generics, .. } ,
12031200 ..
@@ -1211,42 +1208,32 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
12111208 hir:: GenericParamKind :: Const { .. } => { }
12121209 _ => {
12131210 self . dcx ( ) . emit_err ( errors:: RustcLegacyConstGenericsOnly {
1214- attr_span : attr . span ( ) ,
1211+ attr_span,
12151212 param_span : param. span ,
12161213 } ) ;
12171214 return ;
12181215 }
12191216 }
12201217 }
12211218
1222- if list . len ( ) != generics. params . len ( ) {
1219+ if index_list . len ( ) != generics. params . len ( ) {
12231220 self . dcx ( ) . emit_err ( errors:: RustcLegacyConstGenericsIndex {
1224- attr_span : attr . span ( ) ,
1221+ attr_span,
12251222 generics_span : generics. span ,
12261223 } ) ;
12271224 return ;
12281225 }
12291226
12301227 let arg_count = decl. inputs . len ( ) as u128 + generics. params . len ( ) as u128 ;
1231- let mut invalid_args = vec ! [ ] ;
1232- for meta in list {
1233- if let Some ( LitKind :: Int ( val, _) ) = meta. lit ( ) . map ( |lit| & lit. kind ) {
1234- if * val >= arg_count {
1235- let span = meta. span ( ) ;
1236- self . dcx ( ) . emit_err ( errors:: RustcLegacyConstGenericsIndexExceed {
1237- span,
1238- arg_count : arg_count as usize ,
1239- } ) ;
1240- return ;
1241- }
1242- } else {
1243- invalid_args. push ( meta. span ( ) ) ;
1228+ for ( index, span) in index_list {
1229+ if * index >= arg_count {
1230+ self . dcx ( ) . emit_err ( errors:: RustcLegacyConstGenericsIndexExceed {
1231+ span : * span,
1232+ arg_count : arg_count as usize ,
1233+ } ) ;
1234+ return ;
12441235 }
12451236 }
1246-
1247- if !invalid_args. is_empty ( ) {
1248- self . dcx ( ) . emit_err ( errors:: RustcLegacyConstGenericsIndexNegative { invalid_args } ) ;
1249- }
12501237 }
12511238
12521239 /// Helper function for checking that the provided attribute is only applied to a function or
0 commit comments