Implement selection in new trait solver
This commit is contained in:
parent
f798ada7ba
commit
298c0d1a62
7 changed files with 356 additions and 21 deletions
|
@ -49,7 +49,7 @@ pub(super) enum CandidateSource {
|
|||
/// Notable examples are auto traits, `Sized`, and `DiscriminantKind`.
|
||||
/// For a list of all traits with builtin impls, check out the
|
||||
/// [`EvalCtxt::assemble_builtin_impl_candidates`] method. Not
|
||||
BuiltinImpl,
|
||||
BuiltinImpl(BuiltinImplSource),
|
||||
/// An assumption from the environment.
|
||||
///
|
||||
/// More precisely we've used the `n-th` assumption in the `param_env`.
|
||||
|
@ -87,6 +87,16 @@ pub(super) enum CandidateSource {
|
|||
AliasBound,
|
||||
}
|
||||
|
||||
/// Records additional information about what kind of built-in impl this is.
|
||||
/// This should only be used by selection.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub(super) enum BuiltinImplSource {
|
||||
TraitUpcasting,
|
||||
Object,
|
||||
Misc,
|
||||
Ambiguity,
|
||||
}
|
||||
|
||||
/// Methods used to assemble candidates for either trait or projection goals.
|
||||
pub(super) trait GoalKind<'tcx>:
|
||||
TypeFoldable<TyCtxt<'tcx>> + Copy + Eq + std::fmt::Display
|
||||
|
@ -295,7 +305,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
// least structurally resolve the type one layer.
|
||||
if goal.predicate.self_ty().is_ty_var() {
|
||||
return vec![Candidate {
|
||||
source: CandidateSource::BuiltinImpl,
|
||||
source: CandidateSource::BuiltinImpl(BuiltinImplSource::Ambiguity),
|
||||
result: self
|
||||
.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
|
||||
.unwrap(),
|
||||
|
@ -344,7 +354,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
let result = ecx.evaluate_added_goals_and_make_canonical_response(
|
||||
Certainty::Maybe(MaybeCause::Overflow),
|
||||
)?;
|
||||
Ok(vec![Candidate { source: CandidateSource::BuiltinImpl, result }])
|
||||
Ok(vec![Candidate {
|
||||
source: CandidateSource::BuiltinImpl(BuiltinImplSource::Ambiguity),
|
||||
result,
|
||||
}])
|
||||
},
|
||||
|ecx| {
|
||||
let normalized_ty = ecx.next_ty_infer();
|
||||
|
@ -447,9 +460,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
};
|
||||
|
||||
match result {
|
||||
Ok(result) => {
|
||||
candidates.push(Candidate { source: CandidateSource::BuiltinImpl, result })
|
||||
}
|
||||
Ok(result) => candidates.push(Candidate {
|
||||
source: CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
|
||||
result,
|
||||
}),
|
||||
Err(NoSolution) => (),
|
||||
}
|
||||
|
||||
|
@ -457,7 +471,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
// `trait Foo: Bar<A> + Bar<B>` and `dyn Foo: Unsize<dyn Bar<_>>`
|
||||
if lang_items.unsize_trait() == Some(trait_def_id) {
|
||||
for result in G::consider_builtin_dyn_upcast_candidates(self, goal) {
|
||||
candidates.push(Candidate { source: CandidateSource::BuiltinImpl, result });
|
||||
candidates.push(Candidate {
|
||||
source: CandidateSource::BuiltinImpl(BuiltinImplSource::TraitUpcasting),
|
||||
result,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -621,9 +638,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
};
|
||||
|
||||
match result {
|
||||
Ok(result) => {
|
||||
candidates.push(Candidate { source: CandidateSource::BuiltinImpl, result })
|
||||
}
|
||||
Ok(result) => candidates.push(Candidate {
|
||||
source: CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
|
||||
result,
|
||||
}),
|
||||
Err(NoSolution) => (),
|
||||
}
|
||||
}
|
||||
|
@ -688,9 +706,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
}
|
||||
|
||||
match G::consider_object_bound_candidate(self, goal, assumption) {
|
||||
Ok(result) => {
|
||||
candidates.push(Candidate { source: CandidateSource::BuiltinImpl, result })
|
||||
}
|
||||
Ok(result) => candidates.push(Candidate {
|
||||
source: CandidateSource::BuiltinImpl(BuiltinImplSource::Object),
|
||||
result,
|
||||
}),
|
||||
Err(NoSolution) => (),
|
||||
}
|
||||
}
|
||||
|
@ -711,8 +730,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|||
Err(_) => match self
|
||||
.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS)
|
||||
{
|
||||
Ok(result) => candidates
|
||||
.push(Candidate { source: CandidateSource::BuiltinImpl, result }),
|
||||
Ok(result) => candidates.push(Candidate {
|
||||
source: CandidateSource::BuiltinImpl(BuiltinImplSource::Ambiguity),
|
||||
result,
|
||||
}),
|
||||
// FIXME: This will be reachable at some point if we're in
|
||||
// `assemble_candidates_after_normalizing_self_ty` and we get a
|
||||
// universe error. We'll deal with it at this point.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue