Skip to content

Commit 5b49b8e

Browse files
committed
Remove unnecessary closure in favour of just passing the argument directly
1 parent fcba8d3 commit 5b49b8e

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

compiler/rustc_infer/src/infer/opaque_types.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
8686
if !matches!(a.kind(), ty::Opaque(..)) {
8787
return None;
8888
}
89-
self.fold_opaque_ty_new(a, cause.clone(), param_env, |_, _| b)
89+
self.fold_opaque_ty_new(a, cause.clone(), param_env, b)
9090
};
9191
if let Some(res) = process(a, b) {
9292
res
@@ -482,10 +482,10 @@ impl UseKind {
482482
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
483483
fn fold_opaque_ty_new(
484484
&self,
485-
ty: Ty<'tcx>,
485+
opaque_type: Ty<'tcx>,
486486
cause: ObligationCause<'tcx>,
487487
param_env: ty::ParamEnv<'tcx>,
488-
mk_ty: impl FnOnce(&InferCtxt<'_, 'tcx>, Span) -> Ty<'tcx>,
488+
hidden_ty: Ty<'tcx>,
489489
) -> Option<InferResult<'tcx, ()>> {
490490
// Check that this is `impl Trait` type is
491491
// declared by `parent_def_id` -- i.e., one whose
@@ -521,30 +521,35 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
521521
// let x = || foo(); // returns the Opaque assoc with `foo`
522522
// }
523523
// ```
524-
let opaque_type_key = ty.expect_opaque_type();
524+
let opaque_type_key = opaque_type.expect_opaque_type();
525525
if let Some(origin) = self.opaque_type_origin(opaque_type_key.def_id, cause.span) {
526-
return Some(self.fold_opaque_ty(ty, cause, param_env, opaque_type_key, origin, mk_ty));
526+
return Some(self.fold_opaque_ty(
527+
opaque_type,
528+
cause,
529+
param_env,
530+
opaque_type_key,
531+
origin,
532+
hidden_ty,
533+
));
527534
}
528535

529-
debug!(?ty, "encountered opaque outside its definition scope",);
536+
debug!(?opaque_type, "encountered opaque outside its definition scope",);
530537
None
531538
}
532539

533-
#[instrument(skip(self, mk_ty), level = "debug")]
540+
#[instrument(skip(self), level = "debug")]
534541
fn fold_opaque_ty(
535542
&self,
536-
ty: Ty<'tcx>,
543+
opaque_type: Ty<'tcx>,
537544
cause: ObligationCause<'tcx>,
538545
param_env: ty::ParamEnv<'tcx>,
539546
opaque_type_key: OpaqueTypeKey<'tcx>,
540547
origin: hir::OpaqueTyOrigin,
541-
mk_ty: impl FnOnce(&InferCtxt<'_, 'tcx>, Span) -> Ty<'tcx>,
548+
hidden_ty: Ty<'tcx>,
542549
) -> InferResult<'tcx, ()> {
543550
let tcx = self.tcx;
544551
let OpaqueTypeKey { def_id, substs } = opaque_type_key;
545552

546-
let ty_var = mk_ty(self, cause.span);
547-
548553
// Ideally, we'd get the span where *this specific `ty` came
549554
// from*, but right now we just use the span from the overall
550555
// value being folded. In simple cases like `-> impl Foo`,
@@ -555,16 +560,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
555560
let mut obligations = vec![];
556561
let prev = self.inner.borrow_mut().opaque_types().register(
557562
OpaqueTypeKey { def_id, substs },
558-
ty,
559-
OpaqueHiddenType { ty: ty_var, span },
563+
opaque_type,
564+
OpaqueHiddenType { ty: hidden_ty, span },
560565
origin,
561566
);
562567
if let Some(prev) = prev {
563-
obligations = self.at(&cause, param_env).eq(prev, ty_var)?.obligations;
568+
obligations = self.at(&cause, param_env).eq(prev, hidden_ty)?.obligations;
564569
}
565570

566-
debug!("generated new type inference var {:?}", ty_var.kind());
567-
568571
let item_bounds = tcx.explicit_item_bounds(def_id);
569572

570573
for (predicate, _) in item_bounds {
@@ -586,7 +589,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
586589
// Replace all other mentions of the same opaque type with the hidden type,
587590
// as the bounds must hold on the hidden type after all.
588591
ty::Opaque(def_id2, substs2) if def_id == def_id2 && substs == substs2 => {
589-
ty_var
592+
hidden_ty
590593
}
591594
_ => ty,
592595
},

0 commit comments

Comments
 (0)