Rust-analyzer -> "no targets specified in the manifest"

Hi. Current VS Code, rustup as it comes from Manjaro x64 (AUR) repository. Since rustup update today, (re)starting rust-analyzer fails, with both nightly and stable:

rust_analyzer::main_loop: FetchWorkspaceError:
rust-analyzer failed to load workspace: Failed to load the project at /home/pkehl/GIT/cfo/Cargo.toml: Failed to read Cargo metadata from Cargo.toml file /home/pkehl/GIT/cfo/Cargo.toml, Some(Version { major: 1, minor: 77, patch: 1 }): Failed to run `cd "/home/pkehl/GIT/cfo" && RUSTUP_TOOLCHAIN="/home/pkehl/.rustup/toolchains/stable-x86_64-unknown-linux-gnu" "/usr/bin/cargo" "metadata" "--format-version" "1" "--manifest-path" "/home/pkehl/GIT/cfo/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"`: `cargo metadata` exited with an error: error: failed to parse manifest at `/home/pkehl/Cargo.toml`

Caused by:
  no targets specified in the manifest
  either src/lib.rs, src/main.rs, a [lib] section, or [[bin]] section must be present

My projects are non-exotic, pure Rust libraries, created with cargo new. cargo check, cargo build` etc. work fine.

Cargo.toml:

[package]
name = "cfo"
version = "0.1.0"
edition = "2021"

categories = ["algorithms", "caching", "data-structures", "no-std", "text-processing"]

# [lib]

[dependencies]

And rustup update:

...
    stable-x86_64-unknown-linux-gnu unchanged - rustc 1.77.1 (7cf61ebde 2024-03-27)
      beta-x86_64-unknown-linux-gnu unchanged - rustc 1.78.0-beta.5 (9eff51035 2024-04-06)
     nightly-i686-unknown-linux-gnu unchanged - rustc 1.79.0-nightly (ab5bda1aa 2024-04-08)
   nightly-x86_64-unknown-linux-gnu unchanged - rustc 1.79.0-nightly (ab5bda1aa 2024-04-08)
  nightly-x86_64-unknown-linux-musl unchanged - (error reading rustc version)

Notice the path in the Cargo error message: /home/pkehl/Cargo.toml.

You probably don't want a package manifest file in your home directory. You should delete that file (or relocate it appropriately if it belongs to some other package).

Thank you Kevin.

Cause found: Mostly, or fully, self-inflected. (I forgot my routine and) I was opening a project directory in VS Code from a parent directory that is a symlink. In VS Code I opened project directory ~/GIT/cfo and I have ~/GIT being a symlink to /share/my-username/GIT.

Once I got back to my routine and opened the same project directory by a path that has no symlinks in it (/share/my-username/GIT/cfo), rust-analyzer started working.

I'm on x64 Linux (Manjaro = approx. stable Arch), that partition is /dev/sda5 on /share type ext4 (rw,noatime,nobarrier,commit=60). Anything worth investigating or reporting?

I don't know about symlink-related behavior here (I use symlinks for my project directory but in a considerably simpler way, but you should still check the named path for a stray Cargo.toml.

1 Like

Indeed, 2x self-inflected: The problem was not the symlink (on its own), but a stray Cargo.toml in my home directory. Once removed, all works fine (through either path, symlinks or not).
Thank you.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.