Closed
Description
I'm using stable rustc 1.56.0 (09c42c458 2021-10-18)
and rust-analyzer v0.2.809
. I found that derive-macro-helper-attributes have to be placed before related derive-macros when using cfg_attr
. Otherwise, the rust-analyzer will generate red highlights indicating there exist errors.
The problem is related to cfg_attr
, I made a minimal example so that you can verify it locally.
// main.rs
#[cfg(feature = "use_kube_rs")]
use kube::CustomResource;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[cfg_attr(
feature = "use_kube_rs",
kube(group = "clux.dev", version = "v1", kind = "Foo", namespaced),
derive(CustomResource, Clone, Debug, Default, PartialEq, Deserialize, Serialize, JsonSchema)
)]
struct FooSpec {
info: String,
}
#[cfg_attr(
feature = "use_kube_rs",
derive(CustomResource, Clone, Debug, Default, PartialEq, Deserialize, Serialize, JsonSchema),
kube(group = "clux.dev", version = "v1", kind = "Bar", namespaced)
)]
struct BarSpec {
info: String,
}
fn main() {
println!("Hello, world!");
}
# Cargo.toml
[package]
name = "test_cfg_attr"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = ["use_kube_rs"]
use_kube_rs = ["kube", "k8s-openapi"]
[dependencies]
kube = {version="0.63.2", features = ["default","derive", "runtime"], optional=true}
k8s-openapi = {version="0.13.1", features = ["v1_22"], optional=true}
schemars = "0.8.6"
serde = { version = "1.0.126", features = ["derive"]}
serde_json = "1.0.64"
Here are screenshot for illustrations:
I'm not sure but it seems a bug...
Metadata
Metadata
Assignees
Labels
No labels