Skip to content

Commit b08bc78

Browse files
committed
fix MIR fn-ptr pretty-printing
1 parent 090dac0 commit b08bc78

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,15 +1030,19 @@ pub trait PrettyPrinter<'tcx>:
10301030
)?;
10311031
}
10321032
(Scalar::Ptr(ptr), ty::FnPtr(_)) => {
1033-
// FIXME: this can ICE when the ptr is dangling or points to a non-function.
1034-
// We should probably have a helper method to share code with the "Byte strings"
1033+
// FIXME: We should probably have a helper method to share code with the "Byte strings"
10351034
// printing above (which also has to handle pointers to all sorts of things).
1036-
let instance = self.tcx().global_alloc(ptr.alloc_id).unwrap_fn();
1037-
self = self.typed_value(
1038-
|this| this.print_value_path(instance.def_id(), instance.substs),
1039-
|this| this.print_type(ty),
1040-
" as ",
1041-
)?;
1035+
match self.tcx().get_global_alloc(ptr.alloc_id) {
1036+
Some(GlobalAlloc::Function(instance)) => {
1037+
self = self.typed_value(
1038+
|this| this.print_value_path(instance.def_id(), instance.substs),
1039+
|this| this.print_type(ty),
1040+
" as ",
1041+
)?;
1042+
}
1043+
Some(_) => p!("<non-executable memory>"),
1044+
None => p!("<dangling pointer>"),
1045+
}
10421046
}
10431047
// For function type zsts just printing the path is enough
10441048
(Scalar::Int(int), ty::FnDef(d, s)) if int == ScalarInt::ZST => {

compiler/rustc_mir/src/interpret/operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<Tag: Copy> std::fmt::Display for ImmTy<'tcx, Tag> {
106106
}
107107
ScalarMaybeUninit::Uninit => cx.typed_value(
108108
|mut this| {
109-
this.write_str("{uninit ")?;
109+
this.write_str("uninit ")?;
110110
Ok(this)
111111
},
112112
|this| this.print_type(ty),

0 commit comments

Comments
 (0)