Skip to content

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

Open
@joshka

Description

@joshka

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 #132166
Possibly relevant to #129183

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-cfgArea: `cfg` conditional compilationA-diagnosticsArea: Messages for errors, warnings, and lintsA-resolveArea: Name/path resolution done by `rustc_resolve` specificallyD-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions