Skip to content

Commit 4dbf9ba

Browse files
committed
outside of borrowck, do not provide an implicit_region_bound
see comment added to the field in `VerifyBoundCx`.
1 parent 9cf699d commit 4dbf9ba

File tree

10 files changed

+18
-33
lines changed

10 files changed

+18
-33
lines changed

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) struct ConstraintConversion<'a, 'tcx> {
2323
tcx: TyCtxt<'tcx>,
2424
universal_regions: &'a UniversalRegions<'tcx>,
2525
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
26-
implicit_region_bound: Option<ty::Region<'tcx>>,
26+
implicit_region_bound: ty::Region<'tcx>,
2727
param_env: ty::ParamEnv<'tcx>,
2828
locations: Locations,
2929
span: Span,
@@ -36,7 +36,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
3636
infcx: &'a InferCtxt<'a, 'tcx>,
3737
universal_regions: &'a UniversalRegions<'tcx>,
3838
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
39-
implicit_region_bound: Option<ty::Region<'tcx>>,
39+
implicit_region_bound: ty::Region<'tcx>,
4040
param_env: ty::ParamEnv<'tcx>,
4141
locations: Locations,
4242
span: Span,
@@ -120,7 +120,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
120120
&mut *self,
121121
tcx,
122122
region_bound_pairs,
123-
implicit_region_bound,
123+
Some(implicit_region_bound),
124124
param_env,
125125
)
126126
.type_must_outlive(origin, t1, r2);

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(crate) struct CreateResult<'tcx> {
6161
pub(crate) fn create<'tcx>(
6262
infcx: &InferCtxt<'_, 'tcx>,
6363
param_env: ty::ParamEnv<'tcx>,
64-
implicit_region_bound: Option<ty::Region<'tcx>>,
64+
implicit_region_bound: ty::Region<'tcx>,
6565
universal_regions: &Rc<UniversalRegions<'tcx>>,
6666
constraints: &mut MirTypeckRegionConstraints<'tcx>,
6767
) -> CreateResult<'tcx> {
@@ -223,7 +223,7 @@ struct UniversalRegionRelationsBuilder<'this, 'tcx> {
223223
infcx: &'this InferCtxt<'this, 'tcx>,
224224
param_env: ty::ParamEnv<'tcx>,
225225
universal_regions: Rc<UniversalRegions<'tcx>>,
226-
implicit_region_bound: Option<ty::Region<'tcx>>,
226+
implicit_region_bound: ty::Region<'tcx>,
227227
constraints: &'this mut MirTypeckRegionConstraints<'tcx>,
228228

229229
// outputs:

compiler/rustc_borrowck/src/type_check/input_output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
230230
self.infcx,
231231
&self.borrowck_context.universal_regions,
232232
&self.region_bound_pairs,
233-
Some(self.implicit_region_bound),
233+
self.implicit_region_bound,
234234
self.param_env,
235235
Locations::All(DUMMY_SP),
236236
DUMMY_SP,

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
157157
} = free_region_relations::create(
158158
infcx,
159159
param_env,
160-
Some(implicit_region_bound),
160+
implicit_region_bound,
161161
universal_regions,
162162
&mut constraints,
163163
);
@@ -1142,7 +1142,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11421142
self.infcx,
11431143
self.borrowck_context.universal_regions,
11441144
self.region_bound_pairs,
1145-
Some(self.implicit_region_bound),
1145+
self.implicit_region_bound,
11461146
self.param_env,
11471147
locations,
11481148
locations.span(self.body),

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

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,13 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
141141
/// `('a, K)` in this list tells us that the bounds in scope
142142
/// indicate that `K: 'a`, where `K` is either a generic
143143
/// parameter like `T` or a projection like `T::Item`.
144-
/// - `implicit_region_bound`: if some, this is a region bound
145-
/// that is considered to hold for all type parameters (the
146-
/// function body).
147144
/// - `param_env` is the parameter environment for the enclosing function.
148145
/// - `body_id` is the body-id whose region obligations are being
149146
/// processed.
150147
#[instrument(level = "debug", skip(self, region_bound_pairs_map))]
151148
pub fn process_registered_region_obligations(
152149
&self,
153150
region_bound_pairs_map: &FxHashMap<hir::HirId, RegionBoundPairs<'tcx>>,
154-
implicit_region_bound: Option<ty::Region<'tcx>>,
155151
param_env: ty::ParamEnv<'tcx>,
156152
) {
157153
assert!(
@@ -170,13 +166,8 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
170166
let sup_type = self.resolve_vars_if_possible(sup_type);
171167

172168
if let Some(region_bound_pairs) = region_bound_pairs_map.get(&body_id) {
173-
let outlives = &mut TypeOutlives::new(
174-
self,
175-
self.tcx,
176-
&region_bound_pairs,
177-
implicit_region_bound,
178-
param_env,
179-
);
169+
let outlives =
170+
&mut TypeOutlives::new(self, self.tcx, &region_bound_pairs, None, param_env);
180171
outlives.type_must_outlive(origin, sup_type, sub_region);
181172
} else {
182173
self.tcx.sess.delay_span_bug(

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt};
1616
pub struct VerifyBoundCx<'cx, 'tcx> {
1717
tcx: TyCtxt<'tcx>,
1818
region_bound_pairs: &'cx RegionBoundPairs<'tcx>,
19+
/// During borrowck, if there are no outlives bounds on a generic
20+
/// parameter `T`, we assume that `T: 'in_fn_body` holds.
21+
///
22+
/// Outside of borrowck the only way to prove `T: '?0` is by
23+
/// setting `'?0` to `'empty`.
1924
implicit_region_bound: Option<ty::Region<'tcx>>,
2025
param_env: ty::ParamEnv<'tcx>,
2126
}

compiler/rustc_trait_selection/src/traits/auto_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
220220
.map(|&(id, _)| (id, vec![]))
221221
.collect();
222222

223-
infcx.process_registered_region_obligations(&body_id_map, None, full_env);
223+
infcx.process_registered_region_obligations(&body_id_map, full_env);
224224

225225
let region_data = infcx
226226
.inner

compiler/rustc_trait_selection/src/traits/coherence.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,11 +407,7 @@ fn resolve_negative_obligation<'cx, 'tcx>(
407407
// function bodies with closures).
408408
outlives_env.save_implied_bounds(CRATE_HIR_ID);
409409

410-
infcx.process_registered_region_obligations(
411-
outlives_env.region_bound_pairs_map(),
412-
Some(tcx.lifetimes.re_root_empty),
413-
param_env,
414-
);
410+
infcx.process_registered_region_obligations(outlives_env.region_bound_pairs_map(), param_env);
415411

416412
let errors = infcx.resolve_regions(region_context, &outlives_env);
417413

compiler/rustc_typeck/src/check/regionck.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> {
366366
fn resolve_regions_and_report_errors(&self) {
367367
self.infcx.process_registered_region_obligations(
368368
self.outlives_environment.region_bound_pairs_map(),
369-
Some(self.tcx.lifetimes.re_root_empty),
370369
self.param_env,
371370
);
372371

compiler/rustc_typeck/src/check/wfcheck.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -596,13 +596,7 @@ fn ty_known_to_outlive<'tcx>(
596596
) -> bool {
597597
resolve_regions_with_wf_tys(tcx, id, param_env, &wf_tys, |infcx, region_bound_pairs| {
598598
let origin = infer::RelateParamBound(DUMMY_SP, ty, None);
599-
let outlives = &mut TypeOutlives::new(
600-
infcx,
601-
tcx,
602-
region_bound_pairs,
603-
Some(infcx.tcx.lifetimes.re_root_empty),
604-
param_env,
605-
);
599+
let outlives = &mut TypeOutlives::new(infcx, tcx, region_bound_pairs, None, param_env);
606600
outlives.type_must_outlive(origin, ty, region);
607601
})
608602
}

0 commit comments

Comments
 (0)