Key in rustc_middle::query - Rust (original) (raw)
pub trait Key: Sized {
type Cache<V>;
// Required method
fn default_span(&self, tcx: TyCtxt<'_>) -> Span;
// Provided methods
fn key_as_def_id(&self) -> Option<DefId> { ... }
fn def_id_for_ty_in_cycle(&self) -> Option<DefId> { ... }
}
Expand description
The Key
trait controls what types can legally be used as the key for a query.
The type of in-memory cache to use for queries with this key type.
In practice the cache type must implement QueryCache, though that constraint is not enforced here.
In the event that a cycle occurs, if no explicit span has been given for a query with key self
, what span should we use?
If the key is a DefId or DefId
–equivalent, return that DefId
. Otherwise, return None
.
Used to detect when ADT def ids are used as keys in a cycle for better error reporting.
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.