Skip to content

Commit 6075877

Browse files
committed
Pass ConstraintCategory thorough a few more places
1 parent a46376e commit 6075877

File tree

3 files changed

+44
-15
lines changed

3 files changed

+44
-15
lines changed

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
103103
bug!("query_constraint {:?} contained bound vars", query_constraint,);
104104
});
105105

106-
let _constraint_category = query_constraint.1;
106+
let constraint_category = query_constraint.1;
107107

108108
match k1.unpack() {
109109
GenericArgKind::Lifetime(r1) => {
110110
let r1_vid = self.to_region_vid(r1);
111111
let r2_vid = self.to_region_vid(r2);
112-
self.add_outlives(r1_vid, r2_vid);
112+
self.add_outlives(r1_vid, r2_vid, constraint_category);
113113
}
114114

115115
GenericArgKind::Type(t1) => {
@@ -124,7 +124,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
124124
Some(implicit_region_bound),
125125
param_env,
126126
)
127-
.type_must_outlive(origin, t1, r2);
127+
.type_must_outlive(origin, t1, r2, constraint_category);
128128
}
129129

130130
GenericArgKind::Const(_) => {
@@ -171,10 +171,19 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
171171
}
172172
}
173173

174-
fn add_outlives(&mut self, sup: ty::RegionVid, sub: ty::RegionVid) {
174+
fn add_outlives(
175+
&mut self,
176+
sup: ty::RegionVid,
177+
sub: ty::RegionVid,
178+
category: ConstraintCategory<'tcx>,
179+
) {
180+
let category = match self.category {
181+
ConstraintCategory::Boring | ConstraintCategory::BoringNoLocation => category,
182+
_ => self.category,
183+
};
175184
self.constraints.outlives_constraints.push(OutlivesConstraint {
176185
locations: self.locations,
177-
category: self.category,
186+
category,
178187
span: self.span,
179188
sub,
180189
sup,
@@ -194,10 +203,11 @@ impl<'a, 'b, 'tcx> TypeOutlivesDelegate<'tcx> for &'a mut ConstraintConversion<'
194203
_origin: SubregionOrigin<'tcx>,
195204
a: ty::Region<'tcx>,
196205
b: ty::Region<'tcx>,
206+
constraint_category: ConstraintCategory<'tcx>,
197207
) {
198208
let b = self.to_region_vid(b);
199209
let a = self.to_region_vid(a);
200-
self.add_outlives(b, a);
210+
self.add_outlives(b, a, constraint_category);
201211
}
202212

203213
fn push_verify(

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

+20-7
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ use crate::infer::{
6969
use crate::traits::{ObligationCause, ObligationCauseCode};
7070
use rustc_data_structures::undo_log::UndoLogs;
7171
use rustc_hir::def_id::LocalDefId;
72+
use rustc_middle::mir::ConstraintCategory;
7273
use rustc_middle::ty::subst::GenericArgKind;
7374
use rustc_middle::ty::{self, Region, Ty, TyCtxt, TypeVisitable};
7475
use smallvec::smallvec;
@@ -163,7 +164,8 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
163164

164165
let outlives =
165166
&mut TypeOutlives::new(self, self.tcx, &region_bound_pairs, None, param_env);
166-
outlives.type_must_outlive(origin, sup_type, sub_region);
167+
let category = ConstraintCategory::BoringNoLocation;
168+
outlives.type_must_outlive(origin, sup_type, sub_region, category);
167169
}
168170
}
169171

@@ -207,6 +209,7 @@ pub trait TypeOutlivesDelegate<'tcx> {
207209
origin: SubregionOrigin<'tcx>,
208210
a: ty::Region<'tcx>,
209211
b: ty::Region<'tcx>,
212+
constraint_category: ConstraintCategory<'tcx>,
210213
);
211214

212215
fn push_verify(
@@ -255,25 +258,27 @@ where
255258
origin: infer::SubregionOrigin<'tcx>,
256259
ty: Ty<'tcx>,
257260
region: ty::Region<'tcx>,
261+
category: ConstraintCategory<'tcx>,
258262
) {
259263
assert!(!ty.has_escaping_bound_vars());
260264

261265
let mut components = smallvec![];
262266
push_outlives_components(self.tcx, ty, &mut components);
263-
self.components_must_outlive(origin, &components, region);
267+
self.components_must_outlive(origin, &components, region, category);
264268
}
265269

266270
fn components_must_outlive(
267271
&mut self,
268272
origin: infer::SubregionOrigin<'tcx>,
269273
components: &[Component<'tcx>],
270274
region: ty::Region<'tcx>,
275+
category: ConstraintCategory<'tcx>,
271276
) {
272277
for component in components.iter() {
273278
let origin = origin.clone();
274279
match component {
275280
Component::Region(region1) => {
276-
self.delegate.push_sub_region_constraint(origin, region, *region1);
281+
self.delegate.push_sub_region_constraint(origin, region, *region1, category);
277282
}
278283
Component::Param(param_ty) => {
279284
self.param_ty_must_outlive(origin, region, *param_ty);
@@ -282,7 +287,7 @@ where
282287
self.projection_must_outlive(origin, region, *projection_ty);
283288
}
284289
Component::EscapingProjection(subcomponents) => {
285-
self.components_must_outlive(origin, &subcomponents, region);
290+
self.components_must_outlive(origin, &subcomponents, region, category);
286291
}
287292
Component::UnresolvedInferenceVariable(v) => {
288293
// ignore this, we presume it will yield an error
@@ -389,13 +394,19 @@ where
389394
if approx_env_bounds.is_empty() && trait_bounds.is_empty() && needs_infer {
390395
debug!("projection_must_outlive: no declared bounds");
391396

397+
let constraint = ConstraintCategory::BoringNoLocation;
392398
for k in projection_ty.substs {
393399
match k.unpack() {
394400
GenericArgKind::Lifetime(lt) => {
395-
self.delegate.push_sub_region_constraint(origin.clone(), region, lt);
401+
self.delegate.push_sub_region_constraint(
402+
origin.clone(),
403+
region,
404+
lt,
405+
constraint,
406+
);
396407
}
397408
GenericArgKind::Type(ty) => {
398-
self.type_must_outlive(origin.clone(), ty, region);
409+
self.type_must_outlive(origin.clone(), ty, region, constraint);
399410
}
400411
GenericArgKind::Const(_) => {
401412
// Const parameters don't impose constraints.
@@ -433,7 +444,8 @@ where
433444
let unique_bound = trait_bounds[0];
434445
debug!("projection_must_outlive: unique trait bound = {:?}", unique_bound);
435446
debug!("projection_must_outlive: unique declared bound appears in trait ref");
436-
self.delegate.push_sub_region_constraint(origin, region, unique_bound);
447+
let category = ConstraintCategory::BoringNoLocation;
448+
self.delegate.push_sub_region_constraint(origin, region, unique_bound, category);
437449
return;
438450
}
439451

@@ -455,6 +467,7 @@ impl<'cx, 'tcx> TypeOutlivesDelegate<'tcx> for &'cx InferCtxt<'cx, 'tcx> {
455467
origin: SubregionOrigin<'tcx>,
456468
a: ty::Region<'tcx>,
457469
b: ty::Region<'tcx>,
470+
_constraint_category: ConstraintCategory<'tcx>,
458471
) {
459472
self.sub_regions(origin, a, b)
460473
}

compiler/rustc_typeck/src/check/wfcheck.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_hir::ItemKind;
1010
use rustc_infer::infer::outlives::env::{OutlivesEnvironment, RegionBoundPairs};
1111
use rustc_infer::infer::outlives::obligations::TypeOutlives;
1212
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
13+
use rustc_middle::mir::ConstraintCategory;
1314
use rustc_middle::ty::query::Providers;
1415
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts, Subst};
1516
use rustc_middle::ty::trait_def::TraitSpecializationKind;
@@ -663,7 +664,7 @@ fn ty_known_to_outlive<'tcx>(
663664
resolve_regions_with_wf_tys(tcx, id, param_env, &wf_tys, |infcx, region_bound_pairs| {
664665
let origin = infer::RelateParamBound(DUMMY_SP, ty, None);
665666
let outlives = &mut TypeOutlives::new(infcx, tcx, region_bound_pairs, None, param_env);
666-
outlives.type_must_outlive(origin, ty, region);
667+
outlives.type_must_outlive(origin, ty, region, ConstraintCategory::BoringNoLocation);
667668
})
668669
}
669670

@@ -681,7 +682,12 @@ fn region_known_to_outlive<'tcx>(
681682
use rustc_infer::infer::outlives::obligations::TypeOutlivesDelegate;
682683
let origin = infer::RelateRegionParamBound(DUMMY_SP);
683684
// `region_a: region_b` -> `region_b <= region_a`
684-
infcx.push_sub_region_constraint(origin, region_b, region_a);
685+
infcx.push_sub_region_constraint(
686+
origin,
687+
region_b,
688+
region_a,
689+
ConstraintCategory::BoringNoLocation,
690+
);
685691
})
686692
}
687693

0 commit comments

Comments
 (0)