Skip to content

Use (😏) precise capture instead of Captures trait hack #135416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 2 additions & 3 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

use rustc_ast::node_id::NodeMap;
use rustc_ast::{self as ast, *};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::sorted_map::SortedMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
Expand Down Expand Up @@ -1803,7 +1802,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&'s mut self,
params: &'s [GenericParam],
source: hir::GenericParamSource,
) -> impl Iterator<Item = hir::GenericParam<'hir>> + Captures<'a> + Captures<'s> {
) -> impl Iterator<Item = hir::GenericParam<'hir>> + use<'a, 'hir, 's> {
params.iter().map(move |param| self.lower_generic_param(param, source))
}

Expand Down Expand Up @@ -1968,7 +1967,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
&'s mut self,
bounds: &'s [GenericBound],
itctx: ImplTraitContext,
) -> impl Iterator<Item = hir::GenericBound<'hir>> + Captures<'s> + Captures<'a> {
) -> impl Iterator<Item = hir::GenericBound<'hir>> + use<'a, 'hir, 's> {
bounds.iter().map(move |bound| self.lower_param_bound(bound, itctx))
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::ops::ControlFlow;

use either::Either;
use hir::{ClosureKind, Path};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::codes::*;
use rustc_errors::{Applicability, Diag, MultiSpan, struct_span_code_err};
Expand Down Expand Up @@ -3524,7 +3523,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
fn predecessor_locations<'a, 'tcx>(
body: &'a mir::Body<'tcx>,
location: Location,
) -> impl Iterator<Item = Location> + Captures<'tcx> + 'a {
) -> impl Iterator<Item = Location> + use<'a, 'tcx> {
if location.statement_index == 0 {
let predecessors = body.basic_blocks.predecessors()[location.block].to_vec();
Either::Left(predecessors.into_iter().map(move |bb| body.terminator_loc(bb)))
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_borrowck/src/member_constraints.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::hash::Hash;
use std::ops::Index;

use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxIndexMap;
use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::ty::{self, Ty};
Expand Down Expand Up @@ -149,7 +148,7 @@ where
{
pub(crate) fn all_indices(
&self,
) -> impl Iterator<Item = NllMemberConstraintIndex> + Captures<'tcx> + '_ {
) -> impl Iterator<Item = NllMemberConstraintIndex> + use<'tcx, '_, R> {
self.constraints.indices()
}

Expand All @@ -159,7 +158,7 @@ where
pub(crate) fn indices(
&self,
member_region_vid: R,
) -> impl Iterator<Item = NllMemberConstraintIndex> + Captures<'tcx> + '_ {
) -> impl Iterator<Item = NllMemberConstraintIndex> + use<'tcx, '_, R> {
let mut next = self.first_constraints.get(&member_region_vid).cloned();
std::iter::from_fn(move || -> Option<NllMemberConstraintIndex> {
if let Some(current) = next {
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_data_structures/src/captures.rs

This file was deleted.

1 change: 0 additions & 1 deletion compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ pub use rustc_index::static_assert_size;
pub mod aligned;
pub mod base_n;
pub mod binary_search_util;
pub mod captures;
pub mod fingerprint;
pub mod flat_map_in_place;
pub mod flock;
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use std::ops::Bound;

use rustc_abi::ExternAbi;
use rustc_ast::Recovered;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::unord::UnordMap;
use rustc_errors::{
Expand Down Expand Up @@ -1705,7 +1704,7 @@ fn polarity_of_impl(
fn early_bound_lifetimes_from_generics<'a, 'tcx: 'a>(
tcx: TyCtxt<'tcx>,
generics: &'a hir::Generics<'a>,
) -> impl Iterator<Item = &'a hir::GenericParam<'a>> + Captures<'tcx> {
) -> impl Iterator<Item = &'a hir::GenericParam<'a>> + use<'a, 'tcx> {
generics.params.iter().filter(move |param| match param.kind {
GenericParamKind::Lifetime { .. } => !tcx.is_late_bound(param.hir_id),
_ => false,
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_infer/src/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use std::fmt::Debug;
use std::iter;

use rustc_data_structures::captures::Captures;
use rustc_index::{Idx, IndexVec};
use rustc_middle::arena::ArenaAllocatable;
use rustc_middle::mir::ConstraintCategory;
Expand Down Expand Up @@ -547,7 +546,7 @@ impl<'tcx> InferCtxt<'tcx> {
param_env: ty::ParamEnv<'tcx>,
uninstantiated_region_constraints: &'a [QueryOutlivesConstraint<'tcx>],
result_args: &'a CanonicalVarValues<'tcx>,
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a + Captures<'tcx> {
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a {
uninstantiated_region_constraints.iter().map(move |&constraint| {
let predicate = instantiate_value(self.tcx, result_args, constraint);
self.query_outlives_constraint_to_obligation(predicate, cause.clone(), param_env)
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use region_constraints::{
};
pub use relate::StructurallyRelateAliases;
pub use relate::combine::PredicateEmittingRelation;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::undo_log::{Rollback, UndoLogs};
use rustc_data_structures::unify as ut;
Expand Down Expand Up @@ -1297,7 +1296,7 @@ impl<'tcx> InferCtxt<'tcx> {
#[inline]
pub fn is_ty_infer_var_definitely_unchanged<'a>(
&'a self,
) -> (impl Fn(TyOrConstInferVar) -> bool + Captures<'tcx> + 'a) {
) -> (impl Fn(TyOrConstInferVar) -> bool + use<'tcx, 'a>) {
// This hoists the borrow/release out of the loop body.
let inner = self.inner.try_borrow();

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::{io, iter, mem};
pub(super) use cstore_impl::provide;
use proc_macro::bridge::client::ProcMacro;
use rustc_ast as ast;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::owned_slice::OwnedSlice;
Expand Down Expand Up @@ -958,7 +957,7 @@ impl CrateRoot {
pub(crate) fn decode_crate_deps<'a>(
&self,
metadata: &'a MetadataBlob,
) -> impl ExactSizeIterator<Item = CrateDep> + Captures<'a> {
) -> impl ExactSizeIterator<Item = CrateDep> + 'a {
self.crate_deps.decode(metadata)
}
}
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use either::Either;
use polonius_engine::Atom;
use rustc_abi::{FieldIdx, VariantIdx};
pub use rustc_ast::Mutability;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::graph::dominators::Dominators;
use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, ErrorGuaranteed, IntoDiagArg};
Expand Down Expand Up @@ -481,7 +480,7 @@ impl<'tcx> Body<'tcx> {

/// Returns an iterator over all user-declared mutable locals.
#[inline]
pub fn mut_vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + Captures<'tcx> + 'a {
pub fn mut_vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + use<'tcx, 'a> {
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
let local = Local::new(index);
let decl = &self.local_decls[local];
Expand All @@ -491,9 +490,7 @@ impl<'tcx> Body<'tcx> {

/// Returns an iterator over all user-declared mutable arguments and locals.
#[inline]
pub fn mut_vars_and_args_iter<'a>(
&'a self,
) -> impl Iterator<Item = Local> + Captures<'tcx> + 'a {
pub fn mut_vars_and_args_iter<'a>(&'a self) -> impl Iterator<Item = Local> + use<'tcx, 'a> {
(1..self.local_decls.len()).filter_map(move |index| {
let local = Local::new(index);
let decl = &self.local_decls[local];
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/ty/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::ops::Range;
use std::str;

use rustc_abi::{FIRST_VARIANT, ReprOptions, VariantIdx};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::intern::Interned;
Expand Down Expand Up @@ -536,7 +535,7 @@ impl<'tcx> AdtDef<'tcx> {
pub fn discriminants(
self,
tcx: TyCtxt<'tcx>,
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx> {
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + 'tcx {
assert!(self.is_enum());
let repr_type = self.repr().discr_type();
let initial = repr_type.initial_discriminant(tcx);
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/ty/closure.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::fmt::Write;

use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxIndexMap;
use rustc_hir as hir;
use rustc_hir::HirId;
Expand Down Expand Up @@ -415,7 +414,7 @@ pub fn analyze_coroutine_closure_captures<'a, 'tcx: 'a, T>(
parent_captures: impl IntoIterator<Item = &'a CapturedPlace<'tcx>>,
child_captures: impl IntoIterator<Item = &'a CapturedPlace<'tcx>>,
mut for_each: impl FnMut((usize, &'a CapturedPlace<'tcx>), (usize, &'a CapturedPlace<'tcx>)) -> T,
) -> impl Iterator<Item = T> + Captures<'a> + Captures<'tcx> {
) -> impl Iterator<Item = T> {
std::iter::from_coroutine(
#[coroutine]
move || {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/ty/predicate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::cmp::Ordering;

use rustc_data_structures::captures::Captures;
use rustc_data_structures::intern::Interned;
use rustc_hir::def_id::DefId;
use rustc_macros::{HashStable, extension};
Expand Down Expand Up @@ -350,7 +349,7 @@ impl<'tcx> ty::List<ty::PolyExistentialPredicate<'tcx>> {
}

#[inline]
pub fn auto_traits<'a>(&'a self) -> impl Iterator<Item = DefId> + Captures<'tcx> + 'a {
pub fn auto_traits<'a>(&'a self) -> impl Iterator<Item = DefId> + use<'tcx, 'a> {
self.iter().filter_map(|predicate| match predicate.skip_binder() {
ExistentialPredicate::AutoTrait(did) => Some(did),
_ => None,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::ops::{ControlFlow, Range};

use hir::def::{CtorKind, DefKind};
use rustc_abi::{ExternAbi, FIRST_VARIANT, FieldIdx, VariantIdx};
use rustc_data_structures::captures::Captures;
use rustc_errors::{ErrorGuaranteed, MultiSpan};
use rustc_hir as hir;
use rustc_hir::LangItem;
Expand Down Expand Up @@ -105,7 +104,7 @@ impl<'tcx> ty::CoroutineArgs<TyCtxt<'tcx>> {
self,
def_id: DefId,
tcx: TyCtxt<'tcx>,
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx> {
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> {
self.variant_range(def_id, tcx).map(move |index| {
(index, Discr { val: index.as_usize() as u128, ty: self.discr_ty(tcx) })
})
Expand Down Expand Up @@ -139,7 +138,7 @@ impl<'tcx> ty::CoroutineArgs<TyCtxt<'tcx>> {
self,
def_id: DefId,
tcx: TyCtxt<'tcx>,
) -> impl Iterator<Item: Iterator<Item = Ty<'tcx>> + Captures<'tcx>> {
) -> impl Iterator<Item: Iterator<Item = Ty<'tcx>>> {
let layout = tcx.coroutine_layout(def_id, self.kind_ty()).unwrap();
layout.variant_fields.iter().map(move |variant| {
variant.iter().map(move |field| {
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_mir_dataflow/src/value_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::fmt::{Debug, Formatter};
use std::ops::Range;

use rustc_abi::{FieldIdx, VariantIdx};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxIndexSet, StdEntry};
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_index::IndexVec;
Expand Down Expand Up @@ -677,10 +676,7 @@ impl<'tcx> Map<'tcx> {
}

/// Iterate over all direct children.
fn children(
&self,
parent: PlaceIndex,
) -> impl Iterator<Item = PlaceIndex> + Captures<'_> + Captures<'tcx> {
fn children(&self, parent: PlaceIndex) -> impl Iterator<Item = PlaceIndex> + use<'tcx, '_> {
Children::new(self, parent)
}

Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_mir_transform/src/coverage/counters.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::cmp::Ordering;
use std::fmt::{self, Debug};

use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::graph::DirectedGraph;
use rustc_index::IndexVec;
Expand Down Expand Up @@ -144,17 +143,15 @@ impl CoverageCounters {
/// Returns an iterator over all the nodes/edges in the coverage graph that
/// should have a counter-increment statement injected into MIR, along with
/// each site's corresponding counter ID.
pub(super) fn counter_increment_sites(
&self,
) -> impl Iterator<Item = (CounterId, Site)> + Captures<'_> {
pub(super) fn counter_increment_sites(&self) -> impl Iterator<Item = (CounterId, Site)> + '_ {
self.counter_increment_sites.iter_enumerated().map(|(id, &site)| (id, site))
}

/// Returns an iterator over the subset of BCB nodes that have been associated
/// with a counter *expression*, along with the ID of that expression.
pub(super) fn bcb_nodes_with_coverage_expressions(
&self,
) -> impl Iterator<Item = (BasicCoverageBlock, ExpressionId)> + Captures<'_> {
) -> impl Iterator<Item = (BasicCoverageBlock, ExpressionId)> + '_ {
self.node_counters.iter_enumerated().filter_map(|(bcb, &counter)| match counter {
// Yield the BCB along with its associated expression ID.
Some(BcbCounter::Expression { id }) => Some((bcb, id)),
Expand Down Expand Up @@ -212,7 +209,7 @@ fn sibling_out_edge_targets(
graph: &CoverageGraph,
from_bcb: BasicCoverageBlock,
to_bcb: BasicCoverageBlock,
) -> impl Iterator<Item = BasicCoverageBlock> + Captures<'_> {
) -> impl Iterator<Item = BasicCoverageBlock> + '_ {
graph.successors[from_bcb].iter().copied().filter(move |&t| t != to_bcb)
}

Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_mir_transform/src/coverage/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::collections::VecDeque;
use std::ops::{Index, IndexMut};
use std::{iter, mem, slice};

use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::graph::dominators::Dominators;
use rustc_data_structures::graph::{self, DirectedGraph, StartNode};
Expand Down Expand Up @@ -246,7 +245,7 @@ impl CoverageGraph {
pub(crate) fn loop_headers_containing(
&self,
bcb: BasicCoverageBlock,
) -> impl Iterator<Item = BasicCoverageBlock> + Captures<'_> {
) -> impl Iterator<Item = BasicCoverageBlock> + '_ {
let self_if_loop_header = self.is_loop_header.contains(bcb).then_some(bcb).into_iter();

let mut curr = Some(bcb);
Expand All @@ -266,7 +265,7 @@ impl CoverageGraph {
pub(crate) fn reloop_predecessors(
&self,
to_bcb: BasicCoverageBlock,
) -> impl Iterator<Item = BasicCoverageBlock> + Captures<'_> {
) -> impl Iterator<Item = BasicCoverageBlock> + '_ {
self.predecessors[to_bcb].iter().copied().filter(move |&pred| self.dominates(to_bcb, pred))
}
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_mir_transform/src/coverage/query.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use rustc_data_structures::captures::Captures;
use rustc_index::bit_set::DenseBitSet;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::mir::coverage::{
Expand Down Expand Up @@ -134,7 +133,7 @@ fn coverage_ids_info<'tcx>(

fn all_coverage_in_mir_body<'a, 'tcx>(
body: &'a Body<'tcx>,
) -> impl Iterator<Item = &'a CoverageKind> + Captures<'tcx> {
) -> impl Iterator<Item = &'a CoverageKind> + use<'a, 'tcx> {
body.basic_blocks.iter().flat_map(|bb_data| &bb_data.statements).filter_map(|statement| {
match statement.kind {
StatementKind::Coverage(ref kind) if !is_inlined(body, statement) => Some(kind),
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_mir_transform/src/coverage/spans.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::VecDeque;

use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet;
use rustc_middle::mir;
use rustc_span::{DesugaringKind, ExpnKind, MacroKind, Span};
Expand Down Expand Up @@ -179,10 +178,10 @@ fn divide_spans_into_buckets(input_covspans: Vec<Covspan>, holes: &[Hole]) -> Ve

/// Similar to `.drain(..)`, but stops just before it would remove an item not
/// satisfying the predicate.
fn drain_front_while<'a, T>(
fn drain_front_while<'a, T, F: FnMut(&T) -> bool>(
queue: &'a mut VecDeque<T>,
mut pred_fn: impl FnMut(&T) -> bool,
) -> impl Iterator<Item = T> + Captures<'a> {
mut pred_fn: F,
) -> impl Iterator<Item = T> + use<'a, T, F> {
std::iter::from_fn(move || if pred_fn(queue.front()?) { queue.pop_front() } else { None })
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_pattern_analysis/src/pat_column.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::constructor::{Constructor, SplitConstructorSet};
use crate::pat::{DeconstructedPat, PatOrWild};
use crate::{Captures, MatchArm, PatCx};
use crate::{MatchArm, PatCx};

/// A column of patterns in a match, where a column is the intuitive notion of "subpatterns that
/// inspect the same subvalue/place".
Expand Down Expand Up @@ -41,7 +41,7 @@ impl<'p, Cx: PatCx> PatternColumn<'p, Cx> {
pub fn head_ty(&self) -> Option<&Cx::Ty> {
self.patterns.first().map(|pat| pat.ty())
}
pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'p DeconstructedPat<Cx>> + Captures<'a> {
pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'p DeconstructedPat<Cx>> + use<'p, 'a, Cx> {
self.patterns.iter().copied()
}

Expand Down
Loading
Loading