Skip to content

Commit 6bfbf0c

Browse files
committed
Auto merge of rust-lang#83308 - Dylan-DPC:rollup-p2j6sy8, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - rust-lang#79986 (Only build help popup when it's really needed) - rust-lang#82570 (Add `as_str` method for split whitespace str iterators) - rust-lang#83244 (Fix overflowing length in Vec<ZST> to VecDeque) - rust-lang#83254 (Include output stream in `panic!()` documentation) - rust-lang#83269 (Revert the second deprecation of collections::Bound) - rust-lang#83277 (Mark early otherwise optimization unsound) - rust-lang#83285 (Update LLVM to bring in SIMD updates for WebAssembly) - rust-lang#83297 (Do not ICE on ty::Error as an error must already have been reported) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents f5f33ec + 51a29cb commit 6bfbf0c

File tree

18 files changed

+211
-50
lines changed

18 files changed

+211
-50
lines changed

compiler/rustc_middle/src/ty/relate.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
1010
use crate::ty::{self, Ty, TyCtxt, TypeFoldable};
1111
use rustc_hir as ast;
1212
use rustc_hir::def_id::DefId;
13+
use rustc_span::DUMMY_SP;
1314
use rustc_target::spec::abi;
1415
use std::iter;
1516

@@ -499,11 +500,14 @@ pub fn super_relate_consts<R: TypeRelation<'tcx>>(
499500

500501
// FIXME(oli-obk): once const generics can have generic types, this assertion
501502
// will likely get triggered. Move to `normalize_erasing_regions` at that point.
502-
assert_eq!(
503-
tcx.erase_regions(a.ty),
504-
tcx.erase_regions(b.ty),
505-
"cannot relate constants of different types"
506-
);
503+
let a_ty = tcx.erase_regions(a.ty);
504+
let b_ty = tcx.erase_regions(b.ty);
505+
if a_ty != b_ty {
506+
relation.tcx().sess.delay_span_bug(
507+
DUMMY_SP,
508+
&format!("cannot relate constants of different types: {} != {}", a_ty, b_ty),
509+
);
510+
}
507511

508512
let eagerly_eval = |x: &'tcx ty::Const<'tcx>| x.eval(tcx, relation.param_env());
509513
let a = eagerly_eval(a);

compiler/rustc_mir/src/transform/early_otherwise_branch.rs

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ pub struct EarlyOtherwiseBranch;
2626

