Skip to content

Commit da1e6a8

Browse files
Yeet QueryTypeRelatingDelegate
1 parent f8131a4 commit da1e6a8

File tree

3 files changed

+18
-106
lines changed

3 files changed

+18
-106
lines changed

Diff for: compiler/rustc_borrowck/src/type_check/relate_tys.rs

-4
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,6 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
164164
);
165165
}
166166

167-
fn forbid_inference_vars() -> bool {
168-
true
169-
}
170-
171167
fn register_obligations(&mut self, obligations: PredicateObligations<'tcx>) {
172168
let _: Result<_, ErrorGuaranteed> = self.type_checker.fully_perform_op(
173169
self.locations,

Diff for: compiler/rustc_infer/src/infer/canonical/query_response.rs

+13-85
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@ use crate::infer::canonical::{
1212
Canonical, CanonicalQueryResponse, CanonicalVarValues, Certainty, OriginalQueryValues,
1313
QueryOutlivesConstraint, QueryRegionConstraints, QueryResponse,
1414
};
15-
use crate::infer::nll_relate::{TypeRelating, TypeRelatingDelegate};
1615
use crate::infer::region_constraints::{Constraint, RegionConstraintData};
17-
use crate::infer::{DefineOpaqueTypes, InferCtxt, InferOk, InferResult, NllRegionVariableOrigin};
16+
use crate::infer::{DefineOpaqueTypes, InferCtxt, InferOk, InferResult};
1817
use crate::traits::query::NoSolution;
1918
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
20-
use crate::traits::{PredicateObligations, TraitEngine, TraitEngineExt};
19+
use crate::traits::{TraitEngine, TraitEngineExt};
2120
use rustc_data_structures::captures::Captures;
2221
use rustc_index::Idx;
2322
use rustc_index::IndexVec;
2423
use rustc_middle::arena::ArenaAllocatable;
2524
use rustc_middle::mir::ConstraintCategory;
2625
use rustc_middle::ty::fold::TypeFoldable;
27-
use rustc_middle::ty::relate::TypeRelation;
28-
use rustc_middle::ty::{self, BoundVar, ToPredicate, Ty, TyCtxt};
26+
use rustc_middle::ty::{self, BoundVar, Ty, TyCtxt};
2927
use rustc_middle::ty::{GenericArg, GenericArgKind};
30-
use rustc_span::{Span, Symbol};
3128
use std::fmt::Debug;
3229
use std::iter;
3330

@@ -290,31 +287,19 @@ impl<'tcx> InferCtxt<'tcx> {
290287
}
291288

292289
(GenericArgKind::Type(v1), GenericArgKind::Type(v2)) => {
293-
TypeRelating::new(
294-
self,
295-
QueryTypeRelatingDelegate {
296-
infcx: self,
297-
param_env,
298-
cause,
299-
obligations: &mut obligations,
300-
},
301-
ty::Variance::Invariant,
302-
)
303-
.relate(v1, v2)?;
290+
obligations.extend(
291+
self.at(&cause, param_env)
292+
.eq(DefineOpaqueTypes::Yes, v1, v2)?
293+
.into_obligations(),
294+
);
304295
}
305296

306297
(GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {
307-
TypeRelating::new(
308-
self,
309-
QueryTypeRelatingDelegate {
310-
infcx: self,
311-
param_env,
312-
cause,
313-
obligations: &mut obligations,
314-
},
315-
ty::Variance::Invariant,
316-
)
317-
.relate(v1, v2)?;
298+
obligations.extend(
299+
self.at(&cause, param_env)
300+
.eq(DefineOpaqueTypes::Yes, v1, v2)?
301+
.into_obligations(),
302+
);
318303
}
319304

320305
_ => {
@@ -697,60 +682,3 @@ pub fn make_query_region_constraints<'tcx>(
697682

698683
QueryRegionConstraints { outlives, member_constraints: member_constraints.clone() }
699684
}
700-
701-
struct QueryTypeRelatingDelegate<'a, 'tcx> {
702-
infcx: &'a InferCtxt<'tcx>,
703-
obligations: &'a mut Vec<PredicateObligation<'tcx>>,
704-
param_env: ty::ParamEnv<'tcx>,
705-
cause: &'a ObligationCause<'tcx>,
706-
}
707-
708-
impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
709-
fn span(&self) -> Span {
710-
self.cause.span
711-
}
712-
713-
fn param_env(&self) -> ty::ParamEnv<'tcx> {
714-
self.param_env
715-
}
716-
717-
fn create_next_universe(&mut self) -> ty::UniverseIndex {
718-
self.infcx.create_next_universe()
719-
}
720-
721-
fn next_existential_region_var(
722-
&mut self,
723-
from_forall: bool,
724-
_name: Option<Symbol>,
725-
) -> ty::Region<'tcx> {
726-
let origin = NllRegionVariableOrigin::Existential { from_forall };
727-
self.infcx.next_nll_region_var(origin)
728-
}
729-
730-
fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx> {
731-
ty::Region::new_placeholder(self.infcx.tcx, placeholder)
732-
}
733-
734-
fn push_outlives(
735-
&mut self,
736-
sup: ty::Region<'tcx>,
737-
sub: ty::Region<'tcx>,
738-
_info: ty::VarianceDiagInfo<'tcx>,
739-
) {
740-
self.obligations.push(Obligation {
741-
cause: self.cause.clone(),
742-
param_env: self.param_env,
743-
predicate: ty::ClauseKind::RegionOutlives(ty::OutlivesPredicate(sup, sub))
744-
.to_predicate(self.infcx.tcx),
745-
recursion_depth: 0,
746-
});
747-
}
748-
749-
fn forbid_inference_vars() -> bool {
750-
true
751-
}
752-
753-
fn register_obligations(&mut self, obligations: PredicateObligations<'tcx>) {
754-
self.obligations.extend(obligations);
755-
}
756-
}

