|
1 | 1 | use rustc_abi::Align; |
2 | 2 | use rustc_ast::{IntTy, LitIntType, LitKind, UintTy}; |
3 | | -use rustc_attr_data_structures::{AttributeKind, IntType, ReprAttr}; |
| 3 | +use rustc_attr_data_structures::{AttributeKind, IntType, ReprAttr, ScalableElt}; |
4 | 4 | use rustc_feature::{AttributeTemplate, template}; |
5 | 5 | use rustc_span::{DUMMY_SP, Span, Symbol, sym}; |
6 | 6 |
|
@@ -144,6 +144,11 @@ fn parse_repr<S: Stage>( |
144 | 144 | (Some(sym::Rust), ArgParser::NoArgs) => Some(ReprRust), |
145 | 145 | (Some(sym::C), ArgParser::NoArgs) => Some(ReprC), |
146 | 146 | (Some(sym::simd), ArgParser::NoArgs) => Some(ReprSimd), |
| 147 | + (Some(sym::scalable), ArgParser::List(l)) => parse_repr_scalable(cx, l, param.span()), |
| 148 | + (Some(sym::scalable), ArgParser::NoArgs) => { |
| 149 | + cx.emit_err(session_diagnostics::ScalableAttrMissingN { span: param.span() }); |
| 150 | + None |
| 151 | + } |
147 | 152 | (Some(sym::transparent), ArgParser::NoArgs) => Some(ReprTransparent), |
148 | 153 | (Some(name @ int_pat!()), ArgParser::NoArgs) => { |
149 | 154 | // int_pat!() should make sure it always parses |
@@ -322,3 +327,18 @@ impl<S: Stage> AttributeParser<S> for AlignParser { |
322 | 327 | Some(AttributeKind::Align { align, span }) |
323 | 328 | } |
324 | 329 | } |
| 330 | + |
| 331 | +fn parse_repr_scalable<S: Stage>( |
| 332 | + cx: &AcceptContext<'_, '_, S>, |
| 333 | + list: &MetaItemListParser<'_>, |
| 334 | + span: Span, |
| 335 | +) -> Option<ReprAttr> { |
| 336 | + let Some(LitKind::Int(literal, LitIntType::Unsuffixed)) = |
| 337 | + list.single().and_then(|elt| elt.lit()).map(|lit| lit.kind) |
| 338 | + else { |
| 339 | + cx.emit_err(session_diagnostics::ScalableAttrMissingN { span }); |
| 340 | + return None; |
| 341 | + }; |
| 342 | + |
| 343 | + literal.get().try_into().ok().map(|elt| ReprAttr::ReprScalable(ScalableElt { elt })) |
| 344 | +} |
0 commit comments