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
@@ -103,7 +103,10 @@ fn int_type_of_word(s: Symbol) -> Option<IntType> {
103103 }
104104}
105105
106- fn parse_repr < S : Stage > ( cx : & AcceptContext < ' _ , ' _ , S > , param : & MetaItemParser ) -> Option < ReprAttr > {
106+ fn parse_repr < S : Stage > (
107+ cx : & mut AcceptContext < ' _ , ' _ , S > ,
108+ param : & MetaItemParser ,
109+ ) -> Option < ReprAttr > {
107110 use ReprAttr :: * ;
108111
109112 // FIXME(jdonszelmann): invert the parsing here to match on the word first and then the
@@ -198,7 +201,7 @@ enum AlignmentParseError {
198201}
199202
200203fn parse_repr_align < S : Stage > (
201- cx : & AcceptContext < ' _ , ' _ , S > ,
204+ cx : & mut AcceptContext < ' _ , ' _ , S > ,
202205 list : & MetaItemListParser ,
203206 param_span : Span ,
204207 align_kind : AlignKind ,
@@ -281,7 +284,7 @@ fn parse_alignment<S: Stage>(
281284}
282285
283286fn parse_alignment_or_const_path < S : Stage > (
284- cx : & AcceptContext < ' _ , ' _ , S > ,
287+ cx : & mut AcceptContext < ' _ , ' _ , S > ,
285288 arg : & MetaItemOrLitParser ,
286289 attr_name : & ' static str ,
287290) -> Result < AttrIntValue , AlignmentParseError > {
@@ -299,10 +302,15 @@ fn parse_alignment_or_const_path<S: Stage>(
299302 return Err ( AlignmentParseError :: Message ( "not an unsuffixed integer" . to_string ( ) ) ) ;
300303 }
301304
302- if let Some ( features) = cx. features_option ( )
303- && !features. const_attr_paths ( )
304- && !meta. span ( ) . allows_unstable ( sym:: const_attr_paths)
305- {
305+ let path_span = meta. path ( ) . span ( ) ;
306+ let feature_enabled = cx. features_option ( ) . is_some_and ( |features| features. const_attr_paths ( ) )
307+ || path_span. allows_unstable ( sym:: const_attr_paths) ;
308+
309+ if !feature_enabled {
310+ if matches ! ( cx. stage. should_emit( ) , ShouldEmit :: Nothing ) {
311+ return Ok ( AttrIntValue :: Lit ( 1 ) ) ;
312+ }
313+
306314 feature_err (
307315 cx. sess ( ) ,
308316 sym:: const_attr_paths,
@@ -313,7 +321,9 @@ fn parse_alignment_or_const_path<S: Stage>(
313321 return Err ( AlignmentParseError :: AlreadyErrored ) ;
314322 }
315323
316- let Some ( resolution) = cx. attr_const_resolution ( meta. path ( ) . span ( ) ) else {
324+ cx. record_attr_resolution_request ( AttrResolutionKind :: Const , meta. path ( ) . 0 . clone ( ) ) ;
325+
326+ let Some ( resolution) = cx. attr_resolution ( AttrResolutionKind :: Const , path_span) else {
317327 // `parse_limited(sym::repr)` runs before lowering for callers that only care whether
318328 // `repr(packed(...))` exists at all.
319329 if matches ! ( cx. stage. should_emit( ) , ShouldEmit :: Nothing ) {
@@ -323,22 +333,18 @@ fn parse_alignment_or_const_path<S: Stage>(
323333 } ;
324334
325335 match resolution {
326- AttrConstResolved :: Resolved ( Res :: Def ( DefKind :: Const { .. } , def_id) ) => {
327- Ok ( AttrIntValue :: Const { def_id, span : meta . path ( ) . span ( ) } )
336+ AttrResolved :: Resolved ( Res :: Def ( DefKind :: Const { .. } , def_id) ) => {
337+ Ok ( AttrIntValue :: Const { def_id, span : path_span } )
328338 }
329- AttrConstResolved :: Resolved ( Res :: Def ( DefKind :: ConstParam , _) ) => {
330- cx. emit_err ( AttrConstGenericNotSupported { span : meta . path ( ) . span ( ) , attr_name } ) ;
339+ AttrResolved :: Resolved ( Res :: Def ( DefKind :: ConstParam , _) ) => {
340+ cx. emit_err ( AttrConstGenericNotSupported { span : path_span , attr_name } ) ;
331341 Err ( AlignmentParseError :: AlreadyErrored )
332342 }
333- AttrConstResolved :: Resolved ( res) => {
334- cx. emit_err ( AttrConstPathNotConst {
335- span : meta. path ( ) . span ( ) ,
336- attr_name,
337- thing : res. descr ( ) ,
338- } ) ;
343+ AttrResolved :: Resolved ( res) => {
344+ cx. emit_err ( AttrConstPathNotConst { span : path_span, attr_name, thing : res. descr ( ) } ) ;
339345 Err ( AlignmentParseError :: AlreadyErrored )
340346 }
341- AttrConstResolved :: Error => Err ( AlignmentParseError :: AlreadyErrored ) ,
347+ AttrResolved :: Error => Err ( AlignmentParseError :: AlreadyErrored ) ,
342348 }
343349}
344350
0 commit comments