Skip to content

#![cfg_attr] doesn't work for crate-level attributes #25347

Closed
@lilyball

Description

@lilyball

The #[cfg_attr] attribute doesn't work correctly for crate-level attributes. It seems to work in other cases as an inner attribute, but for crate-level attributes it yields the same warning that you'd see if you used the crate attribute on a non-root module:

#![cfg_attr(foo, crate_type="lib")]

fn main() {}

When compiled with rustc --cfg foo:

unnamed.rs:1:18: 1:35 warning: unused attribute, #[warn(unused_attributes)] on by default
unnamed.rs:1 #![cfg_attr(foo, crate_type="lib")]
                              ^~~~~~~~~~~~~~~~~
unnamed.rs:1:18: 1:35 warning: crate-level attribute should be in the root module, #[warn(unused_attributes)] on by default
unnamed.rs:1 #![cfg_attr(foo, crate_type="lib")]
                              ^~~~~~~~~~~~~~~~~

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-attributesArea: Attributes (`#[…]`, `#![…]`)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions