Skip to content

Commit fd68d02

Browse files
committed
Auto merge of #64026 - Centril:rollup-le667lp, r=Centril
Rollup of 7 pull requests Successful merges: - #62957 (Match the loop examples) - #63600 (Merge oli-obk mail addresses) - #63684 (Constify LinkedList new function) - #63847 ([rustdoc] Fix system theme detection) - #63999 (Add missing links on AsRef trait) - #64014 ( miri: detect too large dynamically sized objects ) - #64015 (some const-eval test tweaks) Failed merges: r? @ghost
2 parents 4295eea + d997596 commit fd68d02

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+222
-141
lines changed

.mailmap

+13-6
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,19 @@ Neil Pankey <[email protected]> <[email protected]>
184184
Nick Platt <[email protected]>
185185
Nicole Mazzuca <[email protected]>
186186
187-
Oliver Schneider <[email protected]> oli-obk <[email protected]>
188-
Oliver Schneider <[email protected]> Oliver 'ker' Schneider <[email protected]>
189-
Oliver Schneider <[email protected]> Oliver Schneider <[email protected]>
190-
Oliver Schneider <[email protected]> Oliver Schneider <[email protected]>
191-
Oliver Schneider <[email protected]> Oliver Schneider <[email protected]>
192-
Oliver Schneider <[email protected]> Oliver Schneider <[email protected]>
187+
188+
189+
190+
191+
192+
193+
194+
195+
196+
197+
198+
199+
Oliver Scherer <[email protected]>
193200
Ožbolt Menegatti <[email protected]> gareins <[email protected]>
194201
Paul Faria <[email protected]> Paul Faria <[email protected]>
195202
Peer Aramillo Irizar <[email protected]> parir <[email protected]>

