Help building project with external crates using unstable features

Hi! I’m encountering the following sort of cargo build errors using the nightly toolchain on Linux (cargo 1.29.0-nightly (b42488270 2018-08-04):

error[E0658]: use of unstable library feature 'proc_macro_span' (see issue #38356)
   --> /arc/u/marf/.cargo/registry/src/
284 |     Nightly(proc_macro::SourceFile, FileName),
    |             ^^^^^^^^^^^^^^^^^^^^^^
    = help: add #![feature(proc_macro_span)] to the crate attributes to enable

I’ve attempted to use the RUSTFLAGS environment variable to enable these unstable features (as I saw documented or suggested somewhere) but without success:

$ RUSTFLAGS='--cfg proc_macro_span' cargo +nightly build

Is this the right way to enable unstable features using the command line? I’ve also tried various formulations to specify these unstable feature attributes in .cargo/config, again without success.

As this is someone else’s project I’ve just cloned to install and try out, I’d rather not modify the source code, at least not yet. Am I on the right track here? What’s the best way to do this?


One of the project maintainers explained to me that I was using a too-recent toolchain. I had used a nightly version I had on hand, unaware that rustup should be used to install the project-specific version of the toolchain as specificied in the project’s rust-toolchain file.

I was told that the rustup installer script at, when run in the project directory, would use this rust-toolchain file to install the proper version but that was not my experience. Rather, I had to explicitly use the rustup toolchain install <nightly-version> command.

I’ve subsequently determined the cause of my issue to have been an explicit RUSTUP_TOOLCHAIN="nightly" environment variable I’d set in my .bashrc file when I initially installed rustup several weeks ago. Since unsetting it, cargo build uses the proper toolchain specified in the project’s rust-toolchain file.

Clearly this was a self-infliced wound by a newbie too clever by half! :slight_smile:

1 Like