Change nightly Rust version? - rust

I tried to build rls by the command cargo +nightly build --release -Z unstable-options, but got the following errors:
error[E0599]: no method named `expect_none` found for enum `Option<Fingerprint>` in the current scope
--> /Users/cjw/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-rustc_span-705.0.0/src/lib.rs:2003:48
|
2003 | cache[index].replace(sub_hash).expect_none("Cache slot was filled");
| ^^^^^^^^^^^ method not found in `Option<Fingerprint>`
After searching it, I found that expect_none is a nightly feature and seemingly has been removed.
So I think maybe I should change the rust compiler version to fix the compilation problem. If this is the correct solution, how could I do it? Can anyone provide some detail suggestions?

Using rustup you can manage different nightly versions. See The Edition Guide for more.
As Option::expect_none was removed on March 25th, we can get the nightly for March 24th in the following way:
rustup toolchain install nightly-2021-03-24 --force
Note: the --force option was used as the components rustfmt and clippy might be missing.
Switch to the newly downloaded toolchain:
rustup default nightly-2021-03-24
The following main.rs should now panic, as expected:
#![feature(option_expect_none)]
fn main() {
let value = Some(42);
value.expect_none("The answer");
}
If you're curious, you could try this with nightly-2021-03-26 and you'll find that it will give you the expected error, indicating it was indeed removed:
error[E0599]: no method named `expect_none` found for enum `Option<{integer}>` in the current scope
--> src/main.rs:5:11
|
5 | value.expect_none("Expected none!");
| ^^^^^^^^^^^ method not found in `Option<{integer}>`

Related

Why does cargo use a specific dependency version?

When trying to follow the instructions of the pathfinder library, i.e:
cd demo/native
cargo run --release
I get errors due to the compilation of the dependency winit version 0.19.3:
error[E0308]: mismatched types
--> /Users/yairchu/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.19.3/src/platform/macos/view.rs:209:9
|
205 | extern fn has_marked_text(this: &Object, _sel: Sel) -> BOOL {
| ---- expected `bool` because of return type
...
209 | (marked_text.length() > 0) as i8
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `i8`
If I try changing the version used to the latest (which works fine for me) by changing Cargo.toml:
--- a/demo/native/Cargo.toml
+++ b/demo/native/Cargo.toml
## -43,7 +43,7 ## rev = "f3df871ac8c3926fe9106d86a3e51e20aa50d3cc"
[dependencies.winit]
-version = "<0.19.4" # 0.19.4 causes build errors https://github.com/rust-windowing/winit/pull/1105
+version = "0.27.2"
I still get the same errors!
Interestingly, I notice this in cargo's output:
Compiling winit v0.19.3
Compiling winit v0.27.2
It appears to now be building both the version I specified and the old version.
I'm lost. Also using --verbose didn't help elucidate why cargo chooses to build this specific dependency.
Is it using two versions of the same library in one executable?
How can I find out why cargo chooses to build this library? (so that I can update it to the working version)
Thanks! Rust noob
How can I find out why cargo chooses to build this library?
cargo tree elaborates on whose dependency is each sub-dependency.
Is it using two versions of the same library in one executable?
It is.
You can depend on different versions of the the same crate. This can be useful if you want to use one version of the dependency, but one of your own dependencies uses another version.
(thanks #Masklinn for the answers in the comments!)

Problems installing Inari library

I am new to Rust, so this could be a stupid mistake, but I can't figure out how to fix it.
The problem
I tried to install Inari (a Rust implementation of interval arithmetic, https://crates.io/crates/inari). But when I try to compile the project, I get some errors:
Compiling inari v1.0.0
error: RUSTFLAGS='-Ctarget-cpu=haswell' or later is required. See https://doc.rust-lang.org/rustc/codegen-options/#target-cpu
--> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/inari-1.0.0/src/simd/x86_64.rs:174:9
|
174 | ... compile_error!("RUSTFLAGS='-Ctarget-cpu=haswell' or later is required. See https://doc.rust-lang.org/rustc/codegen-options/#target-cpu...
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0425]: cannot find function `add_ru` in this scope
--> /home/user/.cargo/registry/src/github.com-1ecc6299db9ec823/inari-1.0.0/src/arith.rs:25:21
|
25 | Self { rep: add_ru(x, y) }
| ^^^^^^ help: a function with a similar name exists: `add_rn`
|
...
The error says something about using Haswell, so I tried to add the following lines to Cargo.toml:
[build]
rustflags = ["-Ctarget-cpu=haswell"]
rustdocflags = ["-Ctarget-cpu=haswell"]
but it didn't change anything.
Steps to reproduce
Create a new project with cargo new project-name. Add inari as a dependancy cargo add inari. Run the project with cargo run.
Environment
cargo 1.62.1 (a748cf5a3 2022-06-08)
rustc 1.62.1 (e092d0b6b 2022-07-16)
Ubuntu 20.04.3 LTS (in WSL)
You need to put that in .cargo/config.toml, not in Cargo.toml. Alternatively, set the environment variable RUSTFLAGS before running Cargo.
See Configuration - build.rustflags - The Cargo Book.

How do I compile the rust GTK example to the gtk crate? "#[doc(alias)] is experimental"

I have been trying to learn the Rust language. I have managed to create some simple command line applications but now I am moving on to see if I can create an application that uses a graphical interface. I have looked into several GUI libraries including iced and the Qt API, but they have not worked out. I have most recently landed on GTK. I grabbed the example from the gtk crate documentation at
https://gtk-rs.org/gtk3-rs/stable/latest/docs/gtk/
There is no information on that page on what to put into the Cargo.toml file so I have been trying to figure it out. The answers I have found on the web so far have been no help at all. So I went to crates.io and grabbed the the latest version of the gtk crate, 0.14.3, and put that into the toml.
[package]
name = "gtkhello"
version = "0.1.0"
authors = ["brian"]
edition = "2018"
[dependencies]
gtk = "0.14.3"
Here is the example program, copied unaltered from the documentation.
use gtk::prelude::*;
use gtk::{Application, ApplicationWindow};
fn main() {
let app = Application::builder()
.application_id("org.example.HelloWorld")
.build();
app.connect_activate(|app| {
// We create the main window.
let win = ApplicationWindow::builder()
.application(app)
.default_width(320)
.default_height(200)
.title("Hello, World!")
.build();
// Don't forget to make all widgets visible.
win.show_all();
});
app.run();
}
When I attempt to build this with cargo the compilation of the library fails. I do not know how to continue if the library itself will not compile. Here are the errors:
[brian#localhost gtkhello]$ cargo build
Compiling glib-macros v0.14.1
Compiling gdk-pixbuf-sys v0.14.0
error[E0658]: `#[doc(alias)]` is experimental
--> /home/brian/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-macros-0.14.1/src/clone.rs:202:1
|
202 | #[doc(alias = "get_full_ident")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #50146 <https://github.com/rust-lang/rust/issues/50146> for more information
error[E0658]: `#[doc(alias)]` is experimental
--> /home/brian/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-macros-0.14.1/src/clone.rs:248:1
|
248 | #[doc(alias = "get_keyword")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #50146 <https://github.com/rust-lang/rust/issues/50146> for more information
error[E0658]: `#[doc(alias)]` is experimental
--> /home/brian/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-macros-0.14.1/src/clone.rs:366:1
|
366 | #[doc(alias = "get_expr")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #50146 <https://github.com/rust-lang/rust/issues/50146> for more information
error[E0658]: `#[doc(alias)]` is experimental
--> /home/brian/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-macros-0.14.1/src/clone.rs:413:1
|
413 | #[doc(alias = "get_return_kind")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #50146 <https://github.com/rust-lang/rust/issues/50146> for more information
error[E0658]: `#[doc(alias)]` is experimental
--> /home/brian/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-macros-0.14.1/src/clone.rs:474:5
|
474 | #[doc(alias = "get_closure")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #50146 <https://github.com/rust-lang/rust/issues/50146> for more information
error[E0658]: `#[doc(alias)]` is experimental
--> /home/brian/.cargo/registry/src/github.com-1ecc6299db9ec823/glib-macros-0.14.1/src/clone.rs:579:1
|
579 | #[doc(alias = "get_closure")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #50146 <https://github.com/rust-lang/rust/issues/50146> for more information
Compiling gdk-sys v0.14.0
error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0658`.
error: could not compile `glib-macros`.
To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
I went to the link that was suggested in the error messages for the issue and it ends with:
bors closed this in 57c5f40 on Sep 14, 2020
So I guess my question has several facets. What do I put into the Cargo.toml file to make this example work? How do I find that information in the future should I branch out from this simple example? How do I get around a required crate that will not compile? How do I tell cargo that experimental code is OK by me?
The biggest question is "What am I missing?"
The referenced feature was previously unstable, but stabilized in version 1.48.0. So, minimal supported Rust version for gtk-rs is at least 1.48.0.
In general, if you see some crate failing to compile with reference to "unstable features", but the corresponding tracking issue is already closed, this usually means that your compiler version is older then the minimal supported by the crate in question. If the tracking issue is open, i.e. the feature is not stabilized yet, the crate might be nightly-only - in this case you have to add the necessary toolchain with rustup install nightly and then either set is as global default via rustup default nightly, or set an override (the easiest way is with rustup override nightly) for current project only.

cannot find function `get_platform` in sdl2 0.31.0

I'm using the latest version of sdl2 (0.31.0) but cannot access get_platform:
extern crate sdl2;
pub fn main() {
println!("{}", sdl2::get_platform());
}
$ cargo run
Compiling repro v0.1.0 (file:///private/tmp/repro)
error[E0425]: cannot find function `get_platform` in module `sdl2`
--> src/main.rs:4:30
|
4 | println!("{}", sdl2::get_platform());
| ^^^^^^^^^^^^ not found in `sdl2`
I tried with use sdl2::*; and with cargo +nightly run, but neither removed the error.
The documentation you are reading is is not for the version you are using. Build it yourself (cargo doc --open) or view it on docs.rs.
That function was added recently and has not been released yet. Perhaps you should file an issue for the authors of the crate to let them know that having documentation that doesn't correspond to any released code is confusing.
In the meantime, you can use a git dependency if you really need it.

How to execute cargo test using the nightly channel?

I'm trying to run my tests with nightly Rust using Windows Powershell. I run cargo test in the directory, and I get
Compiling rustcraft v0.1.0 (file:///C:/Users/Phoenix/Desktop/Rust/rustcraft)
error[E0554]: #![feature] may not be used on the stable release channel
--> C:\Users\Phoenix\Desktop\Rust\rustcraft\src\main.rs:1:1
|
1 | #![feature(integer_atomics)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0554]: #![feature] may not be used on the stable release channel
--> C:\Users\Phoenix\Desktop\Rust\rustcraft\src\main.rs:2:1
|
2 | #![feature(collections)]
| ^^^^^^^^^^^^^^^^^^^^^^^^
Obviously, I have to tell Cargo to compile it on the nightly channel, but how? I can't find any reference to specifying a channel in the help section, or any website I've found.
The command line solution may help you to configure your IDE:
cargo +nightly test
Provided, of course, that you have the nightly channel installed. If not, perhaps install it with rustup install nightly (no need to switch to it, but check you're still on stable: rustup show).
The +<toolchain> functionality comes from rustup, the Rust toolchain manager. It works for both cargo +<toolchain> as well as rustc +<toolchain>.
In addition, you can use
rustup run <toolchain> <any arbitrary command goes here>
Since your project requires nightly features, you can change into the directory and run rustup override set <toolchain> to always use the nightly toolchain in that directory.
Create a file called rust-toolchain in your directory containing the name of the toolchain required (e.g. nightly). This has the safe effect as an override, but can be committed to source control.
See also:
Is it possible to have multiple coexisting Rust installations?

Resources