Rollup merge of #156019 - nnethercote:rm-Feed, r=oli-obk

Feed cleanups

Two minor improvements. Details in the individual commits.

r? @oli-obk
This commit is contained in:
Jonathan Brouwer
2026-05-01 13:10:37 +02:00
committed by GitHub
2 changed files with 8 additions and 47 deletions
+7 -46
View File
@@ -10,7 +10,7 @@
use std::env::VarError;
use std::ffi::OsStr;
use std::hash::{Hash, Hasher};
use std::marker::{PhantomData, PointeeSized};
use std::marker::PointeeSized;
use std::ops::{Bound, Deref};
use std::sync::{Arc, OnceLock};
use std::{fmt, iter, mem};
@@ -539,36 +539,14 @@ pub struct FreeRegionInfo {
/// This struct should only be created by `create_def`.
#[derive(Copy, Clone)]
pub struct TyCtxtFeed<'tcx, KEY: Copy> {
pub struct TyCtxtFeed<'tcx, K: Copy> {
pub tcx: TyCtxt<'tcx>,
// Do not allow direct access, as downstream code must not mutate this field.
key: KEY,
key: K,
}
/// Never return a `Feed` from a query. Only queries that create a `DefId` are
/// allowed to feed queries for that `DefId`.
impl<KEY: Copy> !HashStable for TyCtxtFeed<'_, KEY> {}
/// The same as `TyCtxtFeed`, but does not contain a `TyCtxt`.
/// Use this to pass around when you have a `TyCtxt` elsewhere.
/// Just an optimization to save space and not store hundreds of
/// `TyCtxtFeed` in the resolver.
#[derive(Copy, Clone)]
pub struct Feed<'tcx, KEY: Copy> {
_tcx: PhantomData<TyCtxt<'tcx>>,
// Do not allow direct access, as downstream code must not mutate this field.
key: KEY,
}
/// Never return a `Feed` from a query. Only queries that create a `DefId` are
/// allowed to feed queries for that `DefId`.
impl<KEY: Copy> !HashStable for Feed<'_, KEY> {}
impl<T: fmt::Debug + Copy> fmt::Debug for Feed<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.key.fmt(f)
}
}
/// Only queries that create a `DefId` are allowed to feed queries for that `DefId`.
impl<K: Copy> !HashStable for TyCtxtFeed<'_, K> {}
/// Some workarounds to use cases that cannot use `create_def`.
/// Do not add new ways to create `TyCtxtFeed` without consulting
@@ -622,28 +600,11 @@ pub fn feed_visibility_for_trait_impl_item(self, key: LocalDefId, vis: ty::Visib
}
}
impl<'tcx, KEY: Copy> TyCtxtFeed<'tcx, KEY> {
impl<'tcx, K: Copy> TyCtxtFeed<'tcx, K> {
#[inline(always)]
pub fn key(&self) -> KEY {
pub fn key(&self) -> K {
self.key
}
#[inline(always)]
pub fn downgrade(self) -> Feed<'tcx, KEY> {
Feed { _tcx: PhantomData, key: self.key }
}
}
impl<'tcx, KEY: Copy> Feed<'tcx, KEY> {
#[inline(always)]
pub fn key(&self) -> KEY {
self.key
}
#[inline(always)]
pub fn upgrade(self, tcx: TyCtxt<'tcx>) -> TyCtxtFeed<'tcx, KEY> {
TyCtxtFeed { tcx, key: self.key }
}
}
impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
+1 -1
View File
@@ -83,7 +83,7 @@
const_lit_matches_ty,
};
pub use self::context::{
CtxtInterners, CurrentGcx, Feed, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed, tls,
CtxtInterners, CurrentGcx, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, TyCtxtFeed, tls,
};
pub use self::fold::*;
pub use self::instance::{Instance, InstanceKind, ReifyReason};