Differentiate between asm!(), global_asm!() and naked_asm!(), and make only asm!() unsafe

This commit is contained in:
Chayim Refael Friedman 2025-07-09 17:37:27 +03:00
parent edb804a100
commit bd8087e86e
16 changed files with 198 additions and 16 deletions

View file

@ -3220,7 +3220,8 @@ impl Macro {
}
}
pub fn is_asm_or_global_asm(&self, db: &dyn HirDatabase) -> bool {
/// Is this `asm!()`, or a variant of it (e.g. `global_asm!()`)?
pub fn is_asm_like(&self, db: &dyn HirDatabase) -> bool {
match self.id {
MacroId::Macro2Id(it) => {
matches!(it.lookup(db).expander, MacroExpander::BuiltIn(m) if m.is_asm())

View file

@ -1776,7 +1776,7 @@ impl<'db> SemanticsImpl<'db> {
pub fn is_unsafe_macro_call(&self, macro_call: &ast::MacroCall) -> bool {
let Some(mac) = self.resolve_macro_call(macro_call) else { return false };
if mac.is_asm_or_global_asm(self.db) {
if mac.is_asm_like(self.db) {
return true;
}