rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
13.92k stars 1.54k forks source link

In rustc workspace, cranelift errors are ignored #8937

Open RalfJung opened 3 years ago

RalfJung commented 3 years ago

My rustc workspace settings.json looks like this:

{
    "rust-analyzer.checkOnSave.overrideCommand": [
        "./x.py",
        "check",
        "--json-output",
        "library/std",
        "compiler/rustc",
        "compiler/rustc_codegen_cranelift",
    ],
    "rust-analyzer.rustfmt.overrideCommand": [
        "./build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt"
    ],
    "rust-analyzer.cargo.runBuildScripts": false,
    "rust-analyzer.procMacro.enable": false,
    "editor.formatOnSave": false,
    "files.watcherExclude": {
        "*rustc*/src/llvm-project/**": true,
        "*rustc*/build/**": true,
    },
    "files.exclude": {
        "src/llvm-project/**": true,
        "build/**": true
    },
}

However, it seems like RA for some reason ignores the compiler/rustc_codegen_cranelift part of the check-on-save command: even when I deliberately introduce an error in, e.g., compiler/rustc_codegen_cranelift/src/constant.rs, RA shows no diagnostic at all. Running the exact command that is given here on the console does show an error. Errors in rustc itself are shown. It's almost as if RA just "forgets" to pass the last argument to x.py. (Yes I did "reload window" after changing my settings.json. I even tried restarting vscode.)

bjorn3 commented 3 years ago

cg_clif is a separate workspace. You need to point to it's Cargo.toml in the rust-analyzer.linkedProjects array. You may also need to add the root Cargo.toml if you set it.

RalfJung commented 3 years ago

When I set linkedProjects, I get some really strange errors about "Failed to run cargo metadata". Probably the rustc provided by rustup that is set inside the rustc tree is not working, but that rustc should not even be needed -- and it wasn't needed when I did not set linkedProjects.

Does RA just silently drop all errors that it cannot assign to one of the linkedProjects? Couldn't there be a way for it to report all the errors shown by the check-on-save command?

RalfJung commented 1 year ago

When I set linkedProjects, I get some really strange errors about "Failed to run cargo metadata".

This is due to https://github.com/rust-lang/rust-analyzer/issues/10793.

And the "ignoring errors" is because ./x.py check will print paths relative to the cranelift workspace root, but of course RA thinks they are relative to the rustc repo root (where it invoked ./x.py), so it just cannot figure out which file the error refers to. And RA is not wrong here, as a user I would also expect that, but due to https://github.com/rust-lang/cargo/issues/11007, x.py will print paths relative to different roots depending on what it is currently building.