Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit df35723

Browse files
committedJan 5, 2024
Normalize caller bounds
1 parent 18bb2e2 commit df35723

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed
 

‎compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
157157
tcx,
158158
region_bound_pairs,
159159
Some(implicit_region_bound),
160-
param_env,
160+
// FIXME(-Znext-solver): These bounds are not normalized!
161+
param_env.caller_bounds(),
161162
)
162163
.type_must_outlive(origin, t1, r2, constraint_category);
163164
}

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

+24-4
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ use crate::infer::{
6868
use crate::traits::{ObligationCause, ObligationCauseCode};
6969
use rustc_data_structures::undo_log::UndoLogs;
7070
use rustc_middle::mir::ConstraintCategory;
71-
use rustc_middle::ty::GenericArgKind;
7271
use rustc_middle::ty::{self, GenericArgsRef, Region, Ty, TyCtxt, TypeVisitableExt};
72+
use rustc_middle::ty::{GenericArgKind, ToPredicate};
73+
use rustc_span::DUMMY_SP;
7374
use smallvec::smallvec;
7475

7576
use super::env::OutlivesEnvironment;
@@ -131,6 +132,25 @@ impl<'tcx> InferCtxt<'tcx> {
131132
) -> Result<(), (E, SubregionOrigin<'tcx>)> {
132133
assert!(!self.in_snapshot(), "cannot process registered region obligations in a snapshot");
133134

135+
let normalized_caller_bounds: Vec<_> = outlives_env
136+
.param_env
137+
.caller_bounds()
138+
.iter()
139+
.filter_map(|clause| {
140+
let bound_clause = clause.kind();
141+
let ty::ClauseKind::TypeOutlives(outlives) = bound_clause.skip_binder() else {
142+
return None;
143+
};
144+
Some(deeply_normalize_ty(outlives.0).map(|ty| {
145+
bound_clause
146+
.rebind(ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty, outlives.1)))
147+
.to_predicate(self.tcx)
148+
}))
149+
})
150+
// FIXME: How do we accurately report an error here :(
151+
.try_collect()
152+
.map_err(|e| (e, SubregionOrigin::AscribeUserTypeProvePredicate(DUMMY_SP)))?;
153+
134154
let my_region_obligations = self.take_registered_region_obligations();
135155

136156
for RegionObligation { sup_type, sub_region, origin } in my_region_obligations {
@@ -142,7 +162,7 @@ impl<'tcx> InferCtxt<'tcx> {
142162
self.tcx,
143163
outlives_env.region_bound_pairs(),
144164
None,
145-
outlives_env.param_env,
165+
&normalized_caller_bounds,
146166
);
147167
let category = origin.to_constraint_category();
148168
outlives.type_must_outlive(origin, sup_type, sub_region, category);
@@ -196,7 +216,7 @@ where
196216
tcx: TyCtxt<'tcx>,
197217
region_bound_pairs: &'cx RegionBoundPairs<'tcx>,
198218
implicit_region_bound: Option<ty::Region<'tcx>>,
199-
param_env: ty::ParamEnv<'tcx>,
219+
caller_bounds: &'cx [ty::Clause<'tcx>],
200220
) -> Self {
201221
Self {
202222
delegate,
@@ -205,7 +225,7 @@ where
205225
tcx,
206226
region_bound_pairs,
207227
implicit_region_bound,
208-
param_env,
228+
caller_bounds,
209229
),
210230
}
211231
}

‎compiler/rustc_infer/src/infer/outlives/verify.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ pub struct VerifyBoundCx<'cx, 'tcx> {
2323
/// Outside of borrowck the only way to prove `T: '?0` is by
2424
/// setting `'?0` to `'empty`.
2525
implicit_region_bound: Option<ty::Region<'tcx>>,
26-
param_env: ty::ParamEnv<'tcx>,
26+
caller_bounds: &'cx [ty::Clause<'tcx>],
2727
}
2828

2929
impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
3030
pub fn new(
3131
tcx: TyCtxt<'tcx>,
3232
region_bound_pairs: &'cx RegionBoundPairs<'tcx>,
3333
implicit_region_bound: Option<ty::Region<'tcx>>,
34-
param_env: ty::ParamEnv<'tcx>,
34+
caller_bounds: &'cx [ty::Clause<'tcx>],
3535
) -> Self {
36-
Self { tcx, region_bound_pairs, implicit_region_bound, param_env }
36+
Self { tcx, region_bound_pairs, implicit_region_bound, caller_bounds }
3737
}
3838

3939
#[instrument(level = "debug", skip(self))]
@@ -220,8 +220,8 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
220220
// To start, collect bounds from user environment. Note that
221221
// parameter environments are already elaborated, so we don't
222222
// have to worry about that.
223-
let c_b = self.param_env.caller_bounds();
224-
let param_bounds = self.collect_outlives_from_clause_list(erased_ty, c_b.into_iter());
223+
let param_bounds =
224+
self.collect_outlives_from_clause_list(erased_ty, self.caller_bounds.iter().copied());
225225

226226
// Next, collect regions we scraped from the well-formedness
227227
// constraints in the fn signature. To do that, we walk the list

‎compiler/rustc_infer/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#![feature(extend_one)]
2323
#![feature(let_chains)]
2424
#![feature(if_let_guard)]
25+
#![feature(iterator_try_collect)]
2526
#![feature(min_specialization)]
2627
#![feature(never_type)]
2728
#![feature(try_blocks)]

0 commit comments

Comments
 (0)