Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions compiler/rustc_error_codes/src/error_codes/E0412.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
A used type name is not in scope.
#### Note: this error code is no longer emitted by the compiler.

Erroneous code examples:

```compile_fail,E0412
```compile_fail,E0425
impl Something {} // error: type name `Something` is not in scope

// or:
Expand Down Expand Up @@ -42,7 +42,7 @@ module. To fix this, you can follow the suggestion and use File directly or
`use super::File;` which will import the types from the parent namespace. An
example that causes this error is below:

```compile_fail,E0412
```compile_fail,E0425
use std::fs::File;

mod foo {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ impl PathSource<'_, '_, '_> {
(PathSource::Trait(_), true) => E0404,
(PathSource::Trait(_), false) => E0405,
(PathSource::Type | PathSource::DefineOpaques, true) => E0573,
(PathSource::Type | PathSource::DefineOpaques, false) => E0412,
(PathSource::Type | PathSource::DefineOpaques, false) => E0425,
(PathSource::Struct(_), true) => E0574,
(PathSource::Struct(_), false) => E0422,
(PathSource::Expr(..), true) | (PathSource::Delegation, true) => E0423,
Expand Down Expand Up @@ -3158,7 +3158,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
result
}

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

// There are two different error messages user might receive at
// this point:
// - E0412 cannot find type `{}` in this scope
// - E0425 cannot find type `{}` in this scope
// - E0433 failed to resolve: use of undeclared type or module `{}`
//
// The first one is emitted for paths in type-position, and the
// latter one - for paths in expression-position.
//
// Thus (since we're in expression-position at this point), not to
// confuse the user, we want to keep the *message* from E0433 (so
// `parent_err`), but we want *hints* from E0412 (so `err`).
// `parent_err`), but we want *hints* from E0425 (so `err`).
//
// And that's what happens below - we're just mixing both messages
// into a single one.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
if !enum_candidates.is_empty() {
enum_candidates.sort();

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

self.suggest_ident_hidden_by_hygiene(err, path, span);
} else if err_code == E0412 {
// cannot find type in this scope
if let Some(correct) = Self::likely_rust_type(path) {
err.span_suggestion(
span,
Expand Down
7 changes: 4 additions & 3 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ const fn try_from_fn_erased<R: [const] Try<Output: [const] Destruct>>(
/// All write accesses to this structure are unsafe and must maintain a correct
/// count of `initialized` elements.
///
/// To minimize indirection fields are still pub but callers should at least use
/// To minimize indirection, fields are still pub but callers should at least use
/// `push_unchecked` to signal that something unsafe is going on.
struct Guard<'a, T> {
/// The array to be initialized.
Expand All @@ -943,7 +943,7 @@ impl<T> Guard<'_, T> {
#[rustc_const_unstable(feature = "array_try_from_fn", issue = "89379")]
pub(crate) const unsafe fn push_unchecked(&mut self, item: T) {
// SAFETY: If `initialized` was correct before and the caller does not
// invoke this method more than N times then writes will be in-bounds
// invoke this method more than N times, then writes will be in-bounds
// and slots will not be initialized more than once.
unsafe {
self.array_mut.get_unchecked_mut(self.initialized).write(item);
Expand Down Expand Up @@ -972,7 +972,7 @@ impl<T: [const] Destruct> const Drop for Guard<'_, T> {
/// `next` at most `N` times, the iterator can still be used afterwards to
/// retrieve the remaining items.
///
/// If `iter.next()` panicks, all items already yielded by the iterator are
/// If `iter.next()` panics, all items already yielded by the iterator are
/// dropped.
///
/// Used for [`Iterator::next_chunk`].
Expand Down Expand Up @@ -1004,6 +1004,7 @@ fn iter_next_chunk_erased<T>(
buffer: &mut [MaybeUninit<T>],
iter: &mut impl Iterator<Item = T>,
) -> Result<(), usize> {
// if `Iterator::next` panics, this guard will drop already initialized items
let mut guard = Guard { array_mut: buffer, initialized: 0 };
while guard.initialized < guard.array_mut.len() {
let Some(item) = iter.next() else {
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/iter/adapters/array_chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ where
match self.iter.next_chunk() {
Ok(chunk) => acc = f(acc, chunk)?,
Err(remainder) => {
// Make sure to not override `self.remainder` with an empty array
// Make sure to not overwrite `self.remainder` with an empty array
// when `next` is called after `ArrayChunks` exhaustion.
self.remainder.get_or_insert(remainder);

Expand Down
40 changes: 40 additions & 0 deletions library/core/src/iter/adapters/peekable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,8 @@ impl<I: Iterator> Peekable<I> {
/// If the closure panics, the next value will always be consumed and dropped
/// even if the panic is caught, because the closure never returned an `Err` value to put back.
///
/// See also: [`next_if_map_mut`](Self::next_if_map_mut).
///
/// # Examples
///
/// Parse the leading decimal number from an iterator of characters.
Expand Down Expand Up @@ -419,6 +421,44 @@ impl<I: Iterator> Peekable<I> {
self.peeked = Some(unpeek);
None
}

/// Gives a mutable reference to the next value of the iterator and applies a function `f` to it,
/// returning the result and advancing the iterator if `f` returns `Some`.
///
/// Otherwise, if `f` returns `None`, the next value is kept for the next iteration.
///
/// If `f` panics, the item that is consumed from the iterator as if `Some` was returned from `f`.
/// The value will be dropped.
///
/// This is similar to [`next_if_map`](Self::next_if_map), except ownership of the item is not given to `f`.
/// This can be preferable if `f` would copy the item anyway.
///
/// # Examples
///
/// Parse the leading decimal number from an iterator of characters.
/// ```
/// #![feature(peekable_next_if_map)]
/// let mut iter = "125 GOTO 10".chars().peekable();
/// let mut line_num = 0_u32;
/// while let Some(digit) = iter.next_if_map_mut(|c| c.to_digit(10)) {
/// line_num = line_num * 10 + digit;
/// }
/// assert_eq!(line_num, 125);
/// assert_eq!(iter.collect::<String>(), " GOTO 10");
/// ```
#[unstable(feature = "peekable_next_if_map", issue = "143702")]
pub fn next_if_map_mut<R>(&mut self, f: impl FnOnce(&mut I::Item) -> Option<R>) -> Option<R> {
let unpeek = if let Some(mut item) = self.next() {
match f(&mut item) {
Some(result) => return Some(result),
None => Some(item),
}
} else {
None
};
self.peeked = Some(unpeek);
None
}
}

#[unstable(feature = "trusted_len", issue = "37572")]
Expand Down
Loading
Loading