Diff for: compiler/rustc_infer/src/infer/relate/nll.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,6 @@ pub trait TypeRelatingDelegate<'tcx> {
9696
/// we will invoke this method to instantiate `'b` with a
9797
/// placeholder region.
9898
fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx>;
99-
100-
/// Enables some optimizations if we do not expect inference variables
101-
/// in the RHS of the relation.
102-
fn forbid_inference_vars() -> bool;
10399
}
104100

105101
impl<'me, 'tcx, D> TypeRelating<'me, 'tcx, D>
@@ -316,16 +312,11 @@ where
316312
}
317313

318314
#[instrument(skip(self), level = "debug")]
319-
fn tys(&mut self, a: Ty<'tcx>, mut b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
315+
fn tys(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
320316
let infcx = self.infcx;
321317

322318
let a = self.infcx.shallow_resolve(a);
323-
324-
if !D::forbid_inference_vars() {
325-
b = self.infcx.shallow_resolve(b);
326-
} else {
327-
assert!(!b.has_non_region_infer(), "unexpected inference var {:?}", b);
328-
}
319+
assert!(!b.has_non_region_infer(), "unexpected inference var {:?}", b);
329320

330321
if a == b {
331322
return Ok(a);
@@ -409,16 +400,13 @@ where
409400
fn consts(
410401
&mut self,
411402
a: ty::Const<'tcx>,
412-
mut b: ty::Const<'tcx>,
403+
b: ty::Const<'tcx>,
413404
) -> RelateResult<'tcx, ty::Const<'tcx>> {
414405
let a = self.infcx.shallow_resolve(a);
415-
416-
if !D::forbid_inference_vars() {
417-
b = self.infcx.shallow_resolve(b);
418-
}
406+
assert!(!b.has_non_region_infer(), "unexpected inference var {:?}", b);
419407

420408
match b.kind() {
421-
ty::ConstKind::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => {
409+
ty::ConstKind::Infer(InferConst::Var(_)) => {
422410
// Forbid inference variables in the RHS.
423411
self.infcx
424412
.dcx()

0 commit comments

Comments
 (0)