Skip to content

Commit c04e4db

Browse files
authored
Merge pull request #596 from yutannihilation/fix/allow-unsafe-wrap-rust2024
fix(coretex-m-rt-macros): Allow `#[unsafe(link_section = )]` for Rust 2024 edition
2 parents c3d664b + 6f74865 commit c04e4db

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

cortex-m-rt/macros/src/lib.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,8 @@ fn check_attr_whitelist(attrs: &[Attribute], caller: WhiteListCaller) -> Result<
755755
];
756756

757757
'o: for attr in attrs {
758-
for val in whitelist {
759-
if eq(attr, val) {
758+
if let Some(attr_name) = get_attr_name(attr) {
759+
if whitelist.contains(&attr_name.as_str()) {
760760
continue 'o;
761761
}
762762
}
@@ -786,3 +786,24 @@ fn check_attr_whitelist(attrs: &[Attribute], caller: WhiteListCaller) -> Result<
786786
fn eq(attr: &Attribute, name: &str) -> bool {
787787
attr.style == AttrStyle::Outer && attr.path().is_ident(name)
788788
}
789+
790+
fn get_attr_name(attr: &Attribute) -> Option<String> {
791+
if !matches!(attr.style, AttrStyle::Outer) {
792+
return None;
793+
}
794+
795+
let name = attr.path().get_ident().map(|x| x.to_string());
796+
797+
// In Rust 2024 edition, link_section attribute must be marked as unsafe.
798+
// So, in the case, check the inner content of `#[unsafe(...)]`.
799+
match &name {
800+
Some(name) if name == "unsafe" => {
801+
if let Ok(inner_meta) = attr.parse_args::<syn::Meta>() {
802+
inner_meta.path().get_ident().map(|x| x.to_string())
803+
} else {
804+
None
805+
}
806+
}
807+
_ => name,
808+
}
809+
}

0 commit comments

Comments
 (0)