Skip to content
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

Rollup of 11 pull requests #38834

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a99f70b
Clarify zero-value behavior of `ctlz`/`cttz` intrinsics.
frewsxcv Dec 11, 2016
0ab7812
Clarify behavior of `VecDeque::insert`.
frewsxcv Dec 23, 2016
73bb063
Detect double reference when applying binary op
estebank Jun 23, 2016
98218b3
Ensure type is copyable before emitting note suggesting adding manual…
pnkfelix Dec 26, 2016
51b655e
std: Remove unused objects from compiler-builtins
alexcrichton Dec 26, 2016
a52f257
Fix doc for `escape_debug`
bombless Dec 27, 2016
dfb6ae6
Test for appropriate span on second custom derive
estebank Dec 25, 2016
ca9b07b
Replace uses of `#[unsafe_destructor_blind_to_params]` with `#[may_da…
apasel422 Dec 28, 2016
ae23f03
Doc fix
minaguib Jan 3, 2017
031dd81
fix help for the --print option
cardoe Jan 4, 2017
07e844f
Add more docs for CoerceUnsized and Unsize
Manishearth Jan 4, 2017
893f42a
book: use abort() over loop {} for panic
Dec 3, 2016
521d337
Rollup merge of #38138 - rkruppe:no_std-no_loop, r=steveklabnik
steveklabnik Jan 4, 2017
0164b3f
Rollup merge of #38310 - frewsxcv:ctlz-cttz, r=pnkfelix
steveklabnik Jan 4, 2017
9226613
Rollup merge of #38581 - frewsxcv:vecdequeue-insert, r=GuillaumeGomez
steveklabnik Jan 4, 2017
e3a6bdb
Rollup merge of #38607 - estebank:test-for-36935, r=petrochenkov
steveklabnik Jan 4, 2017
30df598
Rollup merge of #38617 - pnkfelix:double-reference, r=pnkfelix
steveklabnik Jan 4, 2017
72a90b3
Rollup merge of #38623 - alexcrichton:less-osx-warnings, r=aturon
steveklabnik Jan 4, 2017
6bc17bf
Rollup merge of #38629 - bombless:patch-4, r=petrochenkov
steveklabnik Jan 4, 2017
c0c7941
Rollup merge of #38664 - apasel422:may-dangle, r=pnkfelix
steveklabnik Jan 4, 2017
1d72dd9
Rollup merge of #38799 - minaguib:patch-1, r=steveklabnik
steveklabnik Jan 4, 2017
e9068c6
Rollup merge of #38815 - cardoe:fix-print, r=nikomatsakis
steveklabnik Jan 4, 2017
6316e43
Rollup merge of #38816 - Manishearth:coercion-doc, r=GuillaumeGomez
steveklabnik Jan 4, 2017
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
11 changes: 4 additions & 7 deletions src/doc/book/lang-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ and one for deallocation. A freestanding program that uses the `Box`
sugar for dynamic allocations via `malloc` and `free`:

```rust,ignore
#![feature(lang_items, box_syntax, start, libc)]
#![feature(lang_items, box_syntax, start, libc, core_intrinsics)]
#![no_std]
use core::intrinsics;

extern crate libc;

extern {
fn abort() -> !;
}

#[lang = "owned_box"]
pub struct Box<T>(*mut T);

