Skip to content

Commit b00a3c0

Browse files
committed
Erase late bound regions while resolving drop_in_place
1 parent c3c6d73 commit b00a3c0

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

compiler/rustc_middle/src/ty/instance.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
22
use crate::ty::print::{FmtPrinter, Printer};
3-
use crate::ty::{self, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable};
3+
use crate::ty::{self, Binder, Ty, TyCtxt, TyKind, TypeFoldable, TypeSuperFoldable, TypeVisitable};
44
use crate::ty::{EarlyBinder, InternalSubsts, SubstsRef};
55
use rustc_errors::ErrorGuaranteed;
66
use rustc_hir::def::Namespace;
@@ -539,8 +539,17 @@ impl<'tcx> Instance<'tcx> {
539539
}
540540

541541
pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
542+
let ty_erased =
543+
if let (true, TyKind::FnPtr(poly_fn_sig)) = (ty.has_late_bound_regions(), ty.kind()) {
544+
let re_erased = tcx.erase_late_bound_regions(*poly_fn_sig);
545+
let rebound = Binder::dummy(re_erased);
546+
let reassembled = tcx.mk_fn_ptr(rebound);
547+
reassembled
548+
} else {
549+
ty
550+
};
542551
let def_id = tcx.require_lang_item(LangItem::DropInPlace, None);
543-
let substs = tcx.intern_substs(&[ty.into()]);
552+
let substs = tcx.intern_substs(&[ty_erased.into()]);
544553
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs)
545554
}
546555

tests/run-make/issue-107205/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include ../../run-make-fulldeps/tools.mk
2+
3+
all:
4+
$(RUSTC) main.rs

tests/run-make/issue-107205/main.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::fmt;
2+
3+
pub struct Wrapper(fn(val: &()));
4+
5+
impl fmt::Debug for Wrapper {
6+
fn fmt<'a>(&'a self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7+
f.debug_tuple("Wrapper").field(&self.0 as &fn(&'a ())).finish()
8+
}
9+
}
10+
11+
fn useful(_: &()) {
12+
}
13+
14+
fn main() {
15+
println!("{:?}", Wrapper(useful));
16+
}

0 commit comments

Comments
 (0)