src/liballoc/collections/linked_list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl<T> LinkedList<T> {
276276
/// ```
277277
#[inline]
278278
#[stable(feature = "rust1", since = "1.0.0")]
279-
pub fn new() -> Self {
279+
pub const fn new() -> Self {
280280
LinkedList {
281281
head: None,
282282
tail: None,

src/libcore/convert.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,17 @@ pub const fn identity<T>(x: T) -> T { x }
104104
/// If you need to do a costly conversion it is better to implement [`From`] with type
105105
/// `&T` or write a custom function.
106106
///
107-
/// `AsRef` has the same signature as [`Borrow`], but `Borrow` is different in few aspects:
107+
/// `AsRef` has the same signature as [`Borrow`], but [`Borrow`] is different in few aspects:
108108
///
109-
/// - Unlike `AsRef`, `Borrow` has a blanket impl for any `T`, and can be used to accept either
109+
/// - Unlike `AsRef`, [`Borrow`] has a blanket impl for any `T`, and can be used to accept either
110110
/// a reference or a value.
111-
/// - `Borrow` also requires that `Hash`, `Eq` and `Ord` for borrowed value are
111+
/// - [`Borrow`] also requires that [`Hash`], [`Eq`] and [`Ord`] for borrowed value are
112112
/// equivalent to those of the owned value. For this reason, if you want to
113-
/// borrow only a single field of a struct you can implement `AsRef`, but not `Borrow`.
114-
///
115-
/// [`Borrow`]: ../../std/borrow/trait.Borrow.html
113+
/// borrow only a single field of a struct you can implement `AsRef`, but not [`Borrow`].
116114
///
117115
/// **Note: This trait must not fail**. If the conversion can fail, use a
118116
/// dedicated method which returns an [`Option<T>`] or a [`Result<T, E>`].
119117
///
120-
/// [`Option<T>`]: ../../std/option/enum.Option.html
121-
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
122-
///
123118
/// # Generic Implementations
124119
///
125120
/// - `AsRef` auto-dereferences if the inner type is a reference or a mutable
@@ -132,9 +127,16 @@ pub const fn identity<T>(x: T) -> T { x }
132127
/// converted to the specified type `T`.
133128
///
134129
/// For example: By creating a generic function that takes an `AsRef<str>` we express that we
135-
/// want to accept all references that can be converted to `&str` as an argument.
136-
/// Since both [`String`] and `&str` implement `AsRef<str>` we can accept both as input argument.
130+
/// want to accept all references that can be converted to [`&str`] as an argument.
131+
/// Since both [`String`] and [`&str`] implement `AsRef<str>` we can accept both as input argument.
137132
///
133+
/// [`Option<T>`]: ../../std/option/enum.Option.html
134+
/// [`Result<T, E>`]: ../../std/result/enum.Result.html
135+
/// [`Borrow`]: ../../std/borrow/trait.Borrow.html
136+
/// [`Hash`]: ../../std/hash/trait.Hash.html
137+
/// [`Eq`]: ../../std/cmp/trait.Eq.html
138+
/// [`Ord`]: ../../std/cmp/trait.Ord.html
139+
/// [`&str`]: ../../std/primitive.str.html
138140
/// [`String`]: ../../std/string/struct.String.html
139141
///
140142
/// ```

src/librustc_mir/interpret/eval_context.rs

+15-12
Original file line numberDiff line numberDiff line change
@@ -442,27 +442,30 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
442442

443443
// Issue #27023: must add any necessary padding to `size`
444444
// (to make it a multiple of `align`) before returning it.
445-
//
446-
// Namely, the returned size should be, in C notation:
447-
//
448-
// `size + ((size & (align-1)) ? align : 0)`
449-
//
450-
// emulated via the semi-standard fast bit trick:
451-
//
452-
// `(size + (align-1)) & -align`
453-
454-
Ok(Some((size.align_to(align), align)))
445+
let size = size.align_to(align);
446+
447+
// Check if this brought us over the size limit.
448+
if size.bytes() >= self.tcx.data_layout().obj_size_bound() {
449+
throw_ub_format!("wide pointer metadata contains invalid information: \
450+
total size is bigger than largest supported object");
451+
}
452+
Ok(Some((size, align)))
455453
}
456454
ty::Dynamic(..) => {
457455
let vtable = metadata.expect("dyn trait fat ptr must have vtable");
458-
// the second entry in the vtable is the dynamic size of the object.
456+
// Read size and align from vtable (already checks size).
459457
Ok(Some(self.read_size_and_align_from_vtable(vtable)?))
460458
}
461459

462460
ty::Slice(_) | ty::Str => {
463461
let len = metadata.expect("slice fat ptr must have vtable").to_usize(self)?;
464462
let elem = layout.field(self, 0)?;
465-
Ok(Some((elem.size * len, elem.align.abi)))
463+
464+
// Make sure the slice is not too big.
465+
let size = elem.size.checked_mul(len, &*self.tcx)
466+
.ok_or_else(|| err_ub_format!("invalid slice: \
467+
total size is bigger than largest supported object"))?;
468+
Ok(Some((size, elem.align.abi)))
466469
}
467470

468471
ty::Foreign(_) => {

src/librustc_mir/interpret/traits.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc::ty::{self, Ty, Instance, TypeFoldable};
2-
use rustc::ty::layout::{Size, Align, LayoutOf};
2+
use rustc::ty::layout::{Size, Align, LayoutOf, HasDataLayout};
33
use rustc::mir::interpret::{Scalar, Pointer, InterpResult, PointerArithmetic,};
44

55
use super::{InterpCx, Machine, MemoryKind, FnVal};
@@ -151,6 +151,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
151151
vtable.offset(pointer_size * 2, self)?,
152152
)?.not_undef()?;
153153
let align = self.force_bits(align, pointer_size)? as u64;
154+
155+
if size >= self.tcx.data_layout().obj_size_bound() {
156+
throw_ub_format!("invalid vtable: \
157+
size is bigger than largest supported object");
158+
}
154159
Ok((Size::from_bytes(size), Align::from_bytes(align).unwrap()))
155160
}
156161
}

src/librustc_mir/interpret/validity.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//! Check the validity invariant of a given value, and tell the user
2+
//! where in the value it got violated.
3+
//! In const context, this goes even further and tries to approximate const safety.
4+
//! That's useful because it means other passes (e.g. promotion) can rely on `const`s
5+
//! to be const-safe.
6+
17
use std::fmt::Write;
28
use std::ops::RangeInclusive;
39

src/librustdoc/html/static/storage.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ function switchTheme(styleElem, mainStyleElem, newTheme, saveTheme) {
118118
}
119119

120120
function getSystemValue() {
121-
return getComputedStyle(document.documentElement).getPropertyValue('content');
121+
var property = getComputedStyle(document.documentElement).getPropertyValue('content');
122+
return property.replace(/\"\'/g, "");
122123
}
123124

124125
switchTheme(currentTheme, mainTheme,

src/libstd/keyword_docs.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -681,14 +681,15 @@ mod while_keyword { }
681681
/// # break;
682682
/// }
683683
///
684-
/// let mut i = 0;
684+
/// let mut i = 1;
685685
/// loop {
686686
/// println!("i is {}", i);
687-
/// if i > 10 {
687+
/// if i > 100 {
688688
/// break;
689689
/// }
690-
/// i += 1;
690+
/// i *= 2;
691691
/// }
692+
/// assert_eq!(i, 128);
692693
/// ```
693694
///
694695
/// Unlike the other kinds of loops in Rust (`while`, `while let`, and `for`), loops can be used as

src/test/ui/consts/const-eval/const-pointer-values-in-various-types.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// only-x86_64
22

3+
#[repr(C)]
34
union Nonsense {
45
u: usize,
56
int_32_ref: &'static i32,

0 commit comments

Comments
 (0)