2

Every time I see an error like:

error: associated constants are experimental (see issue #29646)
...
= help: add #![feature(associated_consts)] to the crate attributes to enable
= note: this error originates in a macro outside of the current crate

I fork the crate and add the feature to the crate attributes and then replace the dependency in my Cargo.toml:

[replace."bitflags:1.0.0"]
git = "https://github.com/boehm-s/bitflags"
rev = "bb2afce"

Is there a way to get rid of these errors without forking crates?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
boehm_s
  • 5,254
  • 4
  • 30
  • 44

2 Answers2

6

Associated constants were stabilized recently in Rust 1.20; this error should disappear without any code changes if you upgrade your Rust compiler.

In addition to [replace] and [patch], there's also the option of using .cargo/config to override a dependency locally without changing Cargo.toml.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Daniel
  • 15,944
  • 2
  • 54
  • 60
4

How do I add #![feature(***)] to another crate's attributes without forking the crate?

You don't. You cannot change another crate without... changing it.

You are using an old nightly compiler; update it. If you are using a nightly compiler, it's your responsibility to keep it up-to-date. If you don't know why you have a nightly compiler, switch to a stable compiler.


This can only occur if:

  1. You are using a nightly compiler. If you weren't, you wouldn't get the suggestion to add the attribute, it'd be a hard error.
  2. You are using a crate that relies on a feature that has not been stabilized in your version of the compiler and thus requires the attribute to enable it.
  3. The feature has been stabilized in a newer version of Rust and thus the crate no longer needs to have the attribute itself.

For this example, you can read the crates changelog:

1.0.0

  • [breaking change] Macro now generates associated constants (#24)

  • [breaking change] Minimum supported version is Rust 1.20, due to usage of associated constants

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
  • 1
    Thanks, I'm using a nightly compiler because I will use crates that relies on non-stable features, and it doesn't only concern the `associated_consts` feature, this was just an example – boehm_s Oct 16 '17 at 20:19
  • 2
    @boehm_s right, which is why I put the stuff specific to `associated_consts` at the end of the answer — all the rest of it is generic. – Shepmaster Oct 16 '17 at 20:25