From c3ceb286fa92a713f8d3d4169c3acd4ffbffa820 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 30 Apr 2026 22:10:25 +1000 Subject: [PATCH 1/2] Remove unused `Feed` type. --- compiler/rustc_middle/src/ty/context.rs | 43 ++----------------------- compiler/rustc_middle/src/ty/mod.rs | 2 +- 2 files changed, 3 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 2e9708483a85..ab7cd218bbeb 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -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}; @@ -545,31 +545,9 @@ pub struct TyCtxtFeed<'tcx, KEY: Copy> { key: KEY, } -/// Never return a `Feed` from a query. Only queries that create a `DefId` are -/// allowed to feed queries for that `DefId`. +/// Only queries that create a `DefId` are allowed to feed queries for that `DefId`. impl !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>, - // 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 !HashStable for Feed<'_, KEY> {} - -impl fmt::Debug for Feed<'_, T> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.key.fmt(f) - } -} - /// Some workarounds to use cases that cannot use `create_def`. /// Do not add new ways to create `TyCtxtFeed` without consulting /// with T-compiler and making an analysis about why your addition @@ -627,23 +605,6 @@ impl<'tcx, KEY: Copy> TyCtxtFeed<'tcx, KEY> { pub fn key(&self) -> KEY { 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> { diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 914fb4314715..74cad5acfc6f 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -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}; From ddc626d2e10217286e55081fcedf254543638fb9 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Thu, 30 Apr 2026 22:13:13 +1000 Subject: [PATCH 2/2] Rename `KEY` type parameters as `K`. RFC 430 says type parameters should be named "concise UpperCamelCase, usually single uppercase letter". So either `Key` or `K` is more appropriate than `KEY`, which looks like a constant. I chose `K` because it's a well-known abbreviation of "key" used in lots of places, e.g. `HashMap`. --- compiler/rustc_middle/src/ty/context.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index ab7cd218bbeb..26f0760b3c56 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -539,14 +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, } /// Only queries that create a `DefId` are allowed to feed queries for that `DefId`. -impl !HashStable for TyCtxtFeed<'_, KEY> {} +impl !HashStable for TyCtxtFeed<'_, K> {} /// Some workarounds to use cases that cannot use `create_def`. /// Do not add new ways to create `TyCtxtFeed` without consulting @@ -600,9 +600,9 @@ 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 } }