Error when build via cargo


#1

i did my best to discover why do i get this compile error
and try to fix it but i could not find any help on-line until i decided to bring it here
link to problematic call
this is the code that suppose to compile properly.

extern crate libc;
use libc::c_char;
use libc::c_int;

#[repr(C)]
pub struct PackChar {
    pub int_val: c_int,
    pub buffer: *mut c_char, // changed
    pub buffer_size: c_int, // added
}

#[no_mangle]
pub extern fn get_packs_char(size: c_int) -> *mut PackChar {
    use std::char;

    let mut out_vec = Vec::new();

    for i in 0..size {
        let int_0 = '0' as u32;
        let last_char_val = int_0 + i as u32 % (126 - int_0);
        let last_char = char::from_u32(last_char_val).unwrap();

        let buffer = format!("abcdefgHi{}", last_char);
        let buffer_size = buffer.len() as c_int;
        let buffer = Box::into_raw(buffer.into_bytes().into_boxed_slice()) as *mut _; // added

        let pack_char = PackChar {
            int_val: i,
            buffer: buffer,
            buffer_size: buffer_size,
        };

        out_vec.push(pack_char);
    }

    Box::into_raw(out_vec.into_boxed_slice()) as *mut _ // changed
}

cargo 0.4.0-nightly (553b363 2015-08-03) (built 2015-08-03)
rustc 1.3.0 (9a92aaf19 2015-09-15)

src\lib.rs:26:22: 26:35 error: use of unstable library feature 'box_raw': may be r
src\lib.rs:26         let buffer = Box::into_raw(buffer.into_bytes().into_boxed_sl
                                   ^~~~~~~~~~~~~
note: in expansion of for loop expansion
src\lib.rs:19:5: 35:6 note: expansion site
src\lib.rs:37:5: 37:18 error: use of unstable library feature 'box_raw': may be re
src\lib.rs:37     Box::into_raw(out_vec.into_boxed_slice()) as *mut _ // changed
                  ^~~~~~~~~~~~~

#2

Use a nightly instead of stable? Cargo is not an issue here.


#3

If you update to Rust 1.4, it should work. Just tried on the playpen. In 1.3, that feature was still unstable, hence why it won’t work.


#4

@DanielKeep cheers i was sure i have most updated version thanks !


#5

do i need this at the top ?

#![feature(box_raw)]

#6

No. It works just fine in stable on playpen.


#7

thanks a lot for your help @DanielKeep ! you too @PeteVine