Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 267cae5

Browse files
committedApr 27, 2025·
Auto merge of #140360 - matthiaskrgr:rollup-savbr84, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #137439 (Stabilise `std::ffi::c_str`) - #137714 (Update safety documentation for `CString::from_ptr` and `str::from_boxed_utf8_unchecked`) - #139031 (Use char::is_whitespace directly in str::trim*) - #139090 (fix docs for `Peekable::next_if{_eq}`) - #140297 (Update example to use CStr::to_string_lossy) - #140330 (Clarified bootstrap optimization "true" argument) - #140339 (session: Cleanup `CanonicalizedPath::new`) - #140346 (rustc_span: Some hygiene cleanups) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8947e16 + aa5c6d4 commit 267cae5

File tree

14 files changed

+89
-143
lines changed

14 files changed

+89
-143
lines changed
 

‎bootstrap.example.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@
500500
# building without optimizations takes much longer than optimizing. Further, some platforms
501501
# fail to build without this optimization (c.f. #65352).
502502
# The valid options are:
503-
# true - Enable optimizations.
503+
# true - Enable optimizations (same as 3).
504504
# false - Disable optimizations.
505505
# 0 - Disable optimizations.
506506
# 1 - Basic optimizations.

‎compiler/rustc_interface/src/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![allow(rustc::bad_opt_access)]
2-
use std::collections::{BTreeMap, BTreeSet};
2+
use std::collections::BTreeMap;
33
use std::num::NonZero;
4-
use std::path::{Path, PathBuf};
4+
use std::path::PathBuf;
55
use std::sync::atomic::AtomicBool;
66

