Skip to content

Commit 58062e1

Browse files
shim.rs: improve docs a bit
1 parent 26e17ae commit 58062e1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/librustc_mir/shim.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,28 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
130130

131131
#[derive(Copy, Clone, Debug, PartialEq)]
132132
enum Adjustment {
133+
/// Pass the receiver as-is.
133134
Identity,
135+
136+
/// We get passed `&[mut] self` and call the target with `*self`.
137+
///
138+
/// This either copies `self` (if `Self: Copy`, eg. for function items), or moves out of it
139+
/// (for `VtableShim`, which effectively is passed `&own Self`).
134140
Deref,
141+
142+
/// We get passed `self: Self` and call the target with `&mut self`.
143+
///
144+
/// In this case we need to ensure that the `Self` is dropped after the call, as the callee
145+
/// won't do it for us.
135146
RefMut,
136147
}
137148

138149
#[derive(Copy, Clone, Debug, PartialEq)]
139150
enum CallKind {
151+
/// Call the `FnPtr` that was passed as the receiver.
140152
Indirect,
153+
154+
/// Call a known `FnDef`.
141155
Direct(DefId),
142156
}
143157

@@ -722,7 +736,10 @@ fn build_call_shim<'tcx>(
722736
});
723737

724738
let (callee, mut args) = match call_kind {
739+
// `FnPtr` call has no receiver. Args are untupled below.
725740
CallKind::Indirect => (rcvr.unwrap(), vec![]),
741+
742+
// `FnDef` call with optional receiver.
726743
CallKind::Direct(def_id) => {
727744
let ty = tcx.type_of(def_id);
728745
(

0 commit comments

Comments
 (0)