2

I have been using 0.10 and recently setup a build of nightly to experiment with Box and friends.

Now I have code for 0.10 using ~str and code for pre0.11 using String because of to_owned being obsolete. I thought I could do this:

#[cfg(rust_version = "0.10")]
fn my_old_func() -> Option<~str> {
}

#[cfg(not(rust_version = "0.10")]
fn my_old_func() -> Option<String> {
}

And pass --cfg rust_version:0.11 during compilation. But the compiler still chokes on the now removed ~ operator. Is there a way to have code that works under both 0.10 and the as yet unreleased 0.11 using conditional compilation or some other mechanism?

I guess I could fall back to using cpp and #ifdef but that seems like stepping out of the Rust mindset.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Sean Perry
  • 3,776
  • 1
  • 19
  • 31
  • Btw, I think you would have to pass `--cfg 'rust_version="0.11"'` for the `cfg` to work. – huon Jun 19 '14 at 09:43

1 Answers1

3

No, there is nothing you can do about this.

Our typical recommendation is not to use 0.10 but to stick with nightlies.

Chris Morgan
  • 86,207
  • 24
  • 208
  • 215