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``
This commit is contained in:
Michael Goulet 2022-05-06 20:49:35 -07:00 committed by GitHub
commit f799c5d897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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]