Skip to content

Commit 4d4e51e

Browse files
committed
Auto merge of rust-lang#101902 - jackh726:revert-static-hrtb-error, r=nikomatsakis
Partially revert rust-lang#101433 reverts rust-lang#101433 to fix rust-lang#101844 We should get this into the beta cut, since the ICE is getting hit quite a bit.
2 parents 54f20bb + d97fdf1 commit 4d4e51e

File tree

34 files changed

+179
-495
lines changed

34 files changed

+179
-495
lines changed

compiler/rustc_borrowck/src/constraints/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ pub(crate) struct OutlivesConstraintSet<'tcx> {
2121

2222
impl<'tcx> OutlivesConstraintSet<'tcx> {
2323
pub(crate) fn push(&mut self, constraint: OutlivesConstraint<'tcx>) {
24-
debug!("OutlivesConstraintSet::push({:?})", constraint);
24+
debug!(
25+
"OutlivesConstraintSet::push({:?}: {:?} @ {:?}",
26+
constraint.sup, constraint.sub, constraint.locations
27+
);
2528
if constraint.sup == constraint.sub {
2629
// 'a: 'a is pretty uninteresting
2730
return;

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+9-21
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::ty::{self, RegionVid, TyCtxt};
1515
use rustc_span::symbol::{kw, Symbol};
1616
use rustc_span::{sym, DesugaringKind, Span};
1717

18-
use crate::region_infer::{BlameConstraint, ExtraConstraintInfo};
18+
use crate::region_infer::BlameConstraint;
1919
use crate::{
2020
borrow_set::BorrowData, nll::ConstraintDescription, region_infer::Cause, MirBorrowckCtxt,
2121
WriteKind,
@@ -38,7 +38,6 @@ pub(crate) enum BorrowExplanation<'tcx> {
3838
span: Span,
3939
region_name: RegionName,
4040
opt_place_desc: Option<String>,
41-
extra_info: Vec<ExtraConstraintInfo>,
4241
},
4342
Unexplained,
4443
}
@@ -244,7 +243,6 @@ impl<'tcx> BorrowExplanation<'tcx> {
244243
ref region_name,
245244
ref opt_place_desc,
246245
from_closure: _,
247-
ref extra_info,
248246
} => {
249247
region_name.highlight_region_name(err);
250248

@@ -270,14 +268,6 @@ impl<'tcx> BorrowExplanation<'tcx> {
270268
);
271269
};
272270

273-
for extra in extra_info {
274-
match extra {
275-
ExtraConstraintInfo::PlaceholderFromPredicate(span) => {
276-
err.span_note(*span, format!("due to current limitations in the borrow checker, this implies a `'static` lifetime"));
277-
}
278-
}
279-
}
280-
281271
self.add_lifetime_bound_suggestion_to_diagnostic(err, &category, span, region_name);
282272
}
283273
_ => {}
@@ -319,17 +309,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
319309
&self,
320310
borrow_region: RegionVid,
321311
outlived_region: RegionVid,
322-
) -> (ConstraintCategory<'tcx>, bool, Span, Option<RegionName>, Vec<ExtraConstraintInfo>) {
323-
let (blame_constraint, extra_info) = self.regioncx.best_blame_constraint(
324-
borrow_region,
325-
NllRegionVariableOrigin::FreeRegion,
326-
|r| self.regioncx.provides_universal_region(r, borrow_region, outlived_region),
327-
);
328-
let BlameConstraint { category, from_closure, cause, .. } = blame_constraint;
312+
) -> (ConstraintCategory<'tcx>, bool, Span, Option<RegionName>) {
313+
let BlameConstraint { category, from_closure, cause, variance_info: _ } = self
314+
.regioncx
315+
.best_blame_constraint(borrow_region, NllRegionVariableOrigin::FreeRegion, |r| {
316+
self.regioncx.provides_universal_region(r, borrow_region, outlived_region)
317+
});
329318

330319
let outlived_fr_name = self.give_region_a_name(outlived_region);
331320

332-
(category, from_closure, cause.span, outlived_fr_name, extra_info)
321+
(category, from_closure, cause.span, outlived_fr_name)
333322
}
334323

335324
/// Returns structured explanation for *why* the borrow contains the
@@ -401,7 +390,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
401390

402391
None => {
403392
if let Some(region) = self.to_error_region_vid(borrow_region_vid) {
404-
let (category, from_closure, span, region_name, extra_info) =
393+
let (category, from_closure, span, region_name) =
405394
self.free_region_constraint_info(borrow_region_vid, region);
406395
if let Some(region_name) = region_name {
407396
let opt_place_desc = self.describe_place(borrow.borrowed_place.as_ref());
@@ -411,7 +400,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
411400
span,
412401
region_name,
413402
opt_place_desc,
414-
extra_info,
415403
}
416404
} else {
417405
debug!("Could not generate a region name");

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use crate::session_diagnostics::{
3131
};
3232

3333
use super::{OutlivesSuggestionBuilder, RegionName};
34-
use crate::region_infer::{BlameConstraint, ExtraConstraintInfo};
34+
use crate::region_infer::BlameConstraint;
3535
use crate::{
3636
nll::ConstraintDescription,
3737
region_infer::{values::RegionElement, TypeTest},
@@ -354,11 +354,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
354354
) {
355355
debug!("report_region_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);
356356

357-
let (blame_constraint, extra_info) =
357+
let BlameConstraint { category, cause, variance_info, from_closure: _ } =
358358
self.regioncx.best_blame_constraint(fr, fr_origin, |r| {
359359
self.regioncx.provides_universal_region(r, fr, outlived_fr)
360360
});
361-
let BlameConstraint { category, cause, variance_info, .. } = blame_constraint;
362361

363362
debug!("report_region_error: category={:?} {:?} {:?}", category, cause, variance_info);
364363

@@ -467,14 +466,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
467466
}
468467
}
469468

470-
for extra in extra_info {
471-
match extra {
472-
ExtraConstraintInfo::PlaceholderFromPredicate(span) => {
473-
diag.span_note(span, format!("due to current limitations in the borrow checker, this implies a `'static` lifetime"));
474-
}
475-
}
476-
}
477-
478469
self.buffer_error(diag);
479470
}
480471

@@ -566,7 +557,6 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
566557
/// LL | ref_obj(x)
567558
/// | ^^^^^^^^^^ `x` escapes the function body here
568559
/// ```
569-
#[instrument(level = "debug", skip(self))]
570560
fn report_escaping_data_error(
571561
&self,
572562
errci: &ErrorConstraintInfo<'tcx>,

compiler/rustc_borrowck/src/region_infer/mod.rs

+11-38
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,6 @@ enum Trace<'tcx> {
245245
NotVisited,
246246
}
247247

248-
#[derive(Clone, PartialEq, Eq, Debug)]
249-
pub enum ExtraConstraintInfo {
250-
PlaceholderFromPredicate(Span),
251-
}
252-
253248
impl<'tcx> RegionInferenceContext<'tcx> {
254249
/// Creates a new region inference context with a total of
255250
/// `num_region_variables` valid inference variables; the first N
@@ -1823,9 +1818,10 @@ impl<'tcx> RegionInferenceContext<'tcx> {
18231818
fr1_origin: NllRegionVariableOrigin,
18241819
fr2: RegionVid,
18251820
) -> (ConstraintCategory<'tcx>, ObligationCause<'tcx>) {
1826-
let BlameConstraint { category, cause, .. } = self
1827-
.best_blame_constraint(fr1, fr1_origin, |r| self.provides_universal_region(r, fr1, fr2))
1828-
.0;
1821+
let BlameConstraint { category, cause, .. } =
1822+
self.best_blame_constraint(fr1, fr1_origin, |r| {
1823+
self.provides_universal_region(r, fr1, fr2)
1824+
});
18291825
(category, cause)
18301826
}
18311827

@@ -2014,7 +2010,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20142010
from_region: RegionVid,
20152011
from_region_origin: NllRegionVariableOrigin,
20162012
target_test: impl Fn(RegionVid) -> bool,
2017-
) -> (BlameConstraint<'tcx>, Vec<ExtraConstraintInfo>) {
2013+
) -> BlameConstraint<'tcx> {
20182014
// Find all paths
20192015
let (path, target_region) =
20202016
self.find_constraint_paths_between_regions(from_region, target_test).unwrap();
@@ -2030,18 +2026,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20302026
.collect::<Vec<_>>()
20312027
);
20322028

2033-
let mut extra_info = vec![];
2034-
for constraint in path.iter() {
2035-
let outlived = constraint.sub;
2036-
let Some(origin) = self.var_infos.get(outlived) else { continue; };
2037-
let RegionVariableOrigin::Nll(NllRegionVariableOrigin::Placeholder(p)) = origin.origin else { continue; };
2038-
debug!(?constraint, ?p);
2039-
let ConstraintCategory::Predicate(span) = constraint.category else { continue; };
2040-
extra_info.push(ExtraConstraintInfo::PlaceholderFromPredicate(span));
2041-
// We only want to point to one
2042-
break;
2043-
}
2044-
20452029
// We try to avoid reporting a `ConstraintCategory::Predicate` as our best constraint.
20462030
// Instead, we use it to produce an improved `ObligationCauseCode`.
20472031
// FIXME - determine what we should do if we encounter multiple `ConstraintCategory::Predicate`
@@ -2089,7 +2073,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20892073
from_closure,
20902074
cause: ObligationCause::new(span, CRATE_HIR_ID, cause_code),
20912075
variance_info: constraint.variance_info,
2092-
outlives_constraint: *constraint,
20932076
}
20942077
})
20952078
.collect();
@@ -2191,7 +2174,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21912174
let best_choice =
21922175
if blame_source { range.rev().find(find_region) } else { range.find(find_region) };
21932176

2194-
debug!(?best_choice, ?blame_source, ?extra_info);
2177+
debug!(?best_choice, ?blame_source);
21952178

21962179
if let Some(i) = best_choice {
21972180
if let Some(next) = categorized_path.get(i + 1) {
@@ -2200,7 +2183,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22002183
{
22012184
// The return expression is being influenced by the return type being
22022185
// impl Trait, point at the return type and not the return expr.
2203-
return (next.clone(), extra_info);
2186+
return next.clone();
22042187
}
22052188
}
22062189

@@ -2220,7 +2203,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22202203
}
22212204
}
22222205

2223-
return (categorized_path[i].clone(), extra_info);
2206+
return categorized_path[i].clone();
22242207
}
22252208

22262209
// If that search fails, that is.. unusual. Maybe everything
@@ -2230,7 +2213,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22302213
categorized_path.sort_by(|p0, p1| p0.category.cmp(&p1.category));
22312214
debug!("sorted_path={:#?}", categorized_path);
22322215

2233-
(categorized_path.remove(0), extra_info)
2216+
categorized_path.remove(0)
22342217
}
22352218

22362219
pub(crate) fn universe_info(&self, universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
@@ -2312,13 +2295,7 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
23122295
outlives_requirement={:?}",
23132296
region, outlived_region, outlives_requirement,
23142297
);
2315-
(
2316-
ty::Binder::dummy(ty::OutlivesPredicate(
2317-
region.into(),
2318-
outlived_region,
2319-
)),
2320-
ConstraintCategory::BoringNoLocation,
2321-
)
2298+
ty::Binder::dummy(ty::OutlivesPredicate(region.into(), outlived_region))
23222299
}
23232300

23242301
ClosureOutlivesSubject::Ty(ty) => {
@@ -2328,10 +2305,7 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
23282305
outlives_requirement={:?}",
23292306
ty, outlived_region, outlives_requirement,
23302307
);
2331-
(
2332-
ty::Binder::dummy(ty::OutlivesPredicate(ty.into(), outlived_region)),
2333-
ConstraintCategory::BoringNoLocation,
2334-
)
2308+
ty::Binder::dummy(ty::OutlivesPredicate(ty.into(), outlived_region))
23352309
}
23362310
}
23372311
})
@@ -2345,5 +2319,4 @@ pub struct BlameConstraint<'tcx> {
23452319
pub from_closure: bool,
23462320
pub cause: ObligationCause<'tcx>,
23472321
pub variance_info: ty::VarianceDiagInfo<'tcx>,
2348-
pub outlives_constraint: OutlivesConstraint<'tcx>,
23492322
}

compiler/rustc_borrowck/src/type_check/canonical.rs

+5-21
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
2525
/// constraints should occur within this method so that those
2626
/// constraints can be properly localized!**
2727
#[instrument(skip(self, op), level = "trace")]
28-
pub(super) fn fully_perform_op<R: fmt::Debug, Op>(
28+
pub(super) fn fully_perform_op<R, Op>(
2929
&mut self,
3030
locations: Locations,
3131
category: ConstraintCategory<'tcx>,
@@ -39,8 +39,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
3939

4040
let TypeOpOutput { output, constraints, error_info } = op.fully_perform(self.infcx)?;
4141

42-
debug!(?output, ?constraints);
43-
4442
if let Some(data) = constraints {
4543
self.push_region_constraints(locations, category, data);
4644
}
@@ -104,7 +102,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
104102
);
105103
}
106104

107-
#[instrument(level = "debug", skip(self))]
108105
pub(super) fn normalize_and_prove_instantiated_predicates(
109106
&mut self,
110107
// Keep this parameter for now, in case we start using
@@ -119,9 +116,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
119116
.zip(instantiated_predicates.spans.into_iter())
120117
{
121118
debug!(?predicate);
122-
let category = ConstraintCategory::Predicate(span);
123-
let predicate = self.normalize_with_category(predicate, locations, category);
124-
self.prove_predicate(predicate, locations, category);
119+
let predicate = self.normalize(predicate, locations);
120+
self.prove_predicate(predicate, locations, ConstraintCategory::Predicate(span));
125121
}
126122
}
127123

@@ -157,27 +153,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
157153
})
158154
}
159155

160-
pub(super) fn normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T
161-
where
162-
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
163-
{
164-
self.normalize_with_category(value, location, ConstraintCategory::Boring)
165-
}
166-
167156
#[instrument(skip(self), level = "debug")]
168-
pub(super) fn normalize_with_category<T>(
169-
&mut self,
170-
value: T,
171-
location: impl NormalizeLocation,
172-
category: ConstraintCategory<'tcx>,
173-
) -> T
157+
pub(super) fn normalize<T>(&mut self, value: T, location: impl NormalizeLocation) -> T
174158
where
175159
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
176160
{
177161
let param_env = self.param_env;
178162
self.fully_perform_op(
179163
location.to_locations(),
180-
category,
164+
ConstraintCategory::Boring,
181165
param_env.and(type_op::normalize::Normalize::new(value)),
182166
)
183167
.unwrap_or_else(|NoSolution| {

0 commit comments

Comments
 (0)