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+
15use rustc_attr_data_structures:: { AttributeKind , InlineAttr } ;
26use rustc_errors:: { E0534 , E0535 , struct_span_code_err} ;
37use rustc_span:: sym;
@@ -6,6 +10,7 @@ use super::{AcceptContext, AttributeOrder, OnDuplicate};
610use crate :: attributes:: SingleAttributeParser ;
711use crate :: context:: Stage ;
812use crate :: parser:: ArgParser ;
13+ use crate :: session_diagnostics:: IncorrectMetaItem ;
914
1015pub ( 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+ }
0 commit comments