]> git.lizzy.rs Git - rust.git/commitdiff
Make it easier to debug where a region error was created
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Mon, 19 Dec 2022 12:10:26 +0000 (12:10 +0000)
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>
Tue, 20 Dec 2022 13:42:07 +0000 (13:42 +0000)
compiler/rustc_borrowck/src/diagnostics/region_errors.rs
compiler/rustc_borrowck/src/region_infer/mod.rs

index b5a0044e9e8cd5512cd9a6041d344a5f515f8bd9..500ce9038bbb9f79c02245b03fe38bf74db1c2d4 100644 (file)
@@ -22,7 +22,7 @@
 use rustc_middle::ty::TypeVisitor;
 use rustc_middle::ty::{self, RegionVid, Ty};
 use rustc_span::symbol::{kw, Ident};
-use rustc_span::Span;
+use rustc_span::{Span, DUMMY_SP};
 
 use crate::borrowck_errors;
 use crate::session_diagnostics::{
@@ -70,7 +70,23 @@ fn description(&self) -> &'static str {
 ///
 /// Usually we expect this to either be empty or contain a small number of items, so we can avoid
 /// allocation most of the time.
-pub(crate) type RegionErrors<'tcx> = Vec<RegionErrorKind<'tcx>>;
+#[derive(Default)]
+pub(crate) struct RegionErrors<'tcx>(Vec<RegionErrorKind<'tcx>>);
+
+impl<'tcx> RegionErrors<'tcx> {
+    #[track_caller]
+    pub fn push(&mut self, val: impl Into<RegionErrorKind<'tcx>>) {
+        let val = val.into();
+        ty::tls::with(|tcx| tcx.sess.delay_span_bug(DUMMY_SP, "{val:?}"));
+        self.0.push(val);
+    }
+    pub fn is_empty(&self) -> bool {
+        self.0.is_empty()
+    }
+    pub fn into_iter(self) -> impl Iterator<Item = RegionErrorKind<'tcx>> {
+        self.0.into_iter()
+    }
+}
 
 #[derive(Clone, Debug)]
 pub(crate) enum RegionErrorKind<'tcx> {
index 0d03346ef0a5e22f5016e2512d2aa86135d347a0..7ccc3cc2896373e96b84ab8cc71d642a40d64219 100644 (file)
@@ -562,7 +562,7 @@ pub(super) fn solve(
         let mir_def_id = body.source.def_id();
         self.propagate_constraints(body);
 
-        let mut errors_buffer = RegionErrors::new();
+        let mut errors_buffer = RegionErrors::default();
 
         // If this is a closure, we can propagate unsatisfied
         // `outlives_requirements` to our creator, so create a vector