Skip to content

Add ide-assist: convert_attr_cfg_to_if #20416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

A4-Tacks
Copy link
Contributor

@A4-Tacks A4-Tacks commented Aug 9, 2025

Close #20274

Convert #[cfg(...)] {} to if cfg!(...) {}.

fn foo() {
    $0#[cfg(feature = "foo")]
    {
        let _x = 2;
    }
}

->

fn foo() {
    if cfg!(feature = "foo") {
        let _x = 2;
    }
}

Convert if cfg!(...) {} to #[cfg(...)] {}.

fn foo() {
    $0if cfg!(feature = "foo") {
        let _x = 2;
    }
}

->

fn foo() {
    #[cfg(feature = "foo")]
    {
        let _x = 2;
    }
}

Convert `#[cfg(...)] {}` to `if cfg!(...) {}`.

```rust
fn foo() {
    $0#[cfg(feature = "foo")]
    {
        let _x = 2;
    }
}
```
->
```rust
fn foo() {
    if cfg!(feature = "foo") {
        let _x = 2;
    }
}
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 9, 2025
@A4-Tacks A4-Tacks force-pushed the conv-cfg-attr-to-if branch from 2d81b62 to 2d8b429 Compare August 11, 2025 15:39
```rust
fn foo() {
    if $0cfg!(feature = "foo") {
        let _x = 2;
    }
}
```
->
```rust
fn foo() {
    #[cfg(feature = "foo")]
    {
        let _x = 2;
    }
}
```
@A4-Tacks A4-Tacks force-pushed the conv-cfg-attr-to-if branch from 2d8b429 to f2ba087 Compare August 11, 2025 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Action to rewrite #[cfg()] as if cfg!()
2 participants