summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorStuart Cook <Zalathar@users.noreply.github.com>2025-07-31 15:42:01 +1000
committerGitHub <noreply@github.com>2025-07-31 15:42:01 +1000
commit45169cbf38ed1ad68b2df83a53ff3f71ca815590 (patch)
tree28cb5f384be73edaf8aef09d1460c9b28257925b /compiler
parent5c123c25e36121730634aa59f8a66a5469d4d73f (diff)
parent3fe0e2435665f857c11acbbd91a063f5a3c8d79d (diff)
downloadrust-45169cbf38ed1ad68b2df83a53ff3f71ca815590.tar.gz
rust-45169cbf38ed1ad68b2df83a53ff3f71ca815590.zip
Rollup merge of #144685 - jdonszelmann:lang-items-once, r=wafflelapkin
Only extract lang items once in codegen_fn_attrs

This one should be obvious. These two extraction points used to be far apart but now that they're refactored to be close it was rather obvious we're just doing double work....

r? ``@WaffleLapkin``

Buils on rust-lang/rust#144655
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_codegen_ssa/src/codegen_attrs.rs8
1 files changed, 3 insertions, 5 deletions
diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
index 5c54bce6e03..78edc69b237 100644
--- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
+++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs
@@ -527,14 +527,14 @@ fn handle_lang_items(
     attrs: &[Attribute],
     codegen_fn_attrs: &mut CodegenFnAttrs,
 ) {
+    let lang_item = lang_items::extract(attrs).and_then(|(name, _)| LangItem::from_name(name));
+
     // Weak lang items have the same semantics as "std internal" symbols in the
     // sense that they're preserved through all our LTO passes and only
     // strippable by the linker.
     //
     // Additionally weak lang items have predetermined symbol names.
-    if let Some((name, _)) = lang_items::extract(attrs)
-        && let Some(lang_item) = LangItem::from_name(name)
-    {
+    if let Some(lang_item) = lang_item {
         if WEAK_LANG_ITEMS.contains(&lang_item) {
             codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL;
         }
@@ -548,8 +548,6 @@ fn handle_lang_items(
     if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL)
         && codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE)
     {
-        let lang_item =
-            lang_items::extract(attrs).map_or(None, |(name, _span)| LangItem::from_name(name));
         let mut err = tcx
             .dcx()
             .struct_span_err(