Expand All @@ -34,7 +31,7 @@ unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {

// Check if `malloc` failed:
if p as usize == 0 {
abort();
intrinsics::abort();
}

p
Expand All @@ -58,7 +55,7 @@ fn main(argc: isize, argv: *const *const u8) -> isize {
}

#[lang = "eh_personality"] extern fn rust_eh_personality() {}
#[lang = "panic_fmt"] extern fn rust_begin_panic() -> ! { loop {} }
#[lang = "panic_fmt"] extern fn rust_begin_panic() -> ! { unsafe { intrinsics::abort() } }
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
# #[no_mangle] pub extern fn rust_eh_register_frames () {}
# #[no_mangle] pub extern fn rust_eh_unregister_frames () {}
Expand Down
10 changes: 6 additions & 4 deletions src/doc/book/no-stdlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,10 @@ The function marked `#[start]` is passed the command line parameters
in the same format as C:

```rust,ignore
#![feature(lang_items)]
#![feature(lang_items, core_intrinsics)]
#![feature(start)]
#![no_std]
use core::intrinsics;

// Pull in the system libc library for what crt0.o likely requires.
extern crate libc;
Expand Down Expand Up @@ -69,7 +70,7 @@ pub extern fn rust_eh_unwind_resume() {
pub extern fn rust_begin_panic(_msg: core::fmt::Arguments,
_file: &'static str,
_line: u32) -> ! {
loop {}
unsafe { intrinsics::abort() }
}
```

Expand All @@ -79,10 +80,11 @@ correct ABI and the correct name, which requires overriding the
compiler's name mangling too:

```rust,ignore
#![feature(lang_items)]
#![feature(lang_items, core_intrinsics)]
#![feature(start)]
#![no_std]
#![no_main]
use core::intrinsics;

// Pull in the system libc library for what crt0.o likely requires.
extern crate libc;
Expand Down Expand Up @@ -112,7 +114,7 @@ pub extern fn rust_eh_unwind_resume() {
pub extern fn rust_begin_panic(_msg: core::fmt::Arguments,
_file: &'static str,
_line: u32) -> ! {
loop {}
unsafe { intrinsics::abort() }
}
```

Expand Down
4 changes: 3 additions & 1 deletion src/doc/nomicon/coercions.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Coercion is allowed between the following types:
* `&T` to `*const T`
* `&mut T` to `*mut T`
* Unsizing: `T` to `U` if `T` implements `CoerceUnsized<U>`
* Deref coercion: Expression `&x` of type `&T` to `&*x` of type `&U` if `T` derefs to `U` (i.e. `T: Deref<Target=U>`)

`CoerceUnsized<Pointer<U>> for Pointer<T> where T: Unsize<U>` is implemented
for all pointer types (including smart pointers like Box and Rc). Unsize is
Expand All @@ -27,8 +28,9 @@ only implemented automatically, and enables the following transformations:
* `Foo<..., T, ...>` => `Foo<..., U, ...>` where:
* `T: Unsize<U>`
* `Foo` is a struct
* Only the last field of `Foo` has type `T`
* Only the last field of `Foo` has type involving `T`
* `T` is not part of the type of any other fields
* `Bar<T>: Unsize<Bar<U>>`, if the last field of `Foo` has type `Bar<T>`

Coercions occur at a *coercion site*. Any location that is explicitly typed
will cause a coercion to its type. If inference is necessary, the coercion will
Expand Down
3 changes: 1 addition & 2 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ impl<T: ?Sized> Arc<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Drop for Arc<T> {
unsafe impl<#[may_dangle] T: ?Sized> Drop for Arc<T> {
/// Drops the `Arc`.
///
/// This will decrement the strong reference count. If the strong reference
Expand Down Expand Up @@ -736,7 +736,6 @@ impl<T: ?Sized> Drop for Arc<T> {
/// drop(foo); // Doesn't print anything
/// drop(foo2); // Prints "dropped!"
/// ```
#[unsafe_destructor_blind_to_params]
#[inline]
fn drop(&mut self) {
// Because `fetch_sub` is already atomic, we do not need to synchronize
Expand Down
3 changes: 2 additions & 1 deletion src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@
#![feature(const_fn)]
#![feature(core_intrinsics)]
#![feature(custom_attribute)]
#![feature(dropck_parametricity)]
#![feature(dropck_eyepatch)]
#![cfg_attr(not(test), feature(exact_size_is_empty))]
#![feature(fundamental)]
#![feature(generic_param_attrs)]
#![feature(lang_items)]
#![feature(needs_allocator)]
#![feature(optin_builtin_traits)]
Expand Down
3 changes: 1 addition & 2 deletions src/liballoc/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,7 @@ impl<T> RawVec<T> {
}
}

impl<T> Drop for RawVec<T> {
#[unsafe_destructor_blind_to_params]
unsafe impl<#[may_dangle] T> Drop for RawVec<T> {
/// Frees the memory owned by the RawVec *without* trying to Drop its contents.
fn drop(&mut self) {
let elem_size = mem::size_of::<T>();
Expand Down
3 changes: 1 addition & 2 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ impl<T: ?Sized> Deref for Rc<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized> Drop for Rc<T> {
unsafe impl<#[may_dangle] T: ?Sized> Drop for Rc<T> {
/// Drops the `Rc`.
///
/// This will decrement the strong reference count. If the strong reference
Expand Down Expand Up @@ -672,7 +672,6 @@ impl<T: ?Sized> Drop for Rc<T> {
/// drop(foo); // Doesn't print anything
/// drop(foo2); // Prints "dropped!"
/// ```
#[unsafe_destructor_blind_to_params]
fn drop(&mut self) {
unsafe {
let ptr = *self.ptr;
Expand Down
7 changes: 3 additions & 4 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@

#![feature(alloc)]
#![feature(core_intrinsics)]
#![feature(dropck_eyepatch)]
#![feature(heap_api)]
#![feature(heap_api)]
#![feature(generic_param_attrs)]
#![feature(staged_api)]
#![feature(dropck_parametricity)]
#![cfg_attr(test, feature(test))]

#![allow(deprecated)]
Expand Down Expand Up @@ -258,8 +258,7 @@ impl<T> TypedArena<T> {
}
}

impl<T> Drop for TypedArena<T> {
#[unsafe_destructor_blind_to_params]
unsafe impl<#[may_dangle] T> Drop for TypedArena<T> {
fn drop(&mut self) {
unsafe {
// Determine how much was filled.
Expand Down
3 changes: 1 addition & 2 deletions src/libcollections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ pub struct BTreeMap<K, V> {
}

#[stable(feature = "btree_drop", since = "1.7.0")]
impl<K, V> Drop for BTreeMap<K, V> {
#[unsafe_destructor_blind_to_params]
unsafe impl<#[may_dangle] K, #[may_dangle] V> Drop for BTreeMap<K, V> {
fn drop(&mut self) {
unsafe {
for _ in ptr::read(self).into_iter() {
Expand Down
3 changes: 2 additions & 1 deletion src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
#![feature(box_syntax)]
#![cfg_attr(not(test), feature(char_escape_debug))]
#![feature(core_intrinsics)]
#![feature(dropck_parametricity)]
#![feature(dropck_eyepatch)]
#![feature(exact_size_is_empty)]
#![feature(fmt_internals)]
#![feature(fused)]
#![feature(generic_param_attrs)]
#![feature(heap_api)]
#![feature(inclusive_range)]
#![feature(lang_items)]
Expand Down
3 changes: 1 addition & 2 deletions src/libcollections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,7 @@ impl<T> LinkedList<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Drop for LinkedList<T> {
#[unsafe_destructor_blind_to_params]
unsafe impl<#[may_dangle] T> Drop for LinkedList<T> {
fn drop(&mut self) {
while let Some(_) = self.pop_front_node() {}
}
Expand Down
6 changes: 2 additions & 4 deletions src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1763,8 +1763,7 @@ impl<T: Ord> Ord for Vec<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Drop for Vec<T> {
#[unsafe_destructor_blind_to_params]
unsafe impl<#[may_dangle] T> Drop for Vec<T> {
fn drop(&mut self) {
unsafe {
// use drop for [T]
Expand Down Expand Up @@ -2033,8 +2032,7 @@ impl<T: Clone> Clone for IntoIter<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Drop for IntoIter<T> {
#[unsafe_destructor_blind_to_params]
unsafe impl<#[may_dangle] T> Drop for IntoIter<T> {
fn drop(&mut self) {
// destroy the remaining elements
for _x in self.by_ref() {}
Expand Down
23 changes: 13 additions & 10 deletions src/libcollections/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ impl<T: Clone> Clone for VecDeque<T> {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Drop for VecDeque<T> {
#[unsafe_destructor_blind_to_params]
unsafe impl<#[may_dangle] T> Drop for VecDeque<T> {
fn drop(&mut self) {
let (front, back) = self.as_mut_slices();
unsafe {
Expand Down Expand Up @@ -1228,9 +1227,8 @@ impl<T> VecDeque<T> {
self.pop_front()
}

/// Inserts an element at `index` within the `VecDeque`. Whichever
/// end is closer to the insertion point will be moved to make room,
/// and all the affected elements will be moved to new positions.
/// Inserts an element at `index` within the `VecDeque`, shifting all elements with indices
/// greater than or equal to `index` towards the back.
///
/// Element at index 0 is the front of the queue.
///
Expand All @@ -1239,14 +1237,19 @@ impl<T> VecDeque<T> {
/// Panics if `index` is greater than `VecDeque`'s length
///
/// # Examples
///
/// ```
/// use std::collections::VecDeque;
///
/// let mut buf = VecDeque::new();
/// buf.push_back(10);
/// buf.push_back(12);
/// buf.insert(1, 11);
/// assert_eq!(Some(&11), buf.get(1));
/// let mut vec_deque = VecDeque::new();
/// vec_deque.push_back('a');
/// vec_deque.push_back('b');
/// vec_deque.push_back('c');
///
/// vec_deque.insert(1, 'd');
///
/// let vec = vec_deque.into_iter().collect::<Vec<_>>();
/// assert_eq!(vec, ['a', 'd', 'b', 'c']);
/// ```
#[stable(feature = "deque_extras_15", since = "1.5.0")]
pub fn insert(&mut self, index: usize, value: T) {
Expand Down
6 changes: 0 additions & 6 deletions src/libcompiler_builtins/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,12 @@ fn main() {

if !target.contains("ios") {
sources.extend(&["absvti2.c",
"addtf3.c",
"addvti3.c",
"ashlti3.c",
"ashrti3.c",
"clzti2.c",
"cmpti2.c",
"ctzti2.c",
"divtf3.c",
"divti3.c",
"ffsti2.c",
"fixdfti.c",
Expand All @@ -216,17 +214,13 @@ fn main() {
"floatuntixf.c",
"lshrti3.c",
"modti3.c",
"multf3.c",
"multi3.c",
"mulvti3.c",
"negti2.c",
"negvti2.c",
"parityti2.c",
"popcountti2.c",
"powitf2.c",
"subtf3.c",
"subvti3.c",
"trampoline_setup.c",
"ucmpti2.c",
"udivmodti4.c",
"udivti3.c",
Expand Down
52 changes: 50 additions & 2 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,10 +1156,58 @@ extern "rust-intrinsic" {
/// Returns the number of bits set in an integer type `T`
pub fn ctpop<T>(x: T) -> T;

/// Returns the number of leading bits unset in an integer type `T`
/// Returns the number of leading unset bits (zeroes) in an integer type `T`.
///
/// # Examples
///
/// ```
/// #![feature(core_intrinsics)]
///
/// use std::intrinsics::ctlz;
///
/// let x = 0b0001_1100_u8;
/// let num_leading = unsafe { ctlz(x) };
/// assert_eq!(num_leading, 3);
/// ```
///
/// An `x` with value `0` will return the bit width of `T`.
///
/// ```
/// #![feature(core_intrinsics)]
///
/// use std::intrinsics::ctlz;
///
/// let x = 0u16;
/// let num_leading = unsafe { ctlz(x) };
/// assert_eq!(num_leading, 16);
/// ```
pub fn ctlz<T>(x: T) -> T;

/// Returns the number of trailing bits unset in an integer type `T`
/// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
///
/// # Examples
///
/// ```
/// #![feature(core_intrinsics)]
///
/// use std::intrinsics::cttz;
///
/// let x = 0b0011_1000_u8;
/// let num_trailing = unsafe { cttz(x) };
/// assert_eq!(num_trailing, 3);
/// ```
///
/// An `x` with value `0` will return the bit width of `T`:
///
/// ```
/// #![feature(core_intrinsics)]
///
/// use std::intrinsics::cttz;
///
/// let x = 0u16;
/// let num_trailing = unsafe { cttz(x) };
/// assert_eq!(num_trailing, 16);
/// ```
pub fn cttz<T>(x: T) -> T;

/// Reverses the bytes in an integer type `T`.
Expand Down
15 changes: 14 additions & 1 deletion src/libcore/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,26 @@ pub trait Sized {
///
/// All implementations of `Unsize` are provided automatically by the compiler.
///
/// `Unsize` is implemented for:
///
/// - `[T; N]` is `Unsize<[T]>`
/// - `T` is `Unsize<Trait>` when `T: Trait`
/// - `Foo<..., T, ...>` is `Unsize<Foo<..., U, ...>>` if:
/// - `T: Unsize<U>`
/// - Foo is a struct
/// - Only the last field of `Foo` has a type involving `T`
/// - `T` is not part of the type of any other fields
/// - `Bar<T>: Unsize<Bar<U>>`, if the last field of `Foo` has type `Bar<T>`
///
/// `Unsize` is used along with [`ops::CoerceUnsized`][coerceunsized] to allow
/// "user-defined" containers such as [`rc::Rc`][rc] to contain dynamically-sized
/// types. See the [DST coercion RFC][RFC982] for more details.
/// types. See the [DST coercion RFC][RFC982] and [the nomicon entry on coercion][nomicon-coerce]
/// for more details.
///
/// [coerceunsized]: ../ops/trait.CoerceUnsized.html
/// [rc]: ../../std/rc/struct.Rc.html
/// [RFC982]: https://github.com/rust-lang/rfcs/blob/master/text/0982-dst-coercion.md

#[unstable(feature = "unsize", issue = "27732")]
#[lang="unsize"]
pub trait Unsize<T: ?Sized> {
Expand Down
Loading