rustc_hir_analysis::check::wfcheck

Function receiver_is_valid

Source
fn receiver_is_valid<'tcx>(
    wfcx: &WfCheckingCtxt<'_, 'tcx>,
    span: Span,
    receiver_ty: Ty<'tcx>,
    self_ty: Ty<'tcx>,
    arbitrary_self_types_enabled: Option<ArbitrarySelfTypesLevel>,
    method_generics: &Generics,
) -> Result<(), ReceiverValidityError>
Expand description

Returns whether receiver_ty would be considered a valid receiver type for self_ty. If arbitrary_self_types is enabled, receiver_ty must transitively deref to self_ty, possibly through a *const/mut T raw pointer if arbitrary_self_types_pointers is also enabled. If neither feature is enabled, the requirements are more strict: receiver_ty must implement Receiver and directly implement Deref<Target = self_ty>.

N.B., there are cases this function returns true but causes an error to be emitted, particularly when receiver_ty derefs to a type that is the same as self_ty but has the wrong lifetime. Be careful of this if you are calling this function speculatively.