Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust-analyzer shows thousands of rustc errors but running the build command on the terminal works fine #15942

Closed
RalfJung opened this issue Nov 20, 2023 · 11 comments
Labels
C-bug Category: bug

Comments

@RalfJung
Copy link
Member

RalfJung commented Nov 20, 2023

Since somewhat recently, RA shows >1800 errors in src/tools/miri in the rustc workspace, even though Miri builds perfectly fine. The errors all claim that various types from rustc cannot be found.

cannot find type `AllocId` in this scope
not found in this scope
cannot find type `MemoryKind` in this scope
not found in this scope
cannot find type `ImmTy` in this scope
not found in this scope

Running the same build command inside vscode in the terminal, everything succeeds just fine -- so it looks very much like this is caused by how RA invokes the build command. The same command still worked last week or so (I don't exactly remember when I used vscode in rustc the last time).

rustc itself builds just fine, it is only Miri where it shows errors.

rust-analyzer version: 0.3.1740-standalone

rustc version: bootstrap beta

relevant settings:

{
    "rust-analyzer.linkedProjects": [
        "Cargo.toml",
        "src/bootstrap/Cargo.toml",
    ],
    "rust-analyzer.check.invocationLocation": "root",
    "rust-analyzer.check.invocationStrategy": "once",
    "rust-analyzer.check.overrideCommand": [
        "./myx",
        "check",
        "--json-output",
        "library/std",
        "compiler/rustc", "src/tools/miri",
    ],
    "rust-analyzer.rustfmt.overrideCommand": [
        "${workspaceFolder}/build/host/rustfmt/bin/rustfmt",
        "--edition=2021",
    ],
    "rust-analyzer.rustc.source": "./Cargo.toml",
    "rust-analyzer.cargo.sysrootSrc": "./library",
    "rust-analyzer.cargo.extraEnv": {
        "RUSTC_BOOTSTRAP": "1"
    },
    // These just make everything way too slow.
    "rust-analyzer.cargo.buildScripts.enable": false,
    "rust-analyzer.procMacro.enable": false,
    // Some diagnostics don't work properly here
    "rust-analyzer.showUnlinkedFileNotification": false,
    "rust-analyzer.diagnostics.enable": false, // without proc macros, there's just too many false positives
    //
    "files.watcherExclude": {
        "*rustc*/src/llvm-project/**": true,
        "*rustc*/build/**": true,
    },
    "files.exclude": {
        "src/llvm-project/**": true,
        "build/**": true
    },
}
@RalfJung RalfJung added the C-bug Category: bug label Nov 20, 2023
@RalfJung
Copy link
Member Author

Actually this is caused by a rustc update, not an RA update... when I go back in the rustc history to before rust-lang/rust#116828, everything is fine. I still have no idea what is actually going on though.

@RalfJung
Copy link
Member Author

I have tried adding "rust-analyzer.cargo.buildScripts.useRustcWrapper": false, it does not make a difference.

@RalfJung
Copy link
Member Author

I am getting similar behavior in stdarch: just checking out https://github.com/rust-lang/stdarch/, setting the rustup override to nightly, and opening the project in RA leads to thousands of errors. However, cargo check on the terminal works just fine. I tried changing the RA config but it did not help:

{
    "rust-analyzer.linkedProjects": [
        "./crates/core_arch/Cargo.toml"
    ],
    "rust-analyzer.cargo.buildScripts.enable": false,
    "rust-analyzer.procMacro.enable": false,
    "rust-analyzer.cargo.buildScripts.useRustcWrapper": false,
}

@RalfJung RalfJung changed the title rust-analyzer shows tons of errors when building Miri in the rustc workspace rust-analyzer shows tons of errors but running the build command on the terminal works fine Nov 21, 2023
@RalfJung RalfJung changed the title rust-analyzer shows tons of errors but running the build command on the terminal works fine rust-analyzer shows thousands of rustc errors but running the build command on the terminal works fine Nov 21, 2023
@Veykril
Copy link
Member

Veykril commented Nov 21, 2023

You can run r-a with RA_LOG set to "flycheck=debug", then triggering the cargo check through r-a will make it log the command invoked. In VSCode you can set that in the rust-analyzer.server.extraEnv config

    "rust-analyzer.server.extraEnv": {
        "RA_LOG": "flycheck=debug",
    }

@RalfJung
Copy link
Member Author

Where should it put those logs? In the "RA language server" output, all I can see is a ton of "cyclic deps" messages.

@Veykril
Copy link
Member

Veykril commented Nov 21, 2023

That's where it should log those whenever you trigger the check

@Veykril
Copy link
Member

Veykril commented Nov 21, 2023

You will have to restart the server fwiw

@RalfJung
Copy link
Member Author

Yes, I even reloaded the vscode window. Nothing. Ctrl-F "fly" in the output window shows no results.

@RalfJung
Copy link
Member Author

Oh, dang, sorry. I added this to the wrong extraEnv. I didn't realize there are multiple of them.

@RalfJung
Copy link
Member Author

Now I am seeing something:

[INFO flycheck] Spawning flycheck id=0 workspace_root=AbsPathBuf("/home/r/src/rust/rustc.2")
[DEBUG flycheck] will restart flycheck command=cd "/home/r/src/rust/rustc.2" && RUSTC_BOOTSTRAP="1" "./myx" "check" "--json-output" "library/std" "compiler/rustc" "src/tools/miri"
[DEBUG flycheck] did  restart flycheck command="cd \"/home/r/src/rust/rustc.2\" && RUSTC_BOOTSTRAP=\"1\" \"./myx\" \"check\" \"--json-output\" \"library/std\" \"compiler/rustc\" \"src/tools/miri\""

However, even RUSTC_BOOTSTRAP="1" ./myx check miri works fine on the terminal...

But indeed if I run "./x.py" "check" library/std compiler/rustc src/tools/miri I sometimes get all these errors on the terminal as well now. If I then run ./x.py check miri, that succeeds. If I then run "./x.py" "check" library/std compiler/rustc src/tools/miri again it succeeds as well.

So this is probably a bootstrap bug.

@RalfJung
Copy link
Member Author

Closing in favor of rust-lang/rust#118129. Thanks for the debugging help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants