Skip to content

Commit 99fa572

Browse files
committed
add def_id and substs to ConstraintCategory::CallArgument
1 parent cbdce42 commit 99fa572

File tree

10 files changed

+77
-45
lines changed

10 files changed

+77
-45
lines changed

compiler/rustc_borrowck/src/constraints/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub struct OutlivesConstraint<'tcx> {
9595
pub span: Span,
9696

9797
/// What caused this constraint?
98-
pub category: ConstraintCategory,
98+
pub category: ConstraintCategory<'tcx>,
9999

100100
/// Variance diagnostic information
101101
pub variance_info: VarianceDiagInfo<'tcx>,

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
788788
err: &mut Diagnostic,
789789
location: Location,
790790
issued_borrow: &BorrowData<'tcx>,
791-
explanation: BorrowExplanation,
791+
explanation: BorrowExplanation<'tcx>,
792792
) {
793793
let used_in_call = matches!(
794794
explanation,
@@ -1088,7 +1088,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10881088
BorrowExplanation::MustBeValidFor {
10891089
category:
10901090
category @ (ConstraintCategory::Return(_)
1091-
| ConstraintCategory::CallArgument
1091+
| ConstraintCategory::CallArgument(_)
10921092
| ConstraintCategory::OpaqueType),
10931093
from_closure: false,
10941094
ref region_name,
@@ -1147,7 +1147,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11471147
borrow: &BorrowData<'tcx>,
11481148
drop_span: Span,
11491149
borrow_spans: UseSpans<'tcx>,
1150-
explanation: BorrowExplanation,
1150+
explanation: BorrowExplanation<'tcx>,
11511151
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
11521152
debug!(
11531153
"report_local_value_does_not_live_long_enough(\
@@ -1352,7 +1352,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13521352
drop_span: Span,
13531353
borrow_spans: UseSpans<'tcx>,
13541354
proper_span: Span,
1355-
explanation: BorrowExplanation,
1355+
explanation: BorrowExplanation<'tcx>,
13561356
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
13571357
debug!(
13581358
"report_temporary_value_does_not_live_long_enough(\
@@ -1410,7 +1410,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14101410
borrow: &BorrowData<'tcx>,
14111411
borrow_span: Span,
14121412
return_span: Span,
1413-
category: ConstraintCategory,
1413+
category: ConstraintCategory<'tcx>,
14141414
opt_place_desc: Option<&String>,
14151415
) -> Option<DiagnosticBuilder<'cx, ErrorGuaranteed>> {
14161416
let return_kind = match category {
@@ -1508,7 +1508,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15081508
use_span: UseSpans<'tcx>,
15091509
var_span: Span,
15101510
fr_name: &RegionName,
1511-
category: ConstraintCategory,
1511+
category: ConstraintCategory<'tcx>,
15121512
constraint_span: Span,
15131513
captured_var: &str,
15141514
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
@@ -1559,7 +1559,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15591559
let msg = format!("{} is returned here", kind);
15601560
err.span_note(constraint_span, &msg);
15611561
}
1562-
ConstraintCategory::CallArgument => {
1562+
ConstraintCategory::CallArgument(_) => {
15631563
fr_name.highlight_region_name(&mut err);
15641564
if matches!(use_span.generator_kind(), Some(GeneratorKind::Async(_))) {
15651565
err.note(

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{
2424
use super::{find_use, RegionName, UseSpans};
2525

2626
#[derive(Debug)]
27-
pub(crate) enum BorrowExplanation {
27+
pub(crate) enum BorrowExplanation<'tcx> {
2828
UsedLater(LaterUseKind, Span, Option<Span>),
2929
UsedLaterInLoop(LaterUseKind, Span, Option<Span>),
3030
UsedLaterWhenDropped {
@@ -33,7 +33,7 @@ pub(crate) enum BorrowExplanation {
3333
should_note_order: bool,
3434
},
3535
MustBeValidFor {
36-
category: ConstraintCategory,
36+
category: ConstraintCategory<'tcx>,
3737
from_closure: bool,
3838
span: Span,
3939
region_name: RegionName,
@@ -51,11 +51,11 @@ pub(crate) enum LaterUseKind {
5151
Other,
5252
}
5353

54-
impl BorrowExplanation {
54+
impl<'tcx> BorrowExplanation<'tcx> {
5555
pub(crate) fn is_explained(&self) -> bool {
5656
!matches!(self, BorrowExplanation::Unexplained)
5757
}
58-
pub(crate) fn add_explanation_to_diagnostic<'tcx>(
58+
pub(crate) fn add_explanation_to_diagnostic(
5959
&self,
6060
tcx: TyCtxt<'tcx>,
6161
body: &Body<'tcx>,
@@ -276,7 +276,7 @@ impl BorrowExplanation {
276276
pub(crate) fn add_lifetime_bound_suggestion_to_diagnostic(
277277
&self,
278278
err: &mut Diagnostic,
279-
category: &ConstraintCategory,
279+
category: &ConstraintCategory<'tcx>,
280280
span: Span,
281281
region_name: &RegionName,
282282
) {
@@ -305,7 +305,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
305305
&self,
306306
borrow_region: RegionVid,
307307
outlived_region: RegionVid,
308-
) -> (ConstraintCategory, bool, Span, Option<RegionName>) {
308+
) -> (ConstraintCategory<'tcx>, bool, Span, Option<RegionName>) {
309309
let BlameConstraint { category, from_closure, cause, variance_info: _ } =
310310
self.regioncx.best_blame_constraint(
311311
&self.body,
@@ -337,7 +337,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
337337
location: Location,
338338
borrow: &BorrowData<'tcx>,
339339
kind_place: Option<(WriteKind, Place<'tcx>)>,
340-
) -> BorrowExplanation {
340+
) -> BorrowExplanation<'tcx> {
341341
debug!(
342342
"explain_why_borrow_contains_point(location={:?}, borrow={:?}, kind_place={:?})",
343343
location, borrow, kind_place

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub struct RegionInferenceContext<'tcx> {
8787

8888
/// Map closure bounds to a `Span` that should be used for error reporting.
8989
closure_bounds_mapping:
90-
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>>,
90+
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory<'tcx>, Span)>>,
9191

9292
/// Map universe indexes to information on why we created it.
9393
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
@@ -259,7 +259,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
259259
member_constraints_in: MemberConstraintSet<'tcx, RegionVid>,
260260
closure_bounds_mapping: FxHashMap<
261261
Location,
262-
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>,
262+
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory<'tcx>, Span)>,
263263
>,
264264
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
265265
type_tests: Vec<TypeTest<'tcx>>,
@@ -1772,7 +1772,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
17721772
fr1: RegionVid,
17731773
fr1_origin: NllRegionVariableOrigin,
17741774
fr2: RegionVid,
1775-
) -> (ConstraintCategory, ObligationCause<'tcx>) {
1775+
) -> (ConstraintCategory<'tcx>, ObligationCause<'tcx>) {
17761776
let BlameConstraint { category, cause, .. } =
17771777
self.best_blame_constraint(body, fr1, fr1_origin, |r| {
17781778
self.provides_universal_region(r, fr1, fr2)
@@ -2270,7 +2270,7 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
22702270

22712271
#[derive(Clone, Debug)]
22722272
pub struct BlameConstraint<'tcx> {
2273-
pub category: ConstraintCategory,
2273+
pub category: ConstraintCategory<'tcx>,
22742274
pub from_closure: bool,
22752275
pub cause: ObligationCause<'tcx>,
22762276
pub variance_info: ty::VarianceDiagInfo<'tcx>,

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2828
pub(super) fn fully_perform_op<R, Op>(
2929
&mut self,
3030
locations: Locations,
31-
category: ConstraintCategory,
31+
category: ConstraintCategory<'tcx>,
3232
op: Op,
3333
) -> Fallible<R>
3434
where
@@ -83,11 +83,12 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
8383
instantiated
8484
}
8585

86+
#[instrument(skip(self), level = "debug")]
8687
pub(super) fn prove_trait_ref(
8788
&mut self,
8889
trait_ref: ty::TraitRef<'tcx>,
8990
locations: Locations,
90-
category: ConstraintCategory,
91+
category: ConstraintCategory<'tcx>,
9192
) {
9293
self.prove_predicates(
9394
Some(ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
@@ -113,6 +114,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
113114
.into_iter()
114115
.zip(instantiated_predicates.spans.into_iter())
115116
{
117+
debug!(?predicate);
116118
let predicate = self.normalize(predicate, locations);
117119
self.prove_predicate(predicate, locations, ConstraintCategory::Predicate(span));
118120
}
@@ -122,7 +124,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
122124
&mut self,
123125
predicates: impl IntoIterator<Item = impl ToPredicate<'tcx>>,
124126
locations: Locations,
125-
category: ConstraintCategory,
127+
category: ConstraintCategory<'tcx>,
126128
) {
127129
for predicate in predicates {
128130
let predicate = predicate.to_predicate(self.tcx());
@@ -137,7 +139,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
137139
&mut self,
138140
predicate: ty::Predicate<'tcx>,
139141
locations: Locations,
140-
category: ConstraintCategory,
142+
category: ConstraintCategory<'tcx>,
141143
) {
142144
let param_env = self.param_env;
143145
self.fully_perform_op(

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) struct ConstraintConversion<'a, 'tcx> {
2727
param_env: ty::ParamEnv<'tcx>,
2828
locations: Locations,
2929
span: Span,
30-
category: ConstraintCategory,
30+
category: ConstraintCategory<'tcx>,
3131
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
3232
}
3333

@@ -40,7 +40,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
4040
param_env: ty::ParamEnv<'tcx>,
4141
locations: Locations,
4242
span: Span,
43-
category: ConstraintCategory,
43+
category: ConstraintCategory<'tcx>,
4444
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
4545
) -> Self {
4646
Self {

0 commit comments

Comments
 (0)