From 98cdb829a8e751a4fa82849bfe3195e3f0756e36 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 17 May 2025 19:35:01 +0000 Subject: [PATCH] Fast path for register_region_obligation --- compiler/rustc_infer/src/infer/outlives/obligations.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index 8dde99c45cfa8..5fd98e35e5ce8 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -98,6 +98,14 @@ impl<'tcx> InferCtxt<'tcx> { sub_region: Region<'tcx>, cause: &ObligationCause<'tcx>, ) { + // `is_global` means the type has no params, infer, placeholder, or non-`'static` + // free regions. If the type has none of these things, then we can skip registering + // this outlives obligation since it has no components which affect lifetime + // checking in an interesting way. + if sup_type.is_global() { + return; + } + debug!(?sup_type, ?sub_region, ?cause); let origin = SubregionOrigin::from_obligation_cause(cause, || { infer::RelateParamBound(