Skip to content

Commit 2b64ab5

Browse files
committed
Use (😏) precise capture instead of Captures trait hack
1 parent 627513a commit 2b64ab5

File tree

27 files changed

+82
-127
lines changed

27 files changed

+82
-127
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343

4444
use rustc_ast::node_id::NodeMap;
4545
use rustc_ast::{self as ast, *};
46-
use rustc_data_structures::captures::Captures;
4746
use rustc_data_structures::fingerprint::Fingerprint;
4847
use rustc_data_structures::sorted_map::SortedMap;
4948
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -1803,7 +1802,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
18031802
&'s mut self,
18041803
params: &'s [GenericParam],
18051804
source: hir::GenericParamSource,
1806-
) -> impl Iterator<Item = hir::GenericParam<'hir>> + Captures<'a> + Captures<'s> {
1805+
) -> impl Iterator<Item = hir::GenericParam<'hir>> + use<'a, 'hir, 's> {
18071806
params.iter().map(move |param| self.lower_generic_param(param, source))
18081807
}
18091808

@@ -1968,7 +1967,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19681967
&'s mut self,
19691968
bounds: &'s [GenericBound],
19701969
itctx: ImplTraitContext,
1971-
) -> impl Iterator<Item = hir::GenericBound<'hir>> + Captures<'s> + Captures<'a> {
1970+
) -> impl Iterator<Item = hir::GenericBound<'hir>> + use<'a, 'hir, 's> {
19721971
bounds.iter().map(move |bound| self.lower_param_bound(bound, itctx))
19731972
}
19741973

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::ops::ControlFlow;
88

