24

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
  • 10,628
  • 21
  • 93
  • 157

2 Answers2

34

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
  • 10,628
  • 21
  • 93
  • 157
DK.
  • 49,288
  • 3
  • 161
  • 146
14

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,131
  • 14
  • 82
  • 102
oli_obk
  • 25,579
  • 3
  • 73
  • 89