Skip to content

Commit 3e735a5

Browse files
committed
Unwrap allocated Location at creation
1 parent 43b55cf commit 3e735a5

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

compiler/rustc_mir/src/const_eval/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ pub(crate) fn const_caller_location(
3131
trace!("const_caller_location: {}:{}:{}", file, line, col);
3232
let mut ecx = mk_eval_cx(tcx, DUMMY_SP, ty::ParamEnv::reveal_all(), false);
3333

34-
// This can fail if rustc runs out of memory right here. Trying to emit an error would be
35-
// pointless, since that would require allocating more memory than a Location.
36-
let loc_place = ecx
37-
.alloc_caller_location(file, line, col)
38-
.expect("not enough memory to allocate location?");
34+
let loc_place = ecx.alloc_caller_location(file, line, col);
3935
if intern_const_alloc_recursive(&mut ecx, InternKind::Constant, &loc_place).is_err() {
4036
bug!("intern_const_alloc_recursive should not error in this case")
4137
}

compiler/rustc_mir/src/interpret/intrinsics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
137137
match intrinsic_name {
138138
sym::caller_location => {
139139
let span = self.find_closest_untracked_caller_location();
140-
let location = self.alloc_caller_location_for_span(span)?;
140+
let location = self.alloc_caller_location_for_span(span);
141141
self.write_scalar(location.ptr, dest)?;
142142
}
143143

compiler/rustc_mir/src/interpret/intrinsics/caller_location.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_target::abi::LayoutOf;
99

1010
use crate::interpret::{
1111
intrinsics::{InterpCx, Machine},
12-
InterpResult, MPlaceTy, MemoryKind, Scalar,
12+
MPlaceTy, MemoryKind, Scalar,
1313
};
1414

1515
impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
@@ -79,7 +79,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
7979
filename: Symbol,
8080
line: u32,
8181
col: u32,
82-
) -> InterpResult<'static, MPlaceTy<'tcx, M::PointerTag>> {
82+
) -> MPlaceTy<'tcx, M::PointerTag> {
8383
let file =
8484
self.allocate_str(&filename.as_str(), MemoryKind::CallerLocation, Mutability::Not);
8585
let line = Scalar::from_u32(line);
@@ -91,7 +91,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9191
.type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None))
9292
.subst(*self.tcx, self.tcx.mk_substs([self.tcx.lifetimes.re_erased.into()].iter()));
9393
let loc_layout = self.layout_of(loc_ty).unwrap();
94-
let location = self.allocate(loc_layout, MemoryKind::CallerLocation)?;
94+
// This can fail if rustc runs out of memory right here. Trying to emit an error would be
95+
// pointless, since that would require allocating more memory than a Location.
96+
let location = self.allocate(loc_layout, MemoryKind::CallerLocation).unwrap();
9597

9698
// Initialize fields.
9799
self.write_immediate(file.to_ref(), &self.mplace_field(&location, 0).unwrap().into())
@@ -101,7 +103,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
101103
self.write_scalar(col, &self.mplace_field(&location, 2).unwrap().into())
102104
.expect("writing to memory we just allocated cannot fail");
103105

104-
Ok(location)
106+
location
105107
}
106108

107109
crate fn location_triple_for_span(&self, span: Span) -> (Symbol, u32, u32) {
@@ -114,10 +116,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
114116
)
115117
}
116118

117-
pub fn alloc_caller_location_for_span(
118-
&mut self,
119-
span: Span,
120-
) -> InterpResult<'static, MPlaceTy<'tcx, M::PointerTag>> {
119+
pub fn alloc_caller_location_for_span(&mut self, span: Span) -> MPlaceTy<'tcx, M::PointerTag> {
121120
let (file, line, column) = self.location_triple_for_span(span);
122121
self.alloc_caller_location(file, line, column)
123122
}

0 commit comments

Comments
 (0)