cleanup: remove ExtraConstraintInfo
`ExtraConstraintInfo` was used only for a single subdiagnostic, so this moves the logic for that to its own function and eliminates the indirection. In order to do so cleanly, this also changes the arguments to `BorrowExplanation::add_explanation_to_diagnostic`, which happens to simplify its call sites.
This commit is contained in:
parent
243d2ca4db
commit
aa8d5bff4c
5 changed files with 68 additions and 131 deletions
|
@ -1516,15 +1516,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
});
|
});
|
||||||
|
|
||||||
self.explain_why_borrow_contains_point(location, borrow, None)
|
self.explain_why_borrow_contains_point(location, borrow, None)
|
||||||
.add_explanation_to_diagnostic(
|
.add_explanation_to_diagnostic(&self, &mut err, "", Some(borrow_span), None);
|
||||||
self.infcx.tcx,
|
|
||||||
self.body,
|
|
||||||
&self.local_names,
|
|
||||||
&mut err,
|
|
||||||
"",
|
|
||||||
Some(borrow_span),
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
self.suggest_copy_for_type_in_cloned_ref(&mut err, place);
|
self.suggest_copy_for_type_in_cloned_ref(&mut err, place);
|
||||||
let typeck_results = self.infcx.tcx.typeck(self.mir_def_id());
|
let typeck_results = self.infcx.tcx.typeck(self.mir_def_id());
|
||||||
if let Some(expr) = self.find_expr(borrow_span) {
|
if let Some(expr) = self.find_expr(borrow_span) {
|
||||||
|
@ -1591,15 +1583,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
});
|
});
|
||||||
|
|
||||||
self.explain_why_borrow_contains_point(location, borrow, None)
|
self.explain_why_borrow_contains_point(location, borrow, None)
|
||||||
.add_explanation_to_diagnostic(
|
.add_explanation_to_diagnostic(&self, &mut err, "", None, None);
|
||||||
self.infcx.tcx,
|
|
||||||
self.body,
|
|
||||||
&self.local_names,
|
|
||||||
&mut err,
|
|
||||||
"",
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
err
|
err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1886,9 +1870,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
explanation.add_explanation_to_diagnostic(
|
explanation.add_explanation_to_diagnostic(
|
||||||
self.infcx.tcx,
|
&self,
|
||||||
self.body,
|
|
||||||
&self.local_names,
|
|
||||||
&mut err,
|
&mut err,
|
||||||
first_borrow_desc,
|
first_borrow_desc,
|
||||||
None,
|
None,
|
||||||
|
@ -3046,15 +3028,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
|
|
||||||
if let BorrowExplanation::MustBeValidFor { .. } = explanation {
|
if let BorrowExplanation::MustBeValidFor { .. } = explanation {
|
||||||
} else {
|
} else {
|
||||||
explanation.add_explanation_to_diagnostic(
|
explanation.add_explanation_to_diagnostic(&self, &mut err, "", None, None);
|
||||||
self.infcx.tcx,
|
|
||||||
self.body,
|
|
||||||
&self.local_names,
|
|
||||||
&mut err,
|
|
||||||
"",
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err.span_label(borrow_span, "borrowed value does not live long enough");
|
err.span_label(borrow_span, "borrowed value does not live long enough");
|
||||||
|
@ -3067,15 +3041,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
explanation.add_explanation_to_diagnostic(
|
explanation.add_explanation_to_diagnostic(&self, &mut err, "", Some(borrow_span), None);
|
||||||
self.infcx.tcx,
|
|
||||||
self.body,
|
|
||||||
&self.local_names,
|
|
||||||
&mut err,
|
|
||||||
"",
|
|
||||||
Some(borrow_span),
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err
|
err
|
||||||
|
@ -3128,15 +3094,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
explanation.add_explanation_to_diagnostic(
|
explanation.add_explanation_to_diagnostic(&self, &mut err, "", None, None);
|
||||||
self.infcx.tcx,
|
|
||||||
self.body,
|
|
||||||
&self.local_names,
|
|
||||||
&mut err,
|
|
||||||
"",
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
|
|
||||||
self.buffer_error(err);
|
self.buffer_error(err);
|
||||||
}
|
}
|
||||||
|
@ -3309,15 +3267,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
explanation.add_explanation_to_diagnostic(
|
explanation.add_explanation_to_diagnostic(&self, &mut err, "", None, None);
|
||||||
self.infcx.tcx,
|
|
||||||
self.body,
|
|
||||||
&self.local_names,
|
|
||||||
&mut err,
|
|
||||||
"",
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
|
|
||||||
borrow_spans.args_subdiag(&mut err, |args_span| {
|
borrow_spans.args_subdiag(&mut err, |args_span| {
|
||||||
crate::session_diagnostics::CaptureArgLabel::Capture {
|
crate::session_diagnostics::CaptureArgLabel::Capture {
|
||||||
|
@ -3808,15 +3758,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.explain_why_borrow_contains_point(location, loan, None).add_explanation_to_diagnostic(
|
self.explain_why_borrow_contains_point(location, loan, None)
|
||||||
self.infcx.tcx,
|
.add_explanation_to_diagnostic(&self, &mut err, "", None, None);
|
||||||
self.body,
|
|
||||||
&self.local_names,
|
|
||||||
&mut err,
|
|
||||||
"",
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
|
|
||||||
self.explain_deref_coercion(loan, &mut err);
|
self.explain_deref_coercion(loan, &mut err);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ use std::assert_matches::assert_matches;
|
||||||
use rustc_errors::{Applicability, Diag};
|
use rustc_errors::{Applicability, Diag};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::intravisit::Visitor;
|
use rustc_hir::intravisit::Visitor;
|
||||||
use rustc_index::IndexSlice;
|
|
||||||
use rustc_infer::infer::NllRegionVariableOrigin;
|
use rustc_infer::infer::NllRegionVariableOrigin;
|
||||||
use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault;
|
use rustc_middle::middle::resolve_bound_vars::ObjectLifetimeDefault;
|
||||||
use rustc_middle::mir::{
|
use rustc_middle::mir::{
|
||||||
|
@ -18,14 +17,15 @@ use rustc_middle::mir::{
|
||||||
use rustc_middle::ty::adjustment::PointerCoercion;
|
use rustc_middle::ty::adjustment::PointerCoercion;
|
||||||
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt};
|
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt};
|
||||||
use rustc_middle::util::CallKind;
|
use rustc_middle::util::CallKind;
|
||||||
use rustc_span::{DesugaringKind, Span, Symbol, kw, sym};
|
use rustc_span::{DesugaringKind, Span, kw, sym};
|
||||||
use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
|
use rustc_trait_selection::error_reporting::traits::FindExprBySpan;
|
||||||
use tracing::{debug, instrument};
|
use tracing::{debug, instrument};
|
||||||
|
|
||||||
use super::{RegionName, UseSpans, find_use};
|
use super::{RegionName, UseSpans, find_use};
|
||||||
use crate::borrow_set::BorrowData;
|
use crate::borrow_set::BorrowData;
|
||||||
|
use crate::constraints::OutlivesConstraint;
|
||||||
use crate::nll::ConstraintDescription;
|
use crate::nll::ConstraintDescription;
|
||||||
use crate::region_infer::{BlameConstraint, Cause, ExtraConstraintInfo};
|
use crate::region_infer::{BlameConstraint, Cause};
|
||||||
use crate::{MirBorrowckCtxt, WriteKind};
|
use crate::{MirBorrowckCtxt, WriteKind};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -43,7 +43,7 @@ pub(crate) enum BorrowExplanation<'tcx> {
|
||||||
span: Span,
|
span: Span,
|
||||||
region_name: RegionName,
|
region_name: RegionName,
|
||||||
opt_place_desc: Option<String>,
|
opt_place_desc: Option<String>,
|
||||||
extra_info: Vec<ExtraConstraintInfo>,
|
path: Vec<OutlivesConstraint<'tcx>>,
|
||||||
},
|
},
|
||||||
Unexplained,
|
Unexplained,
|
||||||
}
|
}
|
||||||
|
@ -63,14 +63,16 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
||||||
}
|
}
|
||||||
pub(crate) fn add_explanation_to_diagnostic(
|
pub(crate) fn add_explanation_to_diagnostic(
|
||||||
&self,
|
&self,
|
||||||
tcx: TyCtxt<'tcx>,
|
cx: &MirBorrowckCtxt<'_, '_, 'tcx>,
|
||||||
body: &Body<'tcx>,
|
|
||||||
local_names: &IndexSlice<Local, Option<Symbol>>,
|
|
||||||
err: &mut Diag<'_>,
|
err: &mut Diag<'_>,
|
||||||
borrow_desc: &str,
|
borrow_desc: &str,
|
||||||
borrow_span: Option<Span>,
|
borrow_span: Option<Span>,
|
||||||
multiple_borrow_span: Option<(Span, Span)>,
|
multiple_borrow_span: Option<(Span, Span)>,
|
||||||
) {
|
) {
|
||||||
|
let tcx = cx.infcx.tcx;
|
||||||
|
let body = cx.body;
|
||||||
|
let local_names = &cx.local_names;
|
||||||
|
|
||||||
if let Some(span) = borrow_span {
|
if let Some(span) = borrow_span {
|
||||||
let def_id = body.source.def_id();
|
let def_id = body.source.def_id();
|
||||||
if let Some(node) = tcx.hir().get_if_local(def_id)
|
if let Some(node) = tcx.hir().get_if_local(def_id)
|
||||||
|
@ -306,7 +308,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
||||||
ref region_name,
|
ref region_name,
|
||||||
ref opt_place_desc,
|
ref opt_place_desc,
|
||||||
from_closure: _,
|
from_closure: _,
|
||||||
ref extra_info,
|
ref path,
|
||||||
} => {
|
} => {
|
||||||
region_name.highlight_region_name(err);
|
region_name.highlight_region_name(err);
|
||||||
|
|
||||||
|
@ -328,13 +330,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
for extra in extra_info {
|
cx.add_placeholder_from_predicate_note(err, &path);
|
||||||
match extra {
|
|
||||||
ExtraConstraintInfo::PlaceholderFromPredicate(span) => {
|
|
||||||
err.span_note(*span, "due to current limitations in the borrow checker, this implies a `'static` lifetime");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let ConstraintCategory::Cast {
|
if let ConstraintCategory::Cast {
|
||||||
is_implicit_coercion: true,
|
is_implicit_coercion: true,
|
||||||
|
@ -487,8 +483,9 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
||||||
&self,
|
&self,
|
||||||
borrow_region: RegionVid,
|
borrow_region: RegionVid,
|
||||||
outlived_region: RegionVid,
|
outlived_region: RegionVid,
|
||||||
) -> (ConstraintCategory<'tcx>, bool, Span, Option<RegionName>, Vec<ExtraConstraintInfo>) {
|
) -> (ConstraintCategory<'tcx>, bool, Span, Option<RegionName>, Vec<OutlivesConstraint<'tcx>>)
|
||||||
let (blame_constraint, extra_info) = self.regioncx.best_blame_constraint(
|
{
|
||||||
|
let (blame_constraint, path) = self.regioncx.best_blame_constraint(
|
||||||
borrow_region,
|
borrow_region,
|
||||||
NllRegionVariableOrigin::FreeRegion,
|
NllRegionVariableOrigin::FreeRegion,
|
||||||
|r| self.regioncx.provides_universal_region(r, borrow_region, outlived_region),
|
|r| self.regioncx.provides_universal_region(r, borrow_region, outlived_region),
|
||||||
|
@ -497,7 +494,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
||||||
|
|
||||||
let outlived_fr_name = self.give_region_a_name(outlived_region);
|
let outlived_fr_name = self.give_region_a_name(outlived_region);
|
||||||
|
|
||||||
(category, from_closure, cause.span, outlived_fr_name, extra_info)
|
(category, from_closure, cause.span, outlived_fr_name, path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns structured explanation for *why* the borrow contains the
|
/// Returns structured explanation for *why* the borrow contains the
|
||||||
|
@ -596,7 +593,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
||||||
|
|
||||||
None => {
|
None => {
|
||||||
if let Some(region) = self.to_error_region_vid(borrow_region_vid) {
|
if let Some(region) = self.to_error_region_vid(borrow_region_vid) {
|
||||||
let (category, from_closure, span, region_name, extra_info) =
|
let (category, from_closure, span, region_name, path) =
|
||||||
self.free_region_constraint_info(borrow_region_vid, region);
|
self.free_region_constraint_info(borrow_region_vid, region);
|
||||||
if let Some(region_name) = region_name {
|
if let Some(region_name) = region_name {
|
||||||
let opt_place_desc = self.describe_place(borrow.borrowed_place.as_ref());
|
let opt_place_desc = self.describe_place(borrow.borrowed_place.as_ref());
|
||||||
|
@ -606,7 +603,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
|
||||||
span,
|
span,
|
||||||
region_name,
|
region_name,
|
||||||
opt_place_desc,
|
opt_place_desc,
|
||||||
extra_info,
|
path,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug!("Could not generate a region name");
|
debug!("Could not generate a region name");
|
||||||
|
|
|
@ -8,14 +8,16 @@ use rustc_errors::{Applicability, Diag, MultiSpan};
|
||||||
use rustc_hir::def::{CtorKind, Namespace};
|
use rustc_hir::def::{CtorKind, Namespace};
|
||||||
use rustc_hir::{self as hir, CoroutineKind, LangItem};
|
use rustc_hir::{self as hir, CoroutineKind, LangItem};
|
||||||
use rustc_index::IndexSlice;
|
use rustc_index::IndexSlice;
|
||||||
use rustc_infer::infer::BoundRegionConversionTime;
|
use rustc_infer::infer::{
|
||||||
|
BoundRegionConversionTime, NllRegionVariableOrigin, RegionVariableOrigin,
|
||||||
|
};
|
||||||
use rustc_infer::traits::SelectionError;
|
use rustc_infer::traits::SelectionError;
|
||||||
use rustc_middle::bug;
|
use rustc_middle::bug;
|
||||||
use rustc_middle::mir::tcx::PlaceTy;
|
use rustc_middle::mir::tcx::PlaceTy;
|
||||||
use rustc_middle::mir::{
|
use rustc_middle::mir::{
|
||||||
AggregateKind, CallSource, ConstOperand, FakeReadCause, Local, LocalInfo, LocalKind, Location,
|
AggregateKind, CallSource, ConstOperand, ConstraintCategory, FakeReadCause, Local, LocalInfo,
|
||||||
Operand, Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator,
|
LocalKind, Location, Operand, Place, PlaceRef, ProjectionElem, Rvalue, Statement,
|
||||||
TerminatorKind,
|
StatementKind, Terminator, TerminatorKind,
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::print::Print;
|
use rustc_middle::ty::print::Print;
|
||||||
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
|
||||||
|
@ -33,6 +35,7 @@ use tracing::debug;
|
||||||
|
|
||||||
use super::MirBorrowckCtxt;
|
use super::MirBorrowckCtxt;
|
||||||
use super::borrow_set::BorrowData;
|
use super::borrow_set::BorrowData;
|
||||||
|
use crate::constraints::OutlivesConstraint;
|
||||||
use crate::fluent_generated as fluent;
|
use crate::fluent_generated as fluent;
|
||||||
use crate::session_diagnostics::{
|
use crate::session_diagnostics::{
|
||||||
CaptureArgLabel, CaptureReasonLabel, CaptureReasonNote, CaptureReasonSuggest, CaptureVarCause,
|
CaptureArgLabel, CaptureReasonLabel, CaptureReasonNote, CaptureReasonSuggest, CaptureVarCause,
|
||||||
|
@ -619,6 +622,31 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
region.print(&mut printer).unwrap();
|
region.print(&mut printer).unwrap();
|
||||||
printer.into_buffer()
|
printer.into_buffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Add a note to region errors and borrow explanations when higher-ranked regions in predicates
|
||||||
|
/// implicitly introduce an "outlives `'static`" constraint.
|
||||||
|
fn add_placeholder_from_predicate_note(
|
||||||
|
&self,
|
||||||
|
err: &mut Diag<'_>,
|
||||||
|
path: &[OutlivesConstraint<'tcx>],
|
||||||
|
) {
|
||||||
|
let predicate_span = path.iter().find_map(|constraint| {
|
||||||
|
let outlived = constraint.sub;
|
||||||
|
if let Some(origin) = self.regioncx.var_infos.get(outlived)
|
||||||
|
&& let RegionVariableOrigin::Nll(NllRegionVariableOrigin::Placeholder(_)) =
|
||||||
|
origin.origin
|
||||||
|
&& let ConstraintCategory::Predicate(span) = constraint.category
|
||||||
|
{
|
||||||
|
Some(span)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if let Some(span) = predicate_span {
|
||||||
|
err.span_note(span, "due to current limitations in the borrow checker, this implies a `'static` lifetime");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The span(s) associated to a use of a place.
|
/// The span(s) associated to a use of a place.
|
||||||
|
|
|
@ -29,7 +29,7 @@ use tracing::{debug, instrument, trace};
|
||||||
use super::{OutlivesSuggestionBuilder, RegionName, RegionNameSource};
|
use super::{OutlivesSuggestionBuilder, RegionName, RegionNameSource};
|
||||||
use crate::nll::ConstraintDescription;
|
use crate::nll::ConstraintDescription;
|
||||||
use crate::region_infer::values::RegionElement;
|
use crate::region_infer::values::RegionElement;
|
||||||
use crate::region_infer::{BlameConstraint, ExtraConstraintInfo, TypeTest};
|
use crate::region_infer::{BlameConstraint, TypeTest};
|
||||||
use crate::session_diagnostics::{
|
use crate::session_diagnostics::{
|
||||||
FnMutError, FnMutReturnTypeErr, GenericDoesNotLiveLongEnough, LifetimeOutliveErr,
|
FnMutError, FnMutReturnTypeErr, GenericDoesNotLiveLongEnough, LifetimeOutliveErr,
|
||||||
LifetimeReturnCategoryErr, RequireStaticErr, VarHereDenote,
|
LifetimeReturnCategoryErr, RequireStaticErr, VarHereDenote,
|
||||||
|
@ -440,10 +440,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
) {
|
) {
|
||||||
debug!("report_region_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);
|
debug!("report_region_error(fr={:?}, outlived_fr={:?})", fr, outlived_fr);
|
||||||
|
|
||||||
let (blame_constraint, extra_info) =
|
let (blame_constraint, path) = self.regioncx.best_blame_constraint(fr, fr_origin, |r| {
|
||||||
self.regioncx.best_blame_constraint(fr, fr_origin, |r| {
|
self.regioncx.provides_universal_region(r, fr, outlived_fr)
|
||||||
self.regioncx.provides_universal_region(r, fr, outlived_fr)
|
});
|
||||||
});
|
|
||||||
let BlameConstraint { category, cause, variance_info, .. } = blame_constraint;
|
let BlameConstraint { category, cause, variance_info, .. } = blame_constraint;
|
||||||
|
|
||||||
debug!("report_region_error: category={:?} {:?} {:?}", category, cause, variance_info);
|
debug!("report_region_error: category={:?} {:?} {:?}", category, cause, variance_info);
|
||||||
|
@ -554,13 +553,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for extra in extra_info {
|
self.add_placeholder_from_predicate_note(&mut diag, &path);
|
||||||
match extra {
|
|
||||||
ExtraConstraintInfo::PlaceholderFromPredicate(span) => {
|
|
||||||
diag.span_note(span, "due to current limitations in the borrow checker, this implies a `'static` lifetime");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.buffer_error(diag);
|
self.buffer_error(diag);
|
||||||
}
|
}
|
||||||
|
|
|
@ -315,11 +315,6 @@ enum Trace<'tcx> {
|
||||||
NotVisited,
|
NotVisited,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
||||||
pub(crate) enum ExtraConstraintInfo {
|
|
||||||
PlaceholderFromPredicate(Span),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[instrument(skip(infcx, sccs), level = "debug")]
|
#[instrument(skip(infcx, sccs), level = "debug")]
|
||||||
fn sccs_info<'tcx>(infcx: &BorrowckInferCtxt<'tcx>, sccs: &ConstraintSccs) {
|
fn sccs_info<'tcx>(infcx: &BorrowckInferCtxt<'tcx>, sccs: &ConstraintSccs) {
|
||||||
use crate::renumber::RegionCtxt;
|
use crate::renumber::RegionCtxt;
|
||||||
|
@ -1948,7 +1943,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
from_region: RegionVid,
|
from_region: RegionVid,
|
||||||
from_region_origin: NllRegionVariableOrigin,
|
from_region_origin: NllRegionVariableOrigin,
|
||||||
target_test: impl Fn(RegionVid) -> bool,
|
target_test: impl Fn(RegionVid) -> bool,
|
||||||
) -> (BlameConstraint<'tcx>, Vec<ExtraConstraintInfo>) {
|
) -> (BlameConstraint<'tcx>, Vec<OutlivesConstraint<'tcx>>) {
|
||||||
// Find all paths
|
// Find all paths
|
||||||
let (path, target_region) = self
|
let (path, target_region) = self
|
||||||
.find_constraint_paths_between_regions(from_region, target_test)
|
.find_constraint_paths_between_regions(from_region, target_test)
|
||||||
|
@ -1970,25 +1965,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut extra_info = vec![];
|
|
||||||
for constraint in path.iter() {
|
|
||||||
let outlived = constraint.sub;
|
|
||||||
let Some(origin) = self.var_infos.get(outlived) else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
let RegionVariableOrigin::Nll(NllRegionVariableOrigin::Placeholder(p)) = origin.origin
|
|
||||||
else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
debug!(?constraint, ?p);
|
|
||||||
let ConstraintCategory::Predicate(span) = constraint.category else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
extra_info.push(ExtraConstraintInfo::PlaceholderFromPredicate(span));
|
|
||||||
// We only want to point to one
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// We try to avoid reporting a `ConstraintCategory::Predicate` as our best constraint.
|
// We try to avoid reporting a `ConstraintCategory::Predicate` as our best constraint.
|
||||||
// Instead, we use it to produce an improved `ObligationCauseCode`.
|
// Instead, we use it to produce an improved `ObligationCauseCode`.
|
||||||
// FIXME - determine what we should do if we encounter multiple
|
// FIXME - determine what we should do if we encounter multiple
|
||||||
|
@ -2115,7 +2091,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
let best_choice =
|
let best_choice =
|
||||||
if blame_source { range.rev().find(find_region) } else { range.find(find_region) };
|
if blame_source { range.rev().find(find_region) } else { range.find(find_region) };
|
||||||
|
|
||||||
debug!(?best_choice, ?blame_source, ?extra_info);
|
debug!(?best_choice, ?blame_source);
|
||||||
|
|
||||||
if let Some(i) = best_choice {
|
if let Some(i) = best_choice {
|
||||||
if let Some(next) = categorized_path.get(i + 1) {
|
if let Some(next) = categorized_path.get(i + 1) {
|
||||||
|
@ -2124,7 +2100,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
{
|
{
|
||||||
// The return expression is being influenced by the return type being
|
// The return expression is being influenced by the return type being
|
||||||
// impl Trait, point at the return type and not the return expr.
|
// impl Trait, point at the return type and not the return expr.
|
||||||
return (next.clone(), extra_info);
|
return (next.clone(), path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2144,7 +2120,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (categorized_path[i].clone(), extra_info);
|
return (categorized_path[i].clone(), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If that search fails, that is.. unusual. Maybe everything
|
// If that search fails, that is.. unusual. Maybe everything
|
||||||
|
@ -2154,7 +2130,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||||
categorized_path.sort_by_key(|p| p.category);
|
categorized_path.sort_by_key(|p| p.category);
|
||||||
debug!("sorted_path={:#?}", categorized_path);
|
debug!("sorted_path={:#?}", categorized_path);
|
||||||
|
|
||||||
(categorized_path.remove(0), extra_info)
|
(categorized_path.remove(0), path)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn universe_info(&self, universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
|
pub(crate) fn universe_info(&self, universe: ty::UniverseIndex) -> UniverseInfo<'tcx> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue