Skip to content

Commit 9a33b59

Browse files
committed
minimal
1 parent 104cb87 commit 9a33b59

File tree

3 files changed

+44
-78
lines changed

3 files changed

+44
-78
lines changed

src/librustc_middle/ty/context.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ use crate::ty::TyKind::*;
1919
use crate::ty::{
2020
self, query, AdtDef, AdtKind, BindingMode, BoundVar, CanonicalPolyFnSig, Const, ConstVid,
2121
DefIdTree, ExistentialPredicate, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy,
22-
IntVar, IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateInner, PredicateKint,
23-
ProjectionTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar,
24-
TyVid, TypeAndMut,
22+
IntVar, IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateInner, PredicateKind,
23+
PredicateKint, ProjectionTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind,
24+
TyS, TyVar, TyVid, TypeAndMut,
2525
};
2626
use rustc_ast::ast;
2727
use rustc_ast::expand::allocator::AllocatorKind;
@@ -2030,12 +2030,6 @@ impl<'tcx> Borrow<Const<'tcx>> for Interned<'tcx, Const<'tcx>> {
20302030
}
20312031
}
20322032

2033-
impl<'tcx> Borrow<PredicateKind<'tcx>> for Interned<'tcx, PredicateKind<'tcx>> {
2034-
fn borrow<'a>(&'a self) -> &'a PredicateKind<'tcx> {
2035-
&self.0
2036-
}
2037-
}
2038-
20392033
impl<'tcx> Borrow<PredicateKint<'tcx>> for Interned<'tcx, PredicateKint<'tcx>> {
20402034
fn borrow<'a>(&'a self) -> &'a PredicateKint<'tcx> {
20412035
&self.0

src/librustc_middle/ty/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,9 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for Predicate<'tcx> {
10631063

10641064
kind.hash_stable(hcx, hasher);
10651065
}
1066+
}
10661067

1068+
impl<'tcx> Predicate<'tcx> {
10671069
pub fn kint(self, tcx: TyCtxt<'tcx>) -> &'tcx PredicateKint<'tcx> {
10681070
// I am efficient
10691071
tcx.intern_predicate_kint(match *self.kind() {

src/librustc_trait_selection/traits/fulfill.rs

Lines changed: 39 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::ErrorReported;
66
use rustc_infer::traits::{TraitEngine, TraitEngineExt as _};
77
use rustc_middle::mir::interpret::ErrorHandled;
88
use rustc_middle::ty::error::ExpectedFound;
9-
use rustc_middle::ty::{self, Const, ToPolyTraitRef, Ty, TypeFoldable};
9+
use rustc_middle::ty::{self, Binder, Const, ToPredicate, Ty, TypeFoldable};
1010
use std::marker::PhantomData;
1111

1212
use super::project;
@@ -317,9 +317,15 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
317317

318318
let infcx = self.selcx.infcx();
319319

320-
match obligation.predicate.kind() {
321-
ty::PredicateKind::Trait(ref data, _) => {
322-
let trait_obligation = obligation.with(*data);
320+
match obligation.predicate.kint(infcx.tcx) {
321+
ty::PredicateKint::ForAll(binder) => {
322+
let (pred, _) = infcx.replace_bound_vars_with_placeholders(binder);
323+
ProcessResult::Changed(mk_pending(vec![
324+
obligation.with(pred.to_predicate(infcx.tcx)),
325+
]))
326+
}
327+
ty::PredicateKint::Trait(ref data, _) => {
328+
let trait_obligation = obligation.with(Binder::dummy(*data));
323329

324330
if obligation.predicate.is_global() {
325331
// no type variables present, can use evaluation for better caching.
@@ -352,7 +358,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
352358
// trait selection is because we don't have enough
353359
// information about the types in the trait.
354360
pending_obligation.stalled_on =
355-
trait_ref_infer_vars(self.selcx, data.to_poly_trait_ref());
361+
trait_ref_infer_vars(self.selcx, data.trait_ref);
356362

357363
debug!(
358364
"process_predicate: pending obligation {:?} now stalled on {:?}",
@@ -373,80 +379,48 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
373379
}
374380
}
375381

376-
&ty::PredicateKind::RegionOutlives(binder) => {
377-
match infcx.region_outlives_predicate(&obligation.cause, binder) {
382+
&ty::PredicateKint::RegionOutlives(data) => {
383+
match infcx.region_outlives_predicate(&obligation.cause, Binder::dummy(data)) {
378384
Ok(()) => ProcessResult::Changed(vec![]),
379385
Err(_) => ProcessResult::Error(CodeSelectionError(Unimplemented)),
380386
}
381387
}
382388

383-
ty::PredicateKind::TypeOutlives(ref binder) => {
384-
// Check if there are higher-ranked vars.
385-
match binder.no_bound_vars() {
386-
// If there are, inspect the underlying type further.
387-
None => {
388-
// Convert from `Binder<OutlivesPredicate<Ty, Region>>` to `Binder<Ty>`.
389-
let binder = binder.map_bound_ref(|pred| pred.0);
390-
391-
// Check if the type has any bound vars.
392-
match binder.no_bound_vars() {
393-
// If so, this obligation is an error (for now). Eventually we should be
394-
// able to support additional cases here, like `for<'a> &'a str: 'a`.
395-
// NOTE: this is duplicate-implemented between here and fulfillment.
396-
None => ProcessResult::Error(CodeSelectionError(Unimplemented)),
397-
// Otherwise, we have something of the form
398-
// `for<'a> T: 'a where 'a not in T`, which we can treat as
399-
// `T: 'static`.
400-
Some(t_a) => {
401-
let r_static = self.selcx.tcx().lifetimes.re_static;
402-
if self.register_region_obligations {
403-
self.selcx.infcx().register_region_obligation_with_cause(
404-
t_a,
405-
r_static,
406-
&obligation.cause,
407-
);
408-
}
409-
ProcessResult::Changed(vec![])
410-
}
411-
}
412-
}
413-
// If there aren't, register the obligation.
414-
Some(ty::OutlivesPredicate(t_a, r_b)) => {
415-
if self.register_region_obligations {
416-
self.selcx.infcx().register_region_obligation_with_cause(
417-
t_a,
418-
r_b,
419-
&obligation.cause,
420-
);
421-
}
422-
ProcessResult::Changed(vec![])
423-
}
389+
ty::PredicateKint::TypeOutlives(ty::OutlivesPredicate(t_a, r_b)) => {
390+
if self.register_region_obligations {
391+
self.selcx.infcx().register_region_obligation_with_cause(
392+
t_a,
393+
r_b,
394+
&obligation.cause,
395+
);
424396
}
397+
ProcessResult::Changed(vec![])
425398
}
426399

427-
ty::PredicateKind::Projection(ref data) => {
428-
let project_obligation = obligation.with(*data);
400+
ty::PredicateKint::Projection(ref data) => {
401+
let project_obligation = obligation.with(Binder::dummy(*data));
429402
match project::poly_project_and_unify_type(self.selcx, &project_obligation) {
430403
Ok(None) => {
431-
let tcx = self.selcx.tcx();
432-
pending_obligation.stalled_on =
433-
trait_ref_infer_vars(self.selcx, data.to_poly_trait_ref(tcx));
404+
pending_obligation.stalled_on = trait_ref_infer_vars(
405+
self.selcx,
406+
data.projection_ty.trait_ref(infcx.tcx),
407+
);
434408
ProcessResult::Unchanged
435409
}
436410
Ok(Some(os)) => ProcessResult::Changed(mk_pending(os)),
437411
Err(e) => ProcessResult::Error(CodeProjectionError(e)),
438412
}
439413
}
440414

441-
&ty::PredicateKind::ObjectSafe(trait_def_id) => {
415+
&ty::PredicateKint::ObjectSafe(trait_def_id) => {
442416
if !self.selcx.tcx().is_object_safe(trait_def_id) {
443417
ProcessResult::Error(CodeSelectionError(Unimplemented))
444418
} else {
445419
ProcessResult::Changed(vec![])
446420
}
447421
}
448422

449-
&ty::PredicateKind::ClosureKind(_, closure_substs, kind) => {
423+
&ty::PredicateKint::ClosureKind(_, closure_substs, kind) => {
450424
match self.selcx.infcx().closure_kind(closure_substs) {
451425
Some(closure_kind) => {
452426
if closure_kind.extends(kind) {
@@ -459,7 +433,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
459433
}
460434
}
461435

462-
&ty::PredicateKind::WellFormed(arg) => {
436+
&ty::PredicateKint::WellFormed(arg) => {
463437
match wf::obligations(
464438
self.selcx.infcx(),
465439
obligation.param_env,
@@ -476,27 +450,24 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
476450
}
477451
}
478452

479-
&ty::PredicateKind::Subtype(subtype) => {
453+
&ty::PredicateKint::Subtype(subtype) => {
480454
match self.selcx.infcx().subtype_predicate(
481455
&obligation.cause,
482456
obligation.param_env,
483-
subtype,
457+
Binder::dummy(subtype),
484458
) {
485459
None => {
486460
// None means that both are unresolved.
487461
pending_obligation.stalled_on = vec![
488-
TyOrConstInferVar::maybe_from_ty(subtype.skip_binder().a).unwrap(),
489-
TyOrConstInferVar::maybe_from_ty(subtype.skip_binder().b).unwrap(),
462+
TyOrConstInferVar::maybe_from_ty(subtype.a).unwrap(),
463+
TyOrConstInferVar::maybe_from_ty(subtype.b).unwrap(),
490464
];
491465
ProcessResult::Unchanged
492466
}
493467
Some(Ok(ok)) => ProcessResult::Changed(mk_pending(ok.obligations)),
494468
Some(Err(err)) => {
495-
let expected_found = ExpectedFound::new(
496-
subtype.skip_binder().a_is_expected,
497-
subtype.skip_binder().a,
498-
subtype.skip_binder().b,
499-
);
469+
let expected_found =
470+
ExpectedFound::new(subtype.a_is_expected, subtype.a, subtype.b);
500471
ProcessResult::Error(FulfillmentErrorCode::CodeSubtypeError(
501472
expected_found,
502473
err,
@@ -505,7 +476,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
505476
}
506477
}
507478

508-
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
479+
&ty::PredicateKint::ConstEvaluatable(def_id, substs) => {
509480
match self.selcx.infcx().const_eval_resolve(
510481
obligation.param_env,
511482
def_id,
@@ -518,7 +489,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
518489
}
519490
}
520491

521-
ty::PredicateKind::ConstEquate(c1, c2) => {
492+
ty::PredicateKint::ConstEquate(c1, c2) => {
522493
debug!("equating consts: c1={:?} c2={:?}", c1, c2);
523494

524495
let stalled_on = &mut pending_obligation.stalled_on;
@@ -601,12 +572,11 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
601572
/// Returns the set of inference variables contained in a trait ref.
602573
fn trait_ref_infer_vars<'a, 'tcx>(
603574
selcx: &mut SelectionContext<'a, 'tcx>,
604-
trait_ref: ty::PolyTraitRef<'tcx>,
575+
trait_ref: ty::TraitRef<'tcx>,
605576
) -> Vec<TyOrConstInferVar<'tcx>> {
606577
selcx
607578
.infcx()
608579
.resolve_vars_if_possible(&trait_ref)
609-
.skip_binder() // ok b/c this check doesn't care about regions
610580
.substs
611581
.iter()
612582
// FIXME(eddyb) try using `skip_current_subtree` to skip everything that

0 commit comments

Comments
 (0)