rustc-dev-guide icon indicating copy to clipboard operation
rustc-dev-guide copied to clipboard

Document rust-analyzer cargo workaround for 2021 edition

Open aDotInTheVoid opened this issue 4 years ago • 5 comments

To get RA to work (currently) you need to run rustup override set beta, so the cargo RA invokes considers rust 2021 stable.

Otherwise you get this error:

rust-analyzer failed to load workspace: Failed to read Cargo metadata from Cargo.toml file /home/nixon/upstreams/rust/rust/Cargo.toml, cargo 1.55.0 (32da73ab1 2021-08-23): Failed to run `cargo metadata --manifest-path /home/nixon/upstreams/rust/rust/Cargo.toml`: `cargo metadata` exited with an error: error: failed to load manifest for workspace member `/home/nixon/upstreams/rust/rust/src/bootstrap` Caused by: failed to parse manifest at `/home/nixon/upstreams/rust/rust/src/bootstrap/Cargo.toml` Caused by: feature `edition2021` is required The package requires the Cargo feature called `edition2021`, but that feature is not stabilized in this version of Cargo (1.55.0 (32da73ab1 2021-08-23)). Consider trying a newer version of Cargo (this may require the nightly release). See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#edition-2021 for more information about the status of this feature.

Either this should be documented or .vscode/settings.json should point RA to the cargo downloaded by x.py.

I think the latter is more "elegant", but I dont know if its possible with RA.

Also, previously RA was fine with stable cargo, as AUIU it just needs it to run cargo metadata, as cargo check is already overridden, so once 1.56 is stable, this may no longer be needed.

aDotInTheVoid avatar Sep 23 '21 17:09 aDotInTheVoid

Also, previously RA was fine with stable cargo, as AUIU it just needs it to run cargo metadata, as cargo check is already overridden, so once 1.56 is stable, this may no longer be needed.

Although in the future, there may be other changes to Cargo.toml that rust-lang/rust uses that are unstable, which I think would require using rustup override set nightly (or a cleaner solution).

camelid avatar Sep 23 '21 17:09 camelid

I marked this as Medium since we're not sure what the "best" solution is yet.

camelid avatar Sep 23 '21 17:09 camelid

which I think would require using rustup override set nightly (or a cleaner solution)

X.py has to be able to build with the beta compiler, so nightly should be never be required. I don't know if there's cases where you'd have to set RUSTC_BOOTSTRAP just to run cargo metadata or not.

jyn514 avatar Sep 23 '21 17:09 jyn514

X.py has to be able to build with the beta compiler, so nightly should be never be required.

However to do that it uses a freshly compiled stdlib. This means that the compiler is able to use stdlib features that are not yet available on beta, not even as unstable. This happened for example with core::iter::zip when rust-lang/rust#82917 added the function to the stdlib and at the same time made the compiler use it. This meant that the beta toolchain wasn't enough for rust-analyzer to typecheck some parts of the compiler because that function was missing, and technically for the first day or less not even nightly was enough.

SkiFire13 avatar Sep 23 '21 20:09 SkiFire13

@SkiFire13 right, well, there's not much we can do about that because rust-analyzer doesn't understand staged builds.

jyn514 avatar Sep 23 '21 20:09 jyn514

Triage: Does this situation still continue? If not, I think we could close this issue.

JohnTitor avatar Nov 20 '22 06:11 JohnTitor

No, 2021 is stable on beta now.

jyn514 avatar Nov 20 '22 06:11 jyn514