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 22 pull requests #40644

Closed
wants to merge 70 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
c7db40f
Rename expected_types_for_fn_args to expected_inputs_for_expected_out…
eddyb Mar 9, 2017
50aee36
Propagate expected type hints through struct literals.
eddyb Mar 9, 2017
6ba494b
Point to let when modifying field of immutable variable
estebank Mar 11, 2017
38b5b29
Change label to "consider changing this to `mut f`"
estebank Mar 12, 2017
197e529
Initial attempt at implementing optimization fuel and re-enabling str…
ahicks92 Mar 8, 2017
8f36057
Make a comment better.
ahicks92 Mar 9, 2017
c2d14fc
Tests for -Z fuel=foo=n
ahicks92 Mar 10, 2017
3fb94b7
UI test for -Z print-fuel=foo
ahicks92 Mar 10, 2017
9ac628d
Add label to primary span for mutable access of immutable struct error
estebank Mar 13, 2017
460bf55
Cleanup.
jseyfried Mar 6, 2017
68c1cc6
Refactor `Attribute` to use `Path` and `TokenStream` instead of `Meta…
jseyfried Mar 3, 2017
839c286
Liberalize attributes.
jseyfried Mar 8, 2017
85e02bd
Add tests.
jseyfried Mar 8, 2017
b43c744
Add feature toggle for rvalue-static-promotion RFC
tbg Mar 11, 2017
20c0f32
Use `&&` instead of `&`
tbg Mar 12, 2017
f06b049
Improve the documentation for `rvalue_static_promotion`
tbg Mar 12, 2017
9741c9d
add test for nested macro def (#31946)
durka Mar 14, 2017
cc23d17
make shift builtins panic-free with new unchecked_sh* intrinsics
TimNN Mar 14, 2017
ff63866
Change how the `0` flag works in format!
Sawyer47 Mar 3, 2017
8065486
Change how the 0 flag works in format! for floats
Sawyer47 Mar 4, 2017
c11ab21
save-analysis: only index path references once
nrc Mar 8, 2017
310f5bd
save-analysis: index extern blocks
nrc Mar 8, 2017
4cf22cb
rebased
nrc Mar 15, 2017
ce616a7
Improve the `TokenStream` quoter.
jseyfried Mar 14, 2017
9b89274
Fix const not displayed in rustdoc
GuillaumeGomez Mar 16, 2017
8c16c45
Check for conflicts between macros 1.0 exports (`#[macro_export]`, `#…
jseyfried Mar 14, 2017
910532e
Add a test for issue 34571
topecongiro Mar 16, 2017
449219a
isolate llvm 4.0 code path
TimNN Mar 16, 2017
222ca3c
clang-format
TimNN Mar 16, 2017
95bd7f2
add missing global metadata
TimNN Mar 16, 2017
50cede0
documented order of conversion between u32 an ipv4addr
Mar 17, 2017
963d4df
minor wording tweak to slice::{as_ptr, as_mut_ptr}
QuietMisdreavus Mar 17, 2017
ec8ecf4
Fix typo in mutex.rs docs
ScottAbbey Mar 17, 2017
33a5665
Stabilize move_cell feature, closes #39264
aturon Mar 15, 2017
65b7c4e
Stabilize expect_err feature, closes #39041
aturon Mar 15, 2017
d38ea8b
Stabilize ptr_unaligned feature, closes #37955
aturon Mar 15, 2017
9511fe6
Stabilize process_abort feature, closes #37838
aturon Mar 15, 2017
10510ae
Stabilize ptr_eq feature, closes #36497
aturon Mar 15, 2017
37b38a2
Stabilize btree_range, closes #27787
aturon Mar 15, 2017
48890d4
Stabilize ordering_chaining, closes #37053
aturon Mar 15, 2017
a8f4a1b
Stabilize rc_raw feature, closes #37197
aturon Mar 15, 2017
1241a88
Minor fixups to fix tidy errors
alexcrichton Mar 15, 2017
27fcdb8
Specialize Vec::from_elem<u8> to use calloc or memset
mbrubeck Mar 10, 2017
ae630ca
Specialize Vec::from_elem for other integer types
mbrubeck Mar 10, 2017
cb96ade
Fix regression when `include!()`ing a `macro_rules!` containing a `$c…
jseyfried Mar 16, 2017
2976ddb
Fix a spelling error in HashMap documentation, and slightly reword it…
jswalden Mar 18, 2017
8eaac08
Parse 0e+10 as a valid floating-point literal
topecongiro Mar 17, 2017
e16d286
add inline attributes to stage 0 methods
TimNN Mar 18, 2017
a6cb1ef
Rollup merge of #40241 - Sawyer47:fix-39997, r=alexcrichton
Mar 18, 2017
67cc915
Rollup merge of #40346 - jseyfried:path_and_tokenstream_attr, r=nrc
Mar 18, 2017
8e6afbf
Rollup merge of #40348 - nrc:save-extern-fn, r=@eddyb
Mar 18, 2017
74028ba
Rollup merge of #40377 - camlorn:optimization_fuel, r=arielb1
Mar 18, 2017
834e2e8
Rollup merge of #40398 - eddyb:struct-hint, r=nikomatsakis
Mar 18, 2017
f340b0b
Rollup merge of #40409 - mbrubeck:calloc, r=sfackler
Mar 18, 2017
d050aee
Rollup merge of #40441 - tschottdorf:promotable-rfc, r=eddyb
Mar 18, 2017
6a6d6de
Rollup merge of #40445 - estebank:issue-18150, r=jonathandturner
Mar 18, 2017
bed891d
Rollup merge of #40509 - jseyfried:duplicate_check_macro_exports, r=nrc
Mar 18, 2017
7474930
Rollup merge of #40521 - TimNN:panic-free-shift, r=alexcrichton
Mar 18, 2017
ca26c79
Rollup merge of #40523 - durka:patch-38, r=petrochenkov
Mar 18, 2017
663409b
Rollup merge of #40532 - jseyfried:improve_tokenstream_quoter, r=nrc
Mar 18, 2017
c2e6d72
Rollup merge of #40538 - aturon:stab-1.17, r=alexcrichton
Mar 18, 2017
196011c
Rollup merge of #40564 - GuillaumeGomez:rustdoc-const, r=frewsxcv
Mar 18, 2017
3c912fb
Rollup merge of #40581 - TimNN:di-global-40, r=alexcrichton
Mar 18, 2017
76c9d17
Rollup merge of #40583 - jseyfried:fix_include_macro_regression, r=nrc
Mar 18, 2017
664d9a5
Rollup merge of #40588 - topecongiro:add-missing-tests, r=alexcrichton
Mar 18, 2017
d3d2866
Rollup merge of #40589 - topecongiro:floating-point-literal, r=nagisa
Mar 18, 2017
a8b619c
Rollup merge of #40590 - z1mvader:master, r=steveklabnik
Mar 18, 2017
42ead56
Rollup merge of #40603 - QuietMisdreavus:slice-ptr-docs, r=GuillaumeG…
Mar 18, 2017
144c9e6
Rollup merge of #40611 - ScottAbbey:patch-1, r=GuillaumeGomez
Mar 18, 2017
337cbc1
Rollup merge of #40621 - jswalden:dependant-spelling-fix, r=sfackler
Mar 18, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/doc/unstable-book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
- [repr_simd](repr-simd.md)
- [rustc_attrs](rustc-attrs.md)
- [rustc_diagnostic_macros](rustc-diagnostic-macros.md)
- [rvalue_static_promotion](rvalue-static-promotion.md)
- [sanitizer_runtime](sanitizer-runtime.md)
- [simd](simd.md)
- [simd_ffi](simd-ffi.md)
Expand Down
5 changes: 5 additions & 0 deletions src/doc/unstable-book/src/allocator.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ pub extern fn __rust_allocate(size: usize, _align: usize) -> *mut u8 {
unsafe { libc::malloc(size as libc::size_t) as *mut u8 }
}

#[no_mangle]
pub extern fn __rust_allocate_zeroed(size: usize, _align: usize) -> *mut u8 {
unsafe { libc::calloc(size as libc::size_t, 1) as *mut u8 }
}

#[no_mangle]
pub extern fn __rust_deallocate(ptr: *mut u8, _old_size: usize, _align: usize) {
unsafe { libc::free(ptr as *mut libc::c_void) }
Expand Down
23 changes: 23 additions & 0 deletions src/doc/unstable-book/src/rvalue-static-promotion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# `rvalue_static_promotion`

The tracking issue for this feature is: [#38865]

[#38865]: https://github.com/rust-lang/rust/issues/38865

------------------------

The `rvalue_static_promotion` feature allows directly creating `'static` references to
constant `rvalue`s, which in particular allowing for more concise code in the common case
in which a `'static` reference is all that's needed.


