about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-05-06 20:49:35 -0700
committerGitHub <noreply@github.com>2022-05-06 20:49:35 -0700
commitf799c5d8973e24f8c5bcc016b9a8b15468f2bb6e (patch)
tree56cbbce0070823a75c607089fb0439d0e004bc6d
parent0f1c067aecd38c7653500b22051122479c7b2aa3 (diff)
parent7b773e890e9b1f85a4cf7ea3893536422ee2b378 (diff)
downloadrust-f799c5d8973e24f8c5bcc016b9a8b15468f2bb6e.tar.gz
rust-f799c5d8973e24f8c5bcc016b9a8b15468f2bb6e.zip
Rollup merge of #96778 - JohnTitor:expect-local-track-caller-take-2, r=petrochenkov
Remove closures on `expect_local` to apply `#[track_caller]`

Pointed out in https://github.com/rust-lang/rust/pull/96747#discussion_r866576196
Didn't change `expect_non_local` as I'm not sure if it's also the case.
r? ``@petrochenkov``
-rw-r--r--compiler/rustc_span/src/def_id.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs
index 6b529d5e083..3976c062221 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]