Environment variable `CARGO_PKG_VERSION` not defined

in a rust hello world project, I used

    let version = env!("CARGO_PKG_VERSION");
    print!("{}", version);

cargo run fails with:

error: linking with x86_64-w64-mingw32-gcc failed: exit code: 1

and rustc error is:

{"message":"environment variable CARGO_PKG_VERSION not defined","code":null,"l

Then I replaced CARGO_PKG_VERSION with CARGO or CARGO_PKG_LICENSE_FILE, rustc error is:

{"message":"unknown codegen option: 'incremental","code":null,"level":"error"

cargo version is
cargo 1.51.0 (43b129a20 2021-03-16)

That sounds like a bug. Can you create a ticket against the rust-lang/cargo repo if one doesn't already exists?