Skip to content

Commit da7ffa2

Browse files
committed
Auto merge of rust-lang#102676 - cuviper:beta-next, r=cuviper
[beta] backports * Avoid duplicating StorageLive in let-else rust-lang#101894 * Re-add HRTB implied static bug note rust-lang#101924 * Revert "Copy stage0 binaries into stage0-sysroot" rust-lang#101942 * implied_bounds: deal with inference vars rust-lang#102016 * fix ConstProp handling of written_only_inside_own_block_locals rust-lang#102045 * Fix wrongly refactored Lift impl rust-lang#102088 * Fix a typo “pararmeter” in error message rust-lang#102119 * Deny associated type bindings within associated type bindings rust-lang#102338 * Continue migration of CSS themes rust-lang#101934 * Fix search result colors rust-lang#102369 * Fix unwind drop glue for if-then scopes rust-lang#102394 * Revert "Use getentropy when possible on all Apple platforms" rust-lang#102693 * Fix associated type bindings with anon const in GAT position rust-lang#102336 * Revert perf-regression 101620 rust-lang#102064 * `EscapeAscii` is not an `ExactSizeIterator` rust-lang#99880
2 parents e5da984 + f73da69 commit da7ffa2

File tree

95 files changed

+1967
-1075
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1967
-1075
lines changed

compiler/rustc_borrowck/src/constraints/mod.rs

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

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

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+21-9
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;
18+
use crate::region_infer::{BlameConstraint, ExtraConstraintInfo};
1919
use crate::{
2020
borrow_set::BorrowData, nll::ConstraintDescription, region_infer::Cause, MirBorrowckCtxt,
2121
WriteKind,
@@ -38,6 +38,7 @@ pub(crate) enum BorrowExplanation<'tcx> {
3838
span: Span,
3939
region_name: RegionName,
4040
opt_place_desc: Option<String>,
41+
extra_info: Vec<ExtraConstraintInfo>,
4142
},
4243
Unexplained,
4344
}
@@ -243,6 +244,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
243244
ref region_name,
244245
ref opt_place_desc,
245246
from_closure: _,
247+
ref extra_info,
246248
} => {
247249
region_name.highlight_region_name(err);
248250

@@ -268,6 +270,14 @@ impl<'tcx> BorrowExplanation<'tcx> {
268270
);
269271
};
270272

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+
271281
self.add_lifetime_bound_suggestion_to_diagnostic(err, &category, span, region_name);
272282
}
273283
_ => {}
@@ -309,16 +319,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
309319
&self,
310320
borrow_region: RegionVid,
311321
outlived_region: RegionVid,
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-
});
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;
318329

319330
let outlived_fr_name = self.give_region_a_name(outlived_region);
320331

321-
(category, from_closure, cause.span, outlived_fr_name)
332+
(category, from_closure, cause.span, outlived_fr_name, extra_info)
322333
}
323334

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

391402
None => {
392403
if let Some(region) = self.to_error_region_vid(borrow_region_vid) {
393-
let (category, from_closure, span, region_name) =
404+
let (category, from_closure, span, region_name, extra_info) =
394405
self.free_region_constraint_info(borrow_region_vid, region);
395406
if let Some(region_name) = region_name {
396407
let opt_place_desc = self.describe_place(borrow.borrowed_place.as_ref());
@@ -400,6 +411,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
400411
span,
401412
region_name,
402413
opt_place_desc,
414+
extra_info,
403415
}
404416
} else {
405417
debug!("Could not generate a region name");

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

+12-2
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;
34+
use crate::region_infer::{BlameConstraint, ExtraConstraintInfo};
3535
use crate::{
3636
nll::ConstraintDescription,
3737
region_infer::{values::RegionElement, TypeTest},
@@ -354,10 +354,11 @@ 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, from_closure: _ } =
357+
let (blame_constraint, extra_info) =
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;
361362

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

@@ -466,6 +467,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
466467
}
467468
}
468469

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+
469478
self.buffer_error(diag);
470479
}
471480

