From f61febf7a4526b35d43626d9d363de21f8d33fd9 Mon Sep 17 00:00:00 2001 From: Oleksandr Babak Date: Sun, 13 Apr 2025 21:16:16 +0200 Subject: [PATCH] fix: in edition 2024 `link_section` is used as `unsafe(link_section = ...)` --- rtic-macros/src/codegen/local_resources.rs | 17 +++++++++++++---- rtic-macros/src/codegen/shared_resources.rs | 17 +++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/rtic-macros/src/codegen/local_resources.rs b/rtic-macros/src/codegen/local_resources.rs index c73ad56d6ed..86dda8626b3 100644 --- a/rtic-macros/src/codegen/local_resources.rs +++ b/rtic-macros/src/codegen/local_resources.rs @@ -19,10 +19,19 @@ pub fn codegen(app: &App, _analysis: &Analysis) -> TokenStream2 { // late resources in `util::link_section_uninit` // unless user specifies custom link section - let section = if attrs - .iter() - .any(|attr| attr.path().is_ident("link_section")) - { + let section = if attrs.iter().any(|attr| { + let is_link_section = attr.path().is_ident("link_section"); + let is_unsafe = attr.path().is_ident("unsafe"); + let is_embedded_link_section = match attr.parse_args() { + Ok(syn::Expr::Assign(assign)) => match &*assign.left { + syn::Expr::Path(path) => path.path.is_ident("link_section"), + _ => false, + }, + _ => false, + }; + + is_link_section || (is_unsafe && is_embedded_link_section) + }) { None } else { Some(util::link_section_uninit()) diff --git a/rtic-macros/src/codegen/shared_resources.rs b/rtic-macros/src/codegen/shared_resources.rs index d89f0c24e70..5e8ca9ae77c 100644 --- a/rtic-macros/src/codegen/shared_resources.rs +++ b/rtic-macros/src/codegen/shared_resources.rs @@ -19,10 +19,19 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { // late resources in `util::link_section_uninit` // unless user specifies custom link section - let section = if attrs - .iter() - .any(|attr| attr.path().is_ident("link_section")) - { + let section = if attrs.iter().any(|attr| { + let is_link_section = attr.path().is_ident("link_section"); + let is_unsafe = attr.path().is_ident("unsafe"); + let is_embedded_link_section = match attr.parse_args() { + Ok(syn::Expr::Assign(assign)) => match &*assign.left { + syn::Expr::Path(path) => path.path.is_ident("link_section"), + _ => false, + }, + _ => false, + }; + + is_link_section || (is_unsafe && is_embedded_link_section) + }) { None } else { Some(util::link_section_uninit())