Skip to content

Commit 7124532

Browse files
committed
Fn-trait goals, eagerly instantiate binder
to avoid overflow from proving `for<'a> opaque<'a>: Sized`
1 parent 7af913f commit 7124532

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -452,22 +452,21 @@ where
452452
}
453453
};
454454

455+
let (inputs, output) = ecx.instantiate_binder_with_infer(tupled_inputs_and_output);
455456
// A built-in `Fn` impl only holds if the output is sized.
456457
// (FIXME: technically we only need to check this if the type is a fn ptr...)
457-
let output_is_sized_pred = tupled_inputs_and_output.map_bound(|(_, output)| {
458-
ty::TraitRef::new(cx, cx.require_trait_lang_item(SolverTraitLangItem::Sized), [output])
459-
});
458+
let output_is_sized_pred =
459+
ty::TraitRef::new(cx, cx.require_trait_lang_item(SolverTraitLangItem::Sized), [output]);
460460

461-
let pred = tupled_inputs_and_output
462-
.map_bound(|(inputs, output)| ty::ProjectionPredicate {
463-
projection_term: ty::AliasTerm::new(
464-
cx,
465-
goal.predicate.def_id(),
466-
[goal.predicate.self_ty(), inputs],
467-
),
468-
term: output.into(),
469-
})
470-
.upcast(cx);
461+
let pred = ty::ProjectionPredicate {
462+
projection_term: ty::AliasTerm::new(
463+
cx,
464+
goal.predicate.def_id(),
465+
[goal.predicate.self_ty(), inputs],
466+
),
467+
term: output.into(),
468+
}
469+
.upcast(cx);
471470

472471
Self::probe_and_consider_implied_clause(
473472
ecx,

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -370,17 +370,16 @@ where
370370
}
371371
};
372372

373+
let (inputs, output) = ecx.instantiate_binder_with_infer(tupled_inputs_and_output);
374+
373375
// A built-in `Fn` impl only holds if the output is sized.
374376
// (FIXME: technically we only need to check this if the type is a fn ptr...)
375-
let output_is_sized_pred = tupled_inputs_and_output.map_bound(|(_, output)| {
376-
ty::TraitRef::new(cx, cx.require_trait_lang_item(SolverTraitLangItem::Sized), [output])
377-
});
377+
let output_is_sized_pred =
378+
ty::TraitRef::new(cx, cx.require_trait_lang_item(SolverTraitLangItem::Sized), [output]);
378379

379-
let pred = tupled_inputs_and_output
380-
.map_bound(|(inputs, _)| {
381-
ty::TraitRef::new(cx, goal.predicate.def_id(), [goal.predicate.self_ty(), inputs])
382-
})
383-
.upcast(cx);
380+
let pred =
381+
ty::TraitRef::new(cx, goal.predicate.def_id(), [goal.predicate.self_ty(), inputs])
382+
.upcast(cx);
384383
Self::probe_and_consider_implied_clause(
385384
ecx,
386385
CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),

0 commit comments

Comments
 (0)