99
use either::Either;
1010
use hir::{ClosureKind, Path};
11-
use rustc_data_structures::captures::Captures;
1211
use rustc_data_structures::fx::FxIndexSet;
1312
use rustc_errors::codes::*;
1413
use rustc_errors::{Applicability, Diag, MultiSpan, struct_span_code_err};
@@ -3524,7 +3523,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
35243523
fn predecessor_locations<'a, 'tcx>(
35253524
body: &'a mir::Body<'tcx>,
35263525
location: Location,
3527-
) -> impl Iterator<Item = Location> + Captures<'tcx> + 'a {
3526+
) -> impl Iterator<Item = Location> + use<'a, 'tcx> {
35283527
if location.statement_index == 0 {
35293528
let predecessors = body.basic_blocks.predecessors()[location.block].to_vec();
35303529
Either::Left(predecessors.into_iter().map(move |bb| body.terminator_loc(bb)))

compiler/rustc_borrowck/src/member_constraints.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::hash::Hash;
22
use std::ops::Index;
33

4-
use rustc_data_structures::captures::Captures;
54
use rustc_data_structures::fx::FxIndexMap;
65
use rustc_index::{IndexSlice, IndexVec};
76
use rustc_middle::ty::{self, Ty};
@@ -149,7 +148,7 @@ where
149148
{
150149
pub(crate) fn all_indices(
151150
&self,
152-
) -> impl Iterator<Item = NllMemberConstraintIndex> + Captures<'tcx> + '_ {
151+
) -> impl Iterator<Item = NllMemberConstraintIndex> + use<'tcx, '_, R> {
153152
self.constraints.indices()
154153
}
155154

@@ -159,7 +158,7 @@ where
159158
pub(crate) fn indices(
160159
&self,
161160
member_region_vid: R,
162-
) -> impl Iterator<Item = NllMemberConstraintIndex> + Captures<'tcx> + '_ {
161+
) -> impl Iterator<Item = NllMemberConstraintIndex> + use<'tcx, '_, R> {
163162
let mut next = self.first_constraints.get(&member_region_vid).cloned();
164163
std::iter::from_fn(move || -> Option<NllMemberConstraintIndex> {
165164
if let Some(current) = next {

compiler/rustc_data_structures/src/captures.rs

-8
This file was deleted.

compiler/rustc_data_structures/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub use rustc_index::static_assert_size;
4848
pub mod aligned;
4949
pub mod base_n;
5050
pub mod binary_search_util;
51-
pub mod captures;
5251
pub mod fingerprint;
5352
pub mod flat_map_in_place;
5453
pub mod flock;

compiler/rustc_hir_analysis/src/collect.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use std::ops::Bound;
2020

2121
use rustc_abi::ExternAbi;
2222
use rustc_ast::Recovered;
23-
use rustc_data_structures::captures::Captures;
2423
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
2524
use rustc_data_structures::unord::UnordMap;
2625
use rustc_errors::{
@@ -1705,7 +1704,7 @@ fn polarity_of_impl(
17051704
fn early_bound_lifetimes_from_generics<'a, 'tcx: 'a>(
17061705
tcx: TyCtxt<'tcx>,
17071706
generics: &'a hir::Generics<'a>,
1708-
) -> impl Iterator<Item = &'a hir::GenericParam<'a>> + Captures<'tcx> {
1707+
) -> impl Iterator<Item = &'a hir::GenericParam<'a>> + use<'a, 'tcx> {
17091708
generics.params.iter().filter(move |param| match param.kind {
17101709
GenericParamKind::Lifetime { .. } => !tcx.is_late_bound(param.hir_id),
17111710
_ => false,

compiler/rustc_infer/src/infer/canonical/query_response.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use std::fmt::Debug;
1111
use std::iter;
1212

13-
use rustc_data_structures::captures::Captures;
1413
use rustc_index::{Idx, IndexVec};
1514
use rustc_middle::arena::ArenaAllocatable;
1615
use rustc_middle::mir::ConstraintCategory;
@@ -547,7 +546,7 @@ impl<'tcx> InferCtxt<'tcx> {
547546
param_env: ty::ParamEnv<'tcx>,
548547
uninstantiated_region_constraints: &'a [QueryOutlivesConstraint<'tcx>],
549548
result_args: &'a CanonicalVarValues<'tcx>,
550-
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a + Captures<'tcx> {
549+
) -> impl Iterator<Item = PredicateObligation<'tcx>> + 'a {
551550
uninstantiated_region_constraints.iter().map(move |&constraint| {
552551
let predicate = instantiate_value(self.tcx, result_args, constraint);
553552
self.query_outlives_constraint_to_obligation(predicate, cause.clone(), param_env)

compiler/rustc_infer/src/infer/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use region_constraints::{
1515
};
1616
pub use relate::StructurallyRelateAliases;
1717
pub use relate::combine::PredicateEmittingRelation;
18-
use rustc_data_structures::captures::Captures;
1918
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
2019
use rustc_data_structures::undo_log::{Rollback, UndoLogs};
2120
use rustc_data_structures::unify as ut;
@@ -1297,7 +1296,7 @@ impl<'tcx> InferCtxt<'tcx> {
12971296
#[inline]
12981297
pub fn is_ty_infer_var_definitely_unchanged<'a>(
12991298
&'a self,
1300-
) -> (impl Fn(TyOrConstInferVar) -> bool + Captures<'tcx> + 'a) {
1299+
) -> (impl Fn(TyOrConstInferVar) -> bool + use<'tcx, 'a>) {
13011300
// This hoists the borrow/release out of the loop body.
13021301
let inner = self.inner.try_borrow();
13031302

compiler/rustc_metadata/src/rmeta/decoder.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::{io, iter, mem};
77
pub(super) use cstore_impl::provide;
88
use proc_macro::bridge::client::ProcMacro;
99
use rustc_ast as ast;
10-
use rustc_data_structures::captures::Captures;
1110
use rustc_data_structures::fingerprint::Fingerprint;
1211
use rustc_data_structures::fx::FxIndexMap;
1312
use rustc_data_structures::owned_slice::OwnedSlice;
@@ -958,7 +957,7 @@ impl CrateRoot {
958957
pub(crate) fn decode_crate_deps<'a>(
959958
&self,
960959
metadata: &'a MetadataBlob,
961-
) -> impl ExactSizeIterator<Item = CrateDep> + Captures<'a> {
960+
) -> impl ExactSizeIterator<Item = CrateDep> + 'a {
962961
self.crate_deps.decode(metadata)
963962
}
964963
}

compiler/rustc_middle/src/mir/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use either::Either;
1212
use polonius_engine::Atom;
1313
use rustc_abi::{FieldIdx, VariantIdx};
1414
pub use rustc_ast::Mutability;
15-
use rustc_data_structures::captures::Captures;
1615
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1716
use rustc_data_structures::graph::dominators::Dominators;
1817
use rustc_errors::{DiagArgName, DiagArgValue, DiagMessage, ErrorGuaranteed, IntoDiagArg};
@@ -481,7 +480,7 @@ impl<'tcx> Body<'tcx> {
481480

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

492491
/// Returns an iterator over all user-declared mutable arguments and locals.
493492
#[inline]
494-
pub fn mut_vars_and_args_iter<'a>(
495-
&'a self,
496-
) -> impl Iterator<Item = Local> + Captures<'tcx> + 'a {
493+
pub fn mut_vars_and_args_iter<'a>(&'a self) -> impl Iterator<Item = Local> + use<'tcx, 'a> {
497494
(1..self.local_decls.len()).filter_map(move |index| {
498495
let local = Local::new(index);
499496
let decl = &self.local_decls[local];

compiler/rustc_middle/src/ty/adt.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::ops::Range;
44
use std::str;
55

66
use rustc_abi::{FIRST_VARIANT, ReprOptions, VariantIdx};
7-
use rustc_data_structures::captures::Captures;
87
use rustc_data_structures::fingerprint::Fingerprint;
98
use rustc_data_structures::fx::FxHashMap;
109
use rustc_data_structures::intern::Interned;
@@ -536,7 +535,7 @@ impl<'tcx> AdtDef<'tcx> {
536535
pub fn discriminants(
537536
self,
538537
tcx: TyCtxt<'tcx>,
539-
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx> {
538+
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + 'tcx {
540539
assert!(self.is_enum());
541540
let repr_type = self.repr().discr_type();
542541
let initial = repr_type.initial_discriminant(tcx);

compiler/rustc_middle/src/ty/closure.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::fmt::Write;
22

3-
use rustc_data_structures::captures::Captures;
43
use rustc_data_structures::fx::FxIndexMap;
54
use rustc_hir as hir;
65
use rustc_hir::HirId;
@@ -415,7 +414,7 @@ pub fn analyze_coroutine_closure_captures<'a, 'tcx: 'a, T>(
415414
parent_captures: impl IntoIterator<Item = &'a CapturedPlace<'tcx>>,
416415
child_captures: impl IntoIterator<Item = &'a CapturedPlace<'tcx>>,
417416
mut for_each: impl FnMut((usize, &'a CapturedPlace<'tcx>), (usize, &'a CapturedPlace<'tcx>)) -> T,
418-
) -> impl Iterator<Item = T> + Captures<'a> + Captures<'tcx> {
417+
) -> impl Iterator<Item = T> {
419418
std::iter::from_coroutine(
420419
#[coroutine]
421420
move || {

compiler/rustc_middle/src/ty/predicate.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::cmp::Ordering;
22

3-
use rustc_data_structures::captures::Captures;
43
use rustc_data_structures::intern::Interned;
54
use rustc_hir::def_id::DefId;
65
use rustc_macros::{HashStable, extension};
@@ -350,7 +349,7 @@ impl<'tcx> ty::List<ty::PolyExistentialPredicate<'tcx>> {
350349
}
351350

352351
#[inline]
353-
pub fn auto_traits<'a>(&'a self) -> impl Iterator<Item = DefId> + Captures<'tcx> + 'a {
352+
pub fn auto_traits<'a>(&'a self) -> impl Iterator<Item = DefId> + use<'tcx, 'a> {
354353
self.iter().filter_map(|predicate| match predicate.skip_binder() {
355354
ExistentialPredicate::AutoTrait(did) => Some(did),
356355
_ => None,

compiler/rustc_middle/src/ty/sty.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use std::ops::{ControlFlow, Range};
99

1010
use hir::def::{CtorKind, DefKind};
1111
use rustc_abi::{ExternAbi, FIRST_VARIANT, FieldIdx, VariantIdx};
12-
use rustc_data_structures::captures::Captures;
1312
use rustc_errors::{ErrorGuaranteed, MultiSpan};
1413
use rustc_hir as hir;
1514
use rustc_hir::LangItem;
@@ -105,7 +104,7 @@ impl<'tcx> ty::CoroutineArgs<TyCtxt<'tcx>> {
105104
self,
106105
def_id: DefId,
107106
tcx: TyCtxt<'tcx>,
108-
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> + Captures<'tcx> {
107+
) -> impl Iterator<Item = (VariantIdx, Discr<'tcx>)> {
109108
self.variant_range(def_id, tcx).map(move |index| {
110109
(index, Discr { val: index.as_usize() as u128, ty: self.discr_ty(tcx) })
111110
})
@@ -139,7 +138,7 @@ impl<'tcx> ty::CoroutineArgs<TyCtxt<'tcx>> {
139138
self,
140139
def_id: DefId,
141140
tcx: TyCtxt<'tcx>,
142-
) -> impl Iterator<Item: Iterator<Item = Ty<'tcx>> + Captures<'tcx>> {
141+
) -> impl Iterator<Item: Iterator<Item = Ty<'tcx>>> {
143142
let layout = tcx.coroutine_layout(def_id, self.kind_ty()).unwrap();
144143
layout.variant_fields.iter().map(move |variant| {
145144
variant.iter().map(move |field| {

compiler/rustc_mir_dataflow/src/value_analysis.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::fmt::{Debug, Formatter};
22
use std::ops::Range;
33

44
use rustc_abi::{FieldIdx, VariantIdx};
5-
use rustc_data_structures::captures::Captures;
65
use rustc_data_structures::fx::{FxHashMap, FxIndexSet, StdEntry};
76
use rustc_data_structures::stack::ensure_sufficient_stack;
87
use rustc_index::IndexVec;
@@ -677,10 +676,7 @@ impl<'tcx> Map<'tcx> {
677676
}
678677

679678
/// Iterate over all direct children.
680-
fn children(
681-
&self,
682-
parent: PlaceIndex,
683-
) -> impl Iterator<Item = PlaceIndex> + Captures<'_> + Captures<'tcx> {
679+
fn children(&self, parent: PlaceIndex) -> impl Iterator<Item = PlaceIndex> + use<'tcx, '_> {
684680
Children::new(self, parent)
685681
}
686682

compiler/rustc_mir_transform/src/coverage/counters.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::cmp::Ordering;
22
use std::fmt::{self, Debug};
33

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

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

compiler/rustc_mir_transform/src/coverage/graph.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::collections::VecDeque;
33
use std::ops::{Index, IndexMut};
44
use std::{iter, mem, slice};
55

6-
use rustc_data_structures::captures::Captures;
76
use rustc_data_structures::fx::FxHashSet;
87
use rustc_data_structures::graph::dominators::Dominators;
98
use rustc_data_structures::graph::{self, DirectedGraph, StartNode};
@@ -246,7 +245,7 @@ impl CoverageGraph {
246245
pub(crate) fn loop_headers_containing(
247246
&self,
248247
bcb: BasicCoverageBlock,
249-
) -> impl Iterator<Item = BasicCoverageBlock> + Captures<'_> {
248+
) -> impl Iterator<Item = BasicCoverageBlock> + '_ {
250249
let self_if_loop_header = self.is_loop_header.contains(bcb).then_some(bcb).into_iter();
251250

252251
let mut curr = Some(bcb);
@@ -266,7 +265,7 @@ impl CoverageGraph {
266265
pub(crate) fn reloop_predecessors(
267266
&self,
268267
to_bcb: BasicCoverageBlock,
269-
) -> impl Iterator<Item = BasicCoverageBlock> + Captures<'_> {
268+
) -> impl Iterator<Item = BasicCoverageBlock> + '_ {
270269
self.predecessors[to_bcb].iter().copied().filter(move |&pred| self.dominates(to_bcb, pred))
271270
}
272271
}

compiler/rustc_mir_transform/src/coverage/query.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_data_structures::captures::Captures;
21
use rustc_index::bit_set::DenseBitSet;
32
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
43
use rustc_middle::mir::coverage::{
@@ -134,7 +133,7 @@ fn coverage_ids_info<'tcx>(
134133

135134
fn all_coverage_in_mir_body<'a, 'tcx>(
136135
body: &'a Body<'tcx>,
137-
) -> impl Iterator<Item = &'a CoverageKind> + Captures<'tcx> {
136+
) -> impl Iterator<Item = &'a CoverageKind> + use<'a, 'tcx> {
138137
body.basic_blocks.iter().flat_map(|bb_data| &bb_data.statements).filter_map(|statement| {
139138
match statement.kind {
140139
StatementKind::Coverage(ref kind) if !is_inlined(body, statement) => Some(kind),

compiler/rustc_mir_transform/src/coverage/spans.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::collections::VecDeque;
22

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

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

compiler/rustc_pattern_analysis/src/pat_column.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::constructor::{Constructor, SplitConstructorSet};
22
use crate::pat::{DeconstructedPat, PatOrWild};
3-
use crate::{Captures, MatchArm, PatCx};
3+
use crate::{MatchArm, PatCx};
44

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

0 commit comments

Comments
 (0)