Skip to content

#[cfg_attr(..., path = "submod_gated.rs")] mod submod; makes RA recognize submod_gated.rs, discarding cfg_attr and submod.rs  #17371

Open
@zjp-CN

Description

@zjp-CN

rust-analyzer version: rust-analyzer 1.80.0-nightly (7c52d2d 2024-06-03)

rustc version: rustc 1.80.0-nightly (7c52d2db6 2024-06-03)

editor or extension: neovim

relevant settings: None

repository link (if public, optional): None. But I found the problem from embassy-executor. For reproducible code, see below.

code snippet to reproduce:

// src/main.rs
fn main() {
    submod::f();
}

#[cfg_attr(feature = "gated", path = "submod_gated.rs")]
mod submod;
// src/submod.rs
pub fn f() {
    println!("from submod.rs");
}
// src/submod_gated.rs
pub fn f() {
    println!("from submod_gated.rs");
}
# Cargo.toml
[features]
gated = []

Currently, RA marks submod.rs as file not included in crate hierarchy when gated feature is nowhere enabled, and treats submod_gated.rs as the default submod file, discarding cfg_attr.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions