Could you please clarify what you mean by that? Does the canister build when you run cargo?
My guess that it might be purely an IDE problem. I wonder if replacing #[pre_upgrade] with #[export_name = "canister_pre_upgrade"] and #[post_upgrade] with #[export_name = "canister_post_upgrade"] could help your IDE figure out what’s going on.
I believe this command tries to build a native binary from your canister code, which is not possible at the moment. Specifying the build target explicitly might resolve the issue:
If you use rustup, I also find it useful to add a toolchain file to the project (rust-toolchain.toml file living right next to Cargo.toml), this is how mine looks like:
This will tell cargo to use the right rustc version and target by default.
Is there some documentation / github reference on this issue?
I’m not sure it’s an issue of the Rust CDK, because as you mentioned, the build works fine. For some reason your IDE becomes confused about the code. Unfortunately, I don’t know much about IDEs, maybe some VSCode users could help you understanding the issue better.