Skip to content

Rollup of 34 pull requests #22352

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
wants to merge 75 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
995b159
rustdoc: Show must_use attribute
sanxiyn Feb 12, 2015
00a6ff9
Adjusting default CPUs for iOS
vhbit Feb 12, 2015
3df5c4a
Update LLVM to disable asserts in the PassInfo cache
dotdash Feb 12, 2015
9c686dc
Correct typo for 'underyling'
duaneedwards Feb 12, 2015
3d9528a
Unstabilise `words` for now.
huonw Feb 13, 2015
e4a9eb9
Remove `_VALUE` from the float extremes constants.
huonw Feb 13, 2015
b4a2861
Rename the "unsafe" lang item to "unsafe_cell"
lambda-fairy Feb 13, 2015
aef5551
Rename `unsafe_lang_item` to `unsafe_cell_lang_item`
lambda-fairy Feb 13, 2015
c5dba72
Remove reference to mailing list
iKevinY Feb 13, 2015
f28a333
Make if after colon lowercase
fhahn Feb 13, 2015
c6a647a
Replace map(|x| *x) with cloned().
ruuda Feb 13, 2015
1c7cb8b
Relpace map(|x| x.clone()) with cloned().
ruuda Feb 13, 2015
539866b
Replace map(|x| (*x).clone()) with cloned().
ruuda Feb 13, 2015
ce22f30
Make note of doc duplication with reexports
steveklabnik Feb 10, 2015
805a31f
Improve documentation for `Select::new()`.
steveklabnik Feb 13, 2015
4b25d75
Remove outdated information about copy/move from the reference
steveklabnik Feb 13, 2015
58a7d58
Re-word paragraph about enums and equality
steveklabnik Feb 13, 2015
114301f
Refer to LLVM rather than GCC wiki for atomic orderings
steveklabnik Feb 13, 2015
d414a39
Re-tag `slicing_syntax` as `Accepted`.
pnkfelix Feb 13, 2015
65eab6e
Add diverging functions to the book.
steveklabnik Feb 13, 2015
c9ad0d1
Revert incorrect map(|x| *x) -> cloned() substitutions.
ruuda Feb 13, 2015
a7d5c3f
Added all active features to the list in reference.md.
pnkfelix Feb 13, 2015
fb05f28
Add `#[rustc_error]` annotation, which causes trans to signal an error
nikomatsakis Feb 12, 2015
f48eda8
Fix small copy-paste typo
unode Feb 13, 2015
e478f66
Don't specify tuple layout.
steveklabnik Feb 13, 2015
9eb4436
Add link to module-level Option documentation.
steveklabnik Feb 13, 2015
ece19bf
Enhance static mut example in FFI chapter.
steveklabnik Feb 13, 2015
b19fda0
Remove ExactSizeIterator from 64-bit ranges.
Feb 13, 2015
effad62
Add the build date to the reported version. #21957
brson Feb 12, 2015
3df8245
add test for #21909
Feb 13, 2015
148d90b
clarfiy reference with regards to the value of block expressions
steveklabnik Feb 13, 2015
f64d912
Generate grammar.html and link to it from the reference.
steveklabnik Feb 13, 2015
6d2e3d4
Note that Vec<T> is heap allocated.
steveklabnik Feb 13, 2015
5e3ae10
Dramatically expand the docs of std::raw.
huonw Feb 12, 2015
7a52932
Make std::raw::Repr an unsafe trait
Feb 13, 2015
1e01f7f
Rename std::failure to std::panicking
iKevinY Feb 14, 2015
657081b
Normalize range syntax used in concurrency.md
Manishearth Feb 14, 2015
af7b891
Correct typo
shepmaster Feb 14, 2015
f658efe
Documentation Fixes
Feb 14, 2015
1a99315
Fix issue with generation
steveklabnik Feb 15, 2015
36ff7b9
Rollup merge of #22132 - steveklabnik:gh16645, r=alexcrichton
steveklabnik Feb 15, 2015
c4f6468
Rollup merge of #22201 - brson:version, r=nick29581
steveklabnik Feb 15, 2015
ee7dea9
Rollup merge of #22218 - huonw:raw-docs, r=steveklabnik,huonw
steveklabnik Feb 15, 2015
f5a2dff
Rollup merge of #22224 - sanxiyn:must-use, r=cmr
steveklabnik Feb 15, 2015
5957a16
Rollup merge of #22229 - vhbit:ios-default-cpus, r=alexcrichton
steveklabnik Feb 15, 2015
168736a
Rollup merge of #22238 - dotdash:llvmup_20150212, r=alexcrichton
steveklabnik Feb 15, 2015
fc104ff
Rollup merge of #22248 - duaneedwards:patch-1, r=Gankro
steveklabnik Feb 15, 2015
a03ff79
Rollup merge of #22253 - huonw:unstable-words, r=aturon
steveklabnik Feb 15, 2015
24cb751
Rollup merge of #22254 - huonw:float-value--, r=aturon
steveklabnik Feb 15, 2015
1eca6fb
Rollup merge of #22262 - lfairy:unsafe-cell-lang-item, r=alexcrichton
steveklabnik Feb 15, 2015
91ea661
Rollup merge of #22263 - iKevinY:no-mailing-list, r=nikomatsakis
steveklabnik Feb 15, 2015
8d4dd8b
Rollup merge of #22264 - fhahn:tiny-doc-fix2, r=Gankro
steveklabnik Feb 15, 2015
9c9a914
Rollup merge of #22268 - steveklabnik:improve_wait, r=nikomatsakis
steveklabnik Feb 15, 2015
79da52e
Rollup merge of #22269 - steveklabnik:gh22136, r=alexcrichton
steveklabnik Feb 15, 2015
48f1e58
Rollup merge of #22271 - steveklabnik:gh22035, r=nikomatsakis
steveklabnik Feb 15, 2015
c242922
Rollup merge of #22272 - steveklabnik:gh22064, r=alexcrichton
steveklabnik Feb 15, 2015
86920c5
Rollup merge of #22274 - pnkfelix:retag-slicing-syntax-as-accepted, r…
steveklabnik Feb 15, 2015
013769e
Rollup merge of #22275 - steveklabnik:gh7538, r=huonw
steveklabnik Feb 15, 2015
91e373a
Rollup merge of #22276 - ruud-v-a:map-clone, r=nikomatsakis
steveklabnik Feb 15, 2015
24ffd5b
Rollup merge of #22277 - pnkfelix:reference-update-feature-gate-list,…
steveklabnik Feb 15, 2015
c34f8fb
Rollup merge of #22278 - nikomatsakis:rustc-error, r=nikomatsakis
steveklabnik Feb 15, 2015
5a3aa4a
Rollup merge of #22280 - Unode:patch-1, r=steveklabnik
steveklabnik Feb 15, 2015
82e42a0
Rollup merge of #22284 - steveklabnik:fix_another_lie, r=nikomatsakis
steveklabnik Feb 15, 2015
51abc97
Rollup merge of #22288 - steveklabnik:add_option_link, r=nikomatsakis
steveklabnik Feb 15, 2015
a3a1f86
Rollup merge of #22295 - steveklabnik:gh9980, r=alexcrichton
steveklabnik Feb 15, 2015
f89168e
Rollup merge of #22299 - bluss:range-64-is-not-exact-size, r=alexcric…
steveklabnik Feb 15, 2015
59feb6f
Rollup merge of #22302 - japaric:gh21909, r=brson
steveklabnik Feb 15, 2015
4587f64
Rollup merge of #22305 - steveklabnik:gh20948, r=alexcrichton
steveklabnik Feb 15, 2015
6aaf535
Rollup merge of #22307 - steveklabnik:gh14849, r=huonw
steveklabnik Feb 15, 2015
5ee9d9e
Rollup merge of #22308 - steveklabnik:gh19278, r=brson
steveklabnik Feb 15, 2015
bf25753
Rollup merge of #22324 - Manishearth:patch-1, r=steveklabnik
steveklabnik Feb 15, 2015
d80e5c7
Rollup merge of #22328 - shepmaster:os_str_typo, r=steveklabnik
steveklabnik Feb 15, 2015
f43546f
Rollup merge of #22329 - thiagooak:book, r=steveklabnik
steveklabnik Feb 15, 2015
3ce2e0d
Rollup merge of #22347 - iKevinY:std-lib-panicking, r=brson
steveklabnik Feb 15, 2015
3ae8b02
remove unneeded slicing_syntax feature gate
steveklabnik Feb 15, 2015
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
Prev Previous commit
Next Next commit
Dramatically expand the docs of std::raw.
This overhauls the very meager docs that currently exist to clarify
various understandable confusions that I've noticed, e.g. people look in
`std::raw` for the "real" types of slices like `&[T]`, or think that
`Slice<T>` refers to `[T]` (fixes #22214).

This patch takes the liberty of offering some "style" guidance around
`raw::Slice`, since there's more restricted ways to duplicate all
functionality connected to it: `std::slice::from_raw_parts{,_mut}` for
construction and `.as_{,mut_}ptr` & `.len` for deconstruction.

It also deprecates the `std::raw::Closure` type which is now useless for
non-type-erased closures, and replaced by `TraitObject` for `&Fn`, `&mut
FnMut` etc, so I guess it should be called a:

[breaking-change]
  • Loading branch information
huonw committed Feb 14, 2015
commit 5e3ae102dbeeb646e8c7d2d423cea263337a76af
113 changes: 108 additions & 5 deletions src/libcore/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,40 @@
use marker::Copy;
use mem;

/// The representation of a Rust slice
/// The representation of a slice like `&[T]`.
///
/// This struct is guaranteed to have the layout of types like `&[T]`,
/// `&str`, and `Box<[T]>`, but is not the type of such slices
/// (e.g. the fields are not directly accessible on a `&[T]`) nor does
/// it control that layout (changing the definition will not change
/// the layout of a `&[T]`). It is only designed to be used by unsafe
/// code that needs to manipulate the low-level details.
///
/// However, it is not recommended to use this type for such code,
/// since there are alternatives which may be safer:
///
/// - Creating a slice from a data pointer and length can be done with
/// `std::slice::from_raw_parts` or `std::slice::from_raw_parts_mut`
/// instead of `std::mem::transmute`ing a value of type `Slice`.
/// - Extracting the data pointer and length from a slice can be
/// performed with the `as_ptr` (or `as_mut_ptr`) and `len`
/// methods.
///
/// If one does decide to convert a slice value to a `Slice`, the
/// `Repr` trait in this module provides a method for a safe
/// conversion from `&[T]` (and `&str`) to a `Slice`, more type-safe
/// than a call to `transmute`.
///
/// # Examples
///
/// ```
/// use std::raw::{self, Repr};
///
/// let slice: &[u16] = &[1, 2, 3, 4];
///
/// let repr: raw::Slice<u16> = slice.repr();
/// println!("data pointer = {:?}, length = {}", repr.data, repr.len);
/// ```
#[repr(C)]
pub struct Slice<T> {
pub data: *const T,
Expand All @@ -30,18 +63,88 @@ pub struct Slice<T> {

impl<T> Copy for Slice<T> {}

/// The representation of a Rust closure
/// The representation of an old closure.
#[repr(C)]
#[derive(Copy)]
#[unstable(feature = "core")]
#[deprecated(reason = "unboxed new closures do not have a universal representation; \
`&Fn` (etc) trait objects should use `TraitObject` instead",
since= "1.0.0")]
pub struct Closure {
pub code: *mut (),
pub env: *mut (),
}

/// The representation of a Rust trait object.
/// The representation of a trait object like `&SomeTrait`.
///
/// This struct has the same layout as types like `&SomeTrait` and
/// `Box<AnotherTrait>`. The [Static and Dynamic Dispatch chapter of the
/// Book][moreinfo] contains more details about the precise nature of
/// these internals.
///
/// [moreinfo]: ../../book/static-and-dynamic-dispatch.html#representation
///
/// `TraitObject` is guaranteed to match layouts, but it is not the
/// type of trait objects (e.g. the fields are not directly accessible
/// on a `&SomeTrait`) nor does it control that layout (changing the
/// definition will not change the layout of a `&SometTrait`). It is
/// only designed to be used by unsafe code that needs to manipulate
/// the low-level details.
///
/// There is no `Repr` implementation for `TraitObject` because there
/// is no way to refer to all trait objects generically, so the only
/// way to create values of this type is with functions like
/// `std::mem::transmute`. Similarly, the only way to create a true
/// trait object from a `TraitObject` value is with `transmute`.
///
/// Synthesizing a trait object with mismatched types—one where the
/// vtable does not correspond to the type of the value to which the
/// data pointer points—is highly likely to lead to undefined
/// behaviour.
///
/// # Examples
///
/// ```
/// use std::mem;
/// use std::raw;
///
/// // an example trait
/// trait Foo {
/// fn bar(&self) -> i32;
/// }
/// impl Foo for i32 {
/// fn bar(&self) -> i32 {
/// *self + 1
/// }
/// }
///
/// let value: i32 = 123;
///
/// // let the compiler make a trait object
/// let object: &Foo = &value;
///
/// // look at the raw representation
/// let raw_object: raw::TraitObject = unsafe { mem::transmute(object) };
///
/// // the data pointer is the address of `value`
/// assert_eq!(raw_object.data as *const i32, &value as *const _);
///
///
/// let other_value: i32 = 456;
///
/// // construct a new object, pointing to a different `i32`, being
/// // careful to use the `i32` vtable from `object`
/// let synthesized: &Foo = unsafe {
/// mem::transmute(raw::TraitObject {
/// data: &other_value as *const _ as *mut (),
/// vtable: raw_object.vtable
/// })
/// };
///
/// This struct does not have a `Repr` implementation
/// because there is no way to refer to all trait objects generically.
/// // it should work just like we constructed a trait object out of
/// // `other_value` directly
/// assert_eq!(synthesized.bar(), 457);
/// ```
#[repr(C)]
#[derive(Copy)]
pub struct TraitObject {
Expand Down