Skip to content

document type_implements_trait #132608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions compiler/rustc_trait_selection/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// and check whether it holds, because it properly handles higher ranked traits
/// 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps

/// 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,
Expand Down
Loading