about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
diff options
context:
space:
mode:
authorDavid Wood <david.wood2@arm.com>2024-12-10 12:05:24 +0000
committerDavid Wood <david.wood2@arm.com>2025-01-10 18:37:55 +0000
commit02d423cd24944b17783e9fa4062e6a4e8e4d351f (patch)
treed036e502c6cb5b8ebcef6783f75a55a50354556f /compiler/rustc_codegen_ssa/src
parentf86169a58f212b174a01aa721545df009e96bfda (diff)
downloadrust-02d423cd24944b17783e9fa4062e6a4e8e4d351f.tar.gz
rust-02d423cd24944b17783e9fa4062e6a4e8e4d351f.zip
codegen_attrs: force inlining takes precedence
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
-rw-r--r--compiler/rustc_codegen_ssa/src/codegen_attrs.rs61
1 files changed, 33 insertions, 28 deletions
diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
index d8f62d543ad..a78826a4629 100644
--- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
+++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
@@ -523,41 +523,46 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
     mixed_export_name_no_mangle_lint_state.lint_if_mixed(tcx);
 
     codegen_fn_attrs.inline = attrs.iter().fold(InlineAttr::None, |ia, attr| {
-        if attr.has_name(sym::inline) {
-            if attr.is_word() {
-                InlineAttr::Hint
-            } else if let Some(ref items) = attr.meta_item_list() {
-                inline_span = Some(attr.span);
-                if items.len() != 1 {
-                    struct_span_code_err!(tcx.dcx(), attr.span, E0534, "expected one argument").emit();
-                    InlineAttr::None
-                } else if list_contains_name(items, sym::always) {
-                    InlineAttr::Always
-                } else if list_contains_name(items, sym::never) {
-                    InlineAttr::Never
-                } else {
-                    struct_span_code_err!(tcx.dcx(), items[0].span(), E0535, "invalid argument")
-                        .with_help("valid inline arguments are `always` and `never`")
-                        .emit();
+        if !attr.has_name(sym::inline) {
+            return ia;
+        }
 
-                    InlineAttr::None
-                }
-            } else {
-                ia
-            }
-        } else if attr.has_name(sym::rustc_force_inline) && tcx.features().rustc_attrs() {
-            if attr.is_word() {
-                InlineAttr::Force { attr_span: attr.span, reason: None }
-            } else if let Some(val) = attr.value_str() {
-                InlineAttr::Force { attr_span: attr.span, reason: Some(val) }
+        if attr.is_word() {
+            InlineAttr::Hint
+        } else if let Some(ref items) = attr.meta_item_list() {
+            inline_span = Some(attr.span);
+            if items.len() != 1 {
+                struct_span_code_err!(tcx.dcx(), attr.span, E0534, "expected one argument").emit();
+                InlineAttr::None
+            } else if list_contains_name(items, sym::always) {
+                InlineAttr::Always
+            } else if list_contains_name(items, sym::never) {
+                InlineAttr::Never
             } else {
-                debug!("`rustc_force_inline` not checked by attribute validation");
-                ia
+                struct_span_code_err!(tcx.dcx(), items[0].span(), E0535, "invalid argument")
+                    .with_help("valid inline arguments are `always` and `never`")
+                    .emit();
+
+                InlineAttr::None
             }
         } else {
             ia
         }
     });
+    codegen_fn_attrs.inline = attrs.iter().fold(codegen_fn_attrs.inline, |ia, attr| {
+        if !attr.has_name(sym::rustc_force_inline) || !tcx.features().rustc_attrs() {
+            return ia;
+        }
+
+        if attr.is_word() {
+            InlineAttr::Force { attr_span: attr.span, reason: None }
+        } else if let Some(val) = attr.value_str() {
+            InlineAttr::Force { attr_span: attr.span, reason: Some(val) }
+        } else {
+            debug!("`rustc_force_inline` not checked by attribute validation");
+            ia
+        }
+    });
 
     // naked function MUST NOT be inlined! This attribute is required for the rust compiler itself,
     // but not for the code generation backend because at that point the naked function will just be