1
Fork 0

LocalCrate key

This commit is contained in:
Michael Goulet 2023-03-13 22:22:59 +00:00
parent dcaf956de0
commit d213114cb5
11 changed files with 33 additions and 21 deletions

View file

@ -13,6 +13,10 @@ use rustc_query_system::query::{DefaultCacheSelector, SingleCacheSelector, VecCa
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};
/// Placeholder for `CrateNum`'s "local" counterpart
#[derive(Copy, Clone, Debug)]
pub struct LocalCrate;
/// The `Key` trait controls what types can legally be used as the key
/// for a query.
pub trait Key: Sized {
@ -115,11 +119,11 @@ impl Key for CrateNum {
}
impl AsLocalKey for CrateNum {
type LocalKey = ();
type LocalKey = LocalCrate;
#[inline(always)]
fn as_local_key(&self) -> Option<Self::LocalKey> {
(*self == LOCAL_CRATE).then_some(())
(*self == LOCAL_CRATE).then_some(LocalCrate)
}
}

View file

@ -8,7 +8,7 @@ use crate::ty::{self, print::describe_as_module, TyCtxt};
use rustc_span::def_id::LOCAL_CRATE;
mod keys;
pub use keys::{AsLocalKey, Key};
pub use keys::{AsLocalKey, Key, LocalCrate};
// Each of these queries corresponds to a function pointer field in the
// `Providers` struct for requesting a value of that type, and a method