about summary refs log tree commit diff
diff options
context:
space:
mode:
authormejrs <59372212+mejrs@users.noreply.github.com>2024-11-04 18:08:30 +0100
committermejrs <59372212+mejrs@users.noreply.github.com>2024-11-04 18:08:30 +0100
commitc88ba28d9a0261f448471255bd913e673858abaa (patch)
tree8d7f45c82d950dea5d4c7af616741181c4a88eb4
parent56c6a2f9b1175b81835f6b3ed41bd6daffb3724e (diff)
downloadrust-c88ba28d9a0261f448471255bd913e673858abaa.tar.gz
rust-c88ba28d9a0261f448471255bd913e673858abaa.zip
document `type_implements_trait`
-rw-r--r--compiler/rustc_trait_selection/src/infer.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs
index bacb3b1b1b8..e91574fa1af 100644
--- a/compiler/rustc_trait_selection/src/infer.rs
+++ b/compiler/rustc_trait_selection/src/infer.rs
@@ -60,6 +60,18 @@ impl<'tcx> InferCtxt<'tcx> {
     ///
     /// Invokes `evaluate_obligation`, so in the event that evaluating
     /// `Ty: Trait` causes overflow, EvaluatedToAmbigStackDependent will be returned.
+    ///
+    /// `type_implements_trait` is a convenience function for simple cases like
+    ///
+    /// ```ignore (illustrative)
+    /// let copy_trait = infcx.tcx.require_lang_item(LangItem::Copy, span);
+    /// let implements_copy = infcx.type_implements_trait(copy_trait, [ty], param_env)
+    /// .must_apply_modulo_regions();
+    /// ```
+    ///
+    /// In most cases you should instead create an [Obligation](traits::Obligation)
+    /// and check whether it holds, because it properly handles higher ranked traits
+    /// and it is more convenient and safer when your `params` are inside a `Binder`.
     #[instrument(level = "debug", skip(self, params), ret)]
     fn type_implements_trait(
         &self,