2727
impl<'tcx> MirPass<'tcx> for EarlyOtherwiseBranch {
2828
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
29+
// FIXME(#78496)
30+
if !tcx.sess.opts.debugging_opts.unsound_mir_opts {
31+
return;
32+
}
33+
2934
if tcx.sess.mir_opt_level() < 3 {
3035
return;
3136
}

library/alloc/src/collections/vec_deque/mod.rs

+18-19
Original file line numberDiff line numberDiff line change
@@ -2783,27 +2783,26 @@ impl<T> From<Vec<T>> for VecDeque<T> {
27832783
/// This avoids reallocating where possible, but the conditions for that are
27842784
/// strict, and subject to change, and so shouldn't be relied upon unless the
27852785
/// `Vec<T>` came from `From<VecDeque<T>>` and hasn't been reallocated.
2786-
fn from(other: Vec<T>) -> Self {
2787-
unsafe {
2788-
let mut other = ManuallyDrop::new(other);
2789-
let other_buf = other.as_mut_ptr();
2790-
let mut buf = RawVec::from_raw_parts(other_buf, other.capacity());
2791-
let len = other.len();
2792-
2793-
// We need to extend the buf if it's not a power of two, too small
2794-
// or doesn't have at least one free space.
2795-
// We check if `T` is a ZST in the first condition,
2796-
// because `usize::MAX` (the capacity returned by `capacity()` for ZST)
2797-
// is not a power of two and thus it'll always try
2798-
// to reserve more memory which will panic for ZST (rust-lang/rust#78532)
2799-
if (!buf.capacity().is_power_of_two() && mem::size_of::<T>() != 0)
2800-
|| (buf.capacity() < (MINIMUM_CAPACITY + 1))
2801-
|| (buf.capacity() == len)
2802-
{
2803-
let cap = cmp::max(buf.capacity() + 1, MINIMUM_CAPACITY + 1).next_power_of_two();
2804-
buf.reserve_exact(len, cap - len);
2786+
fn from(mut other: Vec<T>) -> Self {
2787+
let len = other.len();
2788+
if mem::size_of::<T>() == 0 {
2789+
// There's no actual allocation for ZSTs to worry about capacity,
2790+
// but `VecDeque` can't handle as much length as `Vec`.
2791+
assert!(len < MAXIMUM_ZST_CAPACITY, "capacity overflow");
2792+
} else {
2793+
// We need to resize if the capacity is not a power of two, too small or
2794+
// doesn't have at least one free space. We do this while it's still in
2795+
// the `Vec` so the items will drop on panic.
2796+
let min_cap = cmp::max(MINIMUM_CAPACITY, len) + 1;
2797+
let cap = cmp::max(min_cap, other.capacity()).next_power_of_two();
2798+
if other.capacity() != cap {
2799+
other.reserve_exact(cap - len);
28052800
}
2801+
}
28062802

2803+
unsafe {
2804+
let (other_buf, len, capacity) = other.into_raw_parts();
2805+
let buf = RawVec::from_raw_parts(other_buf, capacity);
28072806
VecDeque { tail: 0, head: len, buf }
28082807
}
28092808
}

library/alloc/src/collections/vec_deque/tests.rs

+15
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,21 @@ fn test_from_vec() {
457457
assert!(vd.into_iter().eq(vec));
458458
}
459459
}
460+
461+
let vec = Vec::from([(); MAXIMUM_ZST_CAPACITY - 1]);
462+
let vd = VecDeque::from(vec.clone());
463+
assert!(vd.cap().is_power_of_two());
464+
assert_eq!(vd.len(), vec.len());
465+
}
466+
467+
#[test]
468+
#[should_panic = "capacity overflow"]
469+
fn test_from_vec_zst_overflow() {
470+
use crate::vec::Vec;
471+
let vec = Vec::from([(); MAXIMUM_ZST_CAPACITY]);
472+
let vd = VecDeque::from(vec.clone()); // no room for +1
473+
assert!(vd.cap().is_power_of_two());
474+
assert_eq!(vd.len(), vec.len());
460475
}
461476

462477
#[test]

library/core/src/iter/adapters/filter.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use crate::ops::Try;
1313
#[stable(feature = "rust1", since = "1.0.0")]
1414
#[derive(Clone)]
1515
pub struct Filter<I, P> {
16-
iter: I,
16+
// Used for `SplitWhitespace` and `SplitAsciiWhitespace` `as_str` methods
17+
pub(crate) iter: I,
1718
predicate: P,
1819
}
1920
impl<I, P> Filter<I, P> {

library/core/src/iter/adapters/map.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ use crate::ops::Try;
5757
#[stable(feature = "rust1", since = "1.0.0")]
5858
#[derive(Clone)]
5959
pub struct Map<I, F> {
60-
iter: I,
60+
// Used for `SplitWhitespace` and `SplitAsciiWhitespace` `as_str` methods
61+
pub(crate) iter: I,
6162
f: F,
6263
}
6364

library/core/src/macros/panic.md

+10-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ tests. `panic!` is closely tied with the `unwrap` method of both
99
[`Option`][ounwrap] and [`Result`][runwrap] enums. Both implementations call
1010
`panic!` when they are set to [`None`] or [`Err`] variants.
1111

12-
This macro is used to inject panic into a Rust thread, causing the thread to
13-
panic entirely. This macro panics with a string and uses the [`format!`] syntax
14-
for building the message.
15-
16-
Each thread's panic can be reaped as the [`Box`]`<`[`Any`]`>` type,
12+
When using `panic!()` you can specify a string payload, that is built using
13+
the [`format!`] syntax. That payload is used when injecting the panic into
14+
the calling Rust thread, causing the thread to panic entirely.
15+
16+
The behavior of the default `std` hook, i.e. the code that runs directly
17+
after the panic is invoked, is to print the message payload to
18+
`stderr` along with the file/line/column information of the `panic!()`
19+
call. You can override the panic hook using [`std::panic::set_hook()`].
20+
Inside the hook a panic can be accessed as a `&dyn Any + Send`,
1721
which contains either a `&str` or `String` for regular `panic!()` invocations.
1822
To panic with a value of another other type, [`panic_any`] can be used.
1923

@@ -26,6 +30,7 @@ See also the macro [`compile_error!`], for raising errors during compilation.
2630

2731
[ounwrap]: Option::unwrap
2832
[runwrap]: Result::unwrap
33+
[`std::panic::set_hook()`]: ../std/panic/fn.set_hook.html
2934
[`panic_any`]: ../std/panic/fn.panic_any.html
3035
[`Box`]: ../std/boxed/struct.Box.html
3136
[`Any`]: crate::any::Any

library/core/src/slice/iter.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,11 @@ pub struct Split<'a, T: 'a, P>
335335
where
336336
P: FnMut(&T) -> bool,
337337
{
338-
v: &'a [T],
338+
// Used for `SplitWhitespace` and `SplitAsciiWhitespace` `as_str` methods
339+
pub(crate) v: &'a [T],
339340
pred: P,
340-
finished: bool,
341+
// Used for `SplitAsciiWhitespace` `as_str` method
342+
pub(crate) finished: bool,
341343
}
342344

343345
impl<'a, T: 'a, P: FnMut(&T) -> bool> Split<'a, T, P> {

library/core/src/str/iter.rs

+53
Original file line numberDiff line numberDiff line change
@@ -1200,6 +1200,30 @@ impl<'a> DoubleEndedIterator for SplitWhitespace<'a> {
12001200
#[stable(feature = "fused", since = "1.26.0")]
12011201
impl FusedIterator for SplitWhitespace<'_> {}
12021202

1203+
impl<'a> SplitWhitespace<'a> {
1204+
/// Returns remainder of the splitted string
1205+
///
1206+
/// # Examples
1207+
///
1208+
/// ```
1209+
/// #![feature(str_split_whitespace_as_str)]
1210+
///
1211+
/// let mut split = "Mary had a little lamb".split_whitespace();
1212+
/// assert_eq!(split.as_str(), "Mary had a little lamb");
1213+
///
1214+
/// split.next();
1215+
/// assert_eq!(split.as_str(), "had a little lamb");
1216+
///
1217+
/// split.by_ref().for_each(drop);
1218+
/// assert_eq!(split.as_str(), "");
1219+
/// ```
1220+
#[inline]
1221+
#[unstable(feature = "str_split_whitespace_as_str", issue = "77998")]
1222+
pub fn as_str(&self) -> &'a str {
1223+
self.inner.iter.as_str()
1224+
}
1225+
}
1226+
12031227
#[stable(feature = "split_ascii_whitespace", since = "1.34.0")]
12041228
impl<'a> Iterator for SplitAsciiWhitespace<'a> {
12051229
type Item = &'a str;
@@ -1231,6 +1255,35 @@ impl<'a> DoubleEndedIterator for SplitAsciiWhitespace<'a> {
12311255
#[stable(feature = "split_ascii_whitespace", since = "1.34.0")]
12321256
impl FusedIterator for SplitAsciiWhitespace<'_> {}
12331257

1258+
impl<'a> SplitAsciiWhitespace<'a> {
1259+
/// Returns remainder of the splitted string
1260+
///
1261+
/// # Examples
1262+
///
1263+
/// ```
1264+
/// #![feature(str_split_whitespace_as_str)]
1265+
///
1266+
/// let mut split = "Mary had a little lamb".split_ascii_whitespace();
1267+
/// assert_eq!(split.as_str(), "Mary had a little lamb");
1268+
///
1269+
/// split.next();
1270+
/// assert_eq!(split.as_str(), "had a little lamb");
1271+
///
1272+
/// split.by_ref().for_each(drop);
1273+
/// assert_eq!(split.as_str(), "");
1274+
/// ```
1275+
#[inline]
1276+
#[unstable(feature = "str_split_whitespace_as_str", issue = "77998")]
1277+
pub fn as_str(&self) -> &'a str {
1278+
if self.inner.iter.iter.finished {
1279+
return "";
1280+
}
1281+
1282+
// SAFETY: Slice is created from str.
1283+
unsafe { crate::str::from_utf8_unchecked(&self.inner.iter.iter.v) }
1284+
}
1285+
}
1286+
12341287
#[stable(feature = "split_inclusive", since = "1.51.0")]
12351288
impl<'a, P: Pattern<'a>> Iterator for SplitInclusive<'a, P> {
12361289
type Item = &'a str;

library/std/src/collections/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,10 @@
401401
#![stable(feature = "rust1", since = "1.0.0")]
402402

403403
#[stable(feature = "rust1", since = "1.0.0")]
404-
#[rustc_deprecated(reason = "moved to `std::ops::Bound`", since = "1.52.0")]
404+
// FIXME(#82080) The deprecation here is only theoretical, and does not actually produce a warning.
405+
#[rustc_deprecated(reason = "moved to `std::ops::Bound`", since = "1.26.0")]
405406
#[doc(hidden)]
406-
pub type Bound<T> = crate::ops::Bound<T>;
407+
pub use crate::ops::Bound;
407408

408409
#[stable(feature = "rust1", since = "1.0.0")]
409410
pub use alloc_crate::collections::{binary_heap, btree_map, btree_set};

src/librustdoc/html/static/main.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-tidy-filelength
12
// Local js definitions:
23
/* global addClass, getSettingValue, hasClass */
34
/* global onEach, onEachLazy, hasOwnProperty, removeClass, updateLocalStorage */
@@ -374,28 +375,35 @@ function defocusSearchBar() {
374375
}
375376
}
376377

377-
function getHelpElement() {
378-
buildHelperPopup();
378+
function getHelpElement(build) {
379+
if (build !== false) {
380+
buildHelperPopup();
381+
}
379382
return document.getElementById("help");
380383
}
381384

382385
function displayHelp(display, ev, help) {
383-
help = help ? help : getHelpElement();
384386
if (display === true) {
387+
help = help ? help : getHelpElement(true);
385388
if (hasClass(help, "hidden")) {
386389
ev.preventDefault();
387390
removeClass(help, "hidden");
388391
addClass(document.body, "blur");
389392
}
390-
} else if (hasClass(help, "hidden") === false) {
391-
ev.preventDefault();
392-
addClass(help, "hidden");
393-
removeClass(document.body, "blur");
393+
} else {
394+
// No need to build the help popup if we want to hide it in case it hasn't been
395+
// built yet...
396+
help = help ? help : getHelpElement(false);
397+
if (help && hasClass(help, "hidden") === false) {
398+
ev.preventDefault();
399+
addClass(help, "hidden");
400+
removeClass(document.body, "blur");
401+
}
394402
}
395403
}
396404

397405
function handleEscape(ev) {
398-
var help = getHelpElement();
406+
var help = getHelpElement(false);
399407
var search = getSearchElement();
400408
if (hasClass(help, "hidden") === false) {
401409
displayHelp(false, ev, help);
@@ -558,6 +566,7 @@ function defocusSearchBar() {
558566
}());
559567

560568
document.addEventListener("click", function(ev) {
569+
var helpElem = getHelpElement(false);
561570
if (hasClass(ev.target, "help-button")) {
562571
displayHelp(true, ev);
563572
} else if (hasClass(ev.target, "collapse-toggle")) {
@@ -566,11 +575,10 @@ function defocusSearchBar() {
566575
collapseDocs(ev.target.parentNode, "toggle");
567576
} else if (ev.target.tagName === "SPAN" && hasClass(ev.target.parentNode, "line-numbers")) {
568577
handleSourceHighlight(ev);
569-
} else if (hasClass(getHelpElement(), "hidden") === false) {
570-
var help = getHelpElement();
571-
var is_inside_help_popup = ev.target !== help && help.contains(ev.target);
578+
} else if (helpElem && hasClass(helpElem, "hidden") === false) {
579+
var is_inside_help_popup = ev.target !== helpElem && helpElem.contains(ev.target);
572580
if (is_inside_help_popup === false) {
573-
addClass(help, "hidden");
581+
addClass(helpElem, "hidden");
574582
removeClass(document.body, "blur");
575583
}
576584
} else {

src/llvm-project

Submodule llvm-project updated 39 files

src/test/mir-opt/early_otherwise_branch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Z mir-opt-level=4
1+
// compile-flags: -Z mir-opt-level=4 -Z unsound-mir-opts
22
// EMIT_MIR early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff
33
fn opt1(x: Option<u32>, y: Option<u32>) -> u32 {
44
match (x, y) {

src/test/mir-opt/early_otherwise_branch_3_element_tuple.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -Z mir-opt-level=4
1+
// compile-flags: -Z mir-opt-level=4 -Z unsound-mir-opts
22

33
// EMIT_MIR early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff
44
fn opt1(x: Option<u32>, y: Option<u32>, z: Option<u32>) -> u32 {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn foo<const N: usize>() -> [u8; N] {
2+
bar::<N>() //~ ERROR mismatched types
3+
}
4+
5+
fn bar<const N: u8>() -> [u8; N] {}
6+
//~^ ERROR mismatched types
7+
//~| ERROR mismatched types
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/type_mismatch.rs:2:11
3+
|
4+
LL | bar::<N>()
5+
| ^ expected `u8`, found `usize`
6+
7+
error[E0308]: mismatched types
8+
--> $DIR/type_mismatch.rs:5:31
9+
|
10+
LL | fn bar<const N: u8>() -> [u8; N] {}
11+
| ^ expected `usize`, found `u8`
12+
13+
error[E0308]: mismatched types
14+
--> $DIR/type_mismatch.rs:5:26
15+
|
16+
LL | fn bar<const N: u8>() -> [u8; N] {}
17+
| --- ^^^^^^^ expected array `[u8; N]`, found `()`
18+
| |
19+
| implicitly returns `()` as its body has no tail or `return` expression
20+
21+
error: aborting due to 3 previous errors
22+
23+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
impl X {
2+
//~^ ERROR cannot find type
3+
fn getn<const N: usize>() -> [u8; N] {
4+
getn::<N>()
5+
}
6+
}
7+
fn getn<const N: cfg_attr>() -> [u8; N] {}
8+
//~^ ERROR expected type, found built-in attribute `cfg_attr`
9+
//~| ERROR mismatched types
10+
11+
fn main() {}

0 commit comments

Comments
 (0)