Skip to content

Commit 9e76fcc

Browse files
committed
Change Search::infcx to tcx.
Because the `infcx` isn't needed. This removes one lifetime from `Search`.
1 parent 788dded commit 9e76fcc

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

compiler/rustc_trait_selection/src/traits/structural_match.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn search_for_structural_match_violation<'tcx>(
6060
) -> Option<NonStructuralMatchTy<'tcx>> {
6161
// FIXME: we should instead pass in an `infcx` from the outside.
6262
tcx.infer_ctxt().enter(|infcx| {
63-
ty.visit_with(&mut Search { infcx, span, seen: FxHashSet::default() }).break_value()
63+
ty.visit_with(&mut Search { tcx: infcx.tcx, span, seen: FxHashSet::default() }).break_value()
6464
})
6565
}
6666

@@ -114,27 +114,23 @@ fn type_marked_structural<'tcx>(
114114
/// This implements the traversal over the structure of a given type to try to
115115
/// find instances of ADTs (specifically structs or enums) that do not implement
116116
/// the structural-match traits (`StructuralPartialEq` and `StructuralEq`).
117-
struct Search<'a, 'tcx> {
117+
struct Search<'tcx> {
118118
span: Span,
119119

120-
infcx: InferCtxt<'a, 'tcx>,
120+
tcx: TyCtxt<'tcx>,
121121

122122
/// Tracks ADTs previously encountered during search, so that
123123
/// we will not recur on them again.
124124
seen: FxHashSet<hir::def_id::DefId>,
125125
}
126126

127-
impl<'a, 'tcx> Search<'a, 'tcx> {
128-
fn tcx(&self) -> TyCtxt<'tcx> {
129-
self.infcx.tcx
130-
}
131-
127+
impl<'tcx> Search<'tcx> {
132128
fn type_marked_structural(&self, adt_ty: Ty<'tcx>) -> bool {
133-
adt_ty.is_structural_eq_shallow(self.tcx())
129+
adt_ty.is_structural_eq_shallow(self.tcx)
134130
}
135131
}
136132

137-
impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
133+
impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> {
138134
type BreakTy = NonStructuralMatchTy<'tcx>;
139135

140136
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
@@ -193,7 +189,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
193189
return ControlFlow::CONTINUE;
194190
}
195191
ty::Array(_, n)
196-
if { n.try_eval_usize(self.tcx(), ty::ParamEnv::reveal_all()) == Some(0) } =>
192+
if { n.try_eval_usize(self.tcx, ty::ParamEnv::reveal_all()) == Some(0) } =>
197193
{
198194
// rust-lang/rust#62336: ignore type of contents
199195
// for empty array.
@@ -214,7 +210,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
214210
bug!("unexpected type during structural-match checking: {:?}", ty);
215211
}
216212
ty::Error(_) => {
217-
self.tcx().sess.delay_span_bug(self.span, "ty::Error in structural-match check");
213+
self.tcx.sess.delay_span_bug(self.span, "ty::Error in structural-match check");
218214
// We still want to check other types after encountering an error,
219215
// as this may still emit relevant errors.
220216
return ControlFlow::CONTINUE;
@@ -244,9 +240,9 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for Search<'a, 'tcx> {
244240

245241
// even though we skip super_visit_with, we must recur on
246242
// fields of ADT.
247-
let tcx = self.tcx();
243+
let tcx = self.tcx;
248244
adt_def.all_fields().map(|field| field.ty(tcx, substs)).try_for_each(|field_ty| {
249-
let ty = self.tcx().normalize_erasing_regions(ty::ParamEnv::empty(), field_ty);
245+
let ty = self.tcx.normalize_erasing_regions(ty::ParamEnv::empty(), field_ty);
250246
debug!("structural-match ADT: field_ty={:?}, ty={:?}", field_ty, ty);
251247
ty.visit_with(self)
252248
})

0 commit comments

Comments
 (0)