Skip to content

Commit a4cfac7

Browse files
committed
Auto merge of #149560 - matthiaskrgr:rollup-lce3baq, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - #146436 (Slice iter cleanup) - #148250 (array_chunks: slightly improve docs) - #148678 (Merge E0412 into E0425) - #149520 (also introduce Peekable::next_if_map_mut next to next_if_map) - #149538 (std: sys: fs: uefi: Make time in FileAttr optional) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 646a3f8 + 3b99d6b commit a4cfac7

File tree

209 files changed

+788
-783
lines changed

Some content is hidden

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

209 files changed

+788
-783
lines changed

compiler/rustc_error_codes/src/error_codes/E0412.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
A used type name is not in scope.
1+
#### Note: this error code is no longer emitted by the compiler.
22

33
Erroneous code examples:
44

5-
```compile_fail,E0412
5+
```compile_fail,E0425
66
impl Something {} // error: type name `Something` is not in scope
77
88
// or:
@@ -42,7 +42,7 @@ module. To fix this, you can follow the suggestion and use File directly or
4242
`use super::File;` which will import the types from the parent namespace. An
4343
example that causes this error is below:
4444

45-
```compile_fail,E0412
45+
```compile_fail,E0425
4646
use std::fs::File;
4747
4848
mod foo {

compiler/rustc_resolve/src/late.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ impl PathSource<'_, '_, '_> {
622622
(PathSource::Trait(_), true) => E0404,
623623
(PathSource::Trait(_), false) => E0405,
624624
(PathSource::Type | PathSource::DefineOpaques, true) => E0573,
625-
(PathSource::Type | PathSource::DefineOpaques, false) => E0412,
625+
(PathSource::Type | PathSource::DefineOpaques, false) => E0425,
626626
(PathSource::Struct(_), true) => E0574,
627627
(PathSource::Struct(_), false) => E0422,
628628
(PathSource::Expr(..), true) | (PathSource::Delegation, true) => E0423,
@@ -3158,7 +3158,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
31583158
result
31593159
}
31603160

