Skip to content

Commit df7bb96

Browse files
BoxyUwUlcnr
authored andcommitted
review
1 parent b513063 commit df7bb96

12 files changed

Lines changed: 57 additions & 59 deletions

File tree

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,22 +173,24 @@ pub(crate) fn type_check<'tcx>(
173173

174174
let polonius_context = typeck.polonius_context;
175175

176-
let mut converter = constraint_conversion::ConstraintConversion::new(
177-
typeck.infcx,
178-
typeck.universal_regions,
179-
typeck.region_bound_pairs,
180-
typeck.known_type_outlives_obligations,
181-
Locations::All(rustc_span::DUMMY_SP),
182-
rustc_span::DUMMY_SP,
183-
ConstraintCategory::Boring,
184-
typeck.constraints,
185-
);
186-
typeck.infcx.destructure_solver_region_constraints_for_borrowck(
187-
&mut converter,
188-
typeck.known_type_outlives_obligations,
189-
universal_region_relations.outlives.clone(),
190-
infcx.tcx.def_span(infcx.root_def_id),
191-
);
176+
if infcx.tcx.assumptions_on_binders() {
177+
let mut converter = constraint_conversion::ConstraintConversion::new(
178+
typeck.infcx,
179+
typeck.universal_regions,
180+
typeck.region_bound_pairs,
181+
typeck.known_type_outlives_obligations,
182+
Locations::All(rustc_span::DUMMY_SP),
183+
rustc_span::DUMMY_SP,
184+
ConstraintCategory::Boring,
185+
typeck.constraints,
186+
);
187+
typeck.infcx.destructure_solver_region_constraints_for_borrowck(
188+
&mut converter,
189+
typeck.known_type_outlives_obligations,
190+
universal_region_relations.outlives.clone(),
191+
infcx.tcx.def_span(infcx.root_def_id),
192+
);
193+
}
192194

193195
// In case type check encountered an error region, we suppress unhelpful extra
194196
// errors in by clearing out all outlives bounds that we may end up checking.

compiler/rustc_infer/src/infer/context.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,6 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
3030
self.typing_mode_raw()
3131
}
3232

33-
fn assumptions_on_binders(&self) -> bool {
34-
self.tcx.sess.opts.unstable_opts.assumptions_on_binders
35-
}
36-
3733
fn universe(&self) -> ty::UniverseIndex {
3834
self.universe()
3935
}

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub struct InferCtxtInner<'tcx> {
124124
/// region constraints would've been added.
125125
region_constraint_storage: Option<RegionConstraintStorage<'tcx>>,
126126

127-
/// Used by the next solver when `-Zhigher-ranked-assumptions=v2` is set.
127+
/// Used by the next solver when `-Zassumptions-on-binders` is set.
128128
solver_region_constraint_storage: SolverRegionConstraintStorage<'tcx>,
129129

130130
/// A set of constraints that regionck must validate.

