Skip to content
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

Move more intrinsics to rustc_intrinsic #122037

Merged
merged 5 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make span_bug panic site useful again
  • Loading branch information
oli-obk committed Mar 19, 2024
commit e91084180e2171fd229241adfb4b1463ebb79958
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#![feature(array_windows)]
#![feature(assert_matches)]
#![feature(box_patterns)]
#![feature(closure_track_caller)]
#![feature(core_intrinsics)]
#![feature(const_type_name)]
#![feature(discriminant_kind)]
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_middle/src/ty/context/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ where

/// Allows access to the current `ImplicitCtxt` in a closure if one is available.
#[inline]
#[track_caller]
pub fn with_context_opt<F, R>(f: F) -> R
where
F: for<'a, 'tcx> FnOnce(Option<&ImplicitCtxt<'a, 'tcx>>) -> R,
Expand Down Expand Up @@ -147,9 +148,13 @@ where
/// Allows access to the `TyCtxt` in the current `ImplicitCtxt`.
/// The closure is passed None if there is no `ImplicitCtxt` available.
#[inline]
#[track_caller]
pub fn with_opt<F, R>(f: F) -> R
where
F: for<'tcx> FnOnce(Option<TyCtxt<'tcx>>) -> R,
{
with_context_opt(|opt_context| f(opt_context.map(|context| context.tcx)))
with_context_opt(
#[track_caller]
|opt_context| f(opt_context.map(|context| context.tcx)),
)
}
19 changes: 11 additions & 8 deletions compiler/rustc_middle/src/util/bug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ fn opt_span_bug_fmt<S: Into<MultiSpan>>(
args: fmt::Arguments<'_>,
location: &Location<'_>,
) -> ! {
tls::with_opt(move |tcx| {
let msg = format!("{location}: {args}");
match (tcx, span) {
(Some(tcx), Some(span)) => tcx.dcx().span_bug(span, msg),
(Some(tcx), None) => tcx.dcx().bug(msg),
(None, _) => panic_any(msg),
}
})
tls::with_opt(
#[track_caller]
move |tcx| {
let msg = format!("{location}: {args}");
match (tcx, span) {
(Some(tcx), Some(span)) => tcx.dcx().span_bug(span, msg),
(Some(tcx), None) => tcx.dcx().bug(msg),
(None, _) => panic_any(msg),
}
},
)
}

/// A query to trigger a delayed bug. Clearly, if one has a `tcx` one can already trigger a
Expand Down