about summary refs log tree commit diff
path: root/src/libstd/cast.rs
AgeCommit message (Collapse)AuthorLines
2014-05-07core: Inherit the cast moduleAlex Crichton-149/+0
2014-05-05std: deprecate cast::transmute_mut.Huon Wilson-0/+1
Turning a `&T` into an `&mut T` carries a large risk of undefined behaviour, and needs to be done very very carefully. Providing a convenience function for exactly this task is a bad idea, just tempting people into doing the wrong thing. The right thing is to use types like `Cell`, `RefCell` or `Unsafe`. For memory safety, Rust has that guarantee that `&mut` pointers do not alias with any other pointer, that is, if you have a `&mut T` then that is the only usable pointer to that `T`. This allows Rust to assume that writes through a `&mut T` do not affect the values of any other `&` or `&mut` references. `&` pointers have no guarantees about aliasing or not, so it's entirely possible for the same pointer to be passed into both arguments of a function like fn foo(x: &int, y: &int) { ... } Converting either of `x` or `y` to a `&mut` pointer and modifying it would affect the other value: invalid behaviour. (Similarly, it's undefined behaviour to modify the value of an immutable local, like `let x = 1;`.) At a low-level, the *only* safe way to obtain an `&mut` out of a `&` is using the `Unsafe` type (there are higher level wrappers around it, like `Cell`, `RefCell`, `Mutex` etc.). The `Unsafe` type is registered with the compiler so that it can reason a little about these `&` to `&mut` casts, but it is still up to the user to ensure that the `&mut`s obtained out of an `Unsafe` never alias. (Note that *any* conversion from `&` to `&mut` can be invalid, including a plain `transmute`, or casting `&T` -> `*T` -> `*mut T` -> `&mut T`.) [breaking-change]
2014-05-02Replace most ~exprs with 'box'. #11779Brian Anderson-1/+1
2014-04-22auto merge of #13651 : ryantm/rust/master, r=brsonbors-3/+2
2014-04-20fix copyright message based on `make check`Ryan Mulligan-3/+3
2014-04-20remove meaningless sentence and update copyright.Ryan Mulligan-5/+4
2014-04-18Replace all ~"" with "".to_owned()Richo Healey-4/+5
2014-04-13Replace 'region' with 'lifetime' in a few transmute function namesJohn Simon-7/+7
2014-03-19Remove std::cast::transmute_immut_unsafeTobias Bucher-6/+0
It can be done in safe code using `as *T`.
2014-02-23std: Move raw to std::rawBrian Anderson-1/+1
Issue #1457
2014-02-23std: Move intrinsics to std::intrinsics.Brian Anderson-1/+1
Issue #1457
2014-02-09std: Stop parameterizing some memcpy functions over RawPtrBrian Anderson-3/+2
It unsafe assumptions that any impl of RawPtr is for actual pointers, that they can be copied by memcpy. Removing it is easy, so I don't think it's solving a real problem.
2014-02-09std: Add init and uninit to mem. Replace direct intrinsic usageBrian Anderson-1/+1
2014-01-07'borrowed pointer' -> 'reference'Brian Anderson-2/+2
2013-12-23std: Fix all code examplesAlex Crichton-1/+3
2013-12-15libstd: Fix merge fallout.Patrick Walton-1/+1
2013-12-15librustc: Remove identifiers named `box`, since it's about to become a keyword.Patrick Walton-4/+4
2013-12-01remove useless `transmute_immut` functionDaniel Micay-6/+0
2013-11-14remove `cast::unsafe_copy`Daniel Micay-8/+0
This is the same functionality as `ptr::read_ptr`.
2013-11-03simplify memcpy/memmove/memset intrinsicsDaniel Micay-13/+2
This moves the per-architecture difference into the compiler.
2013-10-17std: Move size/align functions to std::mem. #2240Brian Anderson-3/+3
2013-09-25rustdoc: Change all code-blocks with a scriptAlex Crichton-2/+2
find src -name '*.rs' | xargs sed -i '' 's/~~~.*{\.rust}/```rust/g' find src -name '*.rs' | xargs sed -i '' 's/ ~~~$/ ```/g' find src -name '*.rs' | xargs sed -i '' 's/^~~~$/ ```/g'
2013-08-27librustc: Remove `&const` and `*const` from the language.Patrick Walton-2/+3
They are still present as part of the borrow check.
2013-08-22doc: Fix transmute exampleKeegan McAllister-1/+4
2013-08-12fix build with the new snapshot compilerDaniel Micay-10/+0
2013-08-04Remove trailing null from stringsErick Tryzelaar-0/+10
2013-07-26Consolidate raw representations of rust valuesAlex Crichton-2/+2
This moves the raw struct layout of closures, vectors, boxes, and strings into a new `unstable::raw` module. This is meant to be a centralized location to find information for the layout of these values. As safe method, `repr`, is provided to convert a rust value to its raw representation. Unsafe methods to convert back are not provided because they are rarely used and too numerous to write an implementation for each (not much of a common pattern).
2013-07-17librustc: Remove all uses of "copy".Patrick Walton-0/+8
2013-07-10Add a `mut_split()` method for dividing one `&mut [T]` into twoNiko Matsakis-1/+0
2013-06-21Remove all #[cfg(stage0)]-protected codeJames Miller-15/+2
New snapshot means this can all go. Also removes places that have comments that say they are workarounds for stage0 errors.
2013-06-18replace #[inline(always)] with #[inline]. r=burningtree.Graydon Hoare-14/+14
2013-06-15std: Remove doc references to reinterpret_castBrian Anderson-5/+2
2013-05-30Require documentation by default for libstdAlex Crichton-0/+2
Adds documentation for various things that I understand. Adds #[allow(missing_doc)] for lots of things that I don't understand.
2013-05-27fix casts on 32-bitDaniel Micay-1/+1
2013-05-26inline bump_box_refcountDaniel Micay-0/+1
2013-05-26make transmute_copy use memcpy, and inline itDaniel Micay-0/+21
2013-05-26use uninit for cast::transmute_copyDaniel Micay-1/+1
2013-05-23cleanup warnings from libstdErick Tryzelaar-1/+0
2013-05-22libstd: Rename libcore to libstd and libstd to libextra; update makefiles.Patrick Walton-0/+160
This only changes the directory names; it does not change the "real" metadata names.