Skip to content

Commit

Permalink
Erase late bound regions while resolving drop_in_place
Browse files Browse the repository at this point in the history
  • Loading branch information
Rattenkrieg committed Feb 14, 2023
1 parent c3c6d73 commit b00a3c0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
13 changes: 11 additions & 2 deletions compiler/rustc_middle/src/ty/instance.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use crate::ty::print::{FmtPrinter, Printer};
use crate::ty::{self, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable};
use crate::ty::{self, Binder, Ty, TyCtxt, TyKind, TypeFoldable, TypeSuperFoldable, TypeVisitable};
use crate::ty::{EarlyBinder, InternalSubsts, SubstsRef};
use rustc_errors::ErrorGuaranteed;
use rustc_hir::def::Namespace;
Expand Down Expand Up @@ -539,8 +539,17 @@ impl<'tcx> Instance<'tcx> {
}

pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
let ty_erased =
if let (true, TyKind::FnPtr(poly_fn_sig)) = (ty.has_late_bound_regions(), ty.kind()) {
let re_erased = tcx.erase_late_bound_regions(*poly_fn_sig);
let rebound = Binder::dummy(re_erased);
let reassembled = tcx.mk_fn_ptr(rebound);
reassembled
} else {
ty
};
let def_id = tcx.require_lang_item(LangItem::DropInPlace, None);
let substs = tcx.intern_substs(&[ty.into()]);
let substs = tcx.intern_substs(&[ty_erased.into()]);
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs)
}

Expand Down
4 changes: 4 additions & 0 deletions tests/run-make/issue-107205/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include ../../run-make-fulldeps/tools.mk

all:
$(RUSTC) main.rs
16 changes: 16 additions & 0 deletions tests/run-make/issue-107205/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::fmt;

pub struct Wrapper(fn(val: &()));

impl fmt::Debug for Wrapper {
fn fmt<'a>(&'a self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("Wrapper").field(&self.0 as &fn(&'a ())).finish()
}
}

fn useful(_: &()) {
}

fn main() {
println!("{:?}", Wrapper(useful));
}

0 comments on commit b00a3c0

Please sign in to comment.