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 7 pull requests #64026

Merged
merged 20 commits into from
Aug 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
19 changes: 13 additions & 6 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,19 @@ Neil Pankey <[email protected]> <[email protected]>
Nick Platt <[email protected]>
Nicole Mazzuca <[email protected]>
Nif Ward <[email protected]>
Oliver Schneider <[email protected]> oli-obk <[email protected]>
Oliver Schneider <[email protected]> Oliver 'ker' Schneider <[email protected]>
Oliver Schneider <[email protected]> Oliver Schneider <[email protected]>
Oliver Schneider <[email protected]> Oliver Schneider <[email protected]>
Oliver Schneider <[email protected]> Oliver Schneider <[email protected]>
Oliver Schneider <[email protected]> Oliver Schneider <[email protected]>
Oliver Scherer <[email protected]> <[email protected]>
Oliver Scherer <[email protected]> <[email protected]>
Oliver Scherer <[email protected]> <[email protected]>
Oliver Scherer <[email protected]> <[email protected]>
Oliver Scherer <[email protected]> <[email protected]>
Oliver Scherer <[email protected]> <[email protected]>
Oliver Scherer <[email protected]> <[email protected]>
Oliver Scherer <[email protected]> <[email protected]>
Oliver Scherer <[email protected]> <[email protected]>
Oliver Scherer <[email protected]> <[email protected]>
Oliver Scherer <[email protected]> <[email protected]>
Oliver Scherer <[email protected]> <[email protected]>
Oliver Scherer <[email protected]>
Ožbolt Menegatti <[email protected]> gareins <[email protected]>
Paul Faria <[email protected]> Paul Faria <[email protected]>
Peer Aramillo Irizar <[email protected]> parir <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion src/liballoc/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl<T> LinkedList<T> {
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new() -> Self {
pub const fn new() -> Self {
LinkedList {
head: None,
tail: None,
Expand Down
24 changes: 13 additions & 11 deletions src/libcore/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,17 @@ pub const fn identity<T>(x: T) -> T { x }
/// If you need to do a costly conversion it is better to implement [`From`] with type
/// `&T` or write a custom function.
///
/// `AsRef` has the same signature as [`Borrow`], but `Borrow` is different in few aspects:
/// `AsRef` has the same signature as [`Borrow`], but [`Borrow`] is different in few aspects:
///
/// - Unlike `AsRef`, `Borrow` has a blanket impl for any `T`, and can be used to accept either
/// - Unlike `AsRef`, [`Borrow`] has a blanket impl for any `T`, and can be used to accept either
/// a reference or a value.
/// - `Borrow` also requires that `Hash`, `Eq` and `Ord` for borrowed value are
/// - [`Borrow`] also requires that [`Hash`], [`Eq`] and [`Ord`] for borrowed value are
/// equivalent to those of the owned value. For this reason, if you want to
/// borrow only a single field of a struct you can implement `AsRef`, but not `Borrow`.
///
/// [`Borrow`]: ../../std/borrow/trait.Borrow.html
/// borrow only a single field of a struct you can implement `AsRef`, but not [`Borrow`].
///
/// **Note: This trait must not fail**. If the conversion can fail, use a
/// dedicated method which returns an [`Option<T>`] or a [`Result<T, E>`].
///
/// [`Option<T>`]: ../../std/option/enum.Option.html
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
///
/// # Generic Implementations
///
/// - `AsRef` auto-dereferences if the inner type is a reference or a mutable
Expand All @@ -132,9 +127,16 @@ pub const fn identity<T>(x: T) -> T { x }
/// converted to the specified type `T`.
///
/// For example: By creating a generic function that takes an `AsRef<str>` we express that we
/// want to accept all references that can be converted to `&str` as an argument.
/// Since both [`String`] and `&str` implement `AsRef<str>` we can accept both as input argument.
/// want to accept all references that can be converted to [`&str`] as an argument.
/// Since both [`String`] and [`&str`] implement `AsRef<str>` we can accept both as input argument.
///
/// [`Option<T>`]: ../../std/option/enum.Option.html
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
/// [`Borrow`]: ../../std/borrow/trait.Borrow.html
/// [`Hash`]: ../../std/hash/trait.Hash.html
/// [`Eq`]: ../../std/cmp/trait.Eq.html
/// [`Ord`]: ../../std/cmp/trait.Ord.html
/// [`&str`]: ../../std/primitive.str.html
/// [`String`]: ../../std/string/struct.String.html
///
/// ```
Expand Down
27 changes: 15 additions & 12 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,27 +442,30 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {

// Issue #27023: must add any necessary padding to `size`
// (to make it a multiple of `align`) before returning it.
//
// Namely, the returned size should be, in C notation:
//
// `size + ((size & (align-1)) ? align : 0)`
//
// emulated via the semi-standard fast bit trick:
//
// `(size + (align-1)) & -align`

Ok(Some((size.align_to(align), align)))
let size = size.align_to(align);

// Check if this brought us over the size limit.
if size.bytes() >= self.tcx.data_layout().obj_size_bound() {
throw_ub_format!("wide pointer metadata contains invalid information: \
total size is bigger than largest supported object");
}
Ok(Some((size, align)))
}
ty::Dynamic(..) => {
let vtable = metadata.expect("dyn trait fat ptr must have vtable");
// the second entry in the vtable is the dynamic size of the object.
// Read size and align from vtable (already checks size).
Ok(Some(self.read_size_and_align_from_vtable(vtable)?))
}

ty::Slice(_) | ty::Str => {
let len = metadata.expect("slice fat ptr must have vtable").to_usize(self)?;
let elem = layout.field(self, 0)?;
Ok(Some((elem.size * len, elem.align.abi)))

// Make sure the slice is not too big.
let size = elem.size.checked_mul(len, &*self.tcx)
.ok_or_else(|| err_ub_format!("invalid slice: \
total size is bigger than largest supported object"))?;
Ok(Some((size, elem.align.abi)))
}

ty::Foreign(_) => {
Expand Down
7 changes: 6 additions & 1 deletion src/librustc_mir/interpret/traits.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use rustc::ty::{self, Ty, Instance, TypeFoldable};
use rustc::ty::layout::{Size, Align, LayoutOf};
use rustc::ty::layout::{Size, Align, LayoutOf, HasDataLayout};
use rustc::mir::interpret::{Scalar, Pointer, InterpResult, PointerArithmetic,};

use super::{InterpCx, Machine, MemoryKind, FnVal};
Expand Down Expand Up @@ -151,6 +151,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
vtable.offset(pointer_size * 2, self)?,
)?.not_undef()?;
let align = self.force_bits(align, pointer_size)? as u64;

if size >= self.tcx.data_layout().obj_size_bound() {
throw_ub_format!("invalid vtable: \
size is bigger than largest supported object");
}
Ok((Size::from_bytes(size), Align::from_bytes(align).unwrap()))
}
}
6 changes: 6 additions & 0 deletions src/librustc_mir/interpret/validity.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! Check the validity invariant of a given value, and tell the user
//! where in the value it got violated.
//! In const context, this goes even further and tries to approximate const safety.
//! That's useful because it means other passes (e.g. promotion) can rely on `const`s
//! to be const-safe.

use std::fmt::Write;
use std::ops::RangeInclusive;

Expand Down
3 changes: 2 additions & 1 deletion src/librustdoc/html/static/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) {
}

function getSystemValue() {
return getComputedStyle(document.documentElement).getPropertyValue('content');
var property = getComputedStyle(document.documentElement).getPropertyValue('content');
return property.replace(/\"\'/g, "");
}

switchTheme(currentTheme, mainTheme,
Expand Down
7 changes: 4 additions & 3 deletions src/libstd/keyword_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,14 +681,15 @@ mod while_keyword { }
/// # break;
/// }
///
/// let mut i = 0;
/// let mut i = 1;
/// loop {
/// println!("i is {}", i);
/// if i > 10 {
/// if i > 100 {
/// break;
/// }
/// i += 1;
/// i *= 2;
/// }
/// assert_eq!(i, 128);
/// ```
///
/// Unlike the other kinds of loops in Rust (`while`, `while let`, and `for`), loops can be used as
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// only-x86_64

#[repr(C)]
union Nonsense {
u: usize,
int_32_ref: &'static i32,
Expand Down
Loading