Unable to specify `edition2021` in order to use unstable packages in Rust - rust

I want to run an example via Cargo but I am facing an error:
error: failed to parse manifest at `/Users/aviralsrivastava/dev/subxt/Cargo.toml`
The full stacktrace is:
error: failed to parse manifest at `/Users/aviralsrivastava/dev/subxt/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.56.0-nightly (b51439fd8 2021-08-09)).
Consider adding `cargo-features = ["edition2021"]` to the top of Cargo.toml (above the [package] table) to tell Cargo you are opting in to use this unstable feature.
See https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#edition-2021 for more information about the status of this feature.
Based on the suggestion, I go ahead and modify the Cargo.toml:
Consider adding `cargo-features = ["edition2021"]` to the top of Cargo.toml (above the [package] table) to tell Cargo you are opting in to use this unstable feature.
diff --git a/Cargo.toml b/Cargo.toml
index 26a02c7..186d09b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
## -1,6 +1,6 ##
[workspace]
members = [".", "cli", "codegen", "macro"]
-
+cargo-features = ["edition2021"]
[package]
name = "subxt"
version = "0.15.0"
(END)
I still face the same error as if nothing was changed in the toml file.
How do I resolve the above error in order to use unstable packages?

Update the Rust to satisfy the new edition 2021.
rustup default nightly && rustup update
Thanks to #ken.
Yes, you can use the stable channel too!
But I love nightly personally.

Edition 2021 is now part of the stable channel.
As what happened to me, you probably just need to update your stable version by running rustup update stable.
That should fix the issue, and not require you to switch over to the nightly channel.

Try:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env && rustup default nightly && rustup update

Seen this error twice when working with Solana. You can get this error if Solana is not up to date. Update it with sh -c "$(curl -sSfL https://release.solana.com/v1.10.26/install)"
Or preferably find the latest version and instructions here
https://docs.solana.com/cli/install-solana-cli-tools

Some machines (including those with M1 chips) may be unable to build

Related

rust-gpu complains about mismatching toolchain file

rust-gpu says:
Copy the rust-toolchain file to your project. (You must use the same version of Rust as rust-gpu.)
So I copied that file into my root getting rust-toolchain with contents:
# If you see this, run `rustup self update` to get rustup 1.23 or newer.
# NOTE: above comment is for older `rustup` (before TOML support was added),
# which will treat the first line as the toolchain name, and therefore show it
# to the user in the error, instead of "error: invalid channel name '[toolchain]'".
[toolchain]
channel = "nightly-2022-10-29"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
# commit_hash = 9565dfeb4e6225177bbe78f18cd48a7982f34401
# Whenever changing the nightly channel, update the commit hash above, and make
# sure to change REQUIRED_TOOLCHAIN in crates/rustc_codegen_spirv/src/build.rs also.
Then I tried building by doing cargo-run, getting:
error: failed to run custom build command for `rustc_codegen_spirv v0.4.0-alpha.17 (https://github.com/EmbarkStudios/rust-gpu#fabcbd9c)`
Caused by:
process didn't exit successfully: `/home/makogan/rust_never_engine/target/debug/build/rustc_codegen_spirv-b4185236522e0515/build-script-build` (exit status: 1)
--- stdout
cargo:rerun-if-env-changed=RUSTGPU_SKIP_TOOLCHAIN_CHECK
--- stderr
error: wrong toolchain detected (found commit hash `e631891f7ad40eac3ef58ec3c2b57ecd81e40615`, expected `9565dfeb4e6225177bbe78f18cd48a7982f34401`).
Make sure your `rust_toolchain` file contains the following:
-------------
[toolchain]
channel = "nightly-2022-10-29"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
I am confused, the toolchain file says the same thing as the error message, what did I do wrong?
You're running a different version of nightly than the crate requires.
To check the version of cargo try to run cargo --version from within the project directory. If it shows anything else than the version you specified in the rust-toolchain file then you can try and check out the list below for possible fixes.
Make sure that:
The cargo you're using is managed by rustup if it is cargo +stable --version should show a version number and not an error.
The rust-toolchain is in the same directory as Cargo.toml if it's not copy or move it there.
There is no override on the crates directory. You can list them with rustup override list if the crate where the error appears is listed you can unset it with rustup override unset from within the crate root.
In this specific case 3. was the culprit.

Build fails with Error: Pear requires a 'dev' or 'nightly' version of rustc even after a successful rustup override set nightly

Windows 10
rustup 1.23.1 (3df2264a9 2020-11-30)
default rustc 1.50.0 (cb75ad5db 2021-02-10)
project rustc 1.52.0-nightly (4a8b6f708 2021-03-11)
rocket = "0.4.4"
I'm trying to build a rust project with rocket but I always get this error when compiling, even after successfully overwriting the project's toolchain:
D:\GitHub\Learning-Rust\poke_api> rustup override set nightly
info: using existing install for 'nightly-x86_64-pc-windows-msvc'
info: override toolchain for 'D:\GitHub\Learning-Rust\poke_api' set to 'nightly-x86_64-pc-windows-msvc'
nightly-x86_64-pc-windows-msvc unchanged - rustc 1.52.0-nightly (4a8b6f708 2021-03-11)
PS D:\GitHub\Learning-Rust\poke_api> cargo build
Compiling winapi v0.3.9
Compiling serde_derive v1.0.124
Compiling rocket v0.4.7
Compiling pear_codegen v0.1.4
Compiling rocket_codegen v0.4.7
Compiling proc-macro2 v1.0.24
Compiling pq-sys v0.4.6
Compiling aho-corasick v0.6.10
Compiling serde_json v1.0.64
error: failed to run custom build command for `pear_codegen v0.1.4`
Caused by:
process didn't exit successfully: `D:\GitHub\Learning-Rust\poke_api\target\debug\build\pear_codegen-e182711746033ac9\build-script-build` (exit code: 101)
--- stderr
Error: Pear requires a 'dev' or 'nightly' version of rustc.
Installed version: 1.48.0 (2020-11-16)
Minimum required: 1.31.0-nightly (2018-10-05)
thread 'main' panicked at 'Aborting compilation due to incompatible compiler.', C:\Users\gabre\.cargo\registry\src\github.com-1ecc6299db9ec823\pear_codegen-0.1.4\build.rs:24:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
I had a similar issue while using rocket. Same error message too, Error: Pear requires a 'dev' or 'nightly' version of rustc.
If you get to the get-started page on rocket framework website. It says, "Rocket makes abundant use of Rust's syntax extensions and other advanced, unstable features. Because of this, we'll need to use a nightly version of Rust."
My issue was I was not using a nightly version of rust. Running this on my terminal in my project directory did it for me.
rustup override set nightly
If you check the cargo version for that directory after,
cargo version
you will confirm it has switched to nightly version
Failed compilation even with nightly
It looks like you have some outdated dependencies (pear-codegen probably being the one that causes trouble), updating these may resolve the compilation issues.
General notes on how to override the toolchain
Using rustups override works fine, but it is bound to your local rustup configuration and not specified inside the project.
In order to achieve this, thereby making the project more portable and allowing others to always use the correct toolchain, I would recommend the toolchain file. It can look something like this (example taken from linked page) and will accurately specify the required toolchain only for the containing project.
# rust-toolchain.toml
[toolchain]
channel = "nightly-2020-07-10"
components = [ "rustfmt", "rustc-dev" ]
targets = [ "wasm32-unknown-unknown", "thumbv2-none-eabi" ]
profile = "minimal"
For your purposes a simple configuration like this will most likely be all you need, although adding the components you want to use would be beneficial.
[toolchain]
channel = "nightly"
My issue was with rust-analyser that wouldn't start because multiple rocket dependencies needed nightly or dev version of rustc.
These steps fixed my issue:
Switch to nightly for my rocket project by running rustup override set nightly inside the app folder.
Remove all target folders in my project. (I also had one in root)
Manually remove the faulty cached packages from cargo cache. cd ~/.cargo/registry/cache/github.com-xxxxxxxxxxxx && rm -r pear_codegen-0.1.5/

How can I find the latest stable version of a crate using cargo?

I want to know the latest actix-web version, so I executed cargo search actix-web. The result is actix-web = "4.0.0-beta.1", showing the beta version number.
I want to know the latest stable version number; how do I get it?
Usually, I only care to know about the version number of a crate when I'm going to add the crate to my Cargo.toml. In those cases, I use two extra Cargo subcommands from the cargo-edit project:
cargo add — adds the current stable version of a crate to Cargo.toml. Options exist for allowing prerelease versions or marking it as a build / dev dependency.
cargo upgrade — updates the version of a crate already in Cargo.toml. Similar to cargo update, but also changes Cargo.toml in addition to Cargo.lock.
cargo show --json $1 | python -m json.tool | jq ".versions[].num"

Rust & Amethyst - Error [E0433]: failed to resolve: could not find `__rt` in `quote`

I'm learning Rust from "Practical Rust Projects" by Shing Lyu. I'm now trying to build a game following the steps in Chapter 4. I'm working on Ubuntu 18.04 LTS.
After installing Rust and the Amethyst command line, I created a new project via amethyst new cat_volleyball. The next step is to run the engine using cargo run --features=vulkan
. When I do so, I get the error prompt below. Do you have suggestions on how to fix this?
error[E0433]: failed to resolve: could not find `__rt` in `quote`
--> /home/alberto/.cargo/registry/src/github.com-1ecc6299db9ec823/err-derive-0.1.6/src/lib.rs:145:63
|
145 | fn display_body(s: &synstructure::Structure) -> Option<quote::__rt::TokenStream> {
| ^^^^ could not find `__rt` in `quote`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0433`.
error: could not compile `err-derive`.
warning: build failed, waiting for other jobs to finish...
TL;DR Edit the Cargo.lock manually, please check the title below : How to force cargo to use yanked version of sub-dependency (for the proper steps)
Why this happens ?
This happened because in err-derive-0.1.6 is using quote-1.0.2 as dependency but in it's cargo.toml dependency declared like this:
[dependencies.quote]
version = "1.0.2"
This means cargo will use the latest minor update, so if quote-1.0.3 is out then cargo will use 1.0.3 instead 1.0.2. Please check caret-requirement. The problem in here is quote-1.0.3 breaks backward compatibility that comes from quote-1.0.2. In this case quote
How to force cargo to use specific version of sub-dependency
You can fix this issue by forcing the sub-dependency to use compatible version for your dependency.
This command will do it :
> cargo update -p quote --precise 1.0.2
How to force cargo to use yanked version of sub-dependency
Looks like quote-1.0.2 was yanked from crates.io, so command up above will not work because cargo will not be able to find the yanked version on crates.io . Since cargo update modifies the cargo.lock we can do it manually. To start clean :
Remove Cargo.lock
Run cargo update ( this will generate latest version Cargo.lock )
Edit Cargo.lock
Find the incompatible version of package in cargo.lock which is quote-1.0.3, It should look like this:
[[package]]
name = "quote"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
then simply change version to the compatible version in our case it is "1.0.2"
[[package]]
name = "quote"
version = "1.0.2"
After doing that do not run cargo update again, it will overwrite your changes and you'll not able to compile your project. Please remember this is a workaround for being able to continue the development, there is a reason to yank crates, do not use it in production it is best to wait dependent crates to update itself.
Note : In some cases you may get an error after editing cargo.lock:
error: Found argument 'Cargo.lock' which wasn't expected, or isn't valid in this context
#albus_c fixed this by doing :
A note for posterity: I fixed the issue removing rustc
(sudo apt remove rustc) and reinstalled as recommended on the Rust website,
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
After that everything worked fine.

Is it possible to download previous nightly builds?

I have downloaded the latest Rust nightly and added this dependency to Cargo.toml:
[dependencies.http]
git = "https://github.com/chris-morgan/rust-http.git"
I'm getting lots of errors for cargo build:
...
error: aborting due to 7 previous errors
...
error: aborting due to previous error
Could not compile `regex`.
I guess this is because some dependencies have not been updated to the latest rust version. Is it possible to download the nightly from yesterday or the day before?
Installed versions:
$ rustc --version
rustc 0.13.0-nightly (c89417130 2015-01-02 21:56:13 +0000)
$ cargo --version
cargo 0.0.1-pre-nightly (1a1868b 2014-12-31 21:39:41 +0000)
If you are using rustup (the currently preferred manner of installing Rust):
rustup install nightly-2016-06-03
If you want to use the standalone Rust installers, previous versions are kept. From this Reddit thread, which links to this Rust issue:
They are officially hosted.
wget https://static.rust-lang.org/dist/2014-12-08/rust-nightly-x86_64-apple-darwin.pkg
wget https://static.rust-lang.org/dist/2014-12-12/rust-nightly-x86_64-unknown-linux-gnu.tar.gz
If you are still using rustup.sh (not .rs), you should be able to use something like:
rustup.sh --channel=nightly --date=2016-06-03

Resources