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

Feature flags + derive macros produce an incorrect "no such field" warning #11661

Closed
alice-i-cecile opened this issue Mar 8, 2022 · 6 comments
Labels
A-macro macro expansion C-bug Category: bug

Comments

@alice-i-cecile
Copy link

rust-analyzer version: rust-analyzer version: 5fae65d 2022-03-07 stable

rustc version: rustc 1.60.0-nightly (bfe156467 2022-01-22)

relevant settings: None

Minimal reproducible example can be found here. The code compiles, both with and without the feature flag, but RA shows an error.

@jonas-schievink
Copy link
Contributor

Likely also caused by #8434

@ClementTsang
Copy link

ClementTsang commented Jun 12, 2023

I think this got worse recently - recent versions of RA have started to give me more warnings in this regard than I remember, at least for things involving #[cfg(target_os = "blah")].

For reference, this is a simplified version of what I'm writing which causes problems (this causes issues even on a brand new project with nothing else):

#[derive(Clone)]
pub struct Results {
    pub name: String,

    #[cfg(target_os = "windows")]
    pub windows_only_field: Option<String>,
}

giving:
image

This can kinda be worked around in some cases by just manually deriving, but then that leads to clippy complaining for things like manually deriving Default.

glehmann added a commit to glehmann/yage that referenced this issue Feb 18, 2024
this has several drawbacks that need to be addressed before going further on this:
* it needs rust nightly
* conditionally building the backtrace support makes rust-analyzer fail - see rust-lang/rust-analyzer#11661
* it will probably fail to display anything useful with the stripped binaries
@EluvK
Copy link

EluvK commented Mar 13, 2024

Confirmed in the latest pre-release version (v0.4.1879 2024-03-13). This issue is fixed, thx to #16789 👍

@acycliczebra
Copy link

Unfortunately I'm still running into this issue when I define my own custom derive macros with field attributes. I tried this both on v0.3.2129 and pre release v0.4.2128

@ChayimFriedman2
Copy link
Contributor

@acycliczebra Can you please open a new issue with a minimal reproducible example?

@acycliczebra
Copy link

New issue opened here: #18224

My minimal reproducible example gives out a slightly different error message, but it's fundamentally the same problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macro macro expansion C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

8 participants