]> git.lizzy.rs Git - rust.git/commitdiff
improve documentation for resolve()
authorDouglas Campos <qmx@qmx.me>
Sat, 30 Sep 2017 01:57:12 +0000 (21:57 -0400)
committerDouglas Campos <qmx@qmx.me>
Sat, 30 Sep 2017 02:34:49 +0000 (22:34 -0400)
src/librustc/ty/instance.rs

index 6f1be020c7bd380cbdcaaa6e71b962fd00ef27ed..9560d6359a53203b138c331f182f07f90172564a 100644 (file)
@@ -116,8 +116,24 @@ pub fn def_id(&self) -> DefId {
         self.def.def_id()
     }
 
-    /// The point where linking happens. Resolve a (def_id, substs)
-    /// pair to an instance.
+    /// Resolve a (def_id, substs) pair to an (optional) instance -- most commonly,
+    /// this is used to find the precise code that will run for a trait method invocation,
+    /// if known.
+    ///
+    /// Returns `None` if we cannot resolve `Instance` to a specific instance.
+    /// For example, in a context like this,
+    ///
+    /// ```
+    /// fn foo<T: Debug>(t: T) { ... }
+    /// ```
+    ///
+    /// trying to resolve `Debug::fmt` applied to `T` will yield `None`, because we do not
+    /// know what code ought to run. (Note that this setting is also affected by the
+    /// `RevealMode` in the parameter environment.)
+    ///
+    /// Presuming that coherence and type-check have succeeded, if this method is invoked
+    /// in a monomorphic context (i.e., like during trans), then it is guaranteed to return
+    /// `Some`.
     pub fn resolve(tcx: TyCtxt<'a, 'tcx, 'tcx>,
                    param_env: ty::ParamEnv<'tcx>,
                    def_id: DefId,