1
Fork 0

Implement unsizing in the new trait solver

This commit is contained in:
Michael Goulet 2023-01-23 22:33:59 +00:00
parent 006ca9b14d
commit 085a48e798
4 changed files with 217 additions and 0 deletions

View file

@ -173,6 +173,14 @@ pub(super) trait GoalKind<'tcx>: TypeFoldable<'tcx> + Copy + Eq {
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
) -> QueryResult<'tcx>;
// Implement unsizing. The most common forms of unsizing are array to slice,
// and concrete (Sized) type into a `dyn Trait`. ADTs and Tuples can also
// have their final field unsized if it's generic.
fn consider_builtin_unsize_candidate(
ecx: &mut EvalCtxt<'_, 'tcx>,
goal: Goal<'tcx, Self>,
) -> QueryResult<'tcx>;
}
impl<'tcx> EvalCtxt<'_, 'tcx> {
@ -303,6 +311,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
G::consider_builtin_future_candidate(self, goal)
} else if lang_items.gen_trait() == Some(trait_def_id) {
G::consider_builtin_generator_candidate(self, goal)
} else if lang_items.unsize_trait() == Some(trait_def_id) {
G::consider_builtin_unsize_candidate(self, goal)
} else {
Err(NoSolution)
};