Skip to content

Commit

Permalink
Clarify comment, dedupe match arms in shim.rs.
Browse files Browse the repository at this point in the history
Also add a missing terminal newline to a test.
  • Loading branch information
anp committed Oct 10, 2019
1 parent b8414c1 commit 8a097f2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/librustc/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ pub enum InstanceDef<'tcx> {
/// `<T as Trait>::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),

/// `<fn() as FnTrait>::call_*`
Expand Down
17 changes: 5 additions & 12 deletions src/librustc_mir/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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_) {
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/rfc-2091-track-caller/taking-fn-pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ fn call_it(x: fn()) {

fn main() {
call_it(f);
}
}

0 comments on commit 8a097f2

Please sign in to comment.