1

I'm working on a rust project and you have to pick some features to decide the linear programming module to get the project to compile. Normally, I can run check with cargo check --features lp_coincbc,blas_openblas-system and everything works fine. However, the Rust Analyzer VSCode Extension gives me errors (compile_error!s that are built into the project) even though I have this set up in my VScode settings.json file.

# ~/.config/Code/User/settings.json
{
  ...
  "rust-analyzer.cargo.features": [
    "lp_coincbc",
    "blas_openblas-system"
  ],
  ...
}

I further checked rust-analyzer.checkOnSave.features and it is supposed to default to rust-analyzer.cargo.features, so I'm just really confused here. Any help would be appreciated.

Edit: Including the language server trace configuration (removed for character limit).

Edit 2: With RA_LOG="flycheck=info" (removed for character limit).

Edit 3: Rust Analyzer Language Server Panel:

[INFO flycheck] restart flycheck "cargo" "check" "--workspace" "--message-format=json" "--manifest-path" "/home/ihowell/Projects/rl/nnv-rs/Cargo.toml" "--all-targets" "--features" "lp_coincbc blas_openblas-system"

Edit 4: Copy of error in mod.rs

[{
    "resource": "/home/ihowell/Projects/rl/nnv-rs/src/lib.rs",
    "owner": "rust",
    "severity": 8,
    "message": "error: Must enable one of \"blas_{{intel_mkl,openblas-system}}\"",
    "startLineNumber": 43,
    "startColumn": 9,
    "endLineNumber": 43,
    "endColumn": 85
}]
iHowell
  • 2,263
  • 1
  • 25
  • 49
  • Try setting the environment variable `RA_LOG` (either via terminal or by specifying `rust-analyzer.server.extraEnv`, [as explained in the manual](https://rust-analyzer.github.io/manual#troubleshooting)) to `flycheck=info`. Restart the language server. Then after `cargo check` by rust-analyzer is completed, open `Output > Rust Analyzer Language Server` in VSCode and copy it here. – Chayim Friedman Mar 01 '22 at 15:35
  • @ChayimFriedman I have included as much as I can from the Language Server logs, but had to cut a lot out due to the character limit. Let me know if there is something more targeted I can do. – iHowell Mar 01 '22 at 15:46
  • This may be a genuine bug in RA. I've seen it mark syntactically valid constructs as syntactically valid (although only when using Rust nightly). – BallpointBen Mar 01 '22 at 21:57
  • @BallpointBen You mean "as syntactically **in**valid", I guess? Anyway, rust-analyzer indeed does not support some of the features, but this should work. iHowell are the errors reported from rustc or from rust-analyzer? (Near the error when you hover it it should be written). – Chayim Friedman Mar 01 '22 at 23:38
  • @iHowell Not the "Rust Analyzer Language Server Trace" panel, but the "Rust Analyzer Language Server" panel. I need the line beginning with "[INFO flycheck] restart flycheck" - it contains the full `cargo check` RA runs. – Chayim Friedman Mar 01 '22 at 23:46
  • Then run it as-is from the workspace folder and see if there is an error. – Chayim Friedman Mar 01 '22 at 23:47
  • @ChayimFriedman I updated to show the flycheck restart command. When I run starting at `"cargo" "check"...` in the workspace directory, the build succeeds. I also can't see where which checker is reported, I only see `error: Must enable one of...` which is the text in the `compile_error!` macro. – iHowell Mar 02 '22 at 02:24
  • [This](https://photos.app.goo.gl/HpypzZYLnKxPK6259) is an example of rustc error (notice the `rustc(E0308)`), while [this](https://photos.app.goo.gl/YjgtRJtuEixJzD7D7) is a rust-analyzer error (notice the `rust-analyzer(syntax-error)`). – Chayim Friedman Mar 02 '22 at 02:44
  • It is neither. Nothing claims the error. If I just type random stuff, like `asdf` into the code it says that it is a rust-analzyer error, but this error does not have an associated checker. Edit: If I type `asdf;` I get an error with no associated checker either, which leads me to believe it is not rust-analyzer. Maybe rustc? – iHowell Mar 02 '22 at 15:40
  • @ChayimFriedman I have found what was going on. I had the Cargo extension installed, which also checks code with cargo check. After disabling it, the compile error went away. I'm not sure as how to mark this question on SO though, since it was solved, but in the end had nothing to do with rust-analyzer. – iHowell Mar 02 '22 at 15:46
  • @iHowell You should post an answer and mark it as correct, so follow visiters with the same problem will know how to solve it. Glad you've found it yourself :) – Chayim Friedman Mar 02 '22 at 23:55

1 Answers1

1

To those that come across this question, Rust Analyzer was not the actual issue here. Instead, there was another plugin cargo that was also performing checks and did not have the features specified. After uninstalling the plugin, everything worked fine.

The way I figured out that this was that it was this issue was by following the advice of @ChayimFriedman to analyze what was actually reporting the problem. Since nothing was claiming the error, it couldn't be Rust Analyzer, as when it reports errors, the source shows rust-analyzer. This led me to look into the other plugins installed.

iHowell
  • 2,263
  • 1
  • 25
  • 49