Skip to content

Commit 562d846

Browse files
committed
Make it easier to debug where a region error was created
1 parent 8b5a96e commit 562d846

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

compiler/rustc_borrowck/src/diagnostics/region_errors.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_middle::ty::Region;
2222
use rustc_middle::ty::TypeVisitor;
2323
use rustc_middle::ty::{self, RegionVid, Ty};
2424
use rustc_span::symbol::{kw, Ident};
25-
use rustc_span::Span;
25+
use rustc_span::{Span, DUMMY_SP};
2626

2727
use crate::borrowck_errors;
2828
use crate::session_diagnostics::{
@@ -70,7 +70,23 @@ impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
7070
///
7171
/// Usually we expect this to either be empty or contain a small number of items, so we can avoid
7272
/// allocation most of the time.
73-
pub(crate) type RegionErrors<'tcx> = Vec<RegionErrorKind<'tcx>>;
73+
#[derive(Default)]
74+
pub(crate) struct RegionErrors<'tcx>(Vec<RegionErrorKind<'tcx>>);
75+
76+
impl<'tcx> RegionErrors<'tcx> {
77+
#[track_caller]
78+
pub fn push(&mut self, val: impl Into<RegionErrorKind<'tcx>>) {
79+
let val = val.into();
80+
ty::tls::with(|tcx| tcx.sess.delay_span_bug(DUMMY_SP, "{val:?}"));
81+
self.0.push(val);
82+
}
83+
pub fn is_empty(&self) -> bool {
84+
self.0.is_empty()
85+
}
86+
pub fn into_iter(self) -> impl Iterator<Item = RegionErrorKind<'tcx>> {
87+
self.0.into_iter()
88+
}
89+
}
7490

7591
#[derive(Clone, Debug)]
7692
pub(crate) enum RegionErrorKind<'tcx> {

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
562562
let mir_def_id = body.source.def_id();
563563
self.propagate_constraints(body);
564564

565-
let mut errors_buffer = RegionErrors::new();
565+
let mut errors_buffer = RegionErrors::default();
566566

567567
// If this is a closure, we can propagate unsatisfied
568568
// `outlives_requirements` to our creator, so create a vector

0 commit comments

Comments
 (0)