Skip to content

fix(coretex-m-rt-macros): Allow #[unsafe(link_section = )] for Rust 2024 edition #596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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,
}
}