Skip to content

Commit 82215e2

Browse files
authored
The last commit certainly didn't do what I thought it did.
I *think* this actually does, though!
1 parent cce1392 commit 82215e2

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/librustc_mir/interpret/intrinsics.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,22 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> InterpretCx<'a, 'mir, 'tcx, M>
8080
}
8181

8282
"type_name" => {
83-
let ty = substs.type_at(0);
84-
let ty_name = type_name(self.tcx.tcx, ty).ty.to_string();
85-
let name_val = self.str_to_immediate(&ty_name)?;
86-
self.write_immediate(name_val, dest)?;
83+
let const_val = type_name(self.tcx.tcx, substs.type_at(0)).val;
84+
if let ConstValue::Slice {
85+
data: slice_val,
86+
start: _,
87+
end: _,
88+
} = const_val
89+
{
90+
// unsafe for from_utf8_unchecked()
91+
unsafe {
92+
let str_val = core::str::from_utf8_unchecked(&slice_val.bytes);
93+
let name_val = self.str_to_immediate(str_val)?;
94+
self.write_immediate(name_val, dest)?;
95+
}
96+
} else {
97+
bug!("type_name() somehow failed to return a ConstValue::Slice");
98+
}
8799
}
88100
| "ctpop"
89101
| "cttz"

0 commit comments

Comments
 (0)