Skip to content

Commit 5fae569

Browse files
committed
Auto merge of #76781 - RalfJung:rollup-ve66o2j, r=RalfJung
Rollup of 10 pull requests Successful merges: - #76056 (Add more info for Vec Drain doc) - #76062 (Vec slice example fix style and show type elision) - #76262 (Use inline(never) instead of cold) - #76335 (Make all methods of `Duration` unstably const) - #76366 (Add Arith Tests in Library) - #76369 (Move Various str tests in library) - #76534 (Add doc comments for From impls) - #76622 (Update bootstrap readme) - #76641 (Some cleanup changes and commenting) - #76662 (Fix liballoc test suite for Miri) Failed merges: r? `@ghost`
2 parents 1e11660 + 9d0a265 commit 5fae569

File tree

26 files changed

+292
-274
lines changed

26 files changed

+292
-274
lines changed

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2280,6 +2280,12 @@ impl<'tcx> TyS<'tcx> {
22802280
///
22812281
/// Returning true means the type is known to be sized. Returning
22822282
/// `false` means nothing -- could be sized, might not be.
2283+
///
2284+
/// Note that we could never rely on the fact that a type such as `[_]` is
2285+
/// trivially `!Sized` because we could be in a type environment with a
2286+
/// bound such as `[_]: Copy`. A function with such a bound obviously never
2287+
/// can be called, but that doesn't mean it shouldn't typecheck. This is why
2288+
/// this method doesn't return `Option<bool>`.
22832289
pub fn is_trivially_sized(&self, tcx: TyCtxt<'tcx>) -> bool {
22842290
match self.kind() {
22852291
ty::Infer(ty::IntVar(_) | ty::FloatVar(_))

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,12 +1512,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
15121512
// avoid inundating the user with unnecessary errors, but we now
15131513
// check upstream for type errors and don't add the obligations to
15141514
// begin with in those cases.
1515-
if self
1516-
.tcx
1517-
.lang_items()
1518-
.sized_trait()
1519-
.map_or(false, |sized_id| sized_id == trait_ref.def_id())
1520-
{
1515+
if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) {
15211516
self.need_type_info_err(body_id, span, self_ty, ErrorCode::E0282).emit();
15221517
return;
15231518
}

compiler/rustc_traits/src/chalk/db.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,25 +110,15 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
110110
.map(|i| chalk_ir::AssocTypeId(i.def_id))
111111
.collect();
112112

113-
let well_known = if self
114-
.interner
115-
.tcx
116-
.lang_items()
117-
.sized_trait()
118-
.map(|t| def_id == t)
119-
.unwrap_or(false)
120-
{
113+
let well_known = if self.interner.tcx.lang_items().sized_trait() == Some(def_id) {
121114
Some(chalk_solve::rust_ir::WellKnownTrait::Sized)
122-
} else if self.interner.tcx.lang_items().copy_trait().map(|t| def_id == t).unwrap_or(false)
123-
{
115+
} else if self.interner.tcx.lang_items().copy_trait() == Some(def_id) {
124116
Some(chalk_solve::rust_ir::WellKnownTrait::Copy)
125-
} else if self.interner.tcx.lang_items().clone_trait().map(|t| def_id == t).unwrap_or(false)
126-
{
117+
} else if self.interner.tcx.lang_items().clone_trait() == Some(def_id) {
127118
Some(chalk_solve::rust_ir::WellKnownTrait::Clone)
128-
} else if self.interner.tcx.lang_items().drop_trait().map(|t| def_id == t).unwrap_or(false)
129-
{
119+
} else if self.interner.tcx.lang_items().drop_trait() == Some(def_id) {
130120
Some(chalk_solve::rust_ir::WellKnownTrait::Drop)
131-
} else if self.interner.tcx.lang_items().fn_trait().map(|t| def_id == t).unwrap_or(false) {
121+
} else if self.interner.tcx.lang_items().fn_trait() == Some(def_id) {
132122
Some(chalk_solve::rust_ir::WellKnownTrait::Fn)
133123
} else if self
134124
.interner

library/alloc/src/collections/binary_heap.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,10 @@ impl<T: Ord> From<Vec<T>> for BinaryHeap<T> {
13431343

13441344
#[stable(feature = "binary_heap_extras_15", since = "1.5.0")]
13451345
impl<T> From<BinaryHeap<T>> for Vec<T> {
1346+
/// Converts a `BinaryHeap<T>` into a `Vec<T>`.
1347+
///
1348+
/// This conversion requires no data movement or allocation, and has
1349+
/// constant time complexity.
13461350
fn from(heap: BinaryHeap<T>) -> Vec<T> {
13471351
heap.data
13481352
}

library/alloc/src/collections/vec_deque.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,11 +1089,7 @@ impl<T> VecDeque<T> {
10891089
where
10901090
R: RangeBounds<usize>,
10911091
{
1092-
// SAFETY: This buffer is only used to check the range. It might be partially
1093-
// uninitialized, but `check_range` needs a contiguous slice.
1094-
// https://github.com/rust-lang/rust/pull/75207#discussion_r471193682
1095-
let buffer = unsafe { slice::from_raw_parts(self.ptr(), self.len()) };
1096-
let Range { start, end } = buffer.check_range(range);
1092+
let Range { start, end } = slice::check_range(self.len(), range);
10971093
let tail = self.wrap_add(self.tail, start);
10981094
let head = self.wrap_add(self.tail, end);
10991095
(tail, head)

library/alloc/src/slice.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ use crate::borrow::ToOwned;
9191
use crate::boxed::Box;
9292
use crate::vec::Vec;
9393

94+
#[unstable(feature = "slice_check_range", issue = "76393")]
95+
pub use core::slice::check_range;
9496
#[unstable(feature = "array_chunks", issue = "74985")]
9597
pub use core::slice::ArrayChunks;
9698
#[unstable(feature = "array_chunks", issue = "74985")]

library/alloc/src/string.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use core::iter::{FromIterator, FusedIterator};
4949
use core::ops::Bound::{Excluded, Included, Unbounded};
5050
use core::ops::{self, Add, AddAssign, Index, IndexMut, Range, RangeBounds};
5151
use core::ptr;
52+
use core::slice;
5253
use core::str::{lossy, pattern::Pattern};
5354

5455
use crate::borrow::{Cow, ToOwned};
@@ -1506,7 +1507,7 @@ impl String {
15061507
// of the vector version. The data is just plain bytes.
15071508
// Because the range removal happens in Drop, if the Drain iterator is leaked,
15081509
// the removal will not happen.
1509-
let Range { start, end } = self.as_bytes().check_range(range);
1510+
let Range { start, end } = slice::check_range(self.len(), range);
15101511
assert!(self.is_char_boundary(start));
15111512
assert!(self.is_char_boundary(end));
15121513

library/alloc/src/vec.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ use crate::raw_vec::RawVec;
174174
///
175175
/// // ... and that's all!
176176
/// // you can also do it like this:
177-
/// let x : &[usize] = &v;
177+
/// let u: &[usize] = &v;
178+
/// // or like this:
179+
/// let u: &[_] = &v;
178180
/// ```
179181
///
180182
/// In Rust, it's more common to pass slices as arguments rather than vectors
@@ -1310,7 +1312,7 @@ impl<T> Vec<T> {
13101312
// the hole, and the vector length is restored to the new length.
13111313
//
13121314
let len = self.len();
1313-
let Range { start, end } = self.check_range(range);
1315+
let Range { start, end } = slice::check_range(len, range);
13141316

13151317
unsafe {
13161318
// set self.vec length's to start, to be safe in case Drain is leaked
@@ -3037,6 +3039,7 @@ impl<T> AsIntoIter for IntoIter<T> {
30373039
/// A draining iterator for `Vec<T>`.
30383040
///
30393041
/// This `struct` is created by [`Vec::drain`].
3042+
/// See its documentation for more.
30403043
#[stable(feature = "drain", since = "1.6.0")]
30413044
pub struct Drain<'a, T: 'a> {
30423045
/// Index of tail to preserve

library/alloc/tests/str.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,3 +1921,24 @@ fn different_str_pattern_forwarding_lifetimes() {
19211921

19221922
foo::<&str>("x");
19231923
}
1924+
1925+
#[test]
1926+
fn test_str_multiline() {
1927+
let a: String = "this \
1928+
is a test"
1929+
.to_string();
1930+
let b: String = "this \
1931+
is \
1932+
another \
1933+
test"
1934+
.to_string();
1935+
assert_eq!(a, "this is a test".to_string());
1936+
assert_eq!(b, "this is another test".to_string());
1937+
}
1938+
1939+
#[test]
1940+
fn test_str_escapes() {
1941+
let x = "\\\\\
1942+
";
1943+
assert_eq!(x, r"\\"); // extraneous whitespace stripped
1944+
}

library/alloc/tests/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ fn test_from_iter_partially_drained_in_place_specialization() {
919919
#[test]
920920
fn test_from_iter_specialization_with_iterator_adapters() {
921921
fn assert_in_place_trait<T: InPlaceIterable>(_: &T) {};
922-
let src: Vec<usize> = vec![0usize; 65535];
922+
let src: Vec<usize> = vec![0usize; 256];
923923
let srcptr = src.as_ptr();
924924
let iter = src
925925
.into_iter()

0 commit comments

Comments
 (0)