3161-
/// When evaluating a `trait` use its associated types' idents for suggestions in E0412.
3161+
/// When evaluating a `trait` use its associated types' idents for suggestions in E0425.
31623162
fn resolve_trait_items(&mut self, trait_items: &'ast [Box<AssocItem>]) {
31633163
let trait_assoc_items =
31643164
replace(&mut self.diag_metadata.current_trait_assoc_items, Some(trait_items));
@@ -4363,15 +4363,15 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
43634363

43644364
// There are two different error messages user might receive at
43654365
// this point:
4366-
// - E0412 cannot find type `{}` in this scope
4366+
// - E0425 cannot find type `{}` in this scope
43674367
// - E0433 failed to resolve: use of undeclared type or module `{}`
43684368
//
43694369
// The first one is emitted for paths in type-position, and the
43704370
// latter one - for paths in expression-position.
43714371
//
43724372
// Thus (since we're in expression-position at this point), not to
43734373
// confuse the user, we want to keep the *message* from E0433 (so
4374-
// `parent_err`), but we want *hints* from E0412 (so `err`).
4374+
// `parent_err`), but we want *hints* from E0425 (so `err`).
43754375
//
43764376
// And that's what happens below - we're just mixing both messages
43774377
// into a single one.

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
705705
if !enum_candidates.is_empty() {
706706
enum_candidates.sort();
707707

708-
// Contextualize for E0412 "cannot find type", but don't belabor the point
708+
// Contextualize for E0425 "cannot find type", but don't belabor the point
709709
// (that it's a variant) for E0573 "expected type, found variant".
710710
let preamble = if res.is_none() {
711711
let others = match enum_candidates.len() {
@@ -1135,7 +1135,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
11351135
}
11361136

11371137
self.suggest_ident_hidden_by_hygiene(err, path, span);
1138-
} else if err_code == E0412 {
1138+
// cannot find type in this scope
11391139
if let Some(correct) = Self::likely_rust_type(path) {
11401140
err.span_suggestion(
11411141
span,

library/core/src/array/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ const fn try_from_fn_erased<R: [const] Try<Output: [const] Destruct>>(
924924
/// All write accesses to this structure are unsafe and must maintain a correct
925925
/// count of `initialized` elements.
926926
///
927-
/// To minimize indirection fields are still pub but callers should at least use
927+
/// To minimize indirection, fields are still pub but callers should at least use
928928
/// `push_unchecked` to signal that something unsafe is going on.
929929
struct Guard<'a, T> {
930930
/// The array to be initialized.
@@ -943,7 +943,7 @@ impl<T> Guard<'_, T> {
943943
#[rustc_const_unstable(feature = "array_try_from_fn", issue = "89379")]
944944
pub(crate) const unsafe fn push_unchecked(&mut self, item: T) {
945945
// SAFETY: If `initialized` was correct before and the caller does not
946-
// invoke this method more than N times then writes will be in-bounds
946+
// invoke this method more than N times, then writes will be in-bounds
947947
// and slots will not be initialized more than once.
948948
unsafe {
949949
self.array_mut.get_unchecked_mut(self.initialized).write(item);
@@ -972,7 +972,7 @@ impl<T: [const] Destruct> const Drop for Guard<'_, T> {
972972
/// `next` at most `N` times, the iterator can still be used afterwards to
973973
/// retrieve the remaining items.
974974
///
975-
/// If `iter.next()` panicks, all items already yielded by the iterator are
975+
/// If `iter.next()` panics, all items already yielded by the iterator are
976976
/// dropped.
977977
///
978978
/// Used for [`Iterator::next_chunk`].
@@ -1004,6 +1004,7 @@ fn iter_next_chunk_erased<T>(
10041004
buffer: &mut [MaybeUninit<T>],
10051005
iter: &mut impl Iterator<Item = T>,
10061006
) -> Result<(), usize> {
1007+
// if `Iterator::next` panics, this guard will drop already initialized items
10071008
let mut guard = Guard { array_mut: buffer, initialized: 0 };
10081009
while guard.initialized < guard.array_mut.len() {
10091010
let Some(item) = iter.next() else {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ where
8989
match self.iter.next_chunk() {
9090
Ok(chunk) => acc = f(acc, chunk)?,
9191
Err(remainder) => {
92-
// Make sure to not override `self.remainder` with an empty array
92+
// Make sure to not overwrite `self.remainder` with an empty array
9393
// when `next` is called after `ArrayChunks` exhaustion.
9494
self.remainder.get_or_insert(remainder);
9595

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,8 @@ impl<I: Iterator> Peekable<I> {
331331
/// If the closure panics, the next value will always be consumed and dropped
332332
/// even if the panic is caught, because the closure never returned an `Err` value to put back.
333333
///
334+
/// See also: [`next_if_map_mut`](Self::next_if_map_mut).
335+
///
334336
/// # Examples
335337
///
336338
/// Parse the leading decimal number from an iterator of characters.
@@ -419,6 +421,44 @@ impl<I: Iterator> Peekable<I> {
419421
self.peeked = Some(unpeek);
420422
None
421423
}
424+
425+
/// Gives a mutable reference to the next value of the iterator and applies a function `f` to it,
426+
/// returning the result and advancing the iterator if `f` returns `Some`.
427+
///
428+
/// Otherwise, if `f` returns `None`, the next value is kept for the next iteration.
429+
///
430+
/// If `f` panics, the item that is consumed from the iterator as if `Some` was returned from `f`.
431+
/// The value will be dropped.
432+
///
433+
/// This is similar to [`next_if_map`](Self::next_if_map), except ownership of the item is not given to `f`.
434+
/// This can be preferable if `f` would copy the item anyway.
435+
///
436+
/// # Examples
437+
///
438+
/// Parse the leading decimal number from an iterator of characters.
439+
/// ```
440+
/// #![feature(peekable_next_if_map)]
441+
/// let mut iter = "125 GOTO 10".chars().peekable();
442+
/// let mut line_num = 0_u32;
443+
/// while let Some(digit) = iter.next_if_map_mut(|c| c.to_digit(10)) {
444+
/// line_num = line_num * 10 + digit;
445+
/// }
446+
/// assert_eq!(line_num, 125);
447+
/// assert_eq!(iter.collect::<String>(), " GOTO 10");
448+
/// ```
449+
#[unstable(feature = "peekable_next_if_map", issue = "143702")]
450+
pub fn next_if_map_mut<R>(&mut self, f: impl FnOnce(&mut I::Item) -> Option<R>) -> Option<R> {
451+
let unpeek = if let Some(mut item) = self.next() {
452+
match f(&mut item) {
453+
Some(result) => return Some(result),
454+
None => Some(item),
455+
}
456+
} else {
457+
None
458+
};
459+
self.peeked = Some(unpeek);
460+
None
461+
}
422462
}
423463

424464
#[unstable(feature = "trusted_len", issue = "37572")]

0 commit comments

Comments
 (0)