compiler/rustc_infer/src/infer/outlives/obligations.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'tcx> InferCtxt<'tcx> {
147147
sub_region: Region<'tcx>,
148148
cause: &ObligationCause<'tcx>,
149149
) {
150-
assert!(!self.tcx.sess.opts.unstable_opts.assumptions_on_binders);
150+
assert!(!self.tcx.assumptions_on_binders());
151151

152152
// `is_global` means the type has no params, infer, placeholder, or non-`'static`
153153
// free regions. If the type has none of these things, then we can skip registering
@@ -237,10 +237,7 @@ impl<'tcx> InferCtxt<'tcx> {
237237
mut conversion: impl TypeOutlivesDelegate<'tcx>,
238238
span: Span,
239239
) {
240-
if !self.tcx.sess.opts.unstable_opts.assumptions_on_binders {
241-
return;
242-
}
243-
240+
assert!(self.tcx.assumptions_on_binders());
244241
assert!(self.next_trait_solver());
245242

246243
let origin = SubregionOrigin::SolverRegionConstraint(span);
@@ -277,8 +274,7 @@ impl<'tcx> InferCtxt<'tcx> {
277274
}
278275
// FIXME(-Zassumptions-on-binders): actually implement OR as an OR
279276
And(nested) | Or(nested) => constraints.extend(nested),
280-
AliasTyOutlivesViaEnv(..) => unreachable!(),
281-
PlaceholderTyOutlives(..) => unreachable!(),
277+
AliasTyOutlivesViaEnv(..) | PlaceholderTyOutlives(..) => unreachable!(),
282278
}
283279
}
284280
}
@@ -305,7 +301,9 @@ impl<'tcx> InferCtxt<'tcx> {
305301
) -> Result<(), (PolyTypeOutlivesPredicate<'tcx>, SubregionOrigin<'tcx>)> {
306302
assert!(!self.in_snapshot(), "cannot process registered region obligations in a snapshot");
307303

308-
self.destructure_solver_region_constraints_for_regionck(outlives_env, span);
304+
if self.tcx.assumptions_on_binders() {
305+
self.destructure_solver_region_constraints_for_regionck(outlives_env, span);
306+
}
309307

310308
// Must loop since the process of normalizing may itself register region obligations.
311309
for iteration in 0.. {

compiler/rustc_middle/src/ty/context.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2652,6 +2652,10 @@ impl<'tcx> TyCtxt<'tcx> {
26522652
self.next_trait_solver_globally() || self.sess.opts.unstable_opts.typing_mode_borrowck
26532653
}
26542654

2655+
pub fn assumptions_on_binders(self) -> bool {
2656+
self.sess.opts.unstable_opts.assumptions_on_binders
2657+
}
2658+
26552659
pub fn is_impl_trait_in_trait(self, def_id: DefId) -> bool {
26562660
self.opt_rpitit_info(def_id).is_some()
26572661
}

compiler/rustc_middle/src/ty/context/impl_interner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
328328
}
329329

330330
fn assumptions_on_binders(self) -> bool {
331-
self.sess.opts.unstable_opts.assumptions_on_binders
331+
self.assumptions_on_binders()
332332
}
333333

334334
fn coroutine_hidden_types(

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,7 @@ where
13421342
) -> U {
13431343
self.delegate.enter_forall(value, |value| {
13441344
let u = self.delegate.universe();
1345-
let assumptions = if self.assumptions_on_binders() {
1345+
let assumptions = if self.cx().assumptions_on_binders() {
13461346
self.region_assumptions_for_placeholders_in_universe(value.clone(), u, param_env)
13471347
} else {
13481348
None
@@ -1379,10 +1379,6 @@ where
13791379
args
13801380
}
13811381

1382-
pub(super) fn assumptions_on_binders(&self) -> bool {
1383-
self.delegate.assumptions_on_binders()
1384-
}
1385-
13861382
pub(super) fn register_solver_region_constraint(&self, c: RegionConstraint<I>) {
13871383
self.delegate.register_solver_region_constraint(c);
13881384
}
@@ -1578,7 +1574,7 @@ where
15781574
previous call to `try_evaluate_added_goals!`"
15791575
);
15801576

1581-
let goals_certainty = match self.delegate.assumptions_on_binders() {
1577+
let goals_certainty = match self.delegate.cx().assumptions_on_binders() {
15821578
true => {
15831579
let certainty = self.eagerly_handle_placeholders()?;
15841580
certainty.and(goals_certainty)
@@ -1707,15 +1703,18 @@ where
17071703
// region constraints from an ambiguous nested goal. This is tested in both
17081704
// `tests/ui/higher-ranked/leak-check/leak-check-in-selection-5-ambig.rs` and
17091705
// `tests/ui/higher-ranked/leak-check/leak-check-in-selection-6-ambig-unify.rs`.
1710-
let region_constraints = match self.assumptions_on_binders() {
1711-
true if let Certainty::Yes = certainty => {
1712-
ExternalRegionConstraints::NextGen(self.delegate.get_solver_region_constraint())
1713-
}
1714-
true => ExternalRegionConstraints::NextGen(RegionConstraint::new_true()),
1715-
false if let Certainty::Yes = certainty => {
1716-
ExternalRegionConstraints::Old(self.delegate.make_deduplicated_region_constraints())
1717-
}
1718-
false => ExternalRegionConstraints::Old(vec![]),
1706+
let region_constraints = if self.cx().assumptions_on_binders() {
1707+
ExternalRegionConstraints::NextGen(if let Certainty::Yes = certainty {
1708+
self.delegate.get_solver_region_constraint()
1709+
} else {
1710+
RegionConstraint::new_true()
1711+
})
1712+
} else {
1713+
ExternalRegionConstraints::Old(if let Certainty::Yes = certainty {
1714+
self.delegate.make_deduplicated_region_constraints()
1715+
} else {
1716+
vec![]
1717+
})
17191718
};
17201719

17211720
// We only return *newly defined* opaque types from canonical queries.

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/solver_region_constraints.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ where
3535
u: UniverseIndex,
3636
param_env: I::ParamEnv,
3737
) -> Option<Assumptions<I>> {
38+
assert!(self.cx().assumptions_on_binders());
39+
3840
struct RawAssumptions<'a, 'b, D: SolverDelegate<Interner = I>, I: Interner> {
3941
ecx: &'a mut EvalCtxt<'b, D, I>,
4042
param_env: I::ParamEnv,
@@ -46,6 +48,8 @@ where
4648
I: Interner,
4749
D: SolverDelegate<Interner = I>,
4850
{
51+
type Result = ();
52+
4953
fn visit_ty(&mut self, t: I::Ty) {
5054
self.out.extend(
5155
self.ecx

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ where
9292
) -> QueryResultOrRerunNonErased<I> {
9393
let ty::OutlivesPredicate(ty, lt) = goal.predicate;
9494

95-
if self.assumptions_on_binders() {
95+
if self.cx().assumptions_on_binders() {
9696
// FIXME(-Zassumptions-on-binders): we need to normalize `ty`
9797
let constraint = self.destructure_type_outlives(ty, lt);
9898
self.register_solver_region_constraint(constraint);
@@ -110,7 +110,7 @@ where
110110
) -> QueryResultOrRerunNonErased<I> {
111111
let ty::OutlivesPredicate(a, b) = goal.predicate;
112112

113-
if self.assumptions_on_binders() {
113+
if self.cx().assumptions_on_binders() {
114114
let constraint =
115115
rustc_type_ir::region_constraint::RegionConstraint::RegionOutlives(a, b);
116116
self.register_solver_region_constraint(constraint);

compiler/rustc_trait_selection/src/solve/delegate.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
7474
span: Span,
7575
) -> Option<Certainty> {
7676
// FIXME(-Zassumptions-on-binders): actually handle fast path
77-
let assumptions_on_binders = self.tcx.sess.opts.unstable_opts.assumptions_on_binders;
77+
if self.tcx.assumptions_on_binders() {
78+
return None;
79+
}
80+
7881
let pred = goal.predicate.kind();
7982
match pred.skip_binder() {
8083
ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred)) => {
@@ -124,9 +127,7 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
124127
ty::PredicateKind::DynCompatible(def_id) if self.0.tcx.is_dyn_compatible(def_id) => {
125128
Some(Certainty::Yes)
126129
}
127-
ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(outlives))
128-
if !assumptions_on_binders =>
129-
{
130+
ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(outlives)) => {
130131
if outlives.has_escaping_bound_vars() {
131132
return None;
132133
}
@@ -139,9 +140,7 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
139140
);
140141
Some(Certainty::Yes)
141142
}
142-
ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(outlives))
143-
if !assumptions_on_binders =>
144-
{
143+
ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(outlives)) => {
145144
if outlives.has_escaping_bound_vars() {
146145
return None;
147146
}

0 commit comments

Comments
 (0)