1
Fork 0

update uses of extract_if in the compiler

This commit is contained in:
The 8472 2024-11-20 23:45:53 +01:00
parent 03f1b73339
commit fe521506a6
7 changed files with 13 additions and 13 deletions

View file

@ -1569,18 +1569,18 @@ impl DiagCtxtInner {
debug!(?diagnostic); debug!(?diagnostic);
debug!(?self.emitted_diagnostics); debug!(?self.emitted_diagnostics);
let already_emitted_sub = |sub: &mut Subdiag| { let not_yet_emitted = |sub: &mut Subdiag| {
debug!(?sub); debug!(?sub);
if sub.level != OnceNote && sub.level != OnceHelp { if sub.level != OnceNote && sub.level != OnceHelp {
return false; return true;
} }
let mut hasher = StableHasher::new(); let mut hasher = StableHasher::new();
sub.hash(&mut hasher); sub.hash(&mut hasher);
let diagnostic_hash = hasher.finish(); let diagnostic_hash = hasher.finish();
debug!(?diagnostic_hash); debug!(?diagnostic_hash);
!self.emitted_diagnostics.insert(diagnostic_hash) self.emitted_diagnostics.insert(diagnostic_hash)
}; };
diagnostic.children.extract_if(already_emitted_sub).for_each(|_| {}); diagnostic.children.retain_mut(not_yet_emitted);
if already_emitted { if already_emitted {
let msg = "duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`"; let msg = "duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`";
diagnostic.sub(Note, msg, MultiSpan::new()); diagnostic.sub(Note, msg, MultiSpan::new());

View file

@ -205,7 +205,7 @@ impl EarlyLintPass for NonAsciiIdents {
(IdentifierType::Not_NFKC, "Not_NFKC"), (IdentifierType::Not_NFKC, "Not_NFKC"),
] { ] {
let codepoints: Vec<_> = let codepoints: Vec<_> =
chars.extract_if(|(_, ty)| *ty == Some(id_ty)).collect(); chars.extract_if(.., |(_, ty)| *ty == Some(id_ty)).collect();
if codepoints.is_empty() { if codepoints.is_empty() {
continue; continue;
} }
@ -217,7 +217,7 @@ impl EarlyLintPass for NonAsciiIdents {
} }
let remaining = chars let remaining = chars
.extract_if(|(c, _)| !GeneralSecurityProfile::identifier_allowed(*c)) .extract_if(.., |(c, _)| !GeneralSecurityProfile::identifier_allowed(*c))
.collect::<Vec<_>>(); .collect::<Vec<_>>();
if !remaining.is_empty() { if !remaining.is_empty() {
cx.emit_span_lint(UNCOMMON_CODEPOINTS, sp, IdentifierUncommonCodepoints { cx.emit_span_lint(UNCOMMON_CODEPOINTS, sp, IdentifierUncommonCodepoints {

View file

@ -544,7 +544,7 @@ impl<'tcx> Collector<'tcx> {
// can move them to the end of the list below. // can move them to the end of the list below.
let mut existing = self let mut existing = self
.libs .libs
.extract_if(|lib| { .extract_if(.., |lib| {
if lib.name.as_str() == passed_lib.name { if lib.name.as_str() == passed_lib.name {
// FIXME: This whole logic is questionable, whether modifiers are // FIXME: This whole logic is questionable, whether modifiers are
// involved or not, library reordering and kind overriding without // involved or not, library reordering and kind overriding without

View file

@ -309,7 +309,7 @@ pub fn suggest_constraining_type_params<'a>(
let Some(param) = param else { return false }; let Some(param) = param else { return false };
{ {
let mut sized_constraints = constraints.extract_if(|(_, def_id, _)| { let mut sized_constraints = constraints.extract_if(.., |(_, def_id, _)| {
def_id.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Sized)) def_id.is_some_and(|def_id| tcx.is_lang_item(def_id, LangItem::Sized))
}); });
if let Some((_, def_id, _)) = sized_constraints.next() { if let Some((_, def_id, _)) = sized_constraints.next() {

View file

@ -2817,11 +2817,11 @@ fn show_candidates(
path_strings.sort_by(|a, b| a.0.cmp(&b.0)); path_strings.sort_by(|a, b| a.0.cmp(&b.0));
path_strings.dedup_by(|a, b| a.0 == b.0); path_strings.dedup_by(|a, b| a.0 == b.0);
let core_path_strings = let core_path_strings =
path_strings.extract_if(|p| p.0.starts_with("core::")).collect::<Vec<_>>(); path_strings.extract_if(.., |p| p.0.starts_with("core::")).collect::<Vec<_>>();
let std_path_strings = let std_path_strings =
path_strings.extract_if(|p| p.0.starts_with("std::")).collect::<Vec<_>>(); path_strings.extract_if(.., |p| p.0.starts_with("std::")).collect::<Vec<_>>();
let foreign_crate_path_strings = let foreign_crate_path_strings =
path_strings.extract_if(|p| !p.0.starts_with("crate::")).collect::<Vec<_>>(); path_strings.extract_if(.., |p| !p.0.starts_with("crate::")).collect::<Vec<_>>();
// We list the `crate` local paths first. // We list the `crate` local paths first.
// Then we list the `std`/`core` paths. // Then we list the `std`/`core` paths.

View file

@ -628,7 +628,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
// Try to filter out intrinsics candidates, as long as we have // Try to filter out intrinsics candidates, as long as we have
// some other candidates to suggest. // some other candidates to suggest.
let intrinsic_candidates: Vec<_> = candidates let intrinsic_candidates: Vec<_> = candidates
.extract_if(|sugg| { .extract_if(.., |sugg| {
let path = path_names_to_string(&sugg.path); let path = path_names_to_string(&sugg.path);
path.starts_with("core::intrinsics::") || path.starts_with("std::intrinsics::") path.starts_with("core::intrinsics::") || path.starts_with("std::intrinsics::")
}) })

View file

@ -447,7 +447,7 @@ pub fn normalize_param_env_or_error<'tcx>(
// This works fairly well because trait matching does not actually care about param-env // This works fairly well because trait matching does not actually care about param-env
// TypeOutlives predicates - these are normally used by regionck. // TypeOutlives predicates - these are normally used by regionck.
let outlives_predicates: Vec<_> = predicates let outlives_predicates: Vec<_> = predicates
.extract_if(|predicate| { .extract_if(.., |predicate| {
matches!(predicate.kind().skip_binder(), ty::ClauseKind::TypeOutlives(..)) matches!(predicate.kind().skip_binder(), ty::ClauseKind::TypeOutlives(..))
}) })
.collect(); .collect();