rust-lang / rust-lang/rust

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

Open
#155,118 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-cfg A-check-cfg C-bug T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I ran into this issue when trying to disable ASAN instrumentation, without breaking stable users (in an attempt to fix https://github.com/dtolnay/inventory/issues/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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the two Rust examples showing how #[cfg_attr] interacts with #[allow(unexpected_cfgs)]. The issue names no files or tests, so investigate the compiler's handling of these attributes and define a resolution that lets macro-generated cfg_attr avoid requiring users to silence the lint.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.