Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions cortex-m-rt/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,8 @@ fn check_attr_whitelist(attrs: &[Attribute], caller: WhiteListCaller) -> Result<
];

'o: for attr in attrs {
for val in whitelist {
if eq(attr, val) {
if let Some(attr_name) = get_attr_name(attr) {
if whitelist.contains(&attr_name.as_str()) {
continue 'o;
}
}
Expand Down Expand Up @@ -786,3 +786,24 @@ fn check_attr_whitelist(attrs: &[Attribute], caller: WhiteListCaller) -> Result<
fn eq(attr: &Attribute, name: &str) -> bool {
attr.style == AttrStyle::Outer && attr.path().is_ident(name)
}

fn get_attr_name(attr: &Attribute) -> Option<String> {
if !matches!(attr.style, AttrStyle::Outer) {
return None;
}

let name = attr.path().get_ident().map(|x| x.to_string());

// In Rust 2024 edition, link_section attribute must be marked as unsafe.
// So, in the case, check the inner content of `#[unsafe(...)]`.
match &name {
Some(name) if name == "unsafe" => {
if let Ok(inner_meta) = attr.parse_args::<syn::Meta>() {
inner_meta.path().get_ident().map(|x| x.to_string())
} else {
None
}
}
_ => name,
}
}