File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
compiler/rustc_trait_selection/src Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,24 @@ impl<'tcx> InferCtxt<'tcx> {
6060 ///
6161 /// Invokes `evaluate_obligation`, so in the event that evaluating
6262 /// `Ty: Trait` causes overflow, EvaluatedToAmbigStackDependent will be returned.
63+ ///
64+ /// `type_implements_trait` is a convenience function for simple cases like
65+ ///
66+ /// ```ignore (illustrative)
67+ /// let copy_trait = infcx.tcx.require_lang_item(LangItem::Copy, span);
68+ /// let implements_copy = infcx.type_implements_trait(copy_trait, [ty], param_env)
69+ /// .must_apply_modulo_regions();
70+ /// ```
71+ ///
72+ /// In most cases you should instead create an [Obligation] and check whether
73+ /// it holds via [`evaluate_obligation`] or one of its helper functions like
74+ /// [`predicate_must_hold_modulo_regions`], because it properly handles higher ranked traits
75+ /// and it is more convenient and safer when your `params` are inside a [`Binder`].
76+ ///
77+ /// [Obligation]: traits::Obligation
78+ /// [`evaluate_obligation`]: crate::traits::query::evaluate_obligation::InferCtxtExt::evaluate_obligation
79+ /// [`predicate_must_hold_modulo_regions`]: crate::traits::query::evaluate_obligation::InferCtxtExt::predicate_must_hold_modulo_regions
80+ /// [`Binder`]: ty::Binder
6381 #[ instrument( level = "debug" , skip( self , params) , ret) ]
6482 fn type_implements_trait (
6583 & self ,
You can’t perform that action at this time.
0 commit comments