Skip to content

Commit 84663ce

Browse files
authored
Rollup merge of #103641 - compiler-errors:issue-103624, r=cjgillot
Don't carry MIR location in `ConstraintCategory::CallArgument` It turns out that `ConstraintCategory::CallArgument` cannot just carry a MIR location in it, since we may bubble them up to totally different MIR bodies. So instead, revert the commit a6b5f95, and instead just erase regions from the original `Option<Ty<'tcx>>` that it carried, so that it doesn't ICE with the changes in #103220. Best reviewed in parts -- the first is just a revert, and the second is where the meaningful changes happen. Fixes #103624
2 parents f541ad9 + 4e0c27b commit 84663ce

File tree

24 files changed

+165
-100
lines changed

24 files changed

+165
-100
lines changed

compiler/rustc_borrowck/src/constraints/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub struct OutlivesConstraint<'tcx> {
9292
pub span: Span,
9393

9494
/// What caused this constraint?
95-
pub category: ConstraintCategory,
95+
pub category: ConstraintCategory<'tcx>,
9696

9797
/// Variance diagnostic information
9898
pub variance_info: VarianceDiagInfo<'tcx>,

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
983983
err: &mut Diagnostic,
984984
location: Location,
985985
issued_borrow: &BorrowData<'tcx>,
986-
explanation: BorrowExplanation,
986+
explanation: BorrowExplanation<'tcx>,
987987
) {
988988
let used_in_call = matches!(
989989
explanation,
@@ -1333,7 +1333,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13331333
borrow: &BorrowData<'tcx>,
13341334
drop_span: Span,
13351335
borrow_spans: UseSpans<'tcx>,
1336-
explanation: BorrowExplanation,
1336+
explanation: BorrowExplanation<'tcx>,
13371337
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
13381338
debug!(
13391339
"report_local_value_does_not_live_long_enough(\
@@ -1539,7 +1539,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15391539
drop_span: Span,
15401540
borrow_spans: UseSpans<'tcx>,
15411541
proper_span: Span,
1542-
explanation: BorrowExplanation,
1542+
explanation: BorrowExplanation<'tcx>,
15431543
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
15441544
if let BorrowExplanation::MustBeValidFor { category, span, from_closure: false, .. } =
15451545
explanation
@@ -1653,7 +1653,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16531653
borrow: &BorrowData<'tcx>,
16541654
borrow_span: Span,
16551655
return_span: Span,
1656-
category: ConstraintCategory,
1656+
category: ConstraintCategory<'tcx>,
16571657
opt_place_desc: Option<&String>,
16581658
) -> Option<DiagnosticBuilder<'cx, ErrorGuaranteed>> {
16591659
let return_kind = match category {
@@ -1748,7 +1748,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17481748
use_span: UseSpans<'tcx>,
17491749
var_span: Span,
17501750
fr_name: &RegionName,
1751-
category: ConstraintCategory,
1751+
category: ConstraintCategory<'tcx>,
17521752
constraint_span: Span,
17531753
captured_var: &str,
17541754
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use crate::{
2121
use super::{find_use, RegionName, UseSpans};
2222

2323
#[derive(Debug)]
24-
pub(crate) enum BorrowExplanation {
24+
pub(crate) enum BorrowExplanation<'tcx> {
2525
UsedLater(LaterUseKind, Span, Option<Span>),
2626
UsedLaterInLoop(LaterUseKind, Span, Option<Span>),
2727
UsedLaterWhenDropped {
@@ -30,7 +30,7 @@ pub(crate) enum BorrowExplanation {
3030
should_note_order: bool,
3131
},
3232
MustBeValidFor {
33-
category: ConstraintCategory,
33+
category: ConstraintCategory<'tcx>,
3434
from_closure: bool,
3535
span: Span,
3636
region_name: RegionName,
@@ -49,7 +49,7 @@ pub(crate) enum LaterUseKind {
4949
Other,
5050
}
5151

52-
impl<'tcx> BorrowExplanation {
52+
impl<'tcx> BorrowExplanation<'tcx> {
5353
pub(crate) fn is_explained(&self) -> bool {
5454
!matches!(self, BorrowExplanation::Unexplained)
5555
}
@@ -284,7 +284,7 @@ impl<'tcx> BorrowExplanation {
284284
fn add_lifetime_bound_suggestion_to_diagnostic(
285285
&self,
286286
err: &mut Diagnostic,
287-
category: &ConstraintCategory,
287+
category: &ConstraintCategory<'tcx>,
288288
span: Span,
289289
region_name: &RegionName,
290290
) {
@@ -316,7 +316,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
316316
&self,
317317
borrow_region: RegionVid,
318318
outlived_region: RegionVid,
319-
) -> (ConstraintCategory, bool, Span, Option<RegionName>, Vec<ExtraConstraintInfo>) {
319+
) -> (ConstraintCategory<'tcx>, bool, Span, Option<RegionName>, Vec<ExtraConstraintInfo>) {
320320
let (blame_constraint, extra_info) = self.regioncx.best_blame_constraint(
321321
borrow_region,
322322
NllRegionVariableOrigin::FreeRegion,
@@ -348,7 +348,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
348348
location: Location,
349349
borrow: &BorrowData<'tcx>,
350350
kind_place: Option<(WriteKind, Place<'tcx>)>,
351-
) -> BorrowExplanation {
351+
) -> BorrowExplanation<'tcx> {
352352
let regioncx = &self.regioncx;
353353
let body: &Body<'_> = &self.body;
354354
let tcx = self.infcx.tcx;

compiler/rustc_borrowck/src/diagnostics/outlives_suggestion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl OutlivesSuggestionBuilder {
161161
pub(crate) fn intermediate_suggestion(
162162
&mut self,
163163
mbcx: &MirBorrowckCtxt<'_, '_>,
164-
errci: &ErrorConstraintInfo,
164+
errci: &ErrorConstraintInfo<'_>,
165165
diag: &mut Diagnostic,
166166
) {
167167
// Emit an intermediate note.

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![deny(rustc::diagnostic_outside_of_impl)]
33
//! Error reporting machinery for lifetime errors.
44
5-
use either::Either;
65
use rustc_data_structures::fx::FxHashSet;
76
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
87
use rustc_hir::def_id::DefId;
@@ -17,7 +16,7 @@ use rustc_infer::infer::{
1716
NllRegionVariableOrigin, RelateParamBound,
1817
};
1918
use rustc_middle::hir::place::PlaceBase;
20-
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint, TerminatorKind};
19+
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
2120
use rustc_middle::ty::subst::InternalSubsts;
2221
use rustc_middle::ty::Region;
2322
use rustc_middle::ty::TypeVisitor;
@@ -40,7 +39,7 @@ use crate::{
4039
MirBorrowckCtxt,
4140
};
4241

43-
impl ConstraintDescription for ConstraintCategory {
42+
impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
4443
fn description(&self) -> &'static str {
4544
// Must end with a space. Allows for empty names to be provided.
4645
match self {
@@ -116,15 +115,15 @@ pub(crate) enum RegionErrorKind<'tcx> {
116115

117116
/// Information about the various region constraints involved in a borrow checker error.
118117
#[derive(Clone, Debug)]
119-
pub struct ErrorConstraintInfo {
118+
pub struct ErrorConstraintInfo<'tcx> {
120119
// fr: outlived_fr
121120
pub(super) fr: RegionVid,
122121
pub(super) fr_is_local: bool,
123122
pub(super) outlived_fr: RegionVid,
124123
pub(super) outlived_fr_is_local: bool,
125124

126125
// Category and span for best blame constraint
127-
pub(super) category: ConstraintCategory,
126+
pub(super) category: ConstraintCategory<'tcx>,
128127
pub(super) span: Span,
129128
}
130129

@@ -499,7 +498,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
499498
/// ```
500499
fn report_fnmut_error(
501500
&self,
502-
errci: &ErrorConstraintInfo,
501+
errci: &ErrorConstraintInfo<'tcx>,
503502
kind: ReturnConstraint,
504503
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
505504
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
@@ -572,7 +571,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
572571
#[instrument(level = "debug", skip(self))]
573572
fn report_escaping_data_error(
574573
&self,
575-
errci: &ErrorConstraintInfo,
574+
errci: &ErrorConstraintInfo<'tcx>,
576575
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
577576
let ErrorConstraintInfo { span, category, .. } = errci;
578577

@@ -676,7 +675,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
676675
/// ```
677676
fn report_general_error(
678677
&self,
679-
errci: &ErrorConstraintInfo,
678+
errci: &ErrorConstraintInfo<'tcx>,
680679
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
681680
let ErrorConstraintInfo {
682681
fr,
@@ -789,20 +788,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
789788
diag: &mut Diagnostic,
790789
f: Region<'tcx>,
791790
o: Region<'tcx>,
792-
category: &ConstraintCategory,
791+
category: &ConstraintCategory<'tcx>,
793792
) {
794793
if !o.is_static() {
795794
return;
796795
}
797796

798797
let tcx = self.infcx.tcx;
799798

800-
let instance =
801-
if let ConstraintCategory::CallArgument(location) = category
802-
&& let Either::Right(term) = self.body.stmt_at(*location)
803-
&& let TerminatorKind::Call { func, .. } = &term.kind
804-
{
805-
let func_ty = func.ty(self.body, tcx);
799+
let instance = if let ConstraintCategory::CallArgument(Some(func_ty)) = category {
806800
let (fn_did, substs) = match func_ty.kind() {
807801
ty::FnDef(fn_did, substs) => (fn_did, substs),
808802
_ => return,

compiler/rustc_borrowck/src/region_infer/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub struct RegionInferenceContext<'tcx> {
9191

9292
/// Map closure bounds to a `Span` that should be used for error reporting.
9393
closure_bounds_mapping:
94-
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>>,
94+
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory<'tcx>, Span)>>,
9595

9696
/// Map universe indexes to information on why we created it.
9797
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
@@ -267,7 +267,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
267267
member_constraints_in: MemberConstraintSet<'tcx, RegionVid>,
268268
closure_bounds_mapping: FxHashMap<
269269
Location,
270-
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>,
270+
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory<'tcx>, Span)>,
271271
>,
272272
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
273273
type_tests: Vec<TypeTest<'tcx>>,
@@ -1807,7 +1807,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
18071807
pub(crate) fn retrieve_closure_constraint_info(
18081808
&self,
18091809
constraint: OutlivesConstraint<'tcx>,
1810-
) -> Option<(ConstraintCategory, Span)> {
1810+
) -> Option<(ConstraintCategory<'tcx>, Span)> {
18111811
match constraint.locations {
18121812
Locations::All(_) => None,
18131813
Locations::Single(loc) => {
@@ -1822,7 +1822,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
18221822
fr1: RegionVid,
18231823
fr1_origin: NllRegionVariableOrigin,
18241824
fr2: RegionVid,
1825-
) -> (ConstraintCategory, ObligationCause<'tcx>) {
1825+
) -> (ConstraintCategory<'tcx>, ObligationCause<'tcx>) {
18261826
let BlameConstraint { category, cause, .. } = self
18271827
.best_blame_constraint(fr1, fr1_origin, |r| self.provides_universal_region(r, fr1, fr2))
18281828
.0;
@@ -2362,7 +2362,7 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
23622362

23632363
#[derive(Clone, Debug)]
23642364
pub struct BlameConstraint<'tcx> {
2365-
pub category: ConstraintCategory,
2365+
pub category: ConstraintCategory<'tcx>,
23662366
pub from_closure: bool,
23672367
pub cause: ObligationCause<'tcx>,
23682368
pub variance_info: ty::VarianceDiagInfo<'tcx>,

compiler/rustc_borrowck/src/type_check/canonical.rs

+5-5
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: fmt::Debug, Op>(
2929
&mut self,
3030
locations: Locations,
31-
category: ConstraintCategory,
31+
category: ConstraintCategory<'tcx>,
3232
op: Op,
3333
) -> Fallible<R>
3434
where
@@ -85,7 +85,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
8585
&mut self,
8686
trait_ref: ty::TraitRef<'tcx>,
8787
locations: Locations,
88-
category: ConstraintCategory,
88+
category: ConstraintCategory<'tcx>,
8989
) {
9090
self.prove_predicate(
9191
ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
@@ -124,7 +124,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
124124
&mut self,
125125
predicates: impl IntoIterator<Item = impl ToPredicate<'tcx>>,
126126
locations: Locations,
127-
category: ConstraintCategory,
127+
category: ConstraintCategory<'tcx>,
128128
) {
129129
for predicate in predicates {
130130
let predicate = predicate.to_predicate(self.tcx());
@@ -139,7 +139,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
139139
&mut self,
140140
predicate: ty::Predicate<'tcx>,
141141
locations: Locations,
142-
category: ConstraintCategory,
142+
category: ConstraintCategory<'tcx>,
143143
) {
144144
let param_env = self.param_env;
145145
self.fully_perform_op(
@@ -164,7 +164,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
164164
&mut self,
165165
value: T,
166166
location: impl NormalizeLocation,
167-
category: ConstraintCategory,
167+
category: ConstraintCategory<'tcx>,
168168
) -> T
169169
where
170170
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub(crate) struct ConstraintConversion<'a, 'tcx> {
3737
param_env: ty::ParamEnv<'tcx>,
3838
locations: Locations,
3939
span: Span,
40-
category: ConstraintCategory,
40+
category: ConstraintCategory<'tcx>,
4141
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
4242
}
4343

@@ -50,7 +50,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
5050
param_env: ty::ParamEnv<'tcx>,
5151
locations: Locations,
5252
span: Span,
53-
category: ConstraintCategory,
53+
category: ConstraintCategory<'tcx>,
5454
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
5555
) -> Self {
5656
Self {
@@ -175,7 +175,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
175175
&mut self,
176176
sup: ty::RegionVid,
177177
sub: ty::RegionVid,
178-
category: ConstraintCategory,
178+
category: ConstraintCategory<'tcx>,
179179
) {
180180
let category = match self.category {
181181
ConstraintCategory::Boring | ConstraintCategory::BoringNoLocation => category,
@@ -203,7 +203,7 @@ impl<'a, 'b, 'tcx> TypeOutlivesDelegate<'tcx> for &'a mut ConstraintConversion<'
203203
_origin: SubregionOrigin<'tcx>,
204204
a: ty::Region<'tcx>,
205205
b: ty::Region<'tcx>,
206-
constraint_category: ConstraintCategory,
206+
constraint_category: ConstraintCategory<'tcx>,
207207
) {
208208
let b = self.to_region_vid(b);
209209
let a = self.to_region_vid(a);

0 commit comments

Comments
 (0)