Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cfg resolve diagnostic doesn't show up for axum macro #134448

Open
joshka opened this issue Dec 18, 2024 · 1 comment
Open

cfg resolve diagnostic doesn't show up for axum macro #134448

joshka opened this issue Dec 18, 2024 · 1 comment
Labels
A-cfg Area: `cfg` conditional compilation A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@joshka
Copy link
Contributor

joshka commented Dec 18, 2024

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

@joshka joshka added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 18, 2024
@fmease fmease added A-resolve Area: Name/path resolution done by `rustc_resolve` specifically A-cfg Area: `cfg` conditional compilation D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Dec 18, 2024
@Noratrieb
Copy link
Member

I think this is caused by an entirely different root cause and the duplicate name is a red herring, it shouldn't matter to resolve whether there's an item of the same name already in a different namespace.
I remember this working correctly for serde, which uses the same pattern.

@Noratrieb Noratrieb changed the title Detect cfg'd out items where they share a name with another item (e.g. macro + trait) cfg resolve diagnostic doesn't show up for axum macro Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cfg Area: `cfg` conditional compilation A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants