Skip to content

Commit b3f0085

Browse files
Implement ObjectSafe and WF in the new solver
1 parent 027c850 commit b3f0085

File tree

1 file changed

+37
-4
lines changed
  • compiler/rustc_trait_selection/src/solve

1 file changed

+37
-4
lines changed

compiler/rustc_trait_selection/src/solve/mod.rs

+37-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use std::mem;
2121

2222
use rustc_hir::def_id::DefId;
23+
use rustc_hir::CRATE_HIR_ID;
2324
use rustc_infer::infer::canonical::{Canonical, CanonicalVarKind, CanonicalVarValues};
2425
use rustc_infer::infer::canonical::{OriginalQueryValues, QueryRegionConstraints, QueryResponse};
2526
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
@@ -277,12 +278,15 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
277278
param_env,
278279
predicate: (def_id, substs, kind),
279280
}),
281+
ty::PredicateKind::ObjectSafe(trait_def_id) => {
282+
self.compute_object_safe_goal(trait_def_id)
283+
}
284+
ty::PredicateKind::WellFormed(arg) => {
285+
self.compute_well_formed_goal(Goal { param_env, predicate: arg })
286+
}
280287
ty::PredicateKind::Ambiguous => self.make_canonical_response(Certainty::AMBIGUOUS),
281288
// FIXME: implement these predicates :)
282-
ty::PredicateKind::WellFormed(_)
283-
| ty::PredicateKind::ObjectSafe(_)
284-
| ty::PredicateKind::ConstEvaluatable(_)
285-
| ty::PredicateKind::ConstEquate(_, _) => {
289+
ty::PredicateKind::ConstEvaluatable(_) | ty::PredicateKind::ConstEquate(_, _) => {
286290
self.make_canonical_response(Certainty::Yes)
287291
}
288292
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
@@ -362,6 +366,35 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
362366
Err(NoSolution)
363367
}
364368
}
369+
370+
fn compute_object_safe_goal(&mut self, trait_def_id: DefId) -> QueryResult<'tcx> {
371+
if self.tcx().is_object_safe(trait_def_id) {
372+
self.make_canonical_response(Certainty::Yes)
373+
} else {
374+
Err(NoSolution)
375+
}
376+
}
377+
378+
fn compute_well_formed_goal(
379+
&mut self,
380+
goal: Goal<'tcx, ty::GenericArg<'tcx>>,
381+
) -> QueryResult<'tcx> {
382+
self.infcx.probe(|_| {
383+
match crate::traits::wf::obligations(
384+
self.infcx,
385+
goal.param_env,
386+
CRATE_HIR_ID, // FIXME body id
387+
0,
388+
goal.predicate,
389+
DUMMY_SP,
390+
) {
391+
Some(obligations) => self.evaluate_all_and_make_canonical_response(
392+
obligations.into_iter().map(|o| o.into()).collect(),
393+
),
394+
None => self.make_canonical_response(Certainty::AMBIGUOUS),
395+
}
396+
})
397+
}
365398
}
366399

367400
impl<'tcx> EvalCtxt<'_, 'tcx> {

0 commit comments

Comments
 (0)