fix: in edition 2024 link_section is used as unsafe(link_section = ...)

This commit is contained in:
Oleksandr Babak 2025-04-13 21:16:16 +02:00 committed by Emil Fresk
parent 2c7dec32e4
commit f61febf7a4
2 changed files with 26 additions and 8 deletions

View file

@ -19,10 +19,19 @@ pub fn codegen(app: &App, _analysis: &Analysis) -> TokenStream2 {
// late resources in `util::link_section_uninit` // late resources in `util::link_section_uninit`
// unless user specifies custom link section // unless user specifies custom link section
let section = if attrs let section = if attrs.iter().any(|attr| {
.iter() let is_link_section = attr.path().is_ident("link_section");
.any(|attr| 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 None
} else { } else {
Some(util::link_section_uninit()) Some(util::link_section_uninit())

View file

@ -19,10 +19,19 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
// late resources in `util::link_section_uninit` // late resources in `util::link_section_uninit`
// unless user specifies custom link section // unless user specifies custom link section
let section = if attrs let section = if attrs.iter().any(|attr| {
.iter() let is_link_section = attr.path().is_ident("link_section");
.any(|attr| 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 None
} else { } else {
Some(util::link_section_uninit()) Some(util::link_section_uninit())