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
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
@@ -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};
@@ -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))
}

@@ -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))
}

3 changes: 1 addition & 2 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
@@ -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};
@@ -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)))
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};
@@ -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()
}

@@ -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 {
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
@@ -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;
3 changes: 1 addition & 2 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
@@ -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::{
@@ -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,
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
@@ -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;
@@ -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)
3 changes: 1 addition & 2 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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();

3 changes: 1 addition & 2 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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)
}
}
7 changes: 2 additions & 5 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
@@ -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];
@@ -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];
3 changes: 1 addition & 2 deletions compiler/rustc_middle/src/ty/adt.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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);
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;
@@ -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 || {
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};
@@ -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,
5 changes: 2 additions & 3 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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) })
})
@@ -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| {
6 changes: 1 addition & 5 deletions compiler/rustc_mir_dataflow/src/value_analysis.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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)
}

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;
@@ -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)),
@@ -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)
}

5 changes: 2 additions & 3 deletions compiler/rustc_mir_transform/src/coverage/graph.rs
Original file line number Diff line number Diff line change
@@ -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};
@@ -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);
@@ -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))
}
}
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::{
@@ -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),
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};
@@ -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 })
}

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".
@@ -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()
}

5 changes: 2 additions & 3 deletions compiler/rustc_pattern_analysis/src/rustc.rs
Original file line number Diff line number Diff line change
@@ -175,8 +175,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
&self,
ty: RevealedTy<'tcx>,
variant: &'tcx VariantDef,
) -> impl Iterator<Item = (&'tcx FieldDef, RevealedTy<'tcx>)> + Captures<'p> + Captures<'_>
{
) -> impl Iterator<Item = (&'tcx FieldDef, RevealedTy<'tcx>)> + use<'p, 'tcx, '_> {
let ty::Adt(_, args) = ty.kind() else { bug!() };
variant.fields.iter().map(move |field| {
let ty = field.ty(self.tcx, args);
@@ -209,7 +208,7 @@ impl<'p, 'tcx: 'p> RustcPatCtxt<'p, 'tcx> {
ty: RevealedTy<'tcx>,
) -> impl Iterator<Item = (RevealedTy<'tcx>, PrivateUninhabitedField)>
+ ExactSizeIterator
+ Captures<'a> {
+ use<'tcx, 'a> {
fn reveal_and_alloc<'a, 'tcx>(
cx: &'a RustcPatCtxt<'_, 'tcx>,
iter: impl Iterator<Item = Ty<'tcx>>,
14 changes: 7 additions & 7 deletions compiler/rustc_pattern_analysis/src/usefulness.rs
Original file line number Diff line number Diff line change
@@ -719,7 +719,7 @@ use tracing::{debug, instrument};
use self::PlaceValidity::*;
use crate::constructor::{Constructor, ConstructorSet, IntRange};
use crate::pat::{DeconstructedPat, PatId, PatOrWild, WitnessPat};
use crate::{Captures, MatchArm, PatCx, PrivateUninhabitedField};
use crate::{MatchArm, PatCx, PrivateUninhabitedField};
#[cfg(not(feature = "rustc"))]
pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {
f()
@@ -905,7 +905,7 @@ impl<Cx: PatCx> PlaceInfo<Cx> {
&'a self,
cx: &'a Cx,
ctor: &'a Constructor<Cx>,
) -> impl Iterator<Item = Self> + ExactSizeIterator + Captures<'a> {
) -> impl Iterator<Item = Self> + ExactSizeIterator + use<'a, Cx> {
let ctor_sub_tys = cx.ctor_sub_tys(ctor, &self.ty);
let ctor_sub_validity = self.validity.specialize(ctor);
ctor_sub_tys.map(move |(ty, PrivateUninhabitedField(private_uninhabited))| PlaceInfo {
@@ -1045,13 +1045,13 @@ impl<'p, Cx: PatCx> PatStack<'p, Cx> {
self.pats[0]
}

fn iter(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> + Captures<'_> {
fn iter(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> + use<'p, '_, Cx> {
self.pats.iter().copied()
}

// Expand the first or-pattern into its subpatterns. Only useful if the pattern is an
// or-pattern. Panics if `self` is empty.
fn expand_or_pat(&self) -> impl Iterator<Item = PatStack<'p, Cx>> + Captures<'_> {
fn expand_or_pat(&self) -> impl Iterator<Item = PatStack<'p, Cx>> + use<'p, '_, Cx> {
self.head().expand_or_pat().into_iter().map(move |pat| {
let mut new = self.clone();
new.pats[0] = pat;
@@ -1156,15 +1156,15 @@ impl<'p, Cx: PatCx> MatrixRow<'p, Cx> {
self.pats.head()
}

fn iter(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> + Captures<'_> {
fn iter(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> + use<'p, '_, Cx> {
self.pats.iter()
}

// Expand the first or-pattern (if any) into its subpatterns. Panics if `self` is empty.
fn expand_or_pat(
&self,
parent_row: usize,
) -> impl Iterator<Item = MatrixRow<'p, Cx>> + Captures<'_> {
) -> impl Iterator<Item = MatrixRow<'p, Cx>> + use<'p, '_, Cx> {
let is_or_pat = self.pats.head().is_or_pat();
self.pats.expand_or_pat().map(move |patstack| MatrixRow {
pats: patstack,
@@ -1274,7 +1274,7 @@ impl<'p, Cx: PatCx> Matrix<'p, Cx> {
}

/// Iterate over the first pattern of each row.
fn heads(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> + Clone + Captures<'_> {
fn heads(&self) -> impl Iterator<Item = PatOrWild<'p, Cx>> + Clone + use<'p, '_, Cx> {
self.rows().map(|r| r.head())
}

3 changes: 1 addition & 2 deletions compiler/rustc_trait_selection/src/traits/fulfill.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::marker::PhantomData;

use rustc_data_structures::captures::Captures;
use rustc_data_structures::obligation_forest::{
Error, ForestObligation, ObligationForest, ObligationProcessor, Outcome, ProcessResult,
};
@@ -903,7 +902,7 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
fn args_infer_vars<'a, 'tcx>(
selcx: &SelectionContext<'a, 'tcx>,
args: ty::Binder<'tcx, GenericArgsRef<'tcx>>,
) -> impl Iterator<Item = TyOrConstInferVar> + Captures<'tcx> {
) -> impl Iterator<Item = TyOrConstInferVar> + 'tcx {
selcx
.infcx
.resolve_vars_if_possible(args)
54 changes: 25 additions & 29 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
@@ -16,7 +16,6 @@ use std::iter::{self, once};
use itertools::Itertools;
use rustc_abi::ExternAbi;
use rustc_attr_parsing::{ConstStability, StabilityLevel, StableSince};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir as hir;
use rustc_hir::def::DefKind;
@@ -164,7 +163,7 @@ pub(crate) fn comma_sep<T: Display>(
pub(crate) fn print_generic_bounds<'a, 'tcx: 'a>(
bounds: &'a [clean::GenericBound],
cx: &'a Context<'tcx>,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| {
let mut bounds_dup = FxHashSet::default();

@@ -182,7 +181,7 @@ impl clean::GenericParamDef {
pub(crate) fn print<'a, 'tcx: 'a>(
&'a self,
cx: &'a Context<'tcx>,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| match &self.kind {
clean::GenericParamDefKind::Lifetime { outlives } => {
write!(f, "{}", self.name)?;
@@ -237,7 +236,7 @@ impl clean::Generics {
pub(crate) fn print<'a, 'tcx: 'a>(
&'a self,
cx: &'a Context<'tcx>,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| {
let mut real_params = self.params.iter().filter(|p| !p.is_synthetic_param()).peekable();
if real_params.peek().is_none() {
@@ -267,7 +266,7 @@ pub(crate) fn print_where_clause<'a, 'tcx: 'a>(
cx: &'a Context<'tcx>,
indent: usize,
ending: Ending,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| {
let mut where_predicates = gens
.where_predicates
@@ -385,7 +384,7 @@ impl clean::ConstantKind {
}

impl clean::PolyTrait {
fn print<'a, 'tcx: 'a>(&'a self, cx: &'a Context<'tcx>) -> impl Display + 'a + Captures<'tcx> {
fn print<'a, 'tcx: 'a>(&'a self, cx: &'a Context<'tcx>) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| {
print_higher_ranked_params_with_space(&self.generic_params, cx, "for").fmt(f)?;
self.trait_.print(cx).fmt(f)
@@ -397,7 +396,7 @@ impl clean::GenericBound {
pub(crate) fn print<'a, 'tcx: 'a>(
&'a self,
cx: &'a Context<'tcx>,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| match self {
clean::GenericBound::Outlives(lt) => write!(f, "{}", lt.print()),
clean::GenericBound::TraitBound(ty, modifiers) => {
@@ -429,7 +428,7 @@ impl clean::GenericBound {
}

impl clean::GenericArgs {
fn print<'a, 'tcx: 'a>(&'a self, cx: &'a Context<'tcx>) -> impl Display + 'a + Captures<'tcx> {
fn print<'a, 'tcx: 'a>(&'a self, cx: &'a Context<'tcx>) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| {
match self {
clean::GenericArgs::AngleBracketed { args, constraints } => {
@@ -949,7 +948,7 @@ fn tybounds<'a, 'tcx: 'a>(
bounds: &'a [clean::PolyTrait],
lt: &'a Option<clean::Lifetime>,
cx: &'a Context<'tcx>,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| {
for (i, bound) in bounds.iter().enumerate() {
if i > 0 {
@@ -970,7 +969,7 @@ fn print_higher_ranked_params_with_space<'a, 'tcx: 'a>(
params: &'a [clean::GenericParamDef],
cx: &'a Context<'tcx>,
keyword: &'static str,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| {
if !params.is_empty() {
f.write_str(keyword)?;
@@ -1266,19 +1265,19 @@ fn fmt_type(
}

impl clean::Type {
pub(crate) fn print<'b, 'a: 'b, 'tcx: 'a>(
pub(crate) fn print<'a, 'tcx: 'a>(
&'a self,
cx: &'a Context<'tcx>,
) -> impl Display + 'b + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| fmt_type(self, f, false, cx))
}
}

impl clean::Path {
pub(crate) fn print<'b, 'a: 'b, 'tcx: 'a>(
pub(crate) fn print<'a, 'tcx: 'a>(
&'a self,
cx: &'a Context<'tcx>,
) -> impl Display + 'b + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| resolved_path(f, self.def_id(), self, false, false, cx))
}
}
@@ -1288,7 +1287,7 @@ impl clean::Impl {
&'a self,
use_absolute: bool,
cx: &'a Context<'tcx>,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| {
f.write_str("impl")?;
self.generics.print(cx).fmt(f)?;
@@ -1406,7 +1405,7 @@ impl clean::Arguments {
pub(crate) fn print<'a, 'tcx: 'a>(
&'a self,
cx: &'a Context<'tcx>,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| {
for (i, input) in self.values.iter().enumerate() {
write!(f, "{}: ", input.name)?;
@@ -1443,10 +1442,10 @@ impl Display for Indent {
}

impl clean::FnDecl {
pub(crate) fn print<'b, 'a: 'b, 'tcx: 'a>(
pub(crate) fn print<'a, 'tcx: 'a>(
&'a self,
cx: &'a Context<'tcx>,
) -> impl Display + 'b + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| {
let ellipsis = if self.c_variadic { ", ..." } else { "" };
if f.alternate() {
@@ -1480,7 +1479,7 @@ impl clean::FnDecl {
header_len: usize,
indent: usize,
cx: &'a Context<'tcx>,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| {
// First, generate the text form of the declaration, with no line wrapping, and count the bytes.
let mut counter = WriteCounter(0);
@@ -1562,10 +1561,7 @@ impl clean::FnDecl {
self.print_output(cx).fmt(f)
}

fn print_output<'a, 'tcx: 'a>(
&'a self,
cx: &'a Context<'tcx>,
) -> impl Display + 'a + Captures<'tcx> {
fn print_output<'a, 'tcx: 'a>(&'a self, cx: &'a Context<'tcx>) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| match &self.output {
clean::Tuple(tys) if tys.is_empty() => Ok(()),
ty if f.alternate() => {
@@ -1579,7 +1575,7 @@ impl clean::FnDecl {
pub(crate) fn visibility_print_with_space<'a, 'tcx: 'a>(
item: &clean::Item,
cx: &'a Context<'tcx>,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
use std::fmt::Write as _;
let vis: Cow<'static, str> = match item.visibility(cx.tcx()) {
None => "".into(),
@@ -1682,7 +1678,7 @@ impl clean::Import {
pub(crate) fn print<'a, 'tcx: 'a>(
&'a self,
cx: &'a Context<'tcx>,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| match self.kind {
clean::ImportKind::Simple(name) => {
if name == self.source.path.last() {
@@ -1706,7 +1702,7 @@ impl clean::ImportSource {
pub(crate) fn print<'a, 'tcx: 'a>(
&'a self,
cx: &'a Context<'tcx>,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| match self.did {
Some(did) => resolved_path(f, did, &self.path, true, false, cx),
_ => {
@@ -1734,7 +1730,7 @@ impl clean::AssocItemConstraint {
pub(crate) fn print<'a, 'tcx: 'a>(
&'a self,
cx: &'a Context<'tcx>,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| {
f.write_str(self.assoc.name.as_str())?;
self.assoc.args.print(cx).fmt(f)?;
@@ -1773,7 +1769,7 @@ impl clean::GenericArg {
pub(crate) fn print<'a, 'tcx: 'a>(
&'a self,
cx: &'a Context<'tcx>,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| match self {
clean::GenericArg::Lifetime(lt) => lt.print().fmt(f),
clean::GenericArg::Type(ty) => ty.print(cx).fmt(f),
@@ -1787,7 +1783,7 @@ impl clean::Term {
pub(crate) fn print<'a, 'tcx: 'a>(
&'a self,
cx: &'a Context<'tcx>,
) -> impl Display + 'a + Captures<'tcx> {
) -> impl Display + use<'a, 'tcx> {
display_fn(move |f| match self {
clean::Term::Type(ty) => ty.print(cx).fmt(f),
clean::Term::Constant(ct) => ct.print(cx.tcx()).fmt(f),
17 changes: 8 additions & 9 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
@@ -47,7 +47,6 @@ use rinja::Template;
use rustc_attr_parsing::{
ConstStability, DeprecatedSince, Deprecation, RustcVersion, StabilityLevel, StableSince,
};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_hir::Mutability;
use rustc_hir::def_id::{DefId, DefIdSet};
@@ -508,7 +507,7 @@ fn document<'a, 'cx: 'a>(
item: &'a clean::Item,
parent: Option<&'a clean::Item>,
heading_offset: HeadingOffset,
) -> impl fmt::Display + 'a + Captures<'cx> {
) -> impl fmt::Display + use<'a, 'cx> {
if let Some(ref name) = item.name {
info!("Documenting {name}");
}
@@ -529,7 +528,7 @@ fn render_markdown<'a, 'cx: 'a>(
md_text: &'a str,
links: Vec<RenderedLink>,
heading_offset: HeadingOffset,
) -> impl fmt::Display + 'a + Captures<'cx> {
) -> impl fmt::Display + use<'a, 'cx> {
display_fn(move |f| {
write!(
f,
@@ -556,7 +555,7 @@ fn document_short<'a, 'cx: 'a>(
link: AssocItemLink<'a>,
parent: &'a clean::Item,
show_def_docs: bool,
) -> impl fmt::Display + 'a + Captures<'cx> {
) -> impl fmt::Display + use<'a, 'cx> {
display_fn(move |f| {
document_item_info(cx, item, Some(parent)).render_into(f).unwrap();
if !show_def_docs {
@@ -587,15 +586,15 @@ fn document_full_collapsible<'a, 'cx: 'a>(
item: &'a clean::Item,
cx: &'a Context<'cx>,
heading_offset: HeadingOffset,
) -> impl fmt::Display + 'a + Captures<'cx> {
) -> impl fmt::Display + use<'a, 'cx> {
document_full_inner(item, cx, true, heading_offset)
}

fn document_full<'a, 'cx: 'a>(
item: &'a clean::Item,
cx: &'a Context<'cx>,
heading_offset: HeadingOffset,
) -> impl fmt::Display + 'a + Captures<'cx> {
) -> impl fmt::Display + use<'a, 'cx> {
document_full_inner(item, cx, false, heading_offset)
}

@@ -604,7 +603,7 @@ fn document_full_inner<'a, 'cx: 'a>(
cx: &'a Context<'cx>,
is_collapsible: bool,
heading_offset: HeadingOffset,
) -> impl fmt::Display + 'a + Captures<'cx> {
) -> impl fmt::Display + use<'a, 'cx> {
display_fn(move |f| {
if let Some(s) = item.opt_doc_value() {
debug!("Doc block: =====\n{s}\n=====");
@@ -1158,7 +1157,7 @@ fn render_attributes_in_pre<'a, 'tcx: 'a>(
it: &'a clean::Item,
prefix: &'a str,
cx: &'a Context<'tcx>,
) -> impl fmt::Display + Captures<'a> + Captures<'tcx> {
) -> impl fmt::Display + use<'a, 'tcx> {
crate::html::format::display_fn(move |f| {
for a in it.attributes(cx.tcx(), cx.cache(), false) {
writeln!(f, "{prefix}{a}")?;
@@ -1255,7 +1254,7 @@ fn render_assoc_items<'a, 'cx: 'a>(
containing_item: &'a clean::Item,
it: DefId,
what: AssocItemRender<'a>,
) -> impl fmt::Display + 'a + Captures<'cx> {
) -> impl fmt::Display + use<'a, 'cx> {
let mut derefs = DefIdSet::default();
derefs.insert(it);
display_fn(move |f| {
24 changes: 10 additions & 14 deletions src/librustdoc/html/render/print_item.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ use std::fmt;
use itertools::Itertools;
use rinja::Template;
use rustc_abi::VariantIdx;
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fx::{FxHashMap, FxIndexSet};
use rustc_hir as hir;
use rustc_hir::def::CtorKind;
@@ -91,7 +90,7 @@ macro_rules! item_template {
macro_rules! item_template_methods {
() => {};
(document $($rest:tt)*) => {
fn document<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
fn document<'b>(&'b self) -> impl fmt::Display + use<'a, 'cx, 'b> {
display_fn(move |f| {
let (item, cx) = self.item_and_cx();
let v = document(cx, item, None, HeadingOffset::H2);
@@ -101,7 +100,7 @@ macro_rules! item_template_methods {
item_template_methods!($($rest)*);
};
(document_type_layout $($rest:tt)*) => {
fn document_type_layout<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
fn document_type_layout<'b>(&'b self) -> impl fmt::Display + use<'a, 'cx, 'b> {
display_fn(move |f| {
let (item, cx) = self.item_and_cx();
let def_id = item.item_id.expect_def_id();
@@ -112,7 +111,7 @@ macro_rules! item_template_methods {
item_template_methods!($($rest)*);
};
(render_attributes_in_pre $($rest:tt)*) => {
fn render_attributes_in_pre<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
fn render_attributes_in_pre<'b>(&'b self) -> impl fmt::Display + use<'a, 'cx, 'b> {
display_fn(move |f| {
let (item, cx) = self.item_and_cx();
let v = render_attributes_in_pre(item, "", cx);
@@ -122,7 +121,7 @@ macro_rules! item_template_methods {
item_template_methods!($($rest)*);
};
(render_assoc_items $($rest:tt)*) => {
fn render_assoc_items<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
fn render_assoc_items<'b>(&'b self) -> impl fmt::Display + use<'a, 'cx, 'b> {
display_fn(move |f| {
let (item, cx) = self.item_and_cx();
let def_id = item.item_id.expect_def_id();
@@ -538,7 +537,7 @@ fn extra_info_tags<'a, 'tcx: 'a>(
item: &'a clean::Item,
parent: &'a clean::Item,
import_def_id: Option<DefId>,
) -> impl fmt::Display + 'a + Captures<'tcx> {
) -> impl fmt::Display + use<'a, 'tcx> {
display_fn(move |f| {
fn tag_html<'a>(
class: &'a str,
@@ -1394,7 +1393,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
);

impl<'a, 'cx: 'a> ItemUnion<'a, 'cx> {
fn render_union<'b>(&'b self) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
fn render_union<'b>(&'b self) -> impl fmt::Display + use<'a, 'cx, 'b> {
display_fn(move |f| {
let v = render_union(self.it, Some(&self.s.generics), &self.s.fields, self.cx);
write!(f, "{v}")
@@ -1404,7 +1403,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
fn document_field<'b>(
&'b self,
field: &'a clean::Item,
) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
) -> impl fmt::Display + use<'a, 'cx, 'b> {
display_fn(move |f| {
let v = document(self.cx, field, Some(self.it), HeadingOffset::H3);
write!(f, "{v}")
@@ -1415,10 +1414,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
field.stability_class(self.cx.tcx())
}

fn print_ty<'b>(
&'b self,
ty: &'a clean::Type,
) -> impl fmt::Display + Captures<'a> + 'b + Captures<'cx> {
fn print_ty<'b>(&'b self, ty: &'a clean::Type) -> impl fmt::Display + use<'a, 'cx, 'b> {
display_fn(move |f| {
let v = ty.print(self.cx);
write!(f, "{v}")
@@ -1445,7 +1441,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
fn print_tuple_struct_fields<'a, 'cx: 'a>(
cx: &'a Context<'cx>,
s: &'a [clean::Item],
) -> impl fmt::Display + 'a + Captures<'cx> {
) -> impl fmt::Display + use<'a, 'cx> {
display_fn(|f| {
if !s.is_empty()
&& s.iter().all(|field| {
@@ -2170,7 +2166,7 @@ fn render_union<'a, 'cx: 'a>(
g: Option<&'a clean::Generics>,
fields: &'a [clean::Item],
cx: &'a Context<'cx>,
) -> impl fmt::Display + 'a + Captures<'cx> {
) -> impl fmt::Display + use<'a, 'cx> {
display_fn(move |mut f| {
write!(f, "{}union {}", visibility_print_with_space(it, cx), it.name.unwrap(),)?;

3 changes: 1 addition & 2 deletions src/librustdoc/html/render/type_layout.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ use std::fmt;

use rinja::Template;
use rustc_abi::{Primitive, TagEncoding, Variants};
use rustc_data_structures::captures::Captures;
use rustc_hir::def_id::DefId;
use rustc_middle::span_bug;
use rustc_middle::ty::layout::LayoutError;
@@ -30,7 +29,7 @@ struct TypeLayoutSize {
pub(crate) fn document_type_layout<'a, 'cx: 'a>(
cx: &'a Context<'cx>,
ty_def_id: DefId,
) -> impl fmt::Display + 'a + Captures<'cx> {
) -> impl fmt::Display + use<'a, 'cx> {
display_fn(move |f| {
if !cx.shared.show_type_layout {
return Ok(());