## Examples

```rust
#![feature(rvalue_static_promotion)]

fn main() {
let DEFAULT_VALUE: &'static u32 = &42;
assert_eq!(*DEFAULT_VALUE, 42);
}
```
31 changes: 13 additions & 18 deletions src/liballoc/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,15 @@ impl<T> Arc<T> {
/// # Examples
///
/// ```
/// #![feature(rc_raw)]
///
/// use std::sync::Arc;
///
/// let x = Arc::new(10);
/// let x_ptr = Arc::into_raw(x);
/// assert_eq!(unsafe { *x_ptr }, 10);
/// ```
#[unstable(feature = "rc_raw", issue = "37197")]
pub fn into_raw(this: Self) -> *mut T {
let ptr = unsafe { &mut (**this.ptr).data as *mut _ };
#[stable(feature = "rc_raw", since = "1.17.0")]
pub fn into_raw(this: Self) -> *const T {
let ptr = unsafe { &(**this.ptr).data as *const _ };
mem::forget(this);
ptr
}
Expand All @@ -315,8 +313,6 @@ impl<T> Arc<T> {
/// # Examples
///
/// ```
/// #![feature(rc_raw)]
///
/// use std::sync::Arc;
///
/// let x = Arc::new(10);
Expand All @@ -332,11 +328,14 @@ impl<T> Arc<T> {
///
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!
/// ```
#[unstable(feature = "rc_raw", issue = "37197")]
pub unsafe fn from_raw(ptr: *mut T) -> Self {
#[stable(feature = "rc_raw", since = "1.17.0")]
pub unsafe fn from_raw(ptr: *const T) -> Self {
// To find the corresponding pointer to the `ArcInner` we need to subtract the offset of the
// `data` field from the pointer.
Arc { ptr: Shared::new((ptr as *mut u8).offset(-offset_of!(ArcInner<T>, data)) as *mut _) }
let ptr = (ptr as *const u8).offset(-offset_of!(ArcInner<T>, data));
Arc {
ptr: Shared::new(ptr as *const _),
}
}
}

Expand Down Expand Up @@ -448,7 +447,7 @@ impl<T: ?Sized> Arc<T> {
// Non-inlined part of `drop`.
#[inline(never)]
unsafe fn drop_slow(&mut self) {
let ptr = *self.ptr;
let ptr = self.ptr.as_mut_ptr();

// Destroy the data at this time, even though we may not free the box
// allocation itself (there may still be weak pointers lying around).
Expand All @@ -461,17 +460,13 @@ impl<T: ?Sized> Arc<T> {
}

#[inline]
#[unstable(feature = "ptr_eq",
reason = "newly added",
issue = "36497")]
#[stable(feature = "ptr_eq", since = "1.17.0")]
/// Returns true if the two `Arc`s point to the same value (not
/// just values that compare as equal).
///
/// # Examples
///
/// ```
/// #![feature(ptr_eq)]
///
/// use std::sync::Arc;
///
/// let five = Arc::new(5);
Expand Down Expand Up @@ -628,7 +623,7 @@ impl<T: Clone> Arc<T> {
// As with `get_mut()`, the unsafety is ok because our reference was
// either unique to begin with, or became one upon cloning the contents.
unsafe {
let inner = &mut **this.ptr;
let inner = &mut *this.ptr.as_mut_ptr();
&mut inner.data
}
}
Expand Down Expand Up @@ -671,7 +666,7 @@ impl<T: ?Sized> Arc<T> {
// the Arc itself to be `mut`, so we're returning the only possible
// reference to the inner data.
unsafe {
let inner = &mut **this.ptr;
let inner = &mut *this.ptr.as_mut_ptr();
Some(&mut inner.data)
}
} else {
Expand Down
32 changes: 32 additions & 0 deletions src/liballoc/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use core::intrinsics::{min_align_of_val, size_of_val};
extern "C" {
#[allocator]
fn __rust_allocate(size: usize, align: usize) -> *mut u8;
fn __rust_allocate_zeroed(size: usize, align: usize) -> *mut u8;
fn __rust_deallocate(ptr: *mut u8, old_size: usize, align: usize);
fn __rust_reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8;
fn __rust_reallocate_inplace(ptr: *mut u8,
Expand Down Expand Up @@ -59,6 +60,20 @@ pub unsafe fn allocate(size: usize, align: usize) -> *mut u8 {
__rust_allocate(size, align)
}

/// Return a pointer to `size` bytes of memory aligned to `align` and
/// initialized to zeroes.
///
/// On failure, return a null pointer.
///
/// Behavior is undefined if the requested size is 0 or the alignment is not a
/// power of 2. The alignment must be no larger than the largest supported page
/// size on the platform.
#[inline]
pub unsafe fn allocate_zeroed(size: usize, align: usize) -> *mut u8 {
check_size_and_alignment(size, align);
__rust_allocate_zeroed(size, align)
}

/// Resize the allocation referenced by `ptr` to `size` bytes.
///
/// On failure, return a null pointer and leave the original allocation intact.
Expand Down Expand Up @@ -162,6 +177,23 @@ mod tests {
use boxed::Box;
use heap;

#[test]
fn allocate_zeroed() {
unsafe {
let size = 1024;
let mut ptr = heap::allocate_zeroed(size, 1);
if ptr.is_null() {
::oom()
}
let end = ptr.offset(size as isize);
while ptr < end {
assert_eq!(*ptr, 0);
ptr = ptr.offset(1);
}
heap::deallocate(ptr, size, 1);
}
}

#[test]
fn basic_reallocate_inplace_noop() {
unsafe {
Expand Down
16 changes: 15 additions & 1 deletion src/liballoc/raw_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ impl<T> RawVec<T> {
///
/// Aborts on OOM
pub fn with_capacity(cap: usize) -> Self {
RawVec::allocate(cap, false)
}

/// Like `with_capacity` but guarantees the buffer is zeroed.
pub fn with_capacity_zeroed(cap: usize) -> Self {
RawVec::allocate(cap, true)
}

#[inline]
fn allocate(cap: usize, zeroed: bool) -> Self {
unsafe {
let elem_size = mem::size_of::<T>();

Expand All @@ -93,7 +103,11 @@ impl<T> RawVec<T> {
heap::EMPTY as *mut u8
} else {
let align = mem::align_of::<T>();
let ptr = heap::allocate(alloc_size, align);
let ptr = if zeroed {
heap::allocate_zeroed(alloc_size, align)
} else {
heap::allocate(alloc_size, align)
};
if ptr.is_null() {
oom()
}
Expand Down
28 changes: 10 additions & 18 deletions src/liballoc/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,17 +364,15 @@ impl<T> Rc<T> {
/// # Examples
///
/// ```
/// #![feature(rc_raw)]
///
/// use std::rc::Rc;
///
/// let x = Rc::new(10);
/// let x_ptr = Rc::into_raw(x);
/// assert_eq!(unsafe { *x_ptr }, 10);
/// ```
#[unstable(feature = "rc_raw", issue = "37197")]
pub fn into_raw(this: Self) -> *mut T {
let ptr = unsafe { &mut (**this.ptr).value as *mut _ };
#[stable(feature = "rc_raw", since = "1.17.0")]
pub fn into_raw(this: Self) -> *const T {
let ptr = unsafe { &mut (*this.ptr.as_mut_ptr()).value as *const _ };
mem::forget(this);
ptr
}
Expand All @@ -392,8 +390,6 @@ impl<T> Rc<T> {
/// # Examples
///
/// ```
/// #![feature(rc_raw)]
///
/// use std::rc::Rc;
///
/// let x = Rc::new(10);
Expand All @@ -409,11 +405,11 @@ impl<T> Rc<T> {
///
/// // The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!
/// ```
#[unstable(feature = "rc_raw", issue = "37197")]
pub unsafe fn from_raw(ptr: *mut T) -> Self {
#[stable(feature = "rc_raw", since = "1.17.0")]
pub unsafe fn from_raw(ptr: *const T) -> Self {
// To find the corresponding pointer to the `RcBox` we need to subtract the offset of the
// `value` field from the pointer.
Rc { ptr: Shared::new((ptr as *mut u8).offset(-offset_of!(RcBox<T>, value)) as *mut _) }
Rc { ptr: Shared::new((ptr as *const u8).offset(-offset_of!(RcBox<T>, value)) as *const _) }
}
}

Expand Down Expand Up @@ -543,25 +539,21 @@ impl<T: ?Sized> Rc<T> {
#[stable(feature = "rc_unique", since = "1.4.0")]
pub fn get_mut(this: &mut Self) -> Option<&mut T> {
if Rc::is_unique(this) {
let inner = unsafe { &mut **this.ptr };
let inner = unsafe { &mut *this.ptr.as_mut_ptr() };
Some(&mut inner.value)
} else {
None
}
}

#[inline]
#[unstable(feature = "ptr_eq",
reason = "newly added",
issue = "36497")]
#[stable(feature = "ptr_eq", since = "1.17.0")]
/// Returns true if the two `Rc`s point to the same value (not
/// just values that compare as equal).
///
/// # Examples
///
/// ```
/// #![feature(ptr_eq)]
///
/// use std::rc::Rc;
///
/// let five = Rc::new(5);
Expand Down Expand Up @@ -631,7 +623,7 @@ impl<T: Clone> Rc<T> {
// reference count is guaranteed to be 1 at this point, and we required
// the `Rc<T>` itself to be `mut`, so we're returning the only possible
// reference to the inner value.
let inner = unsafe { &mut **this.ptr };
let inner = unsafe { &mut *this.ptr.as_mut_ptr() };
&mut inner.value
}
}
Expand Down Expand Up @@ -677,7 +669,7 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Rc<T> {
/// ```
fn drop(&mut self) {
unsafe {
let ptr = *self.ptr;
let ptr = self.ptr.as_mut_ptr();

self.dec_strong();
if self.strong() == 0 {
Expand Down
21 changes: 21 additions & 0 deletions src/liballoc_jemalloc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ mod imp {
target_os = "dragonfly", target_os = "windows"),
link_name = "je_mallocx")]
fn mallocx(size: size_t, flags: c_int) -> *mut c_void;
#[cfg_attr(any(target_os = "macos", target_os = "android", target_os = "ios",
target_os = "dragonfly", target_os = "windows"),
link_name = "je_calloc")]
fn calloc(size: size_t, flags: c_int) -> *mut c_void;
#[cfg_attr(any(target_os = "macos", target_os = "android", target_os = "ios",
target_os = "dragonfly", target_os = "windows"),
link_name = "je_rallocx")]
Expand All @@ -56,6 +60,8 @@ mod imp {
fn nallocx(size: size_t, flags: c_int) -> size_t;
}

const MALLOCX_ZERO: c_int = 0x40;

// The minimum alignment guaranteed by the architecture. This value is used to
// add fast paths for low alignment values. In practice, the alignment is a
// constant at the call site and the branch will be optimized out.
Expand Down Expand Up @@ -91,6 +97,16 @@ mod imp {
unsafe { mallocx(size as size_t, flags) as *mut u8 }
}

#[no_mangle]
pub extern "C" fn __rust_allocate_zeroed(size: usize, align: usize) -> *mut u8 {
if align <= MIN_ALIGN {
unsafe { calloc(size as size_t, 1) as *mut u8 }
} else {
let flags = align_to_flags(align) | MALLOCX_ZERO;
unsafe { mallocx(size as size_t, flags) as *mut u8 }
}
}

#[no_mangle]
pub extern "C" fn __rust_reallocate(ptr: *mut u8,
_old_size: usize,
Expand Down Expand Up @@ -135,6 +151,11 @@ mod imp {
bogus()
}

#[no_mangle]
pub extern "C" fn __rust_allocate_zeroed(_size: usize, _align: usize) -> *mut u8 {
bogus()
}

#[no_mangle]
pub extern "C" fn __rust_reallocate(_ptr: *mut u8,
_old_size: usize,
Expand Down