77
use rustc_abi::Align;
@@ -89,8 +89,8 @@ where
8989
S: Into<String>,
9090
I: IntoIterator<Item = S>,
9191
{
92-
let locations: BTreeSet<CanonicalizedPath> =
93-
locations.into_iter().map(|s| CanonicalizedPath::new(Path::new(&s.into()))).collect();
92+
let locations =
93+
locations.into_iter().map(|s| CanonicalizedPath::new(PathBuf::from(s.into()))).collect();
9494

9595
ExternEntry {
9696
location: ExternLocation::ExactPaths(locations),

‎compiler/rustc_session/src/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2323,14 +2323,13 @@ pub fn parse_externs(
23232323
let ExternOpt { crate_name: name, path, options } =
23242324
split_extern_opt(early_dcx, unstable_opts, &arg).unwrap_or_else(|e| e.emit());
23252325

2326-
let path = path.map(|p| CanonicalizedPath::new(p.as_path()));
2327-
23282326
let entry = externs.entry(name.to_owned());
23292327

23302328
use std::collections::btree_map::Entry;
23312329

23322330
let entry = if let Some(path) = path {
23332331
// --extern prelude_name=some_file.rlib
2332+
let path = CanonicalizedPath::new(path);
23342333
match entry {
23352334
Entry::Vacant(vacant) => {
23362335
let files = BTreeSet::from_iter(iter::once(path));

‎compiler/rustc_session/src/utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::{Path, PathBuf};
1+
use std::path::PathBuf;
22
use std::sync::OnceLock;
33

44
use rustc_data_structures::profiling::VerboseTimingGuard;
@@ -104,8 +104,8 @@ pub struct CanonicalizedPath {
104104
}
105105

106106
impl CanonicalizedPath {
107-
pub fn new(path: &Path) -> Self {
108-
Self { original: path.to_owned(), canonicalized: try_canonicalize(path).ok() }
107+
pub fn new(path: PathBuf) -> Self {
108+
Self { canonicalized: try_canonicalize(&path).ok(), original: path }
109109
}
110110

111111
pub fn canonicalized(&self) -> &PathBuf {

‎compiler/rustc_span/src/hygiene.rs

Lines changed: 54 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,6 @@ struct SyntaxContextData {
7272
}
7373

7474
impl SyntaxContextData {
75-
fn new(
76-
(parent, outer_expn, outer_transparency): SyntaxContextKey,
77-
opaque: SyntaxContext,
78-
opaque_and_semiopaque: SyntaxContext,
79-
) -> SyntaxContextData {
80-
SyntaxContextData {
81-
outer_expn,
82-
outer_transparency,
83-
parent,
84-
opaque,
85-
opaque_and_semiopaque,
86-
dollar_crate_name: kw::DollarCrate,
87-
}
88-
}
89-
9075
fn root() -> SyntaxContextData {
9176
SyntaxContextData {
9277
outer_expn: ExpnId::root(),
@@ -98,14 +83,6 @@ impl SyntaxContextData {
9883
}
9984
}
10085

101-
fn decode_placeholder() -> SyntaxContextData {
102-
SyntaxContextData { dollar_crate_name: kw::Empty, ..SyntaxContextData::root() }
103-
}
104-
105-
fn is_decode_placeholder(&self) -> bool {
106-
self.dollar_crate_name == kw::Empty
107-
}
108-
10986
fn key(&self) -> SyntaxContextKey {
11087
(self.parent, self.outer_expn, self.outer_transparency)
11188
}
@@ -148,7 +125,7 @@ impl !PartialOrd for LocalExpnId {}
148125
/// with a non-default mode. With this check in place, we can avoid the need
149126
/// to maintain separate versions of `ExpnData` hashes for each permutation
150127
/// of `HashingControls` settings.
151-
fn assert_default_hashing_controls<CTX: HashStableContext>(ctx: &CTX, msg: &str) {
128+
fn assert_default_hashing_controls(ctx: &impl HashStableContext, msg: &str) {
152129
match ctx.hashing_controls() {
153130
// Note that we require that `hash_spans` be set according to the global
154131
// `-Z incremental-ignore-spans` option. Normally, this option is disabled,
@@ -416,7 +393,7 @@ impl HygieneData {
416393
}
417394
}
418395

419-
fn with<T, F: FnOnce(&mut HygieneData) -> T>(f: F) -> T {
396+
fn with<R>(f: impl FnOnce(&mut HygieneData) -> R) -> R {
420397
with_session_globals(|session_globals| f(&mut session_globals.hygiene_data.borrow_mut()))
421398
}
422399

@@ -460,28 +437,23 @@ impl HygieneData {
460437
}
461438

462439
fn normalize_to_macros_2_0(&self, ctxt: SyntaxContext) -> SyntaxContext {
463-
debug_assert!(!self.syntax_context_data[ctxt.0 as usize].is_decode_placeholder());
464440
self.syntax_context_data[ctxt.0 as usize].opaque
465441
}
466442

467443
fn normalize_to_macro_rules(&self, ctxt: SyntaxContext) -> SyntaxContext {
468-
debug_assert!(!self.syntax_context_data[ctxt.0 as usize].is_decode_placeholder());
469444
self.syntax_context_data[ctxt.0 as usize].opaque_and_semiopaque
470445
}
471446

472447
fn outer_expn(&self, ctxt: SyntaxContext) -> ExpnId {
473-
debug_assert!(!self.syntax_context_data[ctxt.0 as usize].is_decode_placeholder());
474448
self.syntax_context_data[ctxt.0 as usize].outer_expn
475449
}
476450

477451
fn outer_mark(&self, ctxt: SyntaxContext) -> (ExpnId, Transparency) {
478-
debug_assert!(!self.syntax_context_data[ctxt.0 as usize].is_decode_placeholder());
479452
let data = &self.syntax_context_data[ctxt.0 as usize];
480453
(data.outer_expn, data.outer_transparency)
481454
}
482455

483456
fn parent_ctxt(&self, ctxt: SyntaxContext) -> SyntaxContext {
484-
debug_assert!(!self.syntax_context_data[ctxt.0 as usize].is_decode_placeholder());
485457
self.syntax_context_data[ctxt.0 as usize].parent
486458
}
487459

@@ -592,25 +564,27 @@ impl HygieneData {
592564
expn_id: ExpnId,
593565
transparency: Transparency,
594566
) -> SyntaxContext {
595-
debug_assert!(!self.syntax_context_data[parent.0 as usize].is_decode_placeholder());
596-
597567
// Look into the cache first.
598568
let key = (parent, expn_id, transparency);
599569
if let Some(ctxt) = self.syntax_context_map.get(&key) {
600570
return *ctxt;
601571
}
602572

603573
// Reserve a new syntax context.
574+
// The inserted dummy data can only be potentially accessed by nested `alloc_ctxt` calls,
575+
// the assert below ensures that it doesn't happen.
604576
let ctxt = SyntaxContext::from_usize(self.syntax_context_data.len());
605-
self.syntax_context_data.push(SyntaxContextData::decode_placeholder());
577+
self.syntax_context_data
578+
.push(SyntaxContextData { dollar_crate_name: sym::dummy, ..SyntaxContextData::root() });
606579
self.syntax_context_map.insert(key, ctxt);
607580

608581
// Opaque and semi-opaque versions of the parent. Note that they may be equal to the
609582
// parent itself. E.g. `parent_opaque` == `parent` if the expn chain contains only opaques,
610583
// and `parent_opaque_and_semiopaque` == `parent` if the expn contains only (semi-)opaques.
611-
let parent_opaque = self.syntax_context_data[parent.0 as usize].opaque;
612-
let parent_opaque_and_semiopaque =
613-
self.syntax_context_data[parent.0 as usize].opaque_and_semiopaque;
584+
let parent_data = &self.syntax_context_data[parent.0 as usize];
585+
assert_ne!(parent_data.dollar_crate_name, sym::dummy);
586+
let parent_opaque = parent_data.opaque;
587+
let parent_opaque_and_semiopaque = parent_data.opaque_and_semiopaque;
614588

615589
// Evaluate opaque and semi-opaque versions of the new syntax context.
616590
let (opaque, opaque_and_semiopaque) = match transparency {
@@ -629,8 +603,14 @@ impl HygieneData {
629603
};
630604

631605
// Fill the full data, now that we have it.
632-
self.syntax_context_data[ctxt.as_u32() as usize] =
633-
SyntaxContextData::new(key, opaque, opaque_and_semiopaque);
606+
self.syntax_context_data[ctxt.as_u32() as usize] = SyntaxContextData {
607+
outer_expn: expn_id,
608+
outer_transparency: transparency,
609+
parent,
610+
opaque,
611+
opaque_and_semiopaque,
612+
dollar_crate_name: kw::DollarCrate,
613+
};
634614
ctxt
635615
}
636616
}
@@ -650,13 +630,12 @@ pub fn walk_chain_collapsed(span: Span, to: Span) -> Span {
650630

651631
pub fn update_dollar_crate_names(mut get_name: impl FnMut(SyntaxContext) -> Symbol) {
652632
// The new contexts that need updating are at the end of the list and have `$crate` as a name.
653-
// Also decoding placeholders can be encountered among both old and new contexts.
654633
let mut to_update = vec![];
655634
HygieneData::with(|data| {
656635
for (idx, scdata) in data.syntax_context_data.iter().enumerate().rev() {
657636
if scdata.dollar_crate_name == kw::DollarCrate {
658637
to_update.push((idx, kw::DollarCrate));
659-
} else if !scdata.is_decode_placeholder() {
638+
} else {
660639
break;
661640
}
662641
}
@@ -922,10 +901,7 @@ impl SyntaxContext {
922901
}
923902

924903
pub(crate) fn dollar_crate_name(self) -> Symbol {
925-
HygieneData::with(|data| {
926-
debug_assert!(!data.syntax_context_data[self.0 as usize].is_decode_placeholder());
927-
data.syntax_context_data[self.0 as usize].dollar_crate_name
928-
})
904+
HygieneData::with(|data| data.syntax_context_data[self.0 as usize].dollar_crate_name)
929905
}
930906

931907
pub fn edition(self) -> Edition {
@@ -1293,49 +1269,47 @@ impl HygieneEncodeContext {
12931269
self.latest_ctxts
12941270
);
12951271

1296-
// Consume the current round of SyntaxContexts.
1297-
// Drop the lock() temporary early
1298-
let latest_ctxts = { mem::take(&mut *self.latest_ctxts.lock()) };
1299-
1300-
// It's fine to iterate over a HashMap, because the serialization
1301-
// of the table that we insert data into doesn't depend on insertion
1302-
// order
1272+
// Consume the current round of syntax contexts.
1273+
// Drop the lock() temporary early.
1274+
// It's fine to iterate over a HashMap, because the serialization of the table
1275+
// that we insert data into doesn't depend on insertion order.
13031276
#[allow(rustc::potential_query_instability)]
1304-
for_all_ctxts_in(latest_ctxts.into_iter(), |index, ctxt, data| {
1277+
let latest_ctxts = { mem::take(&mut *self.latest_ctxts.lock()) }.into_iter();
1278+
let all_ctxt_data: Vec<_> = HygieneData::with(|data| {
1279+
latest_ctxts
1280+
.map(|ctxt| (ctxt, data.syntax_context_data[ctxt.0 as usize].key()))
1281+
.collect()
1282+
});
1283+
for (ctxt, ctxt_key) in all_ctxt_data {
13051284
if self.serialized_ctxts.lock().insert(ctxt) {
1306-
encode_ctxt(encoder, index, data);
1285+
encode_ctxt(encoder, ctxt.0, &ctxt_key);
13071286
}
1308-
});
1309-
1310-
let latest_expns = { mem::take(&mut *self.latest_expns.lock()) };
1287+
}
13111288

1312-
// Same as above, this is fine as we are inserting into a order-independent hashset
1289+
// Same as above, but for expansions instead of syntax contexts.
13131290
#[allow(rustc::potential_query_instability)]
1314-
for_all_expns_in(latest_expns.into_iter(), |expn, data, hash| {
1291+
let latest_expns = { mem::take(&mut *self.latest_expns.lock()) }.into_iter();
1292+
let all_expn_data: Vec<_> = HygieneData::with(|data| {
1293+
latest_expns
1294+
.map(|expn| (expn, data.expn_data(expn).clone(), data.expn_hash(expn)))
1295+
.collect()
1296+
});
1297+
for (expn, expn_data, expn_hash) in all_expn_data {
13151298
if self.serialized_expns.lock().insert(expn) {
1316-
encode_expn(encoder, expn, data, hash);
1299+
encode_expn(encoder, expn, &expn_data, expn_hash);
13171300
}
1318-
});
1301+
}
13191302
}
13201303
debug!("encode_hygiene: Done serializing SyntaxContextData");
13211304
}
13221305
}
13231306

1324-
#[derive(Default)]
13251307
/// Additional information used to assist in decoding hygiene data
1326-
struct HygieneDecodeContextInner {
1327-
// Maps serialized `SyntaxContext` ids to a `SyntaxContext` in the current
1328-
// global `HygieneData`. When we deserialize a `SyntaxContext`, we need to create
1329-
// a new id in the global `HygieneData`. This map tracks the ID we end up picking,
1330-
// so that multiple occurrences of the same serialized id are decoded to the same
1331-
// `SyntaxContext`. This only stores `SyntaxContext`s which are completely decoded.
1332-
remapped_ctxts: Vec<Option<SyntaxContext>>,
1333-
}
1334-
13351308
#[derive(Default)]
1336-
/// Additional information used to assist in decoding hygiene data
13371309
pub struct HygieneDecodeContext {
1338-
inner: Lock<HygieneDecodeContextInner>,
1310+
// A cache mapping raw serialized per-crate syntax context ids to corresponding decoded
1311+
// `SyntaxContext`s in the current global `HygieneData`.
1312+
remapped_ctxts: Lock<IndexVec<u32, Option<SyntaxContext>>>,
13391313
}
13401314

13411315
/// Register an expansion which has been decoded from the on-disk-cache for the local crate.
@@ -1406,10 +1380,10 @@ pub fn decode_expn_id(
14061380
// to track which `SyntaxContext`s we have already decoded.
14071381
// The provided closure will be invoked to deserialize a `SyntaxContextData`
14081382
// if we haven't already seen the id of the `SyntaxContext` we are deserializing.
1409-
pub fn decode_syntax_context<D: Decoder, F: FnOnce(&mut D, u32) -> SyntaxContextKey>(
1383+
pub fn decode_syntax_context<D: Decoder>(
14101384
d: &mut D,
14111385
context: &HygieneDecodeContext,
1412-
decode_data: F,
1386+
decode_data: impl FnOnce(&mut D, u32) -> SyntaxContextKey,
14131387
) -> SyntaxContext {
14141388
let raw_id: u32 = Decodable::decode(d);
14151389
if raw_id == 0 {
@@ -1418,12 +1392,11 @@ pub fn decode_syntax_context<D: Decoder, F: FnOnce(&mut D, u32) -> SyntaxContext
14181392
return SyntaxContext::root();
14191393
}
14201394

1395+
// Look into the cache first.
14211396
// Reminder: `HygieneDecodeContext` is per-crate, so there are no collisions between
14221397
// raw ids from different crate metadatas.
1423-
if let Some(ctxt) = context.inner.lock().remapped_ctxts.get(raw_id as usize).copied().flatten()
1424-
{
1425-
// This has already been decoded.
1426-
return ctxt;
1398+
if let Some(Some(ctxt)) = context.remapped_ctxts.lock().get(raw_id) {
1399+
return *ctxt;
14271400
}
14281401

14291402
// Don't try to decode data while holding the lock, since we need to
@@ -1432,48 +1405,11 @@ pub fn decode_syntax_context<D: Decoder, F: FnOnce(&mut D, u32) -> SyntaxContext
14321405
let ctxt =
14331406
HygieneData::with(|hygiene_data| hygiene_data.alloc_ctxt(parent, expn_id, transparency));
14341407

1435-
let mut inner = context.inner.lock();
1436-
let new_len = raw_id as usize + 1;
1437-
if inner.remapped_ctxts.len() < new_len {
1438-
inner.remapped_ctxts.resize(new_len, None);
1439-
}
1440-
inner.remapped_ctxts[raw_id as usize] = Some(ctxt);
1408+
context.remapped_ctxts.lock().insert(raw_id, ctxt);
14411409

14421410
ctxt
14431411
}
14441412

1445-
fn for_all_ctxts_in<F: FnMut(u32, SyntaxContext, &SyntaxContextKey)>(
1446-
ctxts: impl Iterator<Item = SyntaxContext>,
1447-
mut f: F,
1448-
) {
1449-
let all_data: Vec<_> = HygieneData::with(|data| {
1450-
ctxts
1451-
.map(|ctxt| {
1452-
(ctxt, {
1453-
let item = data.syntax_context_data[ctxt.0 as usize];
1454-
debug_assert!(!item.is_decode_placeholder());
1455-
item.key()
1456-
})
1457-
})
1458-
.collect()
1459-
});
1460-
for (ctxt, data) in all_data.into_iter() {
1461-
f(ctxt.0, ctxt, &data);
1462-
}
1463-
}
1464-
1465-
fn for_all_expns_in(
1466-
expns: impl Iterator<Item = ExpnId>,
1467-
mut f: impl FnMut(ExpnId, &ExpnData, ExpnHash),
1468-
) {
1469-
let all_data: Vec<_> = HygieneData::with(|data| {
1470-
expns.map(|expn| (expn, data.expn_data(expn).clone(), data.expn_hash(expn))).collect()
1471-
});
1472-
for (expn, data, hash) in all_data.into_iter() {
1473-
f(expn, &data, hash);
1474-
}
1475-
}
1476-
14771413
impl<E: SpanEncoder> Encodable<E> for LocalExpnId {
14781414
fn encode(&self, e: &mut E) {
14791415
self.to_expn_id().encode(e);
@@ -1486,10 +1422,10 @@ impl<D: SpanDecoder> Decodable<D> for LocalExpnId {
14861422
}
14871423
}
14881424

1489-
pub fn raw_encode_syntax_context<E: Encoder>(
1425+
pub fn raw_encode_syntax_context(
14901426
ctxt: SyntaxContext,
14911427
context: &HygieneEncodeContext,
1492-
e: &mut E,
1428+
e: &mut impl Encoder,
14931429
) {
14941430
if !context.serialized_ctxts.lock().contains(&ctxt) {
14951431
context.latest_ctxts.lock().insert(ctxt);

‎library/alloc/src/ffi/c_str.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,14 @@ impl CString {
351351
/// # Safety
352352
///
353353
/// This should only ever be called with a pointer that was earlier
354-
/// obtained by calling [`CString::into_raw`]. Other usage (e.g., trying to take
355-
/// ownership of a string that was allocated by foreign code) is likely to lead
356-
/// to undefined behavior or allocator corruption.
354+
/// obtained by calling [`CString::into_raw`], and the memory it points to must not be accessed
355+
/// through any other pointer during the lifetime of reconstructed `CString`.
356+
/// Other usage (e.g., trying to take ownership of a string that was allocated by foreign code)
357+
/// is likely to lead to undefined behavior or allocator corruption.
358+
///
359+
/// This function does not validate ownership of the raw pointer's memory.
360+
/// A double-free may occur if the function is called twice on the same raw pointer.
361+
/// Additionally, the caller must ensure the pointer is not dangling.
357362
///
358363
/// It should be noted that the length isn't just "recomputed," but that
359364
/// the recomputed length must match the original length from the
@@ -818,6 +823,7 @@ impl From<Vec<NonZero<u8>>> for CString {
818823
}
819824
}
820825

826+
#[stable(feature = "c_string_from_str", since = "1.85.0")]
821827
impl FromStr for CString {
822828
type Err = NulError;
823829

@@ -830,6 +836,7 @@ impl FromStr for CString {
830836
}
831837
}
832838

839+
#[stable(feature = "c_string_from_str", since = "1.85.0")]
833840
impl TryFrom<CString> for String {
834841
type Error = IntoStringError;
835842

‎library/alloc/src/ffi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@ pub use self::c_str::CString;
8787
#[stable(feature = "alloc_c_string", since = "1.64.0")]
8888
pub use self::c_str::{FromVecWithNulError, IntoStringError, NulError};
8989

90-
#[unstable(feature = "c_str_module", issue = "112134")]
90+
#[stable(feature = "c_str_module", since = "CURRENT_RUSTC_VERSION")]
9191
pub mod c_str;

‎library/alloc/src/str.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,10 @@ impl str {
603603
/// Converts a boxed slice of bytes to a boxed string slice without checking
604604
/// that the string contains valid UTF-8.
605605
///
606+
/// # Safety
607+
///
608+
/// * The provided bytes must contain a valid UTF-8 sequence.
609+
///
606610
/// # Examples
607611
///
608612
/// ```

‎library/core/src/ffi/c_str.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ use crate::{fmt, ops, slice, str};
7979
///
8080
/// fn my_string_safe() -> String {
8181
/// let cstr = unsafe { CStr::from_ptr(my_string()) };
82-
/// // Get copy-on-write Cow<'_, str>, then guarantee a freshly-owned String allocation
83-
/// String::from_utf8_lossy(cstr.to_bytes()).to_string()
82+
/// // Get a copy-on-write Cow<'_, str>, then extract the
83+
/// // allocated String (or allocate a fresh one if needed).
84+
/// cstr.to_string_lossy().into_owned()
8485
/// }
8586
///
8687
/// println!("string: {}", my_string_safe());

‎library/core/src/ffi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub use self::c_str::FromBytesUntilNulError;
2020
pub use self::c_str::FromBytesWithNulError;
2121
use crate::fmt;
2222

23-
#[unstable(feature = "c_str_module", issue = "112134")]
23+
#[stable(feature = "c_str_module", since = "CURRENT_RUSTC_VERSION")]
2424
pub mod c_str;
2525

2626
#[unstable(

‎library/core/src/iter/adapters/peekable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl<I: Iterator> Peekable<I> {
271271
/// assert_eq!(iter.next_if(|&x| x == 0), Some(0));
272272
/// // The next item returned is now 1, so `next_if` will return `None`.
273273
/// assert_eq!(iter.next_if(|&x| x == 0), None);
274-
/// // `next_if` saves the value of the next item if it was not equal to `expected`.
274+
/// // `next_if` retains the next item if the predicate evaluates to `false` for it.
275275
/// assert_eq!(iter.next(), Some(1));
276276
/// ```
277277
///
@@ -304,9 +304,9 @@ impl<I: Iterator> Peekable<I> {
304304
/// let mut iter = (0..5).peekable();
305305
/// // The first item of the iterator is 0; consume it.
306306
/// assert_eq!(iter.next_if_eq(&0), Some(0));
307-
/// // The next item returned is now 1, so `next_if` will return `None`.
307+
/// // The next item returned is now 1, so `next_if_eq` will return `None`.
308308
/// assert_eq!(iter.next_if_eq(&0), None);
309-
/// // `next_if_eq` saves the value of the next item if it was not equal to `expected`.
309+
/// // `next_if_eq` retains the next item if it was not equal to `expected`.
310310
/// assert_eq!(iter.next(), Some(1));
311311
/// ```
312312
#[stable(feature = "peekable_next_if", since = "1.51.0")]

‎library/core/src/str/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,7 @@ impl str {
21152115
#[stable(feature = "rust1", since = "1.0.0")]
21162116
#[rustc_diagnostic_item = "str_trim"]
21172117
pub fn trim(&self) -> &str {
2118-
self.trim_matches(|c: char| c.is_whitespace())
2118+
self.trim_matches(char::is_whitespace)
21192119
}
21202120

21212121
/// Returns a string slice with leading whitespace removed.
@@ -2154,7 +2154,7 @@ impl str {
21542154
#[stable(feature = "trim_direction", since = "1.30.0")]
21552155
#[rustc_diagnostic_item = "str_trim_start"]
21562156
pub fn trim_start(&self) -> &str {
2157-
self.trim_start_matches(|c: char| c.is_whitespace())
2157+
self.trim_start_matches(char::is_whitespace)
21582158
}
21592159

21602160
/// Returns a string slice with trailing whitespace removed.
@@ -2193,7 +2193,7 @@ impl str {
21932193
#[stable(feature = "trim_direction", since = "1.30.0")]
21942194
#[rustc_diagnostic_item = "str_trim_end"]
21952195
pub fn trim_end(&self) -> &str {
2196-
self.trim_end_matches(|c: char| c.is_whitespace())
2196+
self.trim_end_matches(char::is_whitespace)
21972197
}
21982198

21992199
/// Returns a string slice with leading whitespace removed.

‎library/std/src/ffi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
162162
#![stable(feature = "rust1", since = "1.0.0")]
163163

164-
#[unstable(feature = "c_str_module", issue = "112134")]
164+
#[stable(feature = "c_str_module", since = "CURRENT_RUSTC_VERSION")]
165165
pub mod c_str;
166166

167167
#[stable(feature = "core_c_void", since = "1.30.0")]

‎library/std/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@
329329
#![feature(array_chunks)]
330330
#![feature(bstr)]
331331
#![feature(bstr_internals)]
332-
#![feature(c_str_module)]
333332
#![feature(char_internals)]
334333
#![feature(clone_to_uninit)]
335334
#![feature(core_intrinsics)]

0 commit comments

Comments
 (0)
Please sign in to comment.