-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add track_caller
to DefId::expect_local()
#96747
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
@bors r+ rollup |
📌 Commit 2ed38cd has been approved by |
…, r=compiler-errors Add `track_caller` to `DefId::expect_local()` Suggested in rust-lang#96738 (comment). `DefId::expect_local()` often causes ICEs (panics) and should be a good candidate to add `track_caller`.
…, r=compiler-errors Add `track_caller` to `DefId::expect_local()` Suggested in rust-lang#96738 (comment). `DefId::expect_local()` often causes ICEs (panics) and should be a good candidate to add `track_caller`.
…piler-errors Rollup of 7 pull requests Successful merges: - rust-lang#96174 (mark ptr-int-transmute test as no_run) - rust-lang#96639 (Fix typo in `offset_from` documentation) - rust-lang#96704 (Add rotation animation on settings button when loading) - rust-lang#96730 (Add a regression test for rust-lang#64173 and rust-lang#66152) - rust-lang#96741 (Improve settings loading strategy) - rust-lang#96744 (Implement [OsStr]::join) - rust-lang#96747 (Add `track_caller` to `DefId::expect_local()`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
@@ -279,6 +279,7 @@ 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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't work because there's a closure in the middle which doesn't track caller.
So either #[track_caller]
need to be applied to the closure too, or match
need to be used instead of unwrap_or_else
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't know, I'll address it. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the same apply to expect_non_local
?
rust/compiler/rustc_hir/src/def.rs
Lines 633 to 636 in 9714e13
#[track_caller] | |
pub fn expect_non_local<OtherId>(self) -> Res<OtherId> { | |
self.map_id(|_| panic!("unexpected `Res::Local`")) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, fn expect_non_local
should have the same issue.
…-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`
…-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``
Suggested in #96738 (comment).
DefId::expect_local()
often causes ICEs (panics) and should be a good candidate to addtrack_caller
.