11use rustc_abi:: { Align , Size } ;
22use rustc_ast:: { IntTy , LitIntType , LitKind , UintTy } ;
3- use rustc_hir:: attrs:: { AttrConstResolved , AttrIntValue , IntType , ReprAttr } ;
3+ use rustc_hir:: attrs:: { AttrIntValue , AttrResolutionKind , AttrResolved , IntType , ReprAttr } ;
44use rustc_hir:: def:: { DefKind , Res } ;
55use rustc_session:: parse:: feature_err;
66
@@ -105,7 +105,10 @@ fn int_type_of_word(s: Symbol) -> Option<IntType> {
105105 }
106106}
107107
108- fn parse_repr < S : Stage > ( cx : & AcceptContext < ' _ , ' _ , S > , param : & MetaItemParser ) -> Option < ReprAttr > {
108+ fn parse_repr < S : Stage > (
109+ cx : & mut AcceptContext < ' _ , ' _ , S > ,
110+ param : & MetaItemParser ,
111+ ) -> Option < ReprAttr > {
109112 use ReprAttr :: * ;
110113
111114 // FIXME(jdonszelmann): invert the parsing here to match on the word first and then the
@@ -200,7 +203,7 @@ enum AlignmentParseError {
200203}
201204
202205fn parse_repr_align < S : Stage > (
203- cx : & AcceptContext < ' _ , ' _ , S > ,
206+ cx : & mut AcceptContext < ' _ , ' _ , S > ,
204207 list : & MetaItemListParser ,
205208 param_span : Span ,
206209 align_kind : AlignKind ,
@@ -283,7 +286,7 @@ fn parse_alignment<S: Stage>(
283286}
284287
285288fn parse_alignment_or_const_path < S : Stage > (
286- cx : & AcceptContext < ' _ , ' _ , S > ,
289+ cx : & mut AcceptContext < ' _ , ' _ , S > ,
287290 arg : & MetaItemOrLitParser ,
288291 attr_name : & ' static str ,
289292) -> Result < AttrIntValue , AlignmentParseError > {
@@ -301,10 +304,15 @@ fn parse_alignment_or_const_path<S: Stage>(
301304 return Err ( AlignmentParseError :: Message ( "not an unsuffixed integer" . to_string ( ) ) ) ;
302305 }
303306
304- if let Some ( features) = cx. features_option ( )
305- && !features. const_attr_paths ( )
306- && !meta. span ( ) . allows_unstable ( sym:: const_attr_paths)
307- {
307+ let path_span = meta. path ( ) . span ( ) ;
308+ let feature_enabled = cx. features_option ( ) . is_some_and ( |features| features. const_attr_paths ( ) )
309+ || path_span. allows_unstable ( sym:: const_attr_paths) ;
310+
311+ if !feature_enabled {
312+ if matches ! ( cx. stage. should_emit( ) , ShouldEmit :: Nothing ) {
313+ return Ok ( AttrIntValue :: Lit ( 1 ) ) ;
314+ }
315+
308316 feature_err (
309317 cx. sess ( ) ,
310318 sym:: const_attr_paths,
@@ -315,7 +323,9 @@ fn parse_alignment_or_const_path<S: Stage>(
315323 return Err ( AlignmentParseError :: AlreadyErrored ) ;
316324 }
317325
318- let Some ( resolution) = cx. attr_const_resolution ( meta. path ( ) . span ( ) ) else {
326+ cx. record_attr_resolution_request ( AttrResolutionKind :: Const , meta. path ( ) . 0 . clone ( ) ) ;
327+
328+ let Some ( resolution) = cx. attr_resolution ( AttrResolutionKind :: Const , path_span) else {
319329 // `parse_limited(sym::repr)` runs before lowering for callers that only care whether
320330 // `repr(packed(...))` exists at all.
321331 if matches ! ( cx. stage. should_emit( ) , ShouldEmit :: Nothing ) {
@@ -325,22 +335,18 @@ fn parse_alignment_or_const_path<S: Stage>(
325335 } ;
326336
327337 match resolution {
328- AttrConstResolved :: Resolved ( Res :: Def ( DefKind :: Const { .. } , def_id) ) => {
329- Ok ( AttrIntValue :: Const { def_id, span : meta . path ( ) . span ( ) } )
338+ AttrResolved :: Resolved ( Res :: Def ( DefKind :: Const { .. } , def_id) ) => {
339+ Ok ( AttrIntValue :: Const { def_id, span : path_span } )
330340 }
331- AttrConstResolved :: Resolved ( Res :: Def ( DefKind :: ConstParam , _) ) => {
332- cx. emit_err ( AttrConstGenericNotSupported { span : meta . path ( ) . span ( ) , attr_name } ) ;
341+ AttrResolved :: Resolved ( Res :: Def ( DefKind :: ConstParam , _) ) => {
342+ cx. emit_err ( AttrConstGenericNotSupported { span : path_span , attr_name } ) ;
333343 Err ( AlignmentParseError :: AlreadyErrored )
334344 }
335- AttrConstResolved :: Resolved ( res) => {
336- cx. emit_err ( AttrConstPathNotConst {
337- span : meta. path ( ) . span ( ) ,
338- attr_name,
339- thing : res. descr ( ) ,
340- } ) ;
345+ AttrResolved :: Resolved ( res) => {
346+ cx. emit_err ( AttrConstPathNotConst { span : path_span, attr_name, thing : res. descr ( ) } ) ;
341347 Err ( AlignmentParseError :: AlreadyErrored )
342348 }
343- AttrConstResolved :: Error => Err ( AlignmentParseError :: AlreadyErrored ) ,
349+ AttrResolved :: Error => Err ( AlignmentParseError :: AlreadyErrored ) ,
344350 }
345351}
346352
0 commit comments