Skip to content

Commit 8a097f2

Browse files
committed
Clarify comment, dedupe match arms in shim.rs.
Also add a missing terminal newline to a test.
1 parent b8414c1 commit 8a097f2

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

src/librustc/ty/instance.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ pub enum InstanceDef<'tcx> {
2626
/// `<T as Trait>::method` where `method` receives unsizeable `self: Self`.
2727
VtableShim(DefId),
2828

29-
/// `fn()` pointer where the function is annotated with `#[track_caller]`.
29+
/// `fn()` pointer where the function itself cannot be turned into a pointer.
30+
///
31+
/// One example in the compiler today is functions annotated with `#[track_caller]`.
3032
ReifyShim(DefId),
3133

3234
/// `<fn() as FnTrait>::call_*`

src/librustc_mir/shim.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,6 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> &'tcx
4141
None,
4242
)
4343
}
44-
ty::InstanceDef::ReifyShim(def_id) => {
45-
build_call_shim(
46-
tcx,
47-
def_id,
48-
Adjustment::Identity, // TODO(anp) is this the right kind of adjustment?
49-
CallKind::Direct(def_id),
50-
None,
51-
)
52-
}
5344
ty::InstanceDef::FnPtrShim(def_id, ty) => {
5445
let trait_ = tcx.trait_of_item(def_id).unwrap();
5546
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
7566
Some(arg_tys)
7667
)
7768
}
78-
ty::InstanceDef::Virtual(def_id, _) => {
79-
// We are generating a call back to our def-id, which the
80-
// codegen backend knows to turn to an actual virtual call.
69+
// We are generating a call back to our def-id, which the
70+
// codegen backend knows to turn to an actual virtual call.
71+
ty::InstanceDef::Virtual(def_id, _) |
72+
// ...or we are generating a call to the inner closure defined by #[track_caller]
73+
ty::InstanceDef::ReifyShim(def_id) => {
8174
build_call_shim(
8275
tcx,
8376
def_id,

src/test/ui/rfc-2091-track-caller/taking-fn-pointer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ fn call_it(x: fn()) {
1313

1414
fn main() {
1515
call_it(f);
16-
}
16+
}

0 commit comments

Comments
 (0)