diff options
| author | Jubilee <workingjubilee@gmail.com> | 2024-11-04 20:40:49 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-04 20:40:49 -0800 |
| commit | 33ebfff83a9c01920adcbd4f1aaf2fe3668ea5cc (patch) | |
| tree | db2697ef7f9aec40878ac613f6e604193a652c63 /compiler/rustc_trait_selection/src | |
| parent | 67477ca342f0c79ea8f585b1c1e9155e29d009b7 (diff) | |
| parent | e37a3a85e44f2c43442acf41e5d9d704738ee84c (diff) | |
| download | rust-33ebfff83a9c01920adcbd4f1aaf2fe3668ea5cc.tar.gz rust-33ebfff83a9c01920adcbd4f1aaf2fe3668ea5cc.zip | |
Rollup merge of #132608 - mejrs:type_impls_trait, r=compiler-errors
document `type_implements_trait` Rendered:  r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_trait_selection/src')
| -rw-r--r-- | compiler/rustc_trait_selection/src/infer.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index bacb3b1b1b8..8f1c8a29663 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -60,6 +60,24 @@ 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] and check whether + /// it holds via [`evaluate_obligation`] or one of its helper functions like + /// [`predicate_must_hold_modulo_regions`], because it properly handles higher ranked traits + /// and it is more convenient and safer when your `params` are inside a [`Binder`]. + /// + /// [Obligation]: traits::Obligation + /// [`evaluate_obligation`]: crate::traits::query::evaluate_obligation::InferCtxtExt::evaluate_obligation + /// [`predicate_must_hold_modulo_regions`]: crate::traits::query::evaluate_obligation::InferCtxtExt::predicate_must_hold_modulo_regions + /// [`Binder`]: ty::Binder #[instrument(level = "debug", skip(self, params), ret)] fn type_implements_trait( &self, |
