Can't build and run rust application using cargo

I'm just getting started with Rust, and I wanna build and run 'Hello-Rust' demo created by cargo new hello-rust.

but errors happened as follows:

$HOME/.cargo/bin/cargo metadata --verbose --format-version 1 --all-features --filter-platform aarch64-apple-darwin
stdout : error: failed to parse the cfg from rustc --print=cfg, got:


lib___.rlib
lib___.dylib
lib___.dylib
lib___.a
lib___.dylib
$HOME/.rustup/toolchains/stable-aarch64-apple-darwin
off
packed
unpacked


debug_assertions
panic="unwind"
proc_macro
target_arch="aarch64"
target_endian="little"
target_env=""
target_family="unix"
target_feature="aes"
target_feature="crc"
target_feature="dit"
target_feature="dotprod"
target_feature="dpb"
target_feature="dpb2"
target_feature="fcma"
target_feature="fhm"
target_feature="flagm"
target_feature="fp16"
target_feature="frintts"
target_feature="jsconv"
target_feature="lor"
target_feature="lse"
target_feature="neon"
target_feature="paca"
target_feature="pacg"
target_feature="pan"
target_feature="pmuv3"
target_feature="ras"
target_feature="rcpc"
target_feature="rcpc2"
target_feature="rdm"
target_feature="sb"
target_feature="sha2"
target_feature="sha3"
target_feature="ssbs"
target_feature="vh"
target_has_atomic="128"
target_has_atomic="16"
target_has_atomic="32"
target_has_atomic="64"
target_has_atomic="8"
target_has_atomic="ptr"
target_os="macOS"
target_pointer_width="64"
target_vendor="apple"
unix

Caused by:
failed to parse `` as a cfg expression: expected identifier, but cfg expression ended

stderr :

I installed rust by curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh and did nothing except checking the version by cargo -V & rustc -V.

my rustc,cargo version is 1.71.0, and my OS version is MacOS13.4

do you have other installations of rust (e.g. from brew or nix or the like)? make sure you have only installed rust toolchain through rustup.

you can check the output of the commands:

$ which rustc
$ rustup which rustc

if they differ, you must uninstall the other rust toolchains.

Thanks for ur reply. Actually these two paths are different.

which rustc print ~/.cargo/bin/rustc
but rustup which rustc print ~/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc

However, I believe I never installed any other rust. I tried to uninstall and remove all the paths rust has created, but it didn't work when I installed it again. These two paths would be added when rust installed.

that's fine, the first is a link to the second.

there's some unexpected output from rustc, specifically, these lines looks suspicious.

___
lib___.rlib
lib___.dylib
lib___.dylib
lib___.a
lib___.dylib
/Users/xiachuantao/.rustup/toolchains/stable-aarch64-apple-darwin
$HOME/.rustup/toolchains/stable-aarch64-apple-darwin
off
packed
unpacked
___

are you running cargo run from shell directly, or are you using some editor's plugins (e.g. neovim lsp)? your log message contains this command line, which seems generated by a text editor or IDE.

I got same result from macOS basic shell, homebrew shell and CLion(IDE) and it just like what I posted.
By the way, I also tried on my Windows PC with the same installation steps and made it :upside_down_face:.

it's a strange bug, I suggest you report this to cargo. this is such a bad out-of-the-box experience for those who are just started to learn rust.

I will and sorry to waste your time, thx.