@@ -557,6 +566,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
557566
/// LL | ref_obj(x)
558567
/// | ^^^^^^^^^^ `x` escapes the function body here
559568
/// ```
569+
#[instrument(level = "debug", skip(self))]
560570
fn report_escaping_data_error(
561571
&self,
562572
errci: &ErrorConstraintInfo<'tcx>,

compiler/rustc_borrowck/src/region_infer/mod.rs

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

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

@@ -2010,7 +2014,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20102014
from_region: RegionVid,
20112015
from_region_origin: NllRegionVariableOrigin,
20122016
target_test: impl Fn(RegionVid) -> bool,
2013-
) -> BlameConstraint<'tcx> {
2017+
) -> (BlameConstraint<'tcx>, Vec<ExtraConstraintInfo>) {
20142018
// Find all paths
20152019
let (path, target_region) =
20162020
self.find_constraint_paths_between_regions(from_region, target_test).unwrap();
@@ -2026,6 +2030,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20262030
.collect::<Vec<_>>()
20272031
);
20282032

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+
20292045
// We try to avoid reporting a `ConstraintCategory::Predicate` as our best constraint.
20302046
// Instead, we use it to produce an improved `ObligationCauseCode`.
20312047
// FIXME - determine what we should do if we encounter multiple `ConstraintCategory::Predicate`
@@ -2073,6 +2089,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
20732089
from_closure,
20742090
cause: ObligationCause::new(span, CRATE_HIR_ID, cause_code),
20752091
variance_info: constraint.variance_info,
2092+
outlives_constraint: *constraint,
20762093
}
20772094
})
20782095
.collect();
@@ -2174,7 +2191,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21742191
let best_choice =
21752192
if blame_source { range.rev().find(find_region) } else { range.find(find_region) };
21762193

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

21792196
if let Some(i) = best_choice {
21802197
if let Some(next) = categorized_path.get(i + 1) {
@@ -2183,7 +2200,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21832200
{
21842201
// The return expression is being influenced by the return type being
21852202
// impl Trait, point at the return type and not the return expr.
2186-
return next.clone();
2203+
return (next.clone(), extra_info);
21872204
}
21882205
}
21892206

@@ -2203,7 +2220,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
22032220
}
22042221
}
22052222

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

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

2216-
categorized_path.remove(0)
2233+
(categorized_path.remove(0), extra_info)
22172234
}
22182235

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

23012324
ClosureOutlivesSubject::Ty(ty) => {
@@ -2305,7 +2328,10 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx
23052328
outlives_requirement={:?}",
23062329
ty, outlived_region, outlives_requirement,
23072330
);
2308-
ty::Binder::dummy(ty::OutlivesPredicate(ty.into(), outlived_region))
2331+
(
2332+
ty::Binder::dummy(ty::OutlivesPredicate(ty.into(), outlived_region)),
2333+
ConstraintCategory::BoringNoLocation,
2334+
)
23092335
}
23102336
}
23112337
})
@@ -2319,4 +2345,5 @@ pub struct BlameConstraint<'tcx> {
23192345
pub from_closure: bool,
23202346
pub cause: ObligationCause<'tcx>,
23212347
pub variance_info: ty::VarianceDiagInfo<'tcx>,
2348+
pub outlives_constraint: OutlivesConstraint<'tcx>,
23222349
}

compiler/rustc_borrowck/src/type_check/canonical.rs

+21-5
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, Op>(
28+
pub(super) fn fully_perform_op<R: fmt::Debug, Op>(
2929
&mut self,
3030
locations: Locations,
3131
category: ConstraintCategory<'tcx>,
@@ -39,6 +39,8 @@ 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+
4244
if let Some(data) = constraints {
4345
self.push_region_constraints(locations, category, data);
4446
}
@@ -102,6 +104,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
102104
);
103105
}
104106

107+
#[instrument(level = "debug", skip(self))]
105108
pub(super) fn normalize_and_prove_instantiated_predicates(
106109
&mut self,
107110
// Keep this parameter for now, in case we start using
@@ -116,8 +119,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
116119
.zip(instantiated_predicates.spans.into_iter())
117120
{
118121
debug!(?predicate);
119-
let predicate = self.normalize(predicate, locations);
120-
self.prove_predicate(predicate, locations, ConstraintCategory::Predicate(span));
122+
let category = ConstraintCategory::Predicate(span);
123+
let predicate = self.normalize_with_category(predicate, locations, category);
124+
self.prove_predicate(predicate, locations, category);
121125
}
122126
}
123127

@@ -153,15 +157,27 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
153157
})
154158
}
155159

156-
#[instrument(skip(self), level = "debug")]
157160
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+
167+
#[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
158174
where
159175
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
160176
{
161177
let param_env = self.param_env;
162178
self.fully_perform_op(
163179
location.to_locations(),
164-
ConstraintCategory::Boring,
180+
category,
165181
param_env.and(type_op::normalize::Normalize::new(value)),
166182
)
167183
.unwrap_or_else(|NoSolution| {

0 commit comments

Comments
 (0)