From 5988078aa20bf642bc1bbab15a45ac5cb74e77e2 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 26 Jun 2024 10:52:57 +0000 Subject: Restrict diagnostic context lifetime of InferCtxt to itself instead of TyCtxt --- compiler/rustc_errors/src/diagnostic.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'compiler/rustc_errors/src') diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index e580910af77..0231665b64c 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -582,6 +582,11 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { Self::new_diagnostic(dcx, DiagInner::new(level, message)) } + /// Allow moving diagnostics between different error tainting contexts + pub fn with_dcx(mut self, dcx: DiagCtxtHandle<'_>) -> Diag<'_, G> { + Diag { dcx, diag: self.diag.take(), _marker: PhantomData } + } + /// Creates a new `Diag` with an already constructed diagnostic. #[track_caller] pub(crate) fn new_diagnostic(dcx: DiagCtxtHandle<'a>, diag: DiagInner) -> Self { -- cgit 1.4.1-3-g733a5