How do I allow deprecated features? - rust

I have a Rust project that depends on string_cache, which requires nightly. However, the latest version of nightly is refusing to compile due to deprecated features:
$ cargo build
Compiling string_cache v0.1.0 (https://github.com/servo/string-cache#45f19068)
/home/wilfred/.multirust/toolchains/nightly/cargo/git/checkouts/string-cache-efa5c30b1d5a962c/master/src/atom/mod.rs:65:21: 65:37 error: use of deprecated item: use `String::from` instead, #[deny(deprecated)] on by default
/home/wilfred/.multirust/toolchains/nightly/cargo/git/checkouts/string-cache-efa5c30b1d5a962c/master/src/atom/mod.rs:65 string: String::from_str(string_to_add),
^~~~~~~~~~~~~~~~
error: aborting due to previous error
Could not compile `string_cache`.
To learn more, run the command again with --verbose.
How do I compile string_cache? I've tried adding
#![allow(deprecated)]
to my main.rs, but that doesn't change the behaviour.

The compiler doesn't impose any restrictions on the usage of deprecated methods by default:
fn main() {
(32.0f64).is_positive();
}
Compiles, but has the warning:
warning: use of deprecated item: renamed to is_sign_positive, #[warn(deprecated)] on by default
Your error message helps point to the culprit:
#[deny(deprecated)] on by default
You'll have to figure out where the deny is specified.

Related

Is there a way to fix "maybe a missing crate [crate_name]"?

My Rust crate wont load when compiling/running my file
I have reinstalled Rust several times, continuously restarting and checking the Path variables (as well as the current version installed)
I have restarted my system various times, and I am also experiencing this issue on my desktop PC at home; I am currently running Windows 11 as of the time of this post
I have added several other "dependencies" to my Cargo.toml file to no avail, they still refuse to work and I receive the same errors each time I try to utilise it
I have seen that some features of the Rust crate importation system have been deprecated; such as the "extern crate {crate_name}", I still receive these messages from time to time even though I am using the most up to date "rustup" version
I have consulted the Rust discord server and the official Rust language forums with the same issue
I have installed "git" on my system as that appeared to be an issue when adding my desired crates to the Cargo.toml
I expected to be able to use these crates without any hassle after solving my issue on importing these crates within the toml file, but I am still with nothing to show for that expectation.
Below is the code I have fully tested and ran
I have researched the documentation for importing crates with dependencies in Rust,
my directory looks like this: file directory
I have added the "ncurses" to my MinGW package manager, as requested by the "cursive" page on "crates.io"
I also gain the error from the "rust-analyser" extension in VSC
analyser error message
I have the current version of Rust installed,
rustup -V
rustup 1.25.1 (bb60b1e89 2022-07-12)
My File Directory looks like this:
-->Application
---->src
------>main.rs
---->target
---->.gitignore
---->Cargo.lock
---->Cargo.toml
My issue occurs when I try the command "cargo build" within the VSC terminal- which to my knowledge as I am in the bin file, it should run just fine.
I am thrown this error,
c1: fatal error C1083: Cannot open source file: 'C:\Users\dean7\Desktop\main.rs\crates\cratess\target\debug\build\ncurses-
4eee2f93b40e2da2\out\chtype_size.c': Permission denied
--- stderr
cl : Command line warning D9035 : option 'o' has been deprecated and will be removed in a future release
thread 'main' panicked at 'assertion failed: command.status().expect(\"compilation failed\").success()', C:\Users\{%USERPROFILE%}\.cargo\registry\src\github.com-1ecc6299db9ec823\ncurses-5.101.0\build.rs:105:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
My "Cargo.toml" file looks like this,
[package]
name = "cratess"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
cursive = "0.20.0"
My "main.rs" file looks like this,
use cursive::{Cursive, CursiveExt};
fn main() {
let mut app = Cursive::new();
app.run();
println!("Hello, world!");
}
My error when I run the command, run my code is this,
error[E0432]: unresolved import `cursive`
--> tempCodeRunnerFile.rs:1:5
|
1 | use cursive::{Cursive, CursiveExt};
| ^^^^^^^ maybe a missing crate `cursive`?
|
= help: consider adding `extern crate cursive` to use the `cursive` crate
error: aborting due to previous error
For more information about this error, try `rustc --explain E0432`.
An additional warning is given when I run "cargo build" in my terminal (NOT IN CMD),
warning: build failed, waiting for other jobs to finish...

Error running cargo build with clickhouse dependency

I added this to my cargo toml file, following the instructions here
[dependencies]
clickhouse = "0.6.3"
reflection = "0.1.3"
but when I run cargo build I get a failure saying:
Compiling clickhouse v0.6.3
error[E0433]: failed to resolve: could not find `test` in `tokio`
--> /Users/gudjonragnar/.cargo/registry/src/github.com-1ecc6299db9ec823/clickhouse-0.6.3/src/compression/lz4.rs:163:10
|
163 | #[tokio::test]
| ^^^^ could not find `test` in `tokio`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0433`.
error: could not compile `clickhouse`
To learn more, run the command again with --verbose.
warning: build failed, waiting for other jobs to finish...
error: build failed
I am quite new to Rust so I don't know what to do here, any thoughts?
I am running on MacOS BigSur if that is relevant.
I am getting this error on Linux as well. This appears to be an issue in the clickhouse crate, but it can be fixed in your Cargo.toml. #[tokio::test] refers to a macro which requires both the "rt" and "macros" features, but the Cargo.toml file in the clickhouse crate only includes the "rt" feature. In order to add this feature so that the crate will compile, you can add a line to your Cargo.toml for tokio that enables that feature:
tokio = { version = "1.0.1", features = ["rt", "macros"] }
Adding this line fixed the compiler error for me.
I noticed there is another clickhouse crate, which might also be helpful

Crate with diesel and mysql dependencies no longer compiles against mariadb after upgrading NixOS to 20.03

My crate, which depends on diesel with the mysql feature enabled, no longer compiles after upgrading my system from NixOS 19.09 to 20.03. It seems the only significant change is an update of the mariadb-server package from 10.2.17 to 10.3.18. There is no change to the Rust toolchain etc. (it's statically pinned in nix-shell to nightly 2020-04-20).
The very long compiler message starts with:
warning: build failed, waiting for other jobs to finish...
error: linking with `cc` failed: exit code: 1
What should I do?
This build script that tells Cargo to link the crate using the compiler's flag `-lmariadb solved the issue:
fn main() {
println!("cargo:rustc-link-lib=mariadb");
}
Update 2020-05-01
Actually the issue could be solved in mysqlclient-sys crate.

Why is this unrelated crate breaking my project?

$ cargo build
Downloading pear_codegen v0.0.16
Compiling pear_codegen v0.0.16
Compiling ring v0.11.0
error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
--> /.cargo/registry/src/github.com-1ecc6299db9ec823/pear_codegen-0.0.16/src/lib.rs:317:9
|
317 | ExprKind::Block(block) => {
| ^^^^^^^^^^^^^^^^^^^^^^ expected 2 fields, found 1
error: aborting due to previous error
For more information about this error, try `rustc --explain E0023`.
error: Could not compile `pear_codegen`.
warning: build failed, waiting for other jobs to finish...
error: build failed
When I try to compile my project I get an error that a crate that isn't in my cargo.toml is broken. Why is this unrelated crate breaking my project?
You're using Rust nightly, and the crate in question used to depend (in version 0.0.16) on the perma-unstable API of the Rust compiler, which was changed by a nightly you updated to (or just installed).
The author appears to have recently rewritten the crate to avoid that dependency, which means further breakage should be avoided, starting with version 0.0.17 of the crate.
cargo update
fixed the issue for me
https://github.com/SergioBenitez/Pear/issues/7
thanks to reddit user /u/usernamedottxt

Choosing shared or static library with Cargo

I am attempting to modify Racer to emit a shared library instead of an rlib.
To do this, I added crate-type = ["dylib"] to the [lib] section of the Cargo manifest, then ran cargo build --lib. This worked great, and libracer.so was emitted.
Unfortunately, now I could not build the Racer binary, which depends on a static version of the library. Running cargo build complains:
Compiling racer v1.0.0 (file:///home/georgev/dotfiles/vim/bundle/racer)
error: cannot satisfy dependencies so `std` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `core` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `collections` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `rustc_unicode` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `alloc` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `libc` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `rand` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: aborting due to 7 previous errors
Could not compile `racer`.
I changed the crate-type to ["dylib", "bin"], which allowed the compilation to succeed. However, cargo build --lib will not emit a shared library anymore (only an rlib).
How can I specify which type of library I would like to build, while still allowing said library to be built statically for inclusion in an executable?
bin is not a valid crate-type value. The valid values are rlib, lib, staticlib, and dylib. Changing the crate type to
crate-type = ["dylib", "rlib"]
will cause the behavior you're after.
The reason that only an rlib is emitted with ["dylib", "bin"] is because there is currently a Cargo bug that causes invalid values for crate-type to only produce an rlib. I've filed a pull request to fix the issue.

Resources