Skip to content

Macros can't hide unsafety because of unused-unsafe #8472

Closed
@bblum

Description

@bblum

Consider the following.

macro_rules! foo(
        () => {
            unsafe { use std::cast; let () = cast::transmute(()); }
        }   
)
fn main() {
    unsafe { foo!(); }
    foo!();
}

This only does not emit a warning if the first line of code in main is removed. It would be nice to be able to squelch the unused unsafe warning that appears on the first invocation of foo!(), whether automatically or by being able to use #[allow(unused_unsafe)] inside the macro definition.

A workaround is to define a function in the macro that hides the unsafety and to call it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-syntaxextArea: Syntax extensions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions