I'm using rust-analyzer via neovim's coc. When I start editing a project's files it fails with an error "Failed to read Cargo metadata ..." but the error message disappears after a while. From what I can read before it disappears, it's talking about a feature that is missing in Cargo.toml, but the feature was removed a long time ago, and there are no references to that feature in the code base now.
The same error is also generated when I run rust-analyzer.reloadWorkspace command.
I'd like to reproduce this error in the terminal now so that I can either debug it or report it as a bug, but not sure how. rust-analyzer analysis-stats . generates dozens of Rust panics and does not generate the error I'm trying to fix.
How do I replicate an error in rust-analyzer.reloadWorkspace command in the terminal?
cargo metadata works fine. Is rust-analyzer using its own cargo library, or the cargo installed system-wide?
When I look at the neovim language server logs I see the full error is like this:
[ERROR rust_analyzer::reload] failed to switch workspaces: rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file <snip>, cargo 1.54.0 (5ae8d74b3 2021-06-22): Failed to run `cargo metadata --manifest-path <snip>`: `cargo metadata` exited with an error: error: Package `<snip>` does not have the feature `<feature>`
Interestingly the word <feature> does not occur anywhere in the code base (checked with ag <feature>). I have no idea where rust-analyzer/cargo seeing it. I'm guessing rust-analyzer and/or cargo has some cache somewhere that I need to invalidate? <feature> also does not appear in cargo metadata output.
OK, figured it out. ag <feature> does not find anything because it ignores files specified in .gitignore. If I search in all files I see that I have a .vim/coc-settings.json file with an old feature. After updating it everything works fine.
Might be worth it to open an issue on the coc-rust-anlyzer repo about displaying this better -- the idea is that the message is persistant status, not a one-time error message.
I'm having the same problem with VSCode. I have two projects, only one of which uses a number of features. I get the missing feature error in the other project. My workaround is to just list those features in the second project's Cargo.toml, but I'd really like to know what's going on.