From 8a097f26198d9979d88e7c0cd0a3bce283ff038a Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Wed, 9 Oct 2019 21:02:54 -0700 Subject: [PATCH] Clarify comment, dedupe match arms in shim.rs. Also add a missing terminal newline to a test. --- src/librustc/ty/instance.rs | 4 +++- src/librustc_mir/shim.rs | 17 +++++------------ .../rfc-2091-track-caller/taking-fn-pointer.rs | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index 18b625984e1a2..2b9d09b20ccfc 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -26,7 +26,9 @@ pub enum InstanceDef<'tcx> { /// `::method` where `method` receives unsizeable `self: Self`. VtableShim(DefId), - /// `fn()` pointer where the function is annotated with `#[track_caller]`. + /// `fn()` pointer where the function itself cannot be turned into a pointer. + /// + /// One example in the compiler today is functions annotated with `#[track_caller]`. ReifyShim(DefId), /// `::call_*` diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index eced7eb09ae87..0d13daa264309 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -41,15 +41,6 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx None, ) } - ty::InstanceDef::ReifyShim(def_id) => { - build_call_shim( - tcx, - def_id, - Adjustment::Identity, // TODO(anp) is this the right kind of adjustment? - CallKind::Direct(def_id), - None, - ) - } ty::InstanceDef::FnPtrShim(def_id, ty) => { let trait_ = tcx.trait_of_item(def_id).unwrap(); let adjustment = match tcx.lang_items().fn_trait_kind(trait_) { @@ -75,9 +66,11 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx Some(arg_tys) ) } - ty::InstanceDef::Virtual(def_id, _) => { - // We are generating a call back to our def-id, which the - // codegen backend knows to turn to an actual virtual call. + // We are generating a call back to our def-id, which the + // codegen backend knows to turn to an actual virtual call. + ty::InstanceDef::Virtual(def_id, _) | + // ...or we are generating a call to the inner closure defined by #[track_caller] + ty::InstanceDef::ReifyShim(def_id) => { build_call_shim( tcx, def_id, diff --git a/src/test/ui/rfc-2091-track-caller/taking-fn-pointer.rs b/src/test/ui/rfc-2091-track-caller/taking-fn-pointer.rs index df3893f2a6a19..2882d2d83ff81 100644 --- a/src/test/ui/rfc-2091-track-caller/taking-fn-pointer.rs +++ b/src/test/ui/rfc-2091-track-caller/taking-fn-pointer.rs @@ -13,4 +13,4 @@ fn call_it(x: fn()) { fn main() { call_it(f); -} \ No newline at end of file +}