Skip to content

Newtype struct with dtor #5534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/libcore/at_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub mod rustrt {

/// Returns the number of elements the vector can hold without reallocating
#[inline(always)]
pub fn capacity<T>(v: @[const T]) -> uint {
pub fn capacity<T>(v: @[T]) -> uint {
unsafe {
let repr: **raw::VecRepr =
::cast::reinterpret_cast(&addr_of(&v));
Expand All @@ -60,7 +60,7 @@ pub fn capacity<T>(v: @[const T]) -> uint {
*/
#[inline(always)]
pub fn build_sized<A>(size: uint, builder: &fn(push: &fn(v: A))) -> @[A] {
let mut vec: @[const A] = @[];
let mut vec: @[A] = @[];
unsafe { raw::reserve(&mut vec, size); }
builder(|+x| unsafe { raw::push(&mut vec, x) });
return unsafe { transmute(vec) };
Expand Down Expand Up @@ -102,7 +102,7 @@ pub fn build_sized_opt<A>(size: Option<uint>,

// Appending
#[inline(always)]
pub fn append<T:Copy>(lhs: @[T], rhs: &[const T]) -> @[T] {
pub fn append<T:Copy>(lhs: @[T], rhs: &const [T]) -> @[T] {
do build_sized(lhs.len() + rhs.len()) |push| {
for vec::each(lhs) |x| { push(*x); }
for uint::range(0, rhs.len()) |i| { push(rhs[i]); }
Expand Down Expand Up @@ -174,9 +174,9 @@ pub mod traits {
use kinds::Copy;
use ops::Add;

impl<T:Copy> Add<&'self [const T],@[T]> for @[T] {
impl<T:Copy> Add<&'self const [T],@[T]> for @[T] {
#[inline(always)]
fn add(&self, rhs: & &'self [const T]) -> @[T] {
fn add(&self, rhs: & &'self const [T]) -> @[T] {
append(*self, (*rhs))
}
}
Expand Down Expand Up @@ -207,13 +207,13 @@ pub mod raw {
* the vector is actually the specified size.
*/
#[inline(always)]
pub unsafe fn set_len<T>(v: @[const T], new_len: uint) {
pub unsafe fn set_len<T>(v: @[T], new_len: uint) {
let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(&v));
(**repr).unboxed.fill = new_len * sys::size_of::<T>();
}

#[inline(always)]
pub unsafe fn push<T>(v: &mut @[const T], initval: T) {
pub unsafe fn push<T>(v: &mut @[T], initval: T) {
let repr: **VecRepr = ::cast::reinterpret_cast(&v);
let fill = (**repr).unboxed.fill;
if (**repr).unboxed.alloc > fill {
Expand All @@ -225,7 +225,7 @@ pub mod raw {
}

#[inline(always)] // really pretty please
pub unsafe fn push_fast<T>(v: &mut @[const T], initval: T) {
pub unsafe fn push_fast<T>(v: &mut @[T], initval: T) {
let repr: **VecRepr = ::cast::reinterpret_cast(&v);
let fill = (**repr).unboxed.fill;
(**repr).unboxed.fill += sys::size_of::<T>();
Expand All @@ -234,7 +234,7 @@ pub mod raw {
move_val_init(&mut(*p), initval);
}

pub unsafe fn push_slow<T>(v: &mut @[const T], initval: T) {
pub unsafe fn push_slow<T>(v: &mut @[T], initval: T) {
reserve_at_least(&mut *v, v.len() + 1u);
push_fast(v, initval);
}
Expand All @@ -250,7 +250,7 @@ pub mod raw {
* * v - A vector
* * n - The number of elements to reserve space for
*/
pub unsafe fn reserve<T>(v: &mut @[const T], n: uint) {
pub unsafe fn reserve<T>(v: &mut @[T], n: uint) {
// Only make the (slow) call into the runtime if we have to
if capacity(*v) < n {
let ptr: **VecRepr = transmute(v);
Expand All @@ -274,7 +274,7 @@ pub mod raw {
* * v - A vector
* * n - The number of elements to reserve space for
*/
pub unsafe fn reserve_at_least<T>(v: &mut @[const T], n: uint) {
pub unsafe fn reserve_at_least<T>(v: &mut @[T], n: uint) {
reserve(v, uint::next_power_of_two(n));
}

Expand Down
10 changes: 5 additions & 5 deletions src/libcore/cleanup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ struct MemoryRegion { priv opaque: () }
#[cfg(target_arch="x86")]
#[cfg(target_arch="arm")]
struct Registers {
data: [u32 * 16]
data: [u32, ..16]
}

#[cfg(target_arch="mips")]
struct Registers {
data: [u32 * 32]
data: [u32, ..32]
}

#[cfg(target_arch="x86")]
Expand All @@ -52,12 +52,12 @@ struct Registers {
struct Context {
regs: Registers,
next: *Context,
pad: [u32 * 3]
pad: [u32, ..3]
}

#[cfg(target_arch="x86_64")]
struct Registers {
data: [u64 * 22]
data: [u64, ..22]
}

#[cfg(target_arch="x86_64")]
Expand All @@ -80,7 +80,7 @@ struct Task {
// Public fields
refcount: intptr_t, // 0
id: TaskID, // 4
pad: [u32 * 2], // 8
pad: [u32, ..2], // 8
ctx: Context, // 16
stack_segment: *StackSegment, // 96
runtime_sp: uintptr_t, // 100
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/flate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static lz_fast : c_int = 0x1; // LZ with only one probe
static lz_norm : c_int = 0x80; // LZ with 128 probes, "normal"
static lz_best : c_int = 0xfff; // LZ with 4095 probes, "best"

pub fn deflate_bytes(bytes: &[const u8]) -> ~[u8] {
pub fn deflate_bytes(bytes: &const [u8]) -> ~[u8] {
do vec::as_const_buf(bytes) |b, len| {
unsafe {
let mut outsz : size_t = 0;
Expand All @@ -64,7 +64,7 @@ pub fn deflate_bytes(bytes: &[const u8]) -> ~[u8] {
}
}

pub fn inflate_bytes(bytes: &[const u8]) -> ~[u8] {
pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] {
do vec::as_const_buf(bytes) |b, len| {
unsafe {
let mut outsz : size_t = 0;
Expand Down
12 changes: 6 additions & 6 deletions src/libcore/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<A:Hash> HashUtil for A {

/// Streaming hash-functions should implement this.
pub trait Streaming {
fn input(&self, (&[const u8]));
fn input(&self, (&const [u8]));
// These can be refactored some when we have default methods.
fn result_bytes(&self) -> ~[u8];
fn result_str(&self) -> ~str;
Expand Down Expand Up @@ -162,7 +162,7 @@ struct SipState {
mut v1: u64,
mut v2: u64,
mut v3: u64,
mut tail: [u8 * 8], // unprocessed bytes
mut tail: [u8, ..8], // unprocessed bytes
mut ntail: uint, // how many bytes in tail are valid
}

Expand Down Expand Up @@ -221,7 +221,7 @@ impl io::Writer for SipState {

// Methods for io::writer
#[inline(always)]
fn write(&self, msg: &[const u8]) {
fn write(&self, msg: &const [u8]) {

let length = msg.len();
self.length += length;
Expand Down Expand Up @@ -299,7 +299,7 @@ impl io::Writer for SipState {
impl Streaming for SipState {

#[inline(always)]
fn input(&self, buf: &[const u8]) {
fn input(&self, buf: &const [u8]) {
self.write(buf);
}

Expand Down Expand Up @@ -369,7 +369,7 @@ impl Streaming for SipState {

#[test]
pub fn test_siphash() {
let vecs : [[u8 * 8] * 64] = [
let vecs : [[u8, ..8], ..64] = [
[ 0x31, 0x0e, 0x0e, 0xdd, 0x47, 0xdb, 0x6f, 0x72, ],
[ 0xfd, 0x67, 0xdc, 0x93, 0xc5, 0x39, 0xf8, 0x74, ],
[ 0x5a, 0x4f, 0xa9, 0xd9, 0x09, 0x80, 0x6c, 0x0d, ],
Expand Down Expand Up @@ -443,7 +443,7 @@ pub fn test_siphash() {
let stream_inc = &State(k0,k1);
let stream_full = &State(k0,k1);

fn to_hex_str(r: &[u8 * 8]) -> ~str {
fn to_hex_str(r: &[u8, ..8]) -> ~str {
let mut s = ~"";
for vec::each(*r) |b| {
s += uint::to_str_radix(*b as uint, 16u);
Expand Down
18 changes: 10 additions & 8 deletions src/libcore/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ pub enum WriterType { Screen, File }
pub trait Writer {

/// Write all of the given bytes.
fn write(&self, v: &[const u8]);
fn write(&self, v: &const [u8]);

/// Move the current position within the stream. The second parameter
/// determines the position that the first parameter is relative to.
Expand All @@ -684,23 +684,23 @@ pub trait Writer {
}

impl Writer for @Writer {
fn write(&self, v: &[const u8]) { self.write(v) }
fn write(&self, v: &const [u8]) { self.write(v) }
fn seek(&self, a: int, b: SeekStyle) { self.seek(a, b) }
fn tell(&self) -> uint { self.tell() }
fn flush(&self) -> int { self.flush() }
fn get_type(&self) -> WriterType { self.get_type() }
}

impl<W:Writer,C> Writer for Wrapper<W, C> {
fn write(&self, bs: &[const u8]) { self.base.write(bs); }
fn write(&self, bs: &const [u8]) { self.base.write(bs); }
fn seek(&self, off: int, style: SeekStyle) { self.base.seek(off, style); }
fn tell(&self) -> uint { self.base.tell() }
fn flush(&self) -> int { self.base.flush() }
fn get_type(&self) -> WriterType { File }
}

impl Writer for *libc::FILE {
fn write(&self, v: &[const u8]) {
fn write(&self, v: &const [u8]) {
unsafe {
do vec::as_const_buf(v) |vbuf, len| {
let nout = libc::fwrite(vbuf as *c_void,
Expand Down Expand Up @@ -750,7 +750,7 @@ pub fn FILE_writer(f: *libc::FILE, cleanup: bool) -> @Writer {
}

impl Writer for fd_t {
fn write(&self, v: &[const u8]) {
fn write(&self, v: &const [u8]) {
unsafe {
let mut count = 0u;
do vec::as_const_buf(v) |vbuf, len| {
Expand Down Expand Up @@ -907,8 +907,10 @@ pub fn u64_to_be_bytes<T>(n: u64, size: uint,
}
}

pub fn u64_from_be_bytes(data: &[const u8],
start: uint, size: uint) -> u64 {
pub fn u64_from_be_bytes(data: &const [u8],
start: uint,
size: uint)
-> u64 {
let mut sz = size;
fail_unless!((sz <= 8u));
let mut val = 0_u64;
Expand Down Expand Up @@ -1140,7 +1142,7 @@ pub struct BytesWriter {
}

impl Writer for BytesWriter {
fn write(&self, v: &[const u8]) {
fn write(&self, v: &const [u8]) {
let v_len = v.len();
let bytes_len = vec::uniq_len(&const self.bytes);

Expand Down
8 changes: 4 additions & 4 deletions src/libcore/libc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ pub mod types {
st_mtime_nsec: c_long,
st_ctime: time_t,
st_ctime_nsec: c_long,
__unused: [c_long * 3],
__unused: [c_long, ..3],
}
}
pub mod posix08 {
Expand Down Expand Up @@ -430,7 +430,7 @@ pub mod types {
st_lspare: int32_t,
st_birthtime: time_t,
st_birthtime_nsec: c_long,
__unused: [uint8_t * 2],
__unused: [uint8_t, ..2],
}
}
pub mod posix08 {
Expand Down Expand Up @@ -631,7 +631,7 @@ pub mod types {
st_flags: uint32_t,
st_gen: uint32_t,
st_lspare: int32_t,
st_qspare: [int64_t * 2],
st_qspare: [int64_t, ..2],
}
}
pub mod posix08 {
Expand Down Expand Up @@ -712,7 +712,7 @@ pub mod types {
st_flags: uint32_t,
st_gen: uint32_t,
st_lspare: int32_t,
st_qspare: [int64_t * 2],
st_qspare: [int64_t, ..2],
}
}
pub mod posix08 {
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/rt/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn initialize_call_frame(regs: &mut Registers,
}

#[cfg(target_arch = "x86_64")]
type Registers = [uint * 22];
type Registers = [uint, ..22];

#[cfg(target_arch = "x86_64")]
fn new_regs() -> ~Registers { ~[0, .. 22] }
Expand Down Expand Up @@ -137,7 +137,7 @@ fn initialize_call_frame(regs: &mut Registers,
}

#[cfg(target_arch = "arm")]
type Registers = [uint * 32];
type Registers = [uint, ..32];

#[cfg(target_arch = "arm")]
fn new_regs() -> ~Registers { ~[0, .. 32] }
Expand All @@ -156,7 +156,7 @@ fn initialize_call_frame(regs: &mut Registers,
}

#[cfg(target_arch = "mips")]
type Registers = [uint * 32];
type Registers = [uint, ..32];

#[cfg(target_arch = "mips")]
fn new_regs() -> ~Registers { ~[0, .. 32] }
Expand Down
18 changes: 9 additions & 9 deletions src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Section: Creating a string
*
* Fails if invalid UTF-8
*/
pub fn from_bytes(vv: &[const u8]) -> ~str {
pub fn from_bytes(vv: &const [u8]) -> ~str {
fail_unless!(is_utf8(vv));
return unsafe { raw::from_bytes(vv) };
}
Expand Down Expand Up @@ -1574,7 +1574,7 @@ Section: Misc
*/

/// Determines if a vector of bytes contains valid UTF-8
pub fn is_utf8(v: &[const u8]) -> bool {
pub fn is_utf8(v: &const [u8]) -> bool {
let mut i = 0u;
let total = vec::len::<u8>(v);
while i < total {
Expand Down Expand Up @@ -1921,12 +1921,12 @@ static max_five_b: uint = 67108864u;
static tag_six_b: uint = 252u;

// Constants used for converting strs to floats
pub static inf_buf: [u8*3] = ['i' as u8, 'n' as u8, 'f' as u8];
pub static positive_inf_buf: [u8*4] = ['+' as u8, 'i' as u8,
'n' as u8, 'f' as u8];
pub static negative_inf_buf: [u8*4] = ['-' as u8, 'i' as u8,
'n' as u8, 'f' as u8];
pub static nan_buf: [u8*3] = ['N' as u8, 'a' as u8, 'N' as u8];
pub static inf_buf: [u8, ..3] = ['i' as u8, 'n' as u8, 'f' as u8];
pub static positive_inf_buf: [u8, ..4] = ['+' as u8, 'i' as u8,
'n' as u8, 'f' as u8];
pub static negative_inf_buf: [u8, ..4] = ['-' as u8, 'i' as u8,
'n' as u8, 'f' as u8];
pub static nan_buf: [u8, ..3] = ['N' as u8, 'a' as u8, 'N' as u8];

/**
* Work with the byte buffer of a string.
Expand Down Expand Up @@ -2131,7 +2131,7 @@ pub mod raw {
}

/// Converts a vector of bytes to a string.
pub unsafe fn from_bytes(v: &[const u8]) -> ~str {
pub unsafe fn from_bytes(v: &const [u8]) -> ~str {
do vec::as_const_buf(v) |buf, len| {
from_buf_len(buf, len)
}
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ pub mod tests {

#[test]
pub fn nonzero_size_of_basic() {
type Z = [i8 * 0];
type Z = [i8, ..0];
fail_unless!(size_of::<Z>() == 0u);
fail_unless!(nonzero_size_of::<Z>() == 1u);
fail_unless!(nonzero_size_of::<uint>() == size_of::<uint>());
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/to_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use io::Writer;
use option::{None, Option, Some};
use str;

pub type Cb = &'self fn(buf: &[const u8]) -> bool;
pub type Cb = &'self fn(buf: &const [u8]) -> bool;

/**
* A trait to implement in order to make a type hashable;
Expand Down
Loading