|
| 1 | +use rustc_attr_data_structures::{AttributeKind, InlineAttr}; |
| 2 | +use rustc_errors::{E0534, E0535, struct_span_code_err}; |
1 | 3 | use rustc_span::sym;
|
2 | 4 |
|
| 5 | +use super::{AcceptContext, AttributeOrder, OnDuplicate}; |
3 | 6 | use crate::attributes::SingleAttributeParser;
|
| 7 | +use crate::context::Stage; |
| 8 | +use crate::parser::ArgParser; |
4 | 9 |
|
5 | 10 | pub(crate) struct InlineParser;
|
6 | 11 |
|
7 |
| -impl SingleAttributeParser for InlineParser { |
| 12 | +impl<S: Stage> SingleAttributeParser<S> for InlineParser { |
8 | 13 | const PATH: &'static [rustc_span::Symbol] = &[sym::inline];
|
| 14 | + const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast; |
| 15 | + const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError; |
9 | 16 |
|
10 |
| - fn on_duplicate(cx: &super::AcceptContext<'_>, first_span: rustc_span::Span) { |
11 |
| - todo!() |
12 |
| - } |
| 17 | + fn convert(cx: &AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { |
| 18 | + match args { |
| 19 | + ArgParser::NoArgs => Some(AttributeKind::Inline(InlineAttr::Hint, cx.attr_span)), |
| 20 | + ArgParser::List(list) => { |
| 21 | + let Some(l) = list.single() else { |
| 22 | + struct_span_code_err!(cx.dcx(), cx.attr_span, E0534, "expected one argument") |
| 23 | + .emit(); |
| 24 | + return None; |
| 25 | + }; |
13 | 26 |
|
14 |
| - fn convert(cx: &super::AcceptContext<'_>, args: &crate::parser::ArgParser<'_>) -> Option<rustc_attr_data_structures::AttributeKind> { |
15 |
| - todo!() |
| 27 | + match l.meta_item().and_then(|i| i.word_without_args().map(|i| i.name)) { |
| 28 | + Some(sym::always) => { |
| 29 | + Some(AttributeKind::Inline(InlineAttr::Always, cx.attr_span)) |
| 30 | + } |
| 31 | + Some(sym::never) => { |
| 32 | + Some(AttributeKind::Inline(InlineAttr::Never, cx.attr_span)) |
| 33 | + } |
| 34 | + _ => { |
| 35 | + struct_span_code_err!(cx.dcx(), l.span(), E0535, "invalid argument") |
| 36 | + .with_help("valid inline arguments are `always` and `never`") |
| 37 | + .emit(); |
| 38 | + return None; |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + ArgParser::NameValue(_) => { |
| 43 | + // silently ignored, we warn somewhere else. |
| 44 | + // FIXME(jdonszelmann): that warning *should* go here. |
| 45 | + None |
| 46 | + } |
| 47 | + } |
16 | 48 | }
|
17 | 49 | }
|
0 commit comments