Skip to content

Commit

Permalink
Rollup merge of rust-lang#96778 - JohnTitor:expect-local-track-caller…
Browse files Browse the repository at this point in the history
…-take-2, r=petrochenkov

Remove closures on `expect_local` to apply `#[track_caller]`

Pointed out in rust-lang#96747 (comment)
Didn't change `expect_non_local` as I'm not sure if it's also the case.
r? ``@petrochenkov``
  • Loading branch information
compiler-errors committed May 7, 2022
2 parents 0f1c067 + 7b773e8 commit f799c5d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/rustc_span/src/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit f799c5d

Please sign in to comment.