From 7b773e890e9b1f85a4cf7ea3893536422ee2b378 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 7 May 2022 01:11:32 +0900 Subject: [PATCH] Remove closures on `expect_local` to apply `#[track_caller]` --- compiler/rustc_span/src/def_id.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index 6b529d5e0837b..3976c06222187 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -281,7 +281,12 @@ impl DefId { #[inline] #[track_caller] pub fn expect_local(self) -> LocalDefId { - self.as_local().unwrap_or_else(|| panic!("DefId::expect_local: `{:?}` isn't local", self)) + // NOTE: `match` below is required to apply `#[track_caller]`, + // i.e. don't use closures. + match self.as_local() { + Some(local_def_id) => local_def_id, + None => panic!("DefId::expect_local: `{:?}` isn't local", self), + } } #[inline]