Skip to content

Commit c469766

Browse files
committed
Auto merge of rust-lang#82430 - Dylan-DPC:rollup-nu4kfyc, r=Dylan-DPC
Rollup of 12 pull requests Successful merges: - rust-lang#79423 (Enable smart punctuation) - rust-lang#81154 (Improve design of `assert_len`) - rust-lang#81235 (Improve suggestion for tuple struct pattern matching errors.) - rust-lang#81769 (Suggest `return`ing tail expressions that match return type) - rust-lang#81837 (Slight perf improvement on char::to_ascii_lowercase) - rust-lang#81969 (Avoid `cfg_if` in `std::os`) - rust-lang#81984 (Make WASI's `hard_link` behavior match other platforms.) - rust-lang#82091 (use PlaceRef abstractions more consistently) - rust-lang#82128 (add diagnostic items for OsString/PathBuf/Owned as well as to_vec on slice) - rust-lang#82166 (add s390x-unknown-linux-musl target) - rust-lang#82234 (Remove query parameters when skipping search results) - rust-lang#82255 (Make `treat_err_as_bug` Option<NonZeroUsize>) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 802c18c + 41af98d commit c469766

File tree

17 files changed

+188
-142
lines changed

17 files changed

+188
-142
lines changed

alloc/src/borrow.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ where
3131
/// implementing the `Clone` trait. But `Clone` works only for going from `&T`
3232
/// to `T`. The `ToOwned` trait generalizes `Clone` to construct owned data
3333
/// from any borrow of a given type.
34+
#[cfg_attr(not(test), rustc_diagnostic_item = "ToOwned")]
3435
#[stable(feature = "rust1", since = "1.0.0")]
3536
pub trait ToOwned {
3637
/// The resulting type after obtaining ownership.

alloc/src/collections/vec_deque/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ impl<T> VecDeque<T> {
10631063
where
10641064
R: RangeBounds<usize>,
10651065
{
1066-
let Range { start, end } = range.assert_len(self.len());
1066+
let Range { start, end } = slice::range(range, ..self.len());
10671067
let tail = self.wrap_add(self.tail, start);
10681068
let head = self.wrap_add(self.tail, end);
10691069
(tail, head)

alloc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@
115115
#![feature(or_patterns)]
116116
#![feature(pattern)]
117117
#![feature(ptr_internals)]
118-
#![feature(range_bounds_assert_len)]
119118
#![feature(rustc_attrs)]
120119
#![feature(receiver_trait)]
121120
#![cfg_attr(bootstrap, feature(min_const_generics))]
122121
#![feature(min_specialization)]
123122
#![feature(set_ptr_value)]
124123
#![feature(slice_ptr_get)]
125124
#![feature(slice_ptr_len)]
125+
#![feature(slice_range)]
126126
#![feature(staged_api)]
127127
#![feature(str_internals)]
128128
#![feature(trusted_len)]

alloc/src/slice.rs

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

95+
#[unstable(feature = "slice_range", issue = "76393")]
96+
pub use core::slice::range;
9597
#[unstable(feature = "array_chunks", issue = "74985")]
9698
pub use core::slice::ArrayChunks;
9799
#[unstable(feature = "array_chunks", issue = "74985")]
@@ -220,6 +222,7 @@ mod hack {
220222
}
221223

222224
#[lang = "slice_alloc"]
225+
#[cfg_attr(not(test), rustc_diagnostic_item = "slice")]
223226
#[cfg(not(test))]
224227
impl<T> [T] {
225228
/// Sorts the slice.

alloc/src/string.rs

Lines changed: 4 additions & 2 deletions
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};
@@ -1510,14 +1511,14 @@ impl String {
15101511
// of the vector version. The data is just plain bytes.
15111512
// Because the range removal happens in Drop, if the Drain iterator is leaked,
15121513
// the removal will not happen.
1513-
let Range { start, end } = range.assert_len(self.len());
1514+
let Range { start, end } = slice::range(range, ..self.len());
15141515
assert!(self.is_char_boundary(start));
15151516
assert!(self.is_char_boundary(end));
15161517

15171518
// Take out two simultaneous borrows. The &mut String won't be accessed
15181519
// until iteration is over, in Drop.
15191520
let self_ptr = self as *mut _;
1520-
// SAFETY: `assert_len` and `is_char_boundary` do the appropriate bounds checks.
1521+
// SAFETY: `slice::range` and `is_char_boundary` do the appropriate bounds checks.
15211522
let chars_iter = unsafe { self.get_unchecked(start..end) }.chars();
15221523

15231524
Drain { start, end, iter: chars_iter, string: self_ptr }
@@ -2174,6 +2175,7 @@ impl FromStr for String {
21742175
/// implementation for free.
21752176
///
21762177
/// [`Display`]: fmt::Display
2178+
#[cfg_attr(not(test), rustc_diagnostic_item = "ToString")]
21772179
#[stable(feature = "rust1", since = "1.0.0")]
21782180
pub trait ToString {
21792181
/// Converts the given value to a `String`.

alloc/src/vec/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ impl<T, A: Allocator> Vec<T, A> {
16511651
// the hole, and the vector length is restored to the new length.
16521652
//
16531653
let len = self.len();
1654-
let Range { start, end } = range.assert_len(len);
1654+
let Range { start, end } = slice::range(range, ..len);
16551655

16561656
unsafe {
16571657
// set self.vec length's to start, to be safe in case Drain is leaked
@@ -2037,11 +2037,11 @@ impl<T: Clone, A: Allocator> Vec<T, A> {
20372037
where
20382038
R: RangeBounds<usize>,
20392039
{
2040-
let range = src.assert_len(self.len());
2040+
let range = slice::range(src, ..self.len());
20412041
self.reserve(range.len());
20422042

20432043
// SAFETY:
2044-
// - `assert_len` guarantees that the given range is valid for indexing self
2044+
// - `slice::range` guarantees that the given range is valid for indexing self
20452045
unsafe {
20462046
self.spec_extend_from_within(range);
20472047
}

core/benches/ascii.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ macro_rules! benches {
6666
use test::black_box;
6767
use test::Bencher;
6868

69+
const ASCII_CASE_MASK: u8 = 0b0010_0000;
70+
6971
benches! {
7072
fn case00_alloc_only(_bytes: &mut [u8]) {}
7173

@@ -204,7 +206,7 @@ benches! {
204206
}
205207
}
206208
for byte in bytes {
207-
*byte &= !((is_ascii_lowercase(*byte) as u8) << 5)
209+
*byte &= !((is_ascii_lowercase(*byte) as u8) * ASCII_CASE_MASK)
208210
}
209211
}
210212

@@ -216,7 +218,7 @@ benches! {
216218
}
217219
}
218220
for byte in bytes {
219-
*byte -= (is_ascii_lowercase(*byte) as u8) << 5
221+
*byte -= (is_ascii_lowercase(*byte) as u8) * ASCII_CASE_MASK
220222
}
221223
}
222224

core/benches/char/methods.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,13 @@ fn bench_to_digit_radix_var(b: &mut Bencher) {
3535
.min()
3636
})
3737
}
38+
39+
#[bench]
40+
fn bench_to_ascii_uppercase(b: &mut Bencher) {
41+
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_ascii_uppercase()).min())
42+
}
43+
44+
#[bench]
45+
fn bench_to_ascii_lowercase(b: &mut Bencher) {
46+
b.iter(|| CHARS.iter().cycle().take(10_000).map(|c| c.to_ascii_lowercase()).min())
47+
}

core/src/char/methods.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,11 @@ impl char {
10881088
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
10891089
#[inline]
10901090
pub fn to_ascii_uppercase(&self) -> char {
1091-
if self.is_ascii() { (*self as u8).to_ascii_uppercase() as char } else { *self }
1091+
if self.is_ascii_lowercase() {
1092+
(*self as u8).ascii_change_case_unchecked() as char
1093+
} else {
1094+
*self
1095+
}
10921096
}
10931097

10941098
/// Makes a copy of the value in its ASCII lower case equivalent.
@@ -1116,7 +1120,11 @@ impl char {
11161120
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
11171121
#[inline]
11181122
pub fn to_ascii_lowercase(&self) -> char {
1119-
if self.is_ascii() { (*self as u8).to_ascii_lowercase() as char } else { *self }
1123+
if self.is_ascii_uppercase() {
1124+
(*self as u8).ascii_change_case_unchecked() as char
1125+
} else {
1126+
*self
1127+
}
11201128
}
11211129

11221130
/// Checks that two values are an ASCII case-insensitive match.

core/src/num/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ impl isize {
152152
usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() }
153153
}
154154

155+
/// If 6th bit set ascii is upper case.
156+
const ASCII_CASE_MASK: u8 = 0b0010_0000;
157+
155158
#[lang = "u8"]
156159
impl u8 {
157160
uint_impl! { u8, u8, 8, 255, 2, "0x82", "0xa", "0x12", "0x12", "0x48", "[0x12]",
@@ -195,7 +198,7 @@ impl u8 {
195198
#[inline]
196199
pub fn to_ascii_uppercase(&self) -> u8 {
197200
// Unset the fifth bit if this is a lowercase letter
198-
*self & !((self.is_ascii_lowercase() as u8) << 5)
201+
*self & !((self.is_ascii_lowercase() as u8) * ASCII_CASE_MASK)
199202
}
200203

201204
/// Makes a copy of the value in its ASCII lower case equivalent.
@@ -218,7 +221,13 @@ impl u8 {
218221
#[inline]
219222
pub fn to_ascii_lowercase(&self) -> u8 {
220223
// Set the fifth bit if this is an uppercase letter
221-
*self | ((self.is_ascii_uppercase() as u8) << 5)
224+
*self | (self.is_ascii_uppercase() as u8 * ASCII_CASE_MASK)
225+
}
226+
227+
/// Assumes self is ascii
228+
#[inline]
229+
pub(crate) fn ascii_change_case_unchecked(&self) -> u8 {
230+
*self ^ ASCII_CASE_MASK
222231
}
223232

224233
/// Checks that two values are an ASCII case-insensitive match.

0 commit comments

Comments
 (0)