Skip to content

#[cfg_attr] and #[allow(unexpected_cfgs)] do not interact well #155118

@Urgau

Description

@Urgau

I ran into this issue when trying to disable ASAN instrumentation, without breaking stable users (in an attempt to fix dtolnay/inventory#90). Since ASAN is unstable, and detecting if ASAN is enabled is also unstable, the easiest solution is to require users to set a custom cfg.

#[allow(unexpected_cfgs)]
#[cfg_attr(asan, sanitize(address = "off"))]
static MY_ITEM: () = ();
mod my_mod {
    #![allow(unexpected_cfgs)]

    #[cfg_attr(asan, sanitize(address = "off"))]
    static MY_ITEM: () = ();
}

The code in question is intended to be generated by a macro in user crates, so requiring all (existing) users to silence the lint, just so that ASAN works again is maybe too much to ask and it would be preferable if the macro could silence the lint, but it appears there is no way to do that.

Originally posted by @jschwe in #124735

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cfgArea: `cfg` conditional compilationC-bugCategory: This is a bug.F-check-cfg--check-cfgT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions