Skip to content

Commit 3a3a21a

Browse files
committed
implement rustc_force_inline parser
1 parent 518893c commit 3a3a21a

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ pub enum AttributeKind {
192192
Inline(InlineAttr, Span),
193193
MacroTransparency(Transparency),
194194
Repr(ThinVec<(ReprAttr, Span)>),
195+
RustcForceInline(Span, Option<Symbol>),
195196
Stability {
196197
stability: Stability,
197198
/// Span of the `#[stable(...)]` or `#[unstable(...)]` attribute

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// FIXME(jdonszelmann): merge these two parsers and error when both attributes are present here.
2+
// note: need to model better how duplicate attr errors work when not using
3+
// SingleAttributeParser which is what we have two of here.
4+
15
use rustc_attr_data_structures::{AttributeKind, InlineAttr};
26
use rustc_errors::{E0534, E0535, struct_span_code_err};
37
use rustc_span::sym;
@@ -6,6 +10,7 @@ use super::{AcceptContext, AttributeOrder, OnDuplicate};
610
use crate::attributes::SingleAttributeParser;
711
use crate::context::Stage;
812
use crate::parser::ArgParser;
13+
use crate::session_diagnostics::IncorrectMetaItem;
914

1015
pub(crate) struct InlineParser;
1116

@@ -47,3 +52,37 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
4752
}
4853
}
4954
}
55+
56+
pub(crate) struct RustcForceInlineParser;
57+
58+
impl<S: Stage> SingleAttributeParser<S> for RustcForceInlineParser {
59+
const PATH: &'static [rustc_span::Symbol] = &[sym::rustc_force_inline];
60+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
61+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
62+
63+
fn convert(cx: &AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
64+
let reason = match args {
65+
ArgParser::NoArgs => None,
66+
ArgParser::List(list) => {
67+
cx.emit_err(IncorrectMetaItem {
68+
span: list.span,
69+
suggestion: None,
70+
});
71+
return None
72+
}
73+
ArgParser::NameValue(v) => {
74+
let Some(str) = v.value_as_str() else {
75+
cx.emit_err(IncorrectMetaItem {
76+
span: v.value_span,
77+
suggestion: None,
78+
});
79+
return None;
80+
};
81+
82+
Some(str)
83+
}
84+
};
85+
86+
Some(AttributeKind::Inline(InlineAttr::Force { attr_span: cx.attr_span, reason }, cx.attr_span))
87+
}
88+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1919
use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
2020
use crate::attributes::confusables::ConfusablesParser;
2121
use crate::attributes::deprecation::DeprecationParser;
22-
use crate::attributes::inline::InlineParser;
22+
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
2323
use crate::attributes::repr::ReprParser;
2424
use crate::attributes::stability::{
2525
BodyStabilityParser, ConstStabilityIndirectParser, ConstStabilityParser, StabilityParser,
@@ -106,6 +106,7 @@ attribute_groups!(
106106
Single<ConstStabilityIndirectParser>,
107107
Single<DeprecationParser>,
108108
Single<InlineParser>,
109+
Single<RustcForceInlineParser>,
109110
Single<TransparencyParser>,
110111
// tidy-alphabetical-end
111112
];

0 commit comments

Comments
 (0)