rust-lang / rust-lang/rust

cfg resolve diagnostic doesn't show up for derive macro that matches trait name

Open
#134,448 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-cfg A-diagnostics A-resolve D-newcomer-roadblock D-terse T-compiler
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.