[SOLVED] Feature gates not working even when using nightly compiler (error[E0554]: `#![feature]` may not be used on the stable release channel)

Hi there!

I've been working on a simple cryptography crate (for learning purposes) and I'd ideally need generic_const_exprs to determine the size of an array at compile time based on a generic argument. To do this I'd like to enable the generic_const_exprs feature and use the nightly compiler, however, this is proving to be harder than I thought. My lib.rs contains

#![feature(generic_const_exprs)]

at the top, I have downloaded and installed the nightly compiler, and overridden the compiler version using both rustup default nightly and rustup override set nightly. I've even invoked cargo using rustup run nightly cargo build, yet I still keep getting this error!

error[E0554]: `#![feature]` may not be used on the stable release channel
 --> src/lib.rs:1:1
  |
1 | #![feature(generic_const_exprs)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I'm sure I'm just missing something trivial, yet I've been pulling my hair out the past couple of days trying to get it to compile. Could it be Homebrew messing things up or am I missing something? Additional info below.

$ which cargo
/usr/local/bin/cargo

$ which rustup
/Users/jake/.cargo/bin/rustup

$ cargo --version
cargo 1.79.0

$ rustup --version
rustup 1.27.1 (54dd3d00f 2024-04-24)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.81.0-nightly (5affbb171 2024-07-18)`

$ rustup show
Default host: x86_64-apple-darwin
rustup home:  /Users/jake/.rustup

installed toolchains
--------------------

stable-x86_64-apple-darwin
nightly-x86_64-apple-darwin (default)

active toolchain
----------------

nightly-x86_64-apple-darwin (directory override for '/Users/jake/nightly-test')
rustc 1.81.0-nightly (5affbb171 2024-07-18)

Look for rust-toolchain(.toml) files and RUST_TOOLCHAIN env var that may be overriding the default rustup toolchain.

Also check if you have another Rust package installed that isn't from rustup (brew remove rust)

Running brew remove rust magically fixed everything. I was so sure that I hadn't installed it through brew that I didn't bother checking. Lesson learned... Massive thanks and sorry for missing such a simple troubleshooting step!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.