Skip to content

Commit 4b3b731

Browse files
committed
Auto merge of #103220 - compiler-errors:deny-infers, r=lcnr
Deny hashing ty/re/ct inference variables cc `@cjgillot` and #102695 (comment) r? `@lcnr` best reviewed one commit at a time, mostly because the second commit that fixes `ClosureOutlivesRequirement` is mostly noise because of losing its `<'tcx>` lifetime parameter.
2 parents ebdde35 + 6b0ef9c commit 4b3b731

File tree

27 files changed

+119
-120
lines changed

27 files changed

+119
-120
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<'tcx>,
95+
pub category: ConstraintCategory,
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
@@ -976,7 +976,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
976976
err: &mut Diagnostic,
977977
location: Location,
978978
issued_borrow: &BorrowData<'tcx>,
979-
explanation: BorrowExplanation<'tcx>,
979+
explanation: BorrowExplanation,
980980
) {
981981
let used_in_call = matches!(
982982
explanation,
@@ -1326,7 +1326,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13261326
borrow: &BorrowData<'tcx>,
13271327
drop_span: Span,
13281328
borrow_spans: UseSpans<'tcx>,
1329-
explanation: BorrowExplanation<'tcx>,
1329+
explanation: BorrowExplanation,
13301330
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
13311331
debug!(
13321332
"report_local_value_does_not_live_long_enough(\
@@ -1532,7 +1532,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15321532
drop_span: Span,
15331533
borrow_spans: UseSpans<'tcx>,
15341534
proper_span: Span,
1535-
explanation: BorrowExplanation<'tcx>,
1535+
explanation: BorrowExplanation,
15361536
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
15371537
if let BorrowExplanation::MustBeValidFor { category, span, from_closure: false, .. } =
15381538
explanation
@@ -1646,7 +1646,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16461646
borrow: &BorrowData<'tcx>,
16471647
borrow_span: Span,
16481648
return_span: Span,
1649-
category: ConstraintCategory<'tcx>,
1649+
category: ConstraintCategory,
16501650
opt_place_desc: Option<&String>,
16511651
) -> Option<DiagnosticBuilder<'cx, ErrorGuaranteed>> {
16521652
let return_kind = match category {
@@ -1741,7 +1741,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
17411741
use_span: UseSpans<'tcx>,
17421742
var_span: Span,
17431743
fr_name: &RegionName,
1744-
category: ConstraintCategory<'tcx>,
1744+
category: ConstraintCategory,
17451745
constraint_span: Span,
17461746
captured_var: &str,
17471747
) -> 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<'tcx> {
24+
pub(crate) enum BorrowExplanation {
2525
UsedLater(LaterUseKind, Span, Option<Span>),
2626
UsedLaterInLoop(LaterUseKind, Span, Option<Span>),
2727
UsedLaterWhenDropped {
@@ -30,7 +30,7 @@ pub(crate) enum BorrowExplanation<'tcx> {
3030
should_note_order: bool,
3131
},
3232
MustBeValidFor {
33-
category: ConstraintCategory<'tcx>,
33+
category: ConstraintCategory,
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<'tcx> {
52+
impl<'tcx> BorrowExplanation {
5353
pub(crate) fn is_explained(&self) -> bool {
5454
!matches!(self, BorrowExplanation::Unexplained)
5555
}
@@ -284,7 +284,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
284284
fn add_lifetime_bound_suggestion_to_diagnostic(
285285
&self,
286286
err: &mut Diagnostic,
287-
category: &ConstraintCategory<'tcx>,
287+
category: &ConstraintCategory,
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<'tcx>, bool, Span, Option<RegionName>, Vec<ExtraConstraintInfo>) {
319+
) -> (ConstraintCategory, 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<'tcx> {
351+
) -> BorrowExplanation {
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

+15-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![deny(rustc::diagnostic_outside_of_impl)]
33
//! Error reporting machinery for lifetime errors.
44
5+
use either::Either;
56
use rustc_data_structures::fx::FxHashSet;
67
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
78
use rustc_hir::def_id::DefId;
@@ -16,7 +17,7 @@ use rustc_infer::infer::{
1617
NllRegionVariableOrigin, RelateParamBound,
1718
};
1819
use rustc_middle::hir::place::PlaceBase;
19-
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
20+
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint, TerminatorKind};
2021
use rustc_middle::ty::subst::InternalSubsts;
2122
use rustc_middle::ty::Region;
2223
use rustc_middle::ty::TypeVisitor;
@@ -39,7 +40,7 @@ use crate::{
3940
MirBorrowckCtxt,
4041
};
4142

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

116117
/// Information about the various region constraints involved in a borrow checker error.
117118
#[derive(Clone, Debug)]
118-
pub struct ErrorConstraintInfo<'tcx> {
119+
pub struct ErrorConstraintInfo {
119120
// fr: outlived_fr
120121
pub(super) fr: RegionVid,
121122
pub(super) fr_is_local: bool,
122123
pub(super) outlived_fr: RegionVid,
123124
pub(super) outlived_fr_is_local: bool,
124125

125126
// Category and span for best blame constraint
126-
pub(super) category: ConstraintCategory<'tcx>,
127+
pub(super) category: ConstraintCategory,
127128
pub(super) span: Span,
128129
}
129130

@@ -498,7 +499,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
498499
/// ```
499500
fn report_fnmut_error(
500501
&self,
501-
errci: &ErrorConstraintInfo<'tcx>,
502+
errci: &ErrorConstraintInfo,
502503
kind: ReturnConstraint,
503504
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
504505
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
@@ -571,7 +572,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
571572
#[instrument(level = "debug", skip(self))]
572573
fn report_escaping_data_error(
573574
&self,
574-
errci: &ErrorConstraintInfo<'tcx>,
575+
errci: &ErrorConstraintInfo,
575576
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
576577
let ErrorConstraintInfo { span, category, .. } = errci;
577578

@@ -675,7 +676,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
675676
/// ```
676677
fn report_general_error(
677678
&self,
678-
errci: &ErrorConstraintInfo<'tcx>,
679+
errci: &ErrorConstraintInfo,
679680
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
680681
let ErrorConstraintInfo {
681682
fr,
@@ -788,15 +789,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
788789
diag: &mut Diagnostic,
789790
f: Region<'tcx>,
790791
o: Region<'tcx>,
791-
category: &ConstraintCategory<'tcx>,
792+
category: &ConstraintCategory,
792793
) {
793794
if !o.is_static() {
794795
return;
795796
}
796797

797798
let tcx = self.infcx.tcx;
798799

799-
let instance = if let ConstraintCategory::CallArgument(Some(func_ty)) = category {
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);
800806
let (fn_did, substs) = match func_ty.kind() {
801807
ty::FnDef(fn_did, substs) => (fn_did, substs),
802808
_ => 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<'tcx>, Span)>>,
94+
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, 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<'tcx>, Span)>,
270+
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, 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<'tcx>, Span)> {
1810+
) -> Option<(ConstraintCategory, 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<'tcx>, ObligationCause<'tcx>) {
1825+
) -> (ConstraintCategory, 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<'tcx>,
2365+
pub category: ConstraintCategory,
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<'tcx>,
31+
category: ConstraintCategory,
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<'tcx>,
88+
category: ConstraintCategory,
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<'tcx>,
127+
category: ConstraintCategory,
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<'tcx>,
142+
category: ConstraintCategory,
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<'tcx>,
167+
category: ConstraintCategory,
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<'tcx>,
40+
category: ConstraintCategory,
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<'tcx>,
53+
category: ConstraintCategory,
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<'tcx>,
178+
category: ConstraintCategory,
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<'tcx>,
206+
constraint_category: ConstraintCategory,
207207
) {
208208
let b = self.to_region_vid(b);
209209
let a = self.to_region_vid(a);

0 commit comments

Comments
 (0)