pub enum QueryErr {
Unsupported {
def_id: DefId,
err: UnsupportedErr,
},
Ignored {
def_id: DefId,
},
InvalidGenericArg {
def_id: DefId,
},
MissingAssocReft {
impl_id: DefId,
trait_id: DefId,
name: Symbol,
},
OpaqueStruct {
struct_id: DefId,
},
Bug {
def_id: Option<DefId>,
location: String,
msg: String,
},
Emitted(ErrorGuaranteed),
}Expand description
An error produced by a query.
We make a distinction between errors reported at def-site and errors reported at use-site.
For most errors reported at the def-site of an item, it makes little sense to check the definition
of dependent items. For example, if a function signature is ill-formed, checking the body of another
function that calls it, can produce confusing errors. In some cases, we can even fail to produce
a signature for a function in which case we can’t even check its call sites. For these cases, we
emit an error at the definition site and return a QueryErr::Emitted. When checking a dependent,
we detect this and early return without reporting any errors at the use-site.
Other errors are better reported at the use-site. For example, if some code calls a function from
an external crate that has unsupported features, we ought to report the error at the call-site,
because it would be confusing to only mention the definition of the external function without
showing which part of the code is calling it. To attach a span to an error one can use QueryErr::at
to get a QueryErrAt.
Both QueryErr and QueryErrAt implement [Diagnostic]. The implementation for QueryErr
reports the error at the definition site, while the implementation for QueryErrAt reports it at
the (attached) use-site span. This allows us to play a bit lose because we can emit an error without
attaching a span, but this means we may forget to attach spans at some places. We should consider
not implementing [Diagnostic] for QueryErr such that we always make the distinction between
use-site and def-site explicit, e.g., we could have methods QueryErr::at_use_site and
QueryErr::at_def_site returning types with different implementations of [Diagnostic].
Variants§
Unsupported
Ignored
Fields
def_id: DefIdInvalidGenericArg
Fields
def_id: DefIdMissingAssocReft
OpaqueStruct
An operation tried to access the internals of an opaque struct.
Fields
struct_id: DefIdBug
Used to report bugs, typically this means executing an arm in a match we thought it was
unreachable. Use this instead of panicking if it is easy to return a QueryErr. Use
QueryErr::bug or crate::query_bug! to construct this variant to track source location.
Emitted(ErrorGuaranteed)
Implementations§
Source§impl QueryErr
impl QueryErr
pub fn unsupported(def_id: DefId, err: UnsupportedErr) -> Self
pub fn bug(def_id: Option<DefId>, msg: impl ToString) -> Self
pub fn at(self, cx: impl Into<ErrCtxt>) -> QueryErrAt
Trait Implementations§
Auto Trait Implementations§
impl Freeze for QueryErr
impl RefUnwindSafe for QueryErr
impl Send for QueryErr
impl Sync for QueryErr
impl Unpin for QueryErr
impl UnwindSafe for QueryErr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more