|
20 | 20 | use std::mem;
|
21 | 21 |
|
22 | 22 | use rustc_hir::def_id::DefId;
|
| 23 | +use rustc_hir::CRATE_HIR_ID; |
23 | 24 | use rustc_infer::infer::canonical::{Canonical, CanonicalVarKind, CanonicalVarValues};
|
24 | 25 | use rustc_infer::infer::canonical::{OriginalQueryValues, QueryRegionConstraints, QueryResponse};
|
25 | 26 | use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
|
@@ -277,12 +278,15 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
|
277 | 278 | param_env,
|
278 | 279 | predicate: (def_id, substs, kind),
|
279 | 280 | }),
|
| 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 | + } |
280 | 287 | ty::PredicateKind::Ambiguous => self.make_canonical_response(Certainty::AMBIGUOUS),
|
281 | 288 | // 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(_, _) => { |
286 | 290 | self.make_canonical_response(Certainty::Yes)
|
287 | 291 | }
|
288 | 292 | ty::PredicateKind::TypeWellFormedFromEnv(..) => {
|
@@ -362,6 +366,35 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
|
362 | 366 | Err(NoSolution)
|
363 | 367 | }
|
364 | 368 | }
|
| 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 | + } |
365 | 398 | }
|
366 | 399 |
|
367 | 400 | impl<'tcx> EvalCtxt<'_, 'tcx> {
|
|
0 commit comments