Assemble object bound candidates
This commit is contained in:
parent
f99b273d57
commit
3d87a8e848
1 changed files with 52 additions and 0 deletions
|
@ -4,6 +4,7 @@ use super::infcx_ext::InferCtxtExt;
|
||||||
use super::{CanonicalResponse, EvalCtxt, Goal, QueryResult};
|
use super::{CanonicalResponse, EvalCtxt, Goal, QueryResult};
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_infer::traits::query::NoSolution;
|
use rustc_infer::traits::query::NoSolution;
|
||||||
|
use rustc_infer::traits::util::elaborate_predicates;
|
||||||
use rustc_middle::ty::TypeFoldable;
|
use rustc_middle::ty::TypeFoldable;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
|
@ -119,6 +120,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
||||||
|
|
||||||
self.assemble_alias_bound_candidates(goal, &mut candidates);
|
self.assemble_alias_bound_candidates(goal, &mut candidates);
|
||||||
|
|
||||||
|
self.assemble_object_bound_candidates(goal, &mut candidates);
|
||||||
|
|
||||||
candidates
|
candidates
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,4 +275,53 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn assemble_object_bound_candidates<G: GoalKind<'tcx>>(
|
||||||
|
&mut self,
|
||||||
|
goal: Goal<'tcx, G>,
|
||||||
|
candidates: &mut Vec<Candidate<'tcx>>,
|
||||||
|
) {
|
||||||
|
let self_ty = goal.predicate.self_ty();
|
||||||
|
let bounds = match *self_ty.kind() {
|
||||||
|
ty::Bool
|
||||||
|
| ty::Char
|
||||||
|
| ty::Int(_)
|
||||||
|
| ty::Uint(_)
|
||||||
|
| ty::Float(_)
|
||||||
|
| ty::Adt(_, _)
|
||||||
|
| ty::Foreign(_)
|
||||||
|
| ty::Str
|
||||||
|
| ty::Array(_, _)
|
||||||
|
| ty::Slice(_)
|
||||||
|
| ty::RawPtr(_)
|
||||||
|
| ty::Ref(_, _, _)
|
||||||
|
| ty::FnDef(_, _)
|
||||||
|
| ty::FnPtr(_)
|
||||||
|
| ty::Alias(..)
|
||||||
|
| ty::Closure(..)
|
||||||
|
| ty::Generator(..)
|
||||||
|
| ty::GeneratorWitness(_)
|
||||||
|
| ty::Never
|
||||||
|
| ty::Tuple(_)
|
||||||
|
| ty::Param(_)
|
||||||
|
| ty::Placeholder(..)
|
||||||
|
| ty::Infer(_)
|
||||||
|
| ty::Error(_) => return,
|
||||||
|
ty::Bound(..) => bug!("unexpected bound type: {goal:?}"),
|
||||||
|
ty::Dynamic(bounds, ..) => bounds,
|
||||||
|
};
|
||||||
|
|
||||||
|
let tcx = self.tcx();
|
||||||
|
for assumption in
|
||||||
|
elaborate_predicates(tcx, bounds.iter().map(|bound| bound.with_self_ty(tcx, self_ty)))
|
||||||
|
{
|
||||||
|
match G::consider_assumption(self, goal, assumption.predicate)
|
||||||
|
{
|
||||||
|
Ok(result) => {
|
||||||
|
candidates.push(Candidate { source: CandidateSource::BuiltinImpl, result })
|
||||||
|
}
|
||||||
|
Err(NoSolution) => (),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue