Skip to content

Commit 92b759f

Browse files
committed
Revert "Better errors for implied static bound"
This reverts commit c75817b.
1 parent bba514b commit 92b759f

File tree

22 files changed

+98
-330
lines changed

22 files changed

+98
-330
lines changed

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

Lines changed: 9 additions & 21 deletions
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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
354354
) {
355355
debug!("report_region_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);
356356

357-
let BlameConstraint { category, cause, variance_info, .. } = self
358-
.regioncx
359-
.best_blame_constraint(fr, fr_origin, |r| {
357+
let BlameConstraint { category, cause, variance_info, from_closure: _ } =
358+
self.regioncx.best_blame_constraint(fr, fr_origin, |r| {
360359
self.regioncx.provides_universal_region(r, fr, outlived_fr)
361-
})
362-
.0;
360+
});
363361

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

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 11 additions & 38 deletions
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

Lines changed: 1 addition & 3 deletions
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
}

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
8686
}
8787
}
8888

89-
fn convert(&mut self, query_constraint: &QueryOutlivesConstraint<'tcx>) {
89+
pub(super) fn convert(&mut self, query_constraint: &QueryOutlivesConstraint<'tcx>) {
9090
debug!("generate: constraints at: {:#?}", self.locations);
9191

9292
// Extract out various useful fields we'll need below.
@@ -98,18 +98,15 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
9898
// region constraints like `for<'a> 'a: 'b`. At some point
9999
// when we move to universes, we will, and this assertion
100100
// will start to fail.
101-
let ty::OutlivesPredicate(k1, r2) =
102-
query_constraint.0.no_bound_vars().unwrap_or_else(|| {
103-
bug!("query_constraint {:?} contained bound vars", query_constraint,);
104-
});
105-
106-
let constraint_category = query_constraint.1;
101+
let ty::OutlivesPredicate(k1, r2) = query_constraint.no_bound_vars().unwrap_or_else(|| {
102+
bug!("query_constraint {:?} contained bound vars", query_constraint,);
103+
});
107104

108105
match k1.unpack() {
109106
GenericArgKind::Lifetime(r1) => {
110107
let r1_vid = self.to_region_vid(r1);
111108
let r2_vid = self.to_region_vid(r2);
112-
self.add_outlives(r1_vid, r2_vid, constraint_category);
109+
self.add_outlives(r1_vid, r2_vid);
113110
}
114111

115112
GenericArgKind::Type(t1) => {
@@ -124,7 +121,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
124121
Some(implicit_region_bound),
125122
param_env,
126123
)
127-
.type_must_outlive(origin, t1, r2, constraint_category);
124+
.type_must_outlive(origin, t1, r2);
128125
}
129126

130127
GenericArgKind::Const(_) => {
@@ -171,19 +168,10 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
171168
}
172169
}
173170

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-
};
171+
fn add_outlives(&mut self, sup: ty::RegionVid, sub: ty::RegionVid) {
184172
self.constraints.outlives_constraints.push(OutlivesConstraint {
185173
locations: self.locations,
186-
category,
174+
category: self.category,
187175
span: self.span,
188176
sub,
189177
sup,
@@ -203,11 +191,10 @@ impl<'a, 'b, 'tcx> TypeOutlivesDelegate<'tcx> for &'a mut ConstraintConversion<'
203191
_origin: SubregionOrigin<'tcx>,
204192
a: ty::Region<'tcx>,
205193
b: ty::Region<'tcx>,
206-
constraint_category: ConstraintCategory<'tcx>,
207194
) {
208195
let b = self.to_region_vid(b);
209196
let a = self.to_region_vid(a);
210-
self.add_outlives(b, a, constraint_category);
197+
self.add_outlives(b, a);
211198
}
212199

213200
fn push_verify(

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2591,7 +2591,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
25912591
.enumerate()
25922592
.filter_map(|(idx, constraint)| {
25932593
let ty::OutlivesPredicate(k1, r2) =
2594-
constraint.0.no_bound_vars().unwrap_or_else(|| {
2594+
constraint.no_bound_vars().unwrap_or_else(|| {
25952595
bug!("query_constraint {:?} contained bound vars", constraint,);
25962596
});
25972597

compiler/rustc_error_messages/locales/en-US/infer.ftl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ infer_relate_param_bound = ...so that the type `{$name}` will meet its required
110110
infer_relate_param_bound_2 = ...that is required by this bound
111111
infer_relate_region_param_bound = ...so that the declared lifetime parameter bounds are satisfied
112112
infer_compare_impl_item_obligation = ...so that the definition in impl matches the definition from the trait
113-
infer_ascribe_user_type_prove_predicate = ...so that the where clause holds
114113
115114
infer_nothing = {""}
116115

0 commit comments

Comments
 (0)