Skip to content

Commit 33ebfff

Browse files
Rollup merge of #132608 - mejrs:type_impls_trait, r=compiler-errors
document `type_implements_trait` Rendered: ![image](https://github.com/user-attachments/assets/60c00e50-24fd-4b04-bb22-e71b479c0b29) r? `@compiler-errors`
2 parents 67477ca + e37a3a8 commit 33ebfff

File tree

1 file changed

+18
-0
lines changed
  • compiler/rustc_trait_selection/src

1 file changed

+18
-0
lines changed

compiler/rustc_trait_selection/src/infer.rs

+18
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)