rust-lang / rust-lang/rust-analyzer
`#[cfg_attr(..., path = "submod_gated.rs")] mod submod;` makes RA recognize submod_gated.rs, discarding cfg_attr and submod.rs
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal reproduction in src/main.rs, src/submod.rs, src/submod_gated.rs, and Cargo.toml, then reproduce the behavior with the gated feature disabled and enabled. Trace rust-analyzer's module resolution for #[cfg_attr(..., path = ...)] and verify that cfg_attr is preserved, with submod.rs selected when gated is disabled and submod_gated.rs when it is enabled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100