pub trait InferCtxtExt<'tcx> {
// Required methods
fn can_eq<T: ToTrace<'tcx>>(
&self,
param_env: ParamEnv<'tcx>,
a: T,
b: T,
) -> bool;
fn type_is_copy_modulo_regions(
&self,
param_env: ParamEnv<'tcx>,
ty: Ty<'tcx>,
) -> bool;
fn type_is_sized_modulo_regions(
&self,
param_env: ParamEnv<'tcx>,
ty: Ty<'tcx>,
) -> bool;
fn type_implements_trait(
&self,
trait_def_id: DefId,
params: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
param_env: ParamEnv<'tcx>,
) -> EvaluationResult;
fn type_implements_trait_shallow(
&self,
trait_def_id: DefId,
ty: Ty<'tcx>,
param_env: ParamEnv<'tcx>,
) -> Option<Vec<FulfillmentError<'tcx>>>;
}
Required Methods§
fn can_eq<T: ToTrace<'tcx>>( &self, param_env: ParamEnv<'tcx>, a: T, b: T, ) -> bool
fn type_is_copy_modulo_regions( &self, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, ) -> bool
fn type_is_sized_modulo_regions( &self, param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, ) -> bool
Sourcefn type_implements_trait(
&self,
trait_def_id: DefId,
params: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
param_env: ParamEnv<'tcx>,
) -> EvaluationResult
fn type_implements_trait( &self, trait_def_id: DefId, params: impl IntoIterator<Item: Into<GenericArg<'tcx>>>, param_env: ParamEnv<'tcx>, ) -> EvaluationResult
Check whether a ty
implements given trait(trait_def_id) without side-effects.
The inputs are:
- the def-id of the trait
- the type parameters of the trait, including the self-type
- the parameter environment
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
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
.
Sourcefn type_implements_trait_shallow(
&self,
trait_def_id: DefId,
ty: Ty<'tcx>,
param_env: ParamEnv<'tcx>,
) -> Option<Vec<FulfillmentError<'tcx>>>
fn type_implements_trait_shallow( &self, trait_def_id: DefId, ty: Ty<'tcx>, param_env: ParamEnv<'tcx>, ) -> Option<Vec<FulfillmentError<'tcx>>>
Returns Some
if a type implements a trait shallowly, without side-effects,
along with any errors that would have been reported upon further obligation
processing.
- If this returns
Some([])
, then the trait holds modulo regions. - If this returns
Some([errors..])
, then the trait has an impl for the self type, but some nested obligations do not hold. - If this returns
None
, no implementation that applies could be found.
FIXME(-Znext-solver): Due to the recursive nature of the new solver,
this will probably only ever return Some([])
or None
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.