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§
Sourcefn or_else(&self, env: &mut Env<'db>, because: Because<'db>) -> Diagnostic
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”.
Sourcefn to_arc(&self) -> ArcOrElse<'db>
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.
Sourcefn compiler_location(&self) -> &'static Location<'static>
fn compiler_location(&self) -> &'static Location<'static>
Returns the location in the compiler source where this or_else was created.
Useful for debugging.