cfg resolve diagnostic doesn't show up for derive macro that matches trait name
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
Without the macro feature enabled.
use axum::extract::FromRef;
#[derive(Clone, FromRef)]
struct AppState {
db: SqlitePool,
}
Current output
error: cannot find derive macro `FromRef` in this scope
--> src/main.rs:33:17
|
33 | #[derive(Clone, FromRef)]
| ^^^^^^^
|
note: `FromRef` is imported here, but it is only a trait, without a derive macro
--> src/main.rs:1:12
|
1 | use axum::{extract::FromRef, Router};
| ^^^^^^^^^^^^^^^^
Desired output
error[E0432]: unresolved import `axum::extract::FromRef`
--> src/main.rs:2:5
|
2 | use axum::extract::FromRef;
| ^^^^^^^^^^^^^^^^^ no `FromRef` in `extract`
|
note: found an item that was configured out
--> /Users/joshka/.cargo/registry/src/index.crates.io-6f17d22bba15001f/axum-0.7.9/src/extract/mod.rs:xx:yy
|
xx | macro_rules! FromRef;
| ^^
note: the item is gated behind the `macros` feature
--> /Users/joshka/.cargo/registry/src/index.crates.io-6f17d22bba15001f/axum-0.7.9/src/extract/mod.rs:xx:yy
Rationale and extra context
The detection of cfg'd out items should treat items that match the expected type (e.g. a macro) as higher priority than items which match the name (e.g. FromRef)
Other cases
Rust Version
rustc --version --verbose
rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: aarch64-apple-darwin
release: 1.83.0
LLVM version: 19.1.1
Anything else?
Similar to but not the same as https://github.com/rust-lang/rust/issues/132166
Possibly relevant to https://github.com/rust-lang/rust/pull/129183
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
Reproduce the diagnostic with the axum FromRef example and Rust 1.83.0, then compare the behavior with the related issues #132166 and pull request #129183. Trace cfg'd-out item detection for a derive macro versus a same-named trait; done means the macro is prioritized and the diagnostic reports the missing macros feature.
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
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100