about summary refs log tree commit diff
path: root/src/liballoc
AgeCommit message (Collapse)AuthorLines
2015-02-01box: into_raw, from_raw functionsStepan Koltsov-0/+88
Functions are needed for safety and convenience. It is a common pattern to use `mem::transmute` to convert between `Box` and raw pointer, like this: ``` let b = Box::new(3); let p = mem::transmute(b); // pass `p` to some C library ``` After this commit, conversion can be written as: ``` let p = boxed::into_raw(b); ``` `into_raw` and `from_raw` functions are still unsafe, but they are much safer than `mem::transmute`, because *raw functions do not convert between incompatible pointers. For example, this likely incorrect code can be successfully compiled: ``` let p: *mut u64 = ... let b: Box<u32> = mem::transmute(p); ``` Using `from_raw` results in compile-time error: ``` let p: *mut u64 = ... let b: Box<u32> = Box::from_raw(p); // compile-time error ``` `into_raw` and `from_raw` functions are similar to C++ `std::unique_ptr` `release` function [1] and constructor from pointer [2]. [1] http://en.cppreference.com/w/cpp/memory/unique_ptr/release [2] http://en.cppreference.com/w/cpp/memory/unique_ptr/unique_ptr
2015-02-01More deprecating of i/u suffixes in librariesAlfie John-32/+32
2015-01-30Merge remote-tracking branch 'origin/master' into rollupAlex Crichton-0/+1
Conflicts: src/liballoc/lib.rs src/libcore/ops.rs
2015-01-30Test fixes and rebase conflictsAlex Crichton-2/+1
Also some tidying up of a bunch of crate attributes
2015-01-30rollup merge of #21631: tbu-/isize_policeAlex Crichton-63/+63
Conflicts: src/libcoretest/iter.rs
2015-01-30std: Stabilize the std::fmt moduleAlex Crichton-13/+16
This commit performs a final stabilization pass over the std::fmt module, marking all necessary APIs as stable. One of the more interesting aspects of this module is that it exposes a good deal of its runtime representation to the outside world in order for `format_args!` to be able to construct the format strings. Instead of hacking the compiler to assume that these items are stable, this commit instead lays out a story for the stabilization and evolution of these APIs. There are three primary details used by the `format_args!` macro: 1. `Arguments` - an opaque package of a "compiled format string". This structure is passed around and the `write` function is the source of truth for transforming a compiled format string into a string at runtime. This must be able to be constructed in stable code. 2. `Argument` - an opaque structure representing an argument to a format string. This is *almost* a trait object as it's just a pointer/function pair, but due to the function originating from one of many traits, it's not actually a trait object. Like `Arguments`, this must be constructed from stable code. 3. `fmt::rt` - this module contains the runtime type definitions primarily for the `rt::Argument` structure. Whenever an argument is formatted with nonstandard flags, a corresponding `rt::Argument` is generated describing how the argument is being formatted. This can be used to construct an `Arguments`. The primary interface to `std::fmt` is the `Arguments` structure, and as such this type name is stabilize as-is today. It is expected for libraries to pass around an `Arguments` structure to represent a pending formatted computation. The remaining portions are largely "cruft" which would rather not be stabilized, but due to the stability checks they must be. As a result, almost all pieces have been renamed to represent that they are "version 1" of the formatting representation. The theory is that at a later date if we change the representation of these types we can add new definitions called "version 2" and corresponding constructors for `Arguments`. One of the other remaining large questions about the fmt module were how the pending I/O reform would affect the signatures of methods in the module. Due to [RFC 526][rfc], however, the writers of fmt are now incompatible with the writers of io, so this question has largely been solved. As a result the interfaces are largely stabilized as-is today. [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0526-fmt-text-writer.md Specifically, the following changes were made: * The contents of `fmt::rt` were all moved under `fmt::rt::v1` * `fmt::rt` is stable * `fmt::rt::v1` is stable * `Error` is stable * `Writer` is stable * `Writer::write_str` is stable * `Writer::write_fmt` is stable * `Formatter` is stable * `Argument` has been renamed to `ArgumentV1` and is stable * `ArgumentV1::new` is stable * `ArgumentV1::from_uint` is stable * `Arguments::new_v1` is stable (renamed from `new`) * `Arguments::new_v1_formatted` is stable (renamed from `with_placeholders`) * All formatting traits are now stable, as well as the `fmt` method. * `fmt::write` is stable * `fmt::format` is stable * `Formatter::pad_integral` is stable * `Formatter::pad` is stable * `Formatter::write_str` is stable * `Formatter::write_fmt` is stable * Some assorted top level items which were only used by `format_args!` were removed in favor of static functions on `ArgumentV1` as well. * The formatting-flag-accessing methods remain unstable Within the contents of the `fmt::rt::v1` module, the following actions were taken: * Reexports of all enum variants were removed * All prefixes on enum variants were removed * A few miscellaneous enum variants were renamed * Otherwise all structs, fields, and variants were marked stable. In addition to these actions in the `std::fmt` module, many implementations of `Show` and `String` were stabilized as well. In some other modules: * `ToString` is now stable * `ToString::to_string` is now stable * `Vec` no longer implements `fmt::Writer` (this has moved to `String`) This is a breaking change due to all of the changes to the `fmt::rt` module, but this likely will not have much impact on existing programs. Closes #20661 [breaking-change]
2015-01-30Use `#[rustc_paren_sugar]` as a more extensible way of deciding whenNiko Matsakis-0/+1
paren sugar is legal.
2015-01-30Remove all `i` suffixesTobias Bucher-63/+63
2015-01-29Auto merge of #21677 - japaric:no-range, r=alexcrichtonbors-10/+6
Note: Do not merge until we get a newer snapshot that includes #21374 There was some type inference fallout (see 4th commit) because type inference with `a..b` is not as good as with `range(a, b)` (see #21672). r? @alexcrichton
2015-01-29s/Show/Debug/gJorge Aparicio-2/+2
2015-01-29remove #[old_impl_check] now that #21363 has been fixedJorge Aparicio-4/+0
2015-01-29`for x in range(a, b)` -> `for x in a..b`Jorge Aparicio-3/+3
sed -i 's/in range(\([^,]*\), *\([^()]*\))/in \1\.\.\2/g' **/*.rs
2015-01-29`range(a, b).foo()` -> `(a..b).foo()`Jorge Aparicio-1/+1
sed -i 's/ range(\([^,]*\), *\([^()]*\))\./ (\1\.\.\2)\./g' **/*.rs
2015-01-29Rollup merge of 21681 - japaric:no-warn, r=alexcrichtonManish Goregaokar-0/+1
2015-01-27fix #[cfg(test)] warningsJorge Aparicio-0/+1
2015-01-25Merge remote-tracking branch 'rust-lang/master'Brian Anderson-236/+186
Conflicts: mk/tests.mk src/liballoc/arc.rs src/liballoc/boxed.rs src/liballoc/rc.rs src/libcollections/bit.rs src/libcollections/btree/map.rs src/libcollections/btree/set.rs src/libcollections/dlist.rs src/libcollections/ring_buf.rs src/libcollections/slice.rs src/libcollections/str.rs src/libcollections/string.rs src/libcollections/vec.rs src/libcollections/vec_map.rs src/libcore/any.rs src/libcore/array.rs src/libcore/borrow.rs src/libcore/error.rs src/libcore/fmt/mod.rs src/libcore/iter.rs src/libcore/marker.rs src/libcore/ops.rs src/libcore/result.rs src/libcore/slice.rs src/libcore/str/mod.rs src/libregex/lib.rs src/libregex/re.rs src/librustc/lint/builtin.rs src/libstd/collections/hash/map.rs src/libstd/collections/hash/set.rs src/libstd/sync/mpsc/mod.rs src/libstd/sync/mutex.rs src/libstd/sync/poison.rs src/libstd/sync/rwlock.rs src/libsyntax/feature_gate.rs src/libsyntax/test.rs
2015-01-23grandfathered -> rust1Brian Anderson-47/+47
2015-01-23Set unstable feature names appropriatelyBrian Anderson-26/+28
* `core` - for the core crate * `hash` - hashing * `io` - io * `path` - path * `alloc` - alloc crate * `rand` - rand crate * `collections` - collections crate * `std_misc` - other parts of std * `test` - test crate * `rustc_private` - everything else
2015-01-22Beef up docs for Box<T>Steve Klabnik-11/+68
2015-01-22Put #[staged_api] behind the 'staged_api' gateBrian Anderson-0/+1
2015-01-21Remove 'since' from unstable attributesBrian Anderson-25/+25
2015-01-21Minor fixesBrian Anderson-2/+0
2015-01-21Tie stability attributes to feature gatesBrian Anderson-3/+1
2015-01-21Add 'feature' and 'since' to stability attributesBrian Anderson-73/+85
2015-01-21Revert "Use assume to inform the optimiser about refcount invariants"Alex Crichton-13/+2
This reverts commit a729a404945de10f99e2530a5c28952996532b29.
2015-01-21Revert "Add assumptions that the pointer is non-null"Alex Crichton-16/+2
This reverts commit 9bbfd681c9fa47f462a89e8f5eedd3fa2a5de2e7.
2015-01-21Revert "Add more explanation for why the assumes are there"Alex Crichton-9/+1
This reverts commit a7525bc4c8eb8507a5c248d29286e77133217cf3.
2015-01-21Test fixes and rebase conflictsAlex Crichton-1/+1
2015-01-21rollup merge of #21457: alexcrichton/issue-21436Alex Crichton-21/+31
Conflicts: src/liballoc/boxed.rs src/librustc/middle/traits/error_reporting.rs src/libstd/sync/mpsc/mod.rs
2015-01-21rollup merge of #21446: stepancheg/boxed-testAlex Crichton-54/+77
Conflicts: src/liballoc/boxed.rs
2015-01-21rollup merge of #21444: petrochenkov/nullAlex Crichton-1/+1
Conflicts: src/libstd/sync/mpsc/select.rs
2015-01-21rollup merge of #21437: FlaPer87/snapshotAlex Crichton-154/+0
r? @alexcrichton
2015-01-21rollup merge of #21418: Aatch/assume-refcountAlex Crichton-4/+37
The reference count can never be 0, unless we're about to drop the data completely. Using the `assume` intrinsic allows us to inform LLVM about that invariant, meaning it can avoid unnecessary drops. --- Before and after IR: https://gist.github.com/Aatch/3786d20df2edaad6a0e8 Generated from the example in #13018 Fixes #13018
2015-01-21rollup merge of #21392: japaric/iterAlex Crichton-0/+17
closes #20953 closes #21361 --- In the future, we will likely derive these `impl`s via syntax extensions or using compiler magic (see #20617). For the time being we can use these manual `impl`s. r? @aturon cc @burntsushi @Kroisse
2015-01-20std: Rename Show/String to Debug/DisplayAlex Crichton-21/+31
This commit is an implementation of [RFC 565][rfc] which is a stabilization of the `std::fmt` module and the implementations of various formatting traits. Specifically, the following changes were performed: [rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0565-show-string-guidelines.md * The `Show` trait is now deprecated, it was renamed to `Debug` * The `String` trait is now deprecated, it was renamed to `Display` * Many `Debug` and `Display` implementations were audited in accordance with the RFC and audited implementations now have the `#[stable]` attribute * Integers and floats no longer print a suffix * Smart pointers no longer print details that they are a smart pointer * Paths with `Debug` are now quoted and escape characters * The `unwrap` methods on `Result` now require `Display` instead of `Debug` * The `Error` trait no longer has a `detail` method and now requires that `Display` must be implemented. With the loss of `String`, this has moved into libcore. * `impl<E: Error> FromError<E> for Box<Error>` now exists * `derive(Show)` has been renamed to `derive(Debug)`. This is not currently warned about due to warnings being emitted on stage1+ While backwards compatibility is attempted to be maintained with a blanket implementation of `Display` for the old `String` trait (and the same for `Show`/`Debug`) this is still a breaking change due to primitives no longer implementing `String` as well as modifications such as `unwrap` and the `Error` trait. Most code is fairly straightforward to update with a rename or tweaks of method calls. [breaking-change] Closes #21436
2015-01-20also forward Iterator::size_hint()Jorge Aparicio-0/+4
2015-01-20Register snapshot for 9006c3cFlavio Percoco-154/+0
2015-01-20alloc::boxed: enable testStepan Koltsov-53/+77
Previously test was disabled due to `#[cfg(test)]` before `mod boxed`.
2015-01-21Add more explanation for why the assumes are thereJames Miller-1/+9
2015-01-21Add assumptions that the pointer is non-nullJames Miller-2/+16
2015-01-21Rollup merge of #21375 - petrochenkov:ssbsl, r=alexcrichtonBarosl LEE-1/+1
After PR #19766 added implicit coersions `*mut T -> *const T`, the explicit casts can be removed. (The number of such casts turned out to be relatively small).
2015-01-21Use assume to inform the optimiser about refcount invariantsJames Miller-2/+13
The reference count can never be 0, unless we're about to drop the data completely. Using the `assume` intrinsic allows us to inform LLVM about that invariant, meaning it can avoid unnecessary drops.
2015-01-19impl Iterator for &mut Iterator and Box<Iterator>Jorge Aparicio-0/+13
closes #20953 closes #21361
2015-01-19Replace `0 as *const/mut T` with `ptr::null/null_mut()`we-1/+1
2015-01-18std: Stabilize TypeId and tweak BoxAnyAlex Crichton-4/+6
This commit aims to stabilize the `TypeId` abstraction by moving it out of the `intrinsics` module into the `any` module of the standard library. Specifically, * `TypeId` is now defined at `std::any::TypeId` * `TypeId::hash` has been removed in favor of an implementation of `Hash`. This commit also performs a final pass over the `any` module, confirming the following: * `Any::get_type_id` remains unstable as *usage* of the `Any` trait will likely never require this, and the `Any` trait does not need to be implemented for any other types. As a result, this implementation detail can remain unstable until associated statics are implemented. * `Any::downcast_ref` is now stable * `Any::downcast_mut` is now stable * `BoxAny` remains unstable. While a direct impl on `Box<Any>` is allowed today it does not allow downcasting of trait objects like `Box<Any + Send>` (those returned from `Thread::join`). This is covered by #18737. * `BoxAny::downcast` is now stable.
2015-01-17Set allow(unstable) in crates that use unstable featuresBrian Anderson-0/+1
Lets them build with the -dev, -nightly, or snapshot compiler
2015-01-17Register new snapshots.Eduard Burtescu-16/+0
2015-01-17Remove unnecessary explicit conversions to *const Twe-1/+1
2015-01-16Don't use NoSend/NoSync in liballocFlavio Percoco-0/+160
2015-01-15auto merge of #20980 : richo/rust/final-power, r=alexcrichtonbors-1/+2
Originally, this was going to be discussed and revisted, however I've been working on this for months, and a rebase on top of master was about 1 flight's worth of work so I just went ahead and did it. This gets you as far as being able to target powerpc with, eg: LD_LIBRARY_PATH=./x86_64-unknown-linux-gnu/stage2/lib/ x86_64-unknown-linux-gnu/stage2/bin/rustc -C linker=powerpc-linux-gnu-gcc --target powerpc-unknown-linux-gnu hello.rs Would really love to get this out before 1.0. r? @alexcrichton