Skip to content

Commit 59e778e

Browse files
committed
improve documentation for resolve()
1 parent 08e1f0b commit 59e778e

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/librustc/ty/instance.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,24 @@ impl<'a, 'b, 'tcx> Instance<'tcx> {
116116
self.def.def_id()
117117
}
118118

119-
/// The point where linking happens. Resolve a (def_id, substs)
120-
/// pair to an instance.
119+
/// Resolve a (def_id, substs) pair to an (optional) instance -- most commonly,
120+
/// this is used to find the precise code that will run for a trait method invocation,
121+
/// if known.
122+
///
123+
/// Returns `None` if we cannot resolve `Instance` to a specific instance.
124+
/// For example, in a context like this,
125+
///
126+
/// ```
127+
/// fn foo<T: Debug>(t: T) { ... }
128+
/// ```
129+
///
130+
/// trying to resolve `Debug::fmt` applied to `T` will yield `None`, because we do not
131+
/// know what code ought to run. (Note that this setting is also affected by the
132+
/// `RevealMode` in the parameter environment.)
133+
///
134+
/// Presuming that coherence and type-check have succeeded, if this method is invoked
135+
/// in a monomorphic context (i.e., like during trans), then it is guaranteed to return
136+
/// `Some`.
121137
pub fn resolve(tcx: TyCtxt<'a, 'tcx, 'tcx>,
122138
param_env: ty::ParamEnv<'tcx>,
123139
def_id: DefId,

0 commit comments

Comments
 (0)