29

This

fn main() {

    let test = "Foo".to_string();
    test.to_lowercase();

}

produces an error

error: use of unstable library feature 'collections'
       test.to_lowercase();
            ^~~~~~~~~~~~~~

but I am using

rustc 1.2.0-nightly (f76d9bcfc 2015-05-28) (built 2015-05-28)

and according to http://doc.rust-lang.org/1.0.0/book/release-channels.html unstable features are enabled on nightly. I've also tried stable and beta, but the error is exactly the same. So what's the issue here?

Caballero
  • 11,546
  • 22
  • 103
  • 163

3 Answers3

42

You need to explicitly opt-in by placing #![feature(collections)] at the top of your crate's root source file. Using a nightly compiler merely permits you to use unstable features, it doesn't automatically enable them.

See also this related SO question.

Caballero
  • 11,546
  • 22
  • 103
  • 163
DK.
  • 55,277
  • 5
  • 189
  • 162
13

If you look below the error message (on nightly), there's a hint as to what you need to do to activate this feature (just because it's in the nightly, doesn't mean the feature is active)

<anon>:3:10: 3:24 help: add #![feature(collections)] to the crate attributes to enable
error: aborting due to previous error

Always read the full error message, especially the note: and help: parts. These often tell you how to fix the error.

stkent
  • 19,772
  • 14
  • 85
  • 111
oli_obk
  • 28,729
  • 6
  • 82
  • 98
1

I was getting below error when I create

cargo generate --git https://github.com/rustwasm/wasm-pack-template
error[E0658]: use of unstable library feature 'bool_to_option'
   --> /Users/anjum/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-generate-0.17.3/src/user_parsed_input.rs:182:22
    |
182 |                     .then_some(true)
    |                      ^^^^^^^^^
    |
    = note: see issue #80967 <https://github.com/rust-lang/rust/issues/80967> for more information

error[E0658]: use of unstable library feature 'bool_to_option'
   --> /Users/anjum/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-generate-0.17.3/src/user_parsed_input.rs:350:38
    |
350 |     (path.exists() && path.is_dir()).then_some(path)
    |                                      ^^^^^^^^^
    |
    = note: see issue #80967 <https://github.com/rust-lang/rust/issues/80967> for more information

after updating the core rust with below all worked perfectly fine.

rustup update
Anjum....
  • 4,086
  • 1
  • 35
  • 45