Skip to main content

OrElse

Trait OrElse 

Source
pub trait OrElse<'db> {
    // Required methods
    fn or_else(&self, env: &mut Env<'db>, because: Because<'db>) -> Diagnostic;
    fn to_arc(&self) -> ArcOrElse<'db>;
    fn compiler_location(&self) -> &'static Location<'static>;

    // Provided method
    fn report(&self, env: &mut Env<'db>, because: Because<'db>) -> Reported { ... }
}
Expand description

The OrElse trait captures error reporting context. Primitive type operations like subtyping are given an &dyn OrElse<'db> as argument. If the subtyping operation fails, it invokes the OrElse::report method to report the error.

OrElse objects can be converted, using the OrElse::to_arc method, into an ArcOrElse<'db>, which allows the or-else to be preserved for longer than the current stack frame. This is used to store an or-else in inference variable data so that, if a conflict is later generated, we can extract the reason for that original constraint.

Required Methods§

Source

fn or_else(&self, env: &mut Env<'db>, because: Because<'db>) -> Diagnostic

Create a diagnostic representing the error.

The error would typically be expressed in high-level terms, like “cannot assign from a to b” or “incorrect type of function argument”.

The because argument signals the reason the low-level operation failed and will be used to provide additional details, like “our is not assignable to my”.

Source

fn to_arc(&self) -> ArcOrElse<'db>

Convert a &dyn OrElse<'db> into an ArcOrElse<'db> so that it can be stored in an InferenceVarData or otherwise preserved beyond the current stack frame. See the trait comment for more details.

Source

fn compiler_location(&self) -> &'static Location<'static>

Returns the location in the compiler source where this or_else was created. Useful for debugging.

Provided Methods§

Source

fn report(&self, env: &mut Env<'db>, because: Because<'db>) -> Reported

Report the diagnostic created by OrElse::or_else.

Trait Implementations§

Source§

impl<'db> OrElseHelper<'db> for &dyn OrElse<'db>

Source§

fn map_because( self, f: impl 'db + Clone + Fn(Because<'db>) -> Because<'db>, ) -> impl OrElse<'db>

Implementors§

Source§

impl<'db> OrElse<'db> for ArcOrElse<'db>

Source§

impl<'db> OrElse<'db> for AwaitNonFuture<'db>

Source§

impl<'db> OrElse<'db> for BadSubtermError<'db>

Source§

impl<'db> OrElse<'db> for BooleanTypeRequired<'db>

Source§

impl<'db> OrElse<'db> for InferenceFallback<'db>

Source§

impl<'db> OrElse<'db> for InvalidAssignmentType<'db>

Source§

impl<'db> OrElse<'db> for InvalidInitializerType<'db>

Source§

impl<'db> OrElse<'db> for InvalidReturnValue<'db>

Source§

impl<'db> OrElse<'db> for NumericTypeExpected<'db>

Source§

impl<'db> OrElse<'db> for OperatorArgumentsMustHaveSameType<'db>

Source§

impl<'db> OrElse<'db> for OperatorRequiresNumericType<'db>

Source§

impl<'db> OrElse<'db> for WhereClauseError<'db>