Remove unnecessary closure in favour of just passing the argument directly

This commit is contained in:
Oli Scherer 2022-01-27 14:45:15 +00:00
parent fcba8d31c4
commit 5b49b8e2d5

View file

@ -86,7 +86,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
if !matches!(a.kind(), ty::Opaque(..)) { if !matches!(a.kind(), ty::Opaque(..)) {
return None; return None;
} }
self.fold_opaque_ty_new(a, cause.clone(), param_env, |_, _| b) self.fold_opaque_ty_new(a, cause.clone(), param_env, b)
}; };
if let Some(res) = process(a, b) { if let Some(res) = process(a, b) {
res res
@ -482,10 +482,10 @@ impl UseKind {
impl<'a, 'tcx> InferCtxt<'a, 'tcx> { impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
fn fold_opaque_ty_new( fn fold_opaque_ty_new(
&self, &self,
ty: Ty<'tcx>, opaque_type: Ty<'tcx>,
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
mk_ty: impl FnOnce(&InferCtxt<'_, 'tcx>, Span) -> Ty<'tcx>, hidden_ty: Ty<'tcx>,
) -> Option<InferResult<'tcx, ()>> { ) -> Option<InferResult<'tcx, ()>> {
// Check that this is `impl Trait` type is // Check that this is `impl Trait` type is
// declared by `parent_def_id` -- i.e., one whose // declared by `parent_def_id` -- i.e., one whose
@ -521,30 +521,35 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// let x = || foo(); // returns the Opaque assoc with `foo` // let x = || foo(); // returns the Opaque assoc with `foo`
// } // }
// ``` // ```
let opaque_type_key = ty.expect_opaque_type(); let opaque_type_key = opaque_type.expect_opaque_type();
if let Some(origin) = self.opaque_type_origin(opaque_type_key.def_id, cause.span) { if let Some(origin) = self.opaque_type_origin(opaque_type_key.def_id, cause.span) {
return Some(self.fold_opaque_ty(ty, cause, param_env, opaque_type_key, origin, mk_ty)); return Some(self.fold_opaque_ty(
opaque_type,
cause,
param_env,
opaque_type_key,
origin,
hidden_ty,
));
} }
debug!(?ty, "encountered opaque outside its definition scope",); debug!(?opaque_type, "encountered opaque outside its definition scope",);
None None
} }
#[instrument(skip(self, mk_ty), level = "debug")] #[instrument(skip(self), level = "debug")]
fn fold_opaque_ty( fn fold_opaque_ty(
&self, &self,
ty: Ty<'tcx>, opaque_type: Ty<'tcx>,
cause: ObligationCause<'tcx>, cause: ObligationCause<'tcx>,
param_env: ty::ParamEnv<'tcx>, param_env: ty::ParamEnv<'tcx>,
opaque_type_key: OpaqueTypeKey<'tcx>, opaque_type_key: OpaqueTypeKey<'tcx>,
origin: hir::OpaqueTyOrigin, origin: hir::OpaqueTyOrigin,
mk_ty: impl FnOnce(&InferCtxt<'_, 'tcx>, Span) -> Ty<'tcx>, hidden_ty: Ty<'tcx>,
) -> InferResult<'tcx, ()> { ) -> InferResult<'tcx, ()> {
let tcx = self.tcx; let tcx = self.tcx;
let OpaqueTypeKey { def_id, substs } = opaque_type_key; let OpaqueTypeKey { def_id, substs } = opaque_type_key;
let ty_var = mk_ty(self, cause.span);
// Ideally, we'd get the span where *this specific `ty` came // Ideally, we'd get the span where *this specific `ty` came
// from*, but right now we just use the span from the overall // from*, but right now we just use the span from the overall
// value being folded. In simple cases like `-> impl Foo`, // value being folded. In simple cases like `-> impl Foo`,
@ -555,16 +560,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let mut obligations = vec![]; let mut obligations = vec![];
let prev = self.inner.borrow_mut().opaque_types().register( let prev = self.inner.borrow_mut().opaque_types().register(
OpaqueTypeKey { def_id, substs }, OpaqueTypeKey { def_id, substs },
ty, opaque_type,
OpaqueHiddenType { ty: ty_var, span }, OpaqueHiddenType { ty: hidden_ty, span },
origin, origin,
); );
if let Some(prev) = prev { if let Some(prev) = prev {
obligations = self.at(&cause, param_env).eq(prev, ty_var)?.obligations; obligations = self.at(&cause, param_env).eq(prev, hidden_ty)?.obligations;
} }
debug!("generated new type inference var {:?}", ty_var.kind());
let item_bounds = tcx.explicit_item_bounds(def_id); let item_bounds = tcx.explicit_item_bounds(def_id);
for (predicate, _) in item_bounds { for (predicate, _) in item_bounds {
@ -586,7 +589,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// Replace all other mentions of the same opaque type with the hidden type, // Replace all other mentions of the same opaque type with the hidden type,
// as the bounds must hold on the hidden type after all. // as the bounds must hold on the hidden type after all.
ty::Opaque(def_id2, substs2) if def_id == def_id2 && substs == substs2 => { ty::Opaque(def_id2, substs2) if def_id == def_id2 && substs == substs2 => {
ty_var hidden_ty
} }
_ => ty, _ => ty,
}, },