From 8a80739afc3c6d1039eef3538809e42618fc55ea Mon Sep 17 00:00:00 2001 From: James Barford-Evans Date: Mon, 20 Apr 2026 13:39:10 +0100 Subject: [PATCH 1/9] Create `Region` struct in rustc_type_ir and update Interner methods --- .../src/ty/context/impl_interner.rs | 52 ++++- compiler/rustc_type_ir/src/interner.rs | 39 +++- compiler/rustc_type_ir/src/sty/mod.rs | 191 ++++++++++++++++++ 3 files changed, 277 insertions(+), 5 deletions(-) create mode 100644 compiler/rustc_type_ir/src/sty/mod.rs diff --git a/compiler/rustc_middle/src/ty/context/impl_interner.rs b/compiler/rustc_middle/src/ty/context/impl_interner.rs index 6f6317d53d97b..ae358423bc51a 100644 --- a/compiler/rustc_middle/src/ty/context/impl_interner.rs +++ b/compiler/rustc_middle/src/ty/context/impl_interner.rs @@ -1,5 +1,4 @@ //! Implementation of [`rustc_type_ir::Interner`] for [`TyCtxt`]. - use std::{debug_assert_matches, fmt}; use rustc_errors::ErrorGuaranteed; @@ -98,8 +97,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { type ExprConst = ty::Expr<'tcx>; type ValTree = ty::ValTree<'tcx>; type ScalarInt = ty::ScalarInt; - - type Region = Region<'tcx>; + type InternedRegionKind = Interned<'tcx, ty::RegionKind<'tcx>>; type EarlyParamRegion = ty::EarlyParamRegion; type LateParamRegion = ty::LateParamRegion; @@ -729,6 +727,54 @@ impl<'tcx> Interner for TyCtxt<'tcx> { bug!("item_name: no name for {:?}", self.def_path(id)); }) } + + fn get_anon_re_bounds_lifetime(self, idx: usize, var_idx: usize) -> Option> { + if let Some(inner) = self.lifetimes.anon_re_bounds.get(idx) { + inner.get(var_idx).copied() + } else { + None + } + } + + fn get_anon_re_canonical_bounds_lifetime(self, idx: usize) -> Option> { + self.lifetimes.anon_re_canonical_bounds.get(idx).copied() + } + + fn get_re_static_lifetime(self) -> Region<'tcx> { + self.lifetimes.re_static + } + + fn intern_region(self, region_kind: RegionKind<'tcx>) -> Region<'tcx> { + self.intern_region(region_kind) + } + + fn intern_bound_region( + self, + debruijn: DebruijnIndex, + bound_region: BoundRegion<'tcx>, + ) -> Region<'tcx> { + // Use a pre-interned one when possible. + if let ty::BoundRegion { var, kind: ty::BoundRegionKind::Anon } = bound_region + && let Some(inner) = self.lifetimes.anon_re_bounds.get(debruijn.as_usize()) + && let Some(re) = inner.get(var.as_usize()).copied() + { + re + } else { + self.intern_region(ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), bound_region)) + } + } + + fn intern_canonical_bound(self, var: BoundVar) -> Region<'tcx> { + // Use a pre-interned one when possible. + if let Some(re) = self.lifetimes.anon_re_canonical_bounds.get(var.as_usize()).copied() { + re + } else { + self.intern_region(ty::ReBound( + ty::BoundVarIndexKind::Canonical, + BoundRegion { var, kind: ty::BoundRegionKind::Anon }, + )) + } + } } /// Defines trivial conversion functions between the main [`LangItem`] enum, diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs index fba43b9cffbe2..e5c0664825ccb 100644 --- a/compiler/rustc_type_ir/src/interner.rs +++ b/compiler/rustc_type_ir/src/interner.rs @@ -5,6 +5,8 @@ use std::ops::Deref; use rustc_ast_ir::Movability; use rustc_index::bit_set::DenseBitSet; +#[cfg(feature = "nightly")] +use rustc_serialize::Decoder; use crate::fold::TypeFoldable; use crate::inherent::*; @@ -13,7 +15,10 @@ use crate::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem}; use crate::relate::Relate; use crate::solve::{CanonicalInput, Certainty, ExternalConstraintsData, QueryResult, inspect}; use crate::visit::{Flags, TypeVisitable}; -use crate::{self as ty, CanonicalParamEnvCacheEntry, search_graph}; +use crate::{ + self as ty, BoundRegion, BoundVar, CanonicalParamEnvCacheEntry, DebruijnIndex, Region, + RegionKind, search_graph, +}; #[cfg_attr(feature = "nightly", rustc_diagnostic_item = "type_ir_interner")] pub trait Interner: @@ -157,10 +162,16 @@ pub trait Interner: type ScalarInt: Copy + Debug + Hash + Eq; // Kinds of regions - type Region: Region; type EarlyParamRegion: ParamLike; type LateParamRegion: Copy + Debug + Hash + Eq; + type InternedRegionKind: Copy + + Debug + + Hash + + Eq + + PartialEq + + IntoKind>; + type RegionAssumptions: Copy + Debug + Hash @@ -413,6 +424,30 @@ pub trait Interner: ) -> (QueryResult, Self::Probe); fn item_name(self, item_index: Self::DefId) -> Self::Symbol; + + fn get_anon_re_bounds_lifetime(self, idx: usize, var_idx: usize) -> Option>; + + fn get_anon_re_canonical_bounds_lifetime(self, idx: usize) -> Option>; + + fn get_re_static_lifetime(self) -> Region; + + fn intern_region(self, region_kind: RegionKind) -> Region; + + fn intern_bound_region( + self, + debruijn: DebruijnIndex, + bound_region: BoundRegion, + ) -> Region; + + fn intern_canonical_bound(self, var: BoundVar) -> Region; +} + +/// A decoder that can reconstruct interned IR values by supplying an interner. +#[cfg(feature = "nightly")] +pub trait InternerDecoder: Decoder { + type Interner: Interner; + + fn interner(&self) -> Self::Interner; } /// Imagine you have a function `F: FnOnce(&[T]) -> R`, plus an iterator `iter` diff --git a/compiler/rustc_type_ir/src/sty/mod.rs b/compiler/rustc_type_ir/src/sty/mod.rs new file mode 100644 index 0000000000000..7822f3d86ec75 --- /dev/null +++ b/compiler/rustc_type_ir/src/sty/mod.rs @@ -0,0 +1,191 @@ +use std::fmt; + +use derive_where::derive_where; +#[cfg(feature = "nightly")] +use rustc_data_structures::intern::Interned; +#[cfg(feature = "nightly")] +use rustc_macros::HashStable_NoContext; +#[cfg(feature = "nightly")] +use rustc_serialize::{Decodable, Encodable}; +use tracing::debug; + +use crate::inherent::*; +use crate::relate::{Relate, RelateResult, TypeRelation}; +use crate::{ + BoundRegion, BoundRegionKind, BoundVar, BoundVarIndexKind, DebruijnIndex, FallibleTypeFolder, + Flags, Interner, PlaceholderRegion, RegionKind, TypeFlags, TypeFoldable, TypeFolder, + TypeVisitable, TypeVisitor, +}; + +/// Use this rather than `RegionKind`, whenever possible. +#[derive_where(Clone, Copy, PartialEq, Eq, Hash; I: Interner)] +#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] +#[cfg_attr(feature = "nightly", rustc_pass_by_value)] +pub struct Region(pub I::InternedRegionKind); + +// These are only the `inherent` trait methods that have been ported across +impl Region { + #[inline] + pub fn new_bound(interner: I, debruijn: DebruijnIndex, bound_region: BoundRegion) -> Self { + interner.intern_bound_region(debruijn, bound_region) + } + + #[inline] + pub fn new_anon_bound(interner: I, debruijn: DebruijnIndex, var: BoundVar) -> Self { + Self::new_bound(interner, debruijn, BoundRegion { var, kind: BoundRegionKind::Anon }) + } + + #[inline] + pub fn new_canonical_bound(interner: I, var: BoundVar) -> Self { + interner.intern_canonical_bound(var) + } + + #[inline] + pub fn new_placeholder(interner: I, placeholder: PlaceholderRegion) -> Self { + interner.intern_region(RegionKind::RePlaceholder(placeholder)) + } + + #[inline] + pub fn new_static(interner: I) -> Self { + interner.get_re_static_lifetime() + } + + #[inline] + pub fn is_bound(self) -> bool { + matches!(self.0.kind(), RegionKind::ReBound(..)) + } + + #[inline] + pub fn type_flags(self) -> TypeFlags { + let mut flags = TypeFlags::empty(); + + match self.0.kind() { + RegionKind::ReVar(..) => { + flags = flags | TypeFlags::HAS_FREE_REGIONS; + flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS; + flags = flags | TypeFlags::HAS_RE_INFER; + } + RegionKind::RePlaceholder(..) => { + flags = flags | TypeFlags::HAS_FREE_REGIONS; + flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS; + flags = flags | TypeFlags::HAS_RE_PLACEHOLDER; + } + RegionKind::ReEarlyParam(..) => { + flags = flags | TypeFlags::HAS_FREE_REGIONS; + flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS; + flags = flags | TypeFlags::HAS_RE_PARAM; + } + RegionKind::ReLateParam { .. } => { + flags = flags | TypeFlags::HAS_FREE_REGIONS; + flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS; + } + RegionKind::ReStatic => { + flags = flags | TypeFlags::HAS_FREE_REGIONS; + } + RegionKind::ReBound(BoundVarIndexKind::Canonical, _) => { + flags = flags | TypeFlags::HAS_RE_BOUND; + flags = flags | TypeFlags::HAS_CANONICAL_BOUND; + } + RegionKind::ReBound(BoundVarIndexKind::Bound(..), _) => { + flags = flags | TypeFlags::HAS_RE_BOUND; + } + RegionKind::ReErased => { + flags = flags | TypeFlags::HAS_RE_ERASED; + } + RegionKind::ReError(_) => { + flags = flags | TypeFlags::HAS_FREE_REGIONS; + flags = flags | TypeFlags::HAS_RE_ERROR; + } + } + debug!("type_flags({:?}) = {:?}", self, flags); + + flags + } + + #[inline] + pub fn kind(self) -> RegionKind { + self.0.kind() + } +} + +impl Flags for Region { + fn flags(&self) -> TypeFlags { + self.type_flags() + } + + fn outer_exclusive_binder(&self) -> DebruijnIndex { + match self.kind() { + RegionKind::ReBound(BoundVarIndexKind::Bound(debruijn), _) => debruijn.shifted_in(1), + _ => crate::INNERMOST, + } + } +} + +impl IntoKind for Region { + type Kind = RegionKind; + + fn kind(self) -> Self::Kind { + self.0.kind() + } +} + +#[cfg(feature = "nightly")] +impl<'tcx, T: Copy> IntoKind for Interned<'tcx, T> { + type Kind = T; + + fn kind(self) -> Self::Kind { + *self.0 + } +} + +impl Relate for Region { + fn relate>( + relation: &mut R, + a: Region, + b: Region, + ) -> RelateResult> { + relation.regions(a, b) + } +} + +impl fmt::Debug for Region { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{:?}", self.kind()) + } +} + +impl TypeVisitable for Region { + fn visit_with>(&self, visitor: &mut V) -> V::Result { + visitor.visit_region(*self) + } +} + +impl TypeFoldable for Region { + fn try_fold_with>(self, folder: &mut F) -> Result { + folder.try_fold_region(self) + } + + fn fold_with>(self, folder: &mut F) -> Self { + folder.fold_region(self) + } +} + +#[cfg(feature = "nightly")] +impl Encodable for Region +where + RegionKind: Encodable, +{ + fn encode(&self, e: &mut E) { + self.kind().encode(e); + } +} + +#[cfg(feature = "nightly")] +impl> Decodable for Region +where + RegionKind: Decodable, +{ + fn decode(decoder: &mut D) -> Self { + decoder.interner().intern_region(Decodable::decode(decoder)) + } +} From f04383ccaef134c77091d2c8c4819dc8c5da93d8 Mon Sep 17 00:00:00 2001 From: James Barford-Evans Date: Mon, 20 Apr 2026 13:40:23 +0100 Subject: [PATCH 2/9] Modify TyEncoder and TyDecoder --- compiler/rustc_metadata/src/rmeta/decoder.rs | 14 +++++++++----- .../rustc_middle/src/query/on_disk_cache.rs | 14 +++++++++----- compiler/rustc_middle/src/ty/codec.rs | 18 +++--------------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 230ce5686e979..b4d4585a04192 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -401,11 +401,6 @@ impl<'a> BlobDecodeContext<'a> { impl<'a, 'tcx> TyDecoder<'tcx> for MetadataDecodeContext<'a, 'tcx> { const CLEAR_CROSS_CRATE: bool = true; - #[inline] - fn interner(&self) -> TyCtxt<'tcx> { - self.tcx - } - fn cached_ty_for_shorthand(&mut self, shorthand: usize, or_insert_with: F) -> Ty<'tcx> where F: FnOnce(&mut Self) -> Ty<'tcx>, @@ -442,6 +437,15 @@ impl<'a, 'tcx> TyDecoder<'tcx> for MetadataDecodeContext<'a, 'tcx> { } } +impl<'a, 'tcx> rustc_middle::ty::InternerDecoder for MetadataDecodeContext<'a, 'tcx> { + type Interner = TyCtxt<'tcx>; + + #[inline] + fn interner(&self) -> TyCtxt<'tcx> { + self.tcx + } +} + impl<'a, 'tcx> Decodable> for ExpnIndex { #[inline] fn decode(d: &mut MetadataDecodeContext<'a, 'tcx>) -> ExpnIndex { diff --git a/compiler/rustc_middle/src/query/on_disk_cache.rs b/compiler/rustc_middle/src/query/on_disk_cache.rs index 3bbbe3c184eb0..80027a3b4fbe9 100644 --- a/compiler/rustc_middle/src/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/query/on_disk_cache.rs @@ -489,11 +489,6 @@ where impl<'a, 'tcx> TyDecoder<'tcx> for CacheDecoder<'a, 'tcx> { const CLEAR_CROSS_CRATE: bool = false; - #[inline] - fn interner(&self) -> TyCtxt<'tcx> { - self.tcx - } - fn cached_ty_for_shorthand(&mut self, shorthand: usize, or_insert_with: F) -> Ty<'tcx> where F: FnOnce(&mut Self) -> Ty<'tcx>, @@ -531,6 +526,15 @@ impl<'a, 'tcx> TyDecoder<'tcx> for CacheDecoder<'a, 'tcx> { } } +impl<'a, 'tcx> rustc_type_ir::InternerDecoder for CacheDecoder<'a, 'tcx> { + type Interner = TyCtxt<'tcx>; + + #[inline] + fn interner(&self) -> Self::Interner { + self.tcx + } +} + crate::implement_ty_decoder!(CacheDecoder<'a, 'tcx>); // This ensures that the `Decodable::decode` specialization for `Vec` is used diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 28bdeabf34dc1..9feba407f4d6e 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -41,11 +41,11 @@ pub trait TyEncoder<'tcx>: SpanEncoder { fn encode_alloc_id(&mut self, alloc_id: &AllocId); } -pub trait TyDecoder<'tcx>: SpanDecoder { +pub trait TyDecoder<'tcx>: + SpanDecoder + rustc_type_ir::InternerDecoder> +{ const CLEAR_CROSS_CRATE: bool; - fn interner(&self) -> TyCtxt<'tcx>; - fn cached_ty_for_shorthand(&mut self, shorthand: usize, or_insert_with: F) -> Ty<'tcx> where F: FnOnce(&mut Self) -> Ty<'tcx>; @@ -158,12 +158,6 @@ impl<'tcx, E: TyEncoder<'tcx>> Encodable for ty::Clause<'tcx> { } } -impl<'tcx, E: TyEncoder<'tcx>> Encodable for ty::Region<'tcx> { - fn encode(&self, e: &mut E) { - self.kind().encode(e); - } -} - impl<'tcx, E: TyEncoder<'tcx>> Encodable for ty::Const<'tcx> { fn encode(&self, e: &mut E) { self.0.0.encode(e); @@ -297,12 +291,6 @@ impl<'tcx, D: TyDecoder<'tcx>> Decodable for mir::Place<'tcx> { } } -impl<'tcx, D: TyDecoder<'tcx>> Decodable for ty::Region<'tcx> { - fn decode(decoder: &mut D) -> Self { - ty::Region::new_from_kind(decoder.interner(), Decodable::decode(decoder)) - } -} - impl<'tcx, D: TyDecoder<'tcx>> Decodable for CanonicalVarKinds<'tcx> { fn decode(decoder: &mut D) -> Self { let len = decoder.read_usize(); From 766ade3d0a3e712c9b64aa0f867001813b3a1194 Mon Sep 17 00:00:00 2001 From: James Barford-Evans Date: Mon, 20 Apr 2026 13:41:03 +0100 Subject: [PATCH 3/9] Remove `Region` from rustc_middle and create extension traits --- compiler/rustc_middle/src/ty/region.rs | 127 ++++++------------------- 1 file changed, 28 insertions(+), 99 deletions(-) diff --git a/compiler/rustc_middle/src/ty/region.rs b/compiler/rustc_middle/src/ty/region.rs index 041c6201c71bf..5799d16af4d16 100644 --- a/compiler/rustc_middle/src/ty/region.rs +++ b/compiler/rustc_middle/src/ty/region.rs @@ -1,21 +1,16 @@ -use rustc_data_structures::intern::Interned; use rustc_errors::MultiSpan; use rustc_hir::def_id::DefId; -use rustc_macros::{StableHash, TyDecodable, TyEncodable}; +use rustc_macros::{HashStable, TyDecodable, TyEncodable, extension}; use rustc_span::{DUMMY_SP, ErrorGuaranteed, Symbol, kw, sym}; -use rustc_type_ir::RegionKind as IrRegionKind; pub use rustc_type_ir::RegionVid; +use rustc_type_ir::{Region as IrRegion, RegionKind as IrRegionKind}; use tracing::debug; use crate::ty::{self, BoundVar, TyCtxt, TypeFlags}; +pub type Region<'tcx> = IrRegion>; pub type RegionKind<'tcx> = IrRegionKind>; -/// Use this rather than `RegionKind`, whenever possible. -#[derive(Copy, Clone, PartialEq, Eq, Hash, StableHash)] -#[rustc_pass_by_value] -pub struct Region<'tcx>(pub Interned<'tcx, RegionKind<'tcx>>); - impl<'tcx> rustc_type_ir::inherent::IntoKind for Region<'tcx> { type Kind = RegionKind<'tcx>; @@ -37,9 +32,10 @@ impl<'tcx> rustc_type_ir::Flags for Region<'tcx> { } } +#[extension(pub trait RegionExt<'tcx>)] impl<'tcx> Region<'tcx> { #[inline] - pub fn new_early_param( + fn new_early_param( tcx: TyCtxt<'tcx>, early_bound_region: ty::EarlyParamRegion, ) -> Region<'tcx> { @@ -47,47 +43,13 @@ impl<'tcx> Region<'tcx> { } #[inline] - pub fn new_bound( - tcx: TyCtxt<'tcx>, - debruijn: ty::DebruijnIndex, - bound_region: ty::BoundRegion<'tcx>, - ) -> Region<'tcx> { - // Use a pre-interned one when possible. - if let ty::BoundRegion { var, kind: ty::BoundRegionKind::Anon } = bound_region - && let Some(inner) = tcx.lifetimes.anon_re_bounds.get(debruijn.as_usize()) - && let Some(re) = inner.get(var.as_usize()).copied() - { - re - } else { - tcx.intern_region(ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), bound_region)) - } - } - - #[inline] - pub fn new_canonical_bound(tcx: TyCtxt<'tcx>, var: ty::BoundVar) -> Region<'tcx> { - // Use a pre-interned one when possible. - if let Some(re) = tcx.lifetimes.anon_re_canonical_bounds.get(var.as_usize()).copied() { - re - } else { - tcx.intern_region(ty::ReBound( - ty::BoundVarIndexKind::Canonical, - ty::BoundRegion { var, kind: ty::BoundRegionKind::Anon }, - )) - } - } - - #[inline] - pub fn new_late_param( - tcx: TyCtxt<'tcx>, - scope: DefId, - kind: LateParamRegionKind, - ) -> Region<'tcx> { + fn new_late_param(tcx: TyCtxt<'tcx>, scope: DefId, kind: LateParamRegionKind) -> Region<'tcx> { let data = LateParamRegion { scope, kind }; tcx.intern_region(ty::ReLateParam(data)) } #[inline] - pub fn new_var(tcx: TyCtxt<'tcx>, v: ty::RegionVid) -> Region<'tcx> { + fn new_var(tcx: TyCtxt<'tcx>, v: ty::RegionVid) -> Region<'tcx> { // Use a pre-interned one when possible. tcx.lifetimes .re_vars @@ -96,24 +58,16 @@ impl<'tcx> Region<'tcx> { .unwrap_or_else(|| tcx.intern_region(ty::ReVar(v))) } - #[inline] - pub fn new_placeholder( - tcx: TyCtxt<'tcx>, - placeholder: ty::PlaceholderRegion<'tcx>, - ) -> Region<'tcx> { - tcx.intern_region(ty::RePlaceholder(placeholder)) - } - /// Constructs a `RegionKind::ReError` region. #[track_caller] - pub fn new_error(tcx: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> Region<'tcx> { + fn new_error(tcx: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> Region<'tcx> { tcx.intern_region(ty::ReError(guar)) } /// Constructs a `RegionKind::ReError` region and registers a delayed bug to ensure it gets /// used. #[track_caller] - pub fn new_error_misc(tcx: TyCtxt<'tcx>) -> Region<'tcx> { + fn new_error_misc(tcx: TyCtxt<'tcx>) -> Region<'tcx> { Region::new_error_with_message( tcx, DUMMY_SP, @@ -124,7 +78,7 @@ impl<'tcx> Region<'tcx> { /// Constructs a `RegionKind::ReError` region and registers a delayed bug with the given `msg` /// to ensure it gets used. #[track_caller] - pub fn new_error_with_message>( + fn new_error_with_message>( tcx: TyCtxt<'tcx>, span: S, msg: &'static str, @@ -135,7 +89,7 @@ impl<'tcx> Region<'tcx> { /// Avoid this in favour of more specific `new_*` methods, where possible, /// to avoid the cost of the `match`. - pub fn new_from_kind(tcx: TyCtxt<'tcx>, kind: RegionKind<'tcx>) -> Region<'tcx> { + fn new_from_kind(tcx: TyCtxt<'tcx>, kind: RegionKind<'tcx>) -> Region<'tcx> { match kind { ty::ReEarlyParam(region) => Region::new_early_param(tcx, region), ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), region) => { @@ -156,39 +110,14 @@ impl<'tcx> Region<'tcx> { } } -impl<'tcx> rustc_type_ir::inherent::Region> for Region<'tcx> { - fn new_bound( - interner: TyCtxt<'tcx>, - debruijn: ty::DebruijnIndex, - var: ty::BoundRegion<'tcx>, - ) -> Self { - Region::new_bound(interner, debruijn, var) - } - - fn new_anon_bound(tcx: TyCtxt<'tcx>, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self { - Region::new_bound(tcx, debruijn, ty::BoundRegion { var, kind: ty::BoundRegionKind::Anon }) - } - - fn new_canonical_bound(tcx: TyCtxt<'tcx>, var: rustc_type_ir::BoundVar) -> Self { - Region::new_canonical_bound(tcx, var) - } - - fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderRegion<'tcx>) -> Self { - Region::new_placeholder(tcx, placeholder) - } - - fn new_static(tcx: TyCtxt<'tcx>) -> Self { - tcx.lifetimes.re_static - } -} - /// Region utilities +#[extension(pub trait RegionUtilitiesExt<'tcx>)] impl<'tcx> Region<'tcx> { - pub fn kind(self) -> RegionKind<'tcx> { + fn kind(self) -> RegionKind<'tcx> { *self.0.0 } - pub fn get_name(self, tcx: TyCtxt<'tcx>) -> Option { + fn get_name(self, tcx: TyCtxt<'tcx>) -> Option { match self.kind() { ty::ReEarlyParam(ebr) => ebr.is_named().then_some(ebr.name), ty::ReBound(_, br) => br.kind.get_name(tcx), @@ -199,7 +128,7 @@ impl<'tcx> Region<'tcx> { } } - pub fn get_name_or_anon(self, tcx: TyCtxt<'tcx>) -> Symbol { + fn get_name_or_anon(self, tcx: TyCtxt<'tcx>) -> Symbol { match self.get_name(tcx) { Some(name) => name, None => sym::anon, @@ -207,7 +136,7 @@ impl<'tcx> Region<'tcx> { } /// Is this region named by the user? - pub fn is_named(self, tcx: TyCtxt<'tcx>) -> bool { + fn is_named(self, tcx: TyCtxt<'tcx>) -> bool { match self.kind() { ty::ReEarlyParam(ebr) => ebr.is_named(), ty::ReBound(_, br) => br.kind.is_named(tcx), @@ -221,39 +150,39 @@ impl<'tcx> Region<'tcx> { } #[inline] - pub fn is_error(self) -> bool { + fn is_error(self) -> bool { matches!(self.kind(), ty::ReError(_)) } #[inline] - pub fn is_static(self) -> bool { + fn is_static(self) -> bool { matches!(self.kind(), ty::ReStatic) } #[inline] - pub fn is_erased(self) -> bool { + fn is_erased(self) -> bool { matches!(self.kind(), ty::ReErased) } #[inline] - pub fn is_bound(self) -> bool { + fn is_bound(self) -> bool { matches!(self.kind(), ty::ReBound(..)) } #[inline] - pub fn is_placeholder(self) -> bool { + fn is_placeholder(self) -> bool { matches!(self.kind(), ty::RePlaceholder(..)) } #[inline] - pub fn bound_at_or_above_binder(self, index: ty::DebruijnIndex) -> bool { + fn bound_at_or_above_binder(self, index: ty::DebruijnIndex) -> bool { match self.kind() { ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), _) => debruijn >= index, _ => false, } } - pub fn type_flags(self) -> TypeFlags { + fn type_flags(self) -> TypeFlags { let mut flags = TypeFlags::empty(); match self.kind() { @@ -301,14 +230,14 @@ impl<'tcx> Region<'tcx> { } /// True for free regions other than `'static`. - pub fn is_param(self) -> bool { + fn is_param(self) -> bool { matches!(self.kind(), ty::ReEarlyParam(_) | ty::ReLateParam(_)) } /// True for free region in the current context. /// /// This is the case for `'static` and param regions. - pub fn is_free(self) -> bool { + fn is_free(self) -> bool { match self.kind() { ty::ReStatic | ty::ReEarlyParam(..) | ty::ReLateParam(..) => true, ty::ReVar(..) @@ -319,11 +248,11 @@ impl<'tcx> Region<'tcx> { } } - pub fn is_var(self) -> bool { + fn is_var(self) -> bool { matches!(self.kind(), ty::ReVar(_)) } - pub fn as_var(self) -> RegionVid { + fn as_var(self) -> RegionVid { match self.kind() { ty::ReVar(vid) => vid, _ => bug!("expected region {:?} to be of kind ReVar", self), @@ -332,7 +261,7 @@ impl<'tcx> Region<'tcx> { /// Given some item `binding_item`, check if this region is a generic parameter introduced by it /// or one of the parent generics. Returns the `DefId` of the parameter definition if so. - pub fn opt_param_def_id(self, tcx: TyCtxt<'tcx>, binding_item: DefId) -> Option { + fn opt_param_def_id(self, tcx: TyCtxt<'tcx>, binding_item: DefId) -> Option { match self.kind() { ty::ReEarlyParam(ebr) => { Some(tcx.generics_of(binding_item).region_param(ebr, tcx).def_id) From 985755d398bed2bec16eabd2a76370186234530e Mon Sep 17 00:00:00 2001 From: James Barford-Evans Date: Mon, 20 Apr 2026 14:37:01 +0100 Subject: [PATCH 4/9] Add & remove various trait implementations for Region --- compiler/rustc_middle/src/ty/diagnostics.rs | 4 --- compiler/rustc_middle/src/ty/print/pretty.rs | 1 - compiler/rustc_middle/src/ty/relate.rs | 10 ------- .../rustc_middle/src/ty/structural_impls.rs | 27 +------------------ compiler/rustc_type_ir/src/binder.rs | 8 ++++++ compiler/rustc_type_ir/src/inherent.rs | 27 ------------------- compiler/rustc_type_ir/src/ir_print.rs | 19 +++++++++++-- 7 files changed, 26 insertions(+), 70 deletions(-) diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index a9e7425fdcbf6..daae5c6037f2a 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -37,10 +37,6 @@ impl IntoDiagArg for Instance<'_> { } } -into_diag_arg_using_display! { - ty::Region<'_>, -} - impl<'tcx> Ty<'tcx> { /// Similar to `Ty::is_primitive`, but also considers inferred numeric values to be primitive. pub fn is_primitive_ty(self) -> bool { diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index daead99b977c1..ea9825298fc96 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -3125,7 +3125,6 @@ macro_rules! define_print_and_forward_display { } forward_display_to_print! { - ty::Region<'tcx>, Ty<'tcx>, &'tcx ty::List>, ty::Const<'tcx> diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 9f2a1187a9ddc..f4b46ee3ca582 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -98,16 +98,6 @@ impl<'tcx> Relate> for ty::GenericArgsRef<'tcx> { } } -impl<'tcx> Relate> for ty::Region<'tcx> { - fn relate>>( - relation: &mut R, - a: ty::Region<'tcx>, - b: ty::Region<'tcx>, - ) -> RelateResult<'tcx, ty::Region<'tcx>> { - relation.regions(a, b) - } -} - impl<'tcx> Relate> for ty::Const<'tcx> { fn relate>>( relation: &mut R, diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 08a8491bab6c5..4738ce23258fd 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -11,7 +11,7 @@ use rustc_hir::def_id::LocalDefId; use rustc_span::Spanned; use rustc_type_ir::{ConstKind, TypeFolder, VisitorResult, try_visit}; -use super::{GenericArg, GenericArgKind, Pattern, Region}; +use super::{GenericArg, GenericArgKind, Pattern}; use crate::mir::PlaceElem; use crate::ty::print::{FmtPrinter, Printer, with_no_trimmed_paths}; use crate::ty::{ @@ -169,12 +169,6 @@ impl<'tcx> fmt::Debug for GenericArg<'tcx> { } } -impl<'tcx> fmt::Debug for Region<'tcx> { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{:?}", self.kind()) - } -} - /////////////////////////////////////////////////////////////////////////// // Atomic structs // @@ -475,25 +469,6 @@ impl<'tcx> TypeSuperVisitable> for Ty<'tcx> { } } -impl<'tcx> TypeFoldable> for ty::Region<'tcx> { - fn try_fold_with>>( - self, - folder: &mut F, - ) -> Result { - folder.try_fold_region(self) - } - - fn fold_with>>(self, folder: &mut F) -> Self { - folder.fold_region(self) - } -} - -impl<'tcx> TypeVisitable> for ty::Region<'tcx> { - fn visit_with>>(&self, visitor: &mut V) -> V::Result { - visitor.visit_region(*self) - } -} - impl<'tcx> TypeFoldable> for ty::Predicate<'tcx> { fn try_fold_with>>( self, diff --git a/compiler/rustc_type_ir/src/binder.rs b/compiler/rustc_type_ir/src/binder.rs index b55cbc3164d96..a277741488e4e 100644 --- a/compiler/rustc_type_ir/src/binder.rs +++ b/compiler/rustc_type_ir/src/binder.rs @@ -958,6 +958,14 @@ pub enum BoundVarIndexKind { Canonical, } +impl Lift for BoundVarIndexKind { + type Lifted = BoundVarIndexKind; + + fn lift_to_interner(self, _interner: U) -> Option { + Some(self) + } +} + /// The "placeholder index" fully defines a placeholder region, type, or const. Placeholders are /// identified by both a universe, as well as a name residing within that universe. Distinct bound /// regions/types/consts within the same universe simply have an unknown relationship to one diff --git a/compiler/rustc_type_ir/src/inherent.rs b/compiler/rustc_type_ir/src/inherent.rs index 3539215072ad9..6db48047bc3cb 100644 --- a/compiler/rustc_type_ir/src/inherent.rs +++ b/compiler/rustc_type_ir/src/inherent.rs @@ -220,33 +220,6 @@ pub trait Safety>: Copy + Debug + Hash + Eq { fn prefix_str(self) -> &'static str; } -#[rust_analyzer::prefer_underscore_import] -pub trait Region>: - Copy - + Debug - + Hash - + Eq - + Into - + IntoKind> - + Flags - + Relate -{ - fn new_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundRegion) -> Self; - - fn new_anon_bound(interner: I, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self; - - fn new_canonical_bound(interner: I, var: ty::BoundVar) -> Self; - - fn new_static(interner: I) -> Self; - - fn new_placeholder(interner: I, var: ty::PlaceholderRegion) -> Self; - - fn is_bound(self) -> bool { - matches!(self.kind(), ty::ReBound(..)) - } -} - -#[rust_analyzer::prefer_underscore_import] pub trait Const>: Copy + Debug diff --git a/compiler/rustc_type_ir/src/ir_print.rs b/compiler/rustc_type_ir/src/ir_print.rs index 5af2bd811bab4..952571c903aa8 100644 --- a/compiler/rustc_type_ir/src/ir_print.rs +++ b/compiler/rustc_type_ir/src/ir_print.rs @@ -3,8 +3,8 @@ use std::fmt; use crate::{ AliasTerm, AliasTy, Binder, ClosureKind, CoercePredicate, ExistentialProjection, ExistentialTraitRef, FnSig, HostEffectPredicate, Interner, NormalizesTo, OutlivesPredicate, - PatternKind, Placeholder, ProjectionPredicate, SubtypePredicate, TraitPredicate, TraitRef, - UnevaluatedConst, + PatternKind, Placeholder, ProjectionPredicate, Region, SubtypePredicate, TraitPredicate, + TraitRef, UnevaluatedConst, }; pub trait IrPrint { @@ -54,6 +54,15 @@ define_display_via_print!( define_debug_via_print!(TraitRef, ExistentialTraitRef, PatternKind); +impl fmt::Display for Region +where + I: IrPrint>, +{ + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + >>::print(self, fmt) + } +} + impl fmt::Display for OutlivesPredicate where I: IrPrint>, @@ -99,6 +108,12 @@ mod into_diag_arg_impls { } } + impl>> IntoDiagArg for Region { + fn into_diag_arg(self, path: &mut Option) -> DiagArgValue { + self.to_string().into_diag_arg(path) + } + } + impl IntoDiagArg for UnevaluatedConst { fn into_diag_arg(self, path: &mut Option) -> DiagArgValue { format!("{self:?}").into_diag_arg(path) From 8934e2e15465fbcc87ebfff916c6accc226dae7f Mon Sep 17 00:00:00 2001 From: James Barford-Evans Date: Mon, 20 Apr 2026 14:32:22 +0100 Subject: [PATCH 5/9] use extension traits --- compiler/rustc_borrowck/src/borrow_set.rs | 2 +- .../rustc_borrowck/src/diagnostics/bound_region_errors.rs | 3 ++- compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs | 2 +- compiler/rustc_borrowck/src/diagnostics/find_use.rs | 2 +- compiler/rustc_borrowck/src/diagnostics/region_errors.rs | 4 ++-- compiler/rustc_borrowck/src/diagnostics/region_name.rs | 4 +++- compiler/rustc_borrowck/src/diagnostics/var_name.rs | 2 +- compiler/rustc_borrowck/src/lib.rs | 3 ++- compiler/rustc_borrowck/src/nll.rs | 2 +- compiler/rustc_borrowck/src/polonius/dump.rs | 2 +- .../rustc_borrowck/src/polonius/liveness_constraints.rs | 2 +- compiler/rustc_borrowck/src/region_infer/graphviz.rs | 2 +- compiler/rustc_borrowck/src/region_infer/mod.rs | 4 +++- .../rustc_borrowck/src/region_infer/opaque_types/mod.rs | 5 +++-- .../rustc_borrowck/src/type_check/constraint_conversion.rs | 3 ++- compiler/rustc_borrowck/src/type_check/liveness/mod.rs | 4 +++- compiler/rustc_borrowck/src/type_check/mod.rs | 3 ++- compiler/rustc_borrowck/src/type_check/relate_tys.rs | 2 +- compiler/rustc_borrowck/src/universal_regions.rs | 4 ++-- compiler/rustc_hir_analysis/src/check/always_applicable.rs | 2 +- compiler/rustc_hir_analysis/src/check/compare_impl_item.rs | 6 +++--- compiler/rustc_hir_analysis/src/check/mod.rs | 4 ++-- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 6 +++--- compiler/rustc_hir_analysis/src/collect.rs | 4 ++-- compiler/rustc_hir_analysis/src/collect/predicates_of.rs | 3 ++- compiler/rustc_hir_analysis/src/delegation.rs | 3 ++- compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs | 4 ++-- .../src/impl_wf_check/min_specialization.rs | 3 ++- compiler/rustc_hir_typeck/src/method/suggest.rs | 4 +++- compiler/rustc_infer/src/infer/canonical/canonicalizer.rs | 4 ++-- compiler/rustc_infer/src/infer/canonical/query_response.rs | 4 +++- compiler/rustc_infer/src/infer/free_regions.rs | 2 +- .../src/infer/lexical_region_resolve/indexed_edges.rs | 1 + .../rustc_infer/src/infer/lexical_region_resolve/mod.rs | 2 +- compiler/rustc_infer/src/infer/mod.rs | 5 +++-- compiler/rustc_infer/src/infer/region_constraints/mod.rs | 4 +++- compiler/rustc_lint/src/impl_trait_overcaptures.rs | 4 ++-- compiler/rustc_middle/src/ty/context.rs | 1 + compiler/rustc_middle/src/ty/diagnostics.rs | 4 +--- compiler/rustc_middle/src/ty/fold.rs | 1 + compiler/rustc_middle/src/ty/generics.rs | 1 + compiler/rustc_middle/src/ty/mod.rs | 3 ++- compiler/rustc_middle/src/ty/opaque_types.rs | 5 +++-- compiler/rustc_middle/src/ty/print/pretty.rs | 1 + compiler/rustc_mir_transform/src/promote_consts.rs | 2 +- compiler/rustc_symbol_mangling/src/v0.rs | 4 ++-- .../rustc_trait_selection/src/error_reporting/infer/mod.rs | 4 ++-- .../infer/nice_region_error/mismatched_static_lifetime.rs | 2 +- .../infer/nice_region_error/named_anon_conflict.rs | 1 + .../infer/nice_region_error/placeholder_error.rs | 4 +++- .../infer/nice_region_error/static_impl_trait.rs | 2 +- .../infer/nice_region_error/trait_impl_difference.rs | 2 +- .../src/error_reporting/infer/region.rs | 2 +- compiler/rustc_trait_selection/src/opaque_types.rs | 4 ++-- compiler/rustc_trait_selection/src/traits/auto_trait.rs | 2 +- compiler/rustc_trait_selection/src/traits/coherence.rs | 4 ++-- compiler/rustc_ty_utils/src/implied_bounds.rs | 2 +- compiler/rustc_ty_utils/src/ty.rs | 4 ++-- 58 files changed, 102 insertions(+), 73 deletions(-) diff --git a/compiler/rustc_borrowck/src/borrow_set.rs b/compiler/rustc_borrowck/src/borrow_set.rs index 4644c210137fe..0879eba87196b 100644 --- a/compiler/rustc_borrowck/src/borrow_set.rs +++ b/compiler/rustc_borrowck/src/borrow_set.rs @@ -6,7 +6,7 @@ use rustc_index::bit_set::DenseBitSet; use rustc_middle::mir::visit::{MutatingUseContext, NonUseContext, PlaceContext, Visitor}; use rustc_middle::mir::{self, Body, Local, Location, traversal}; use rustc_middle::span_bug; -use rustc_middle::ty::{RegionVid, TyCtxt}; +use rustc_middle::ty::{RegionUtilitiesExt, RegionVid, TyCtxt}; use rustc_mir_dataflow::move_paths::MoveData; use tracing::debug; diff --git a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs index 538c5887118e6..1559186457073 100644 --- a/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/bound_region_errors.rs @@ -14,7 +14,8 @@ use rustc_infer::traits::query::{ }; use rustc_middle::ty::error::TypeError; use rustc_middle::ty::{ - self, RePlaceholder, Region, RegionVid, Ty, TyCtxt, TypeFoldable, UniverseIndex, Unnormalized, + self, RePlaceholder, Region, RegionExt, RegionUtilitiesExt, RegionVid, Ty, TyCtxt, + TypeFoldable, UniverseIndex, Unnormalized, }; use rustc_span::Span; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index c4fbe1b9e5d61..09e4b333678a0 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -25,7 +25,7 @@ use rustc_middle::mir::{ }; use rustc_middle::ty::print::PrintTraitRefExt as _; use rustc_middle::ty::{ - self, PredicateKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor, Upcast, + self, PredicateKind, RegionUtilitiesExt, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor, Upcast, suggest_constraining_type_params, }; use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex}; diff --git a/compiler/rustc_borrowck/src/diagnostics/find_use.rs b/compiler/rustc_borrowck/src/diagnostics/find_use.rs index 96f48840468e5..ba244700313aa 100644 --- a/compiler/rustc_borrowck/src/diagnostics/find_use.rs +++ b/compiler/rustc_borrowck/src/diagnostics/find_use.rs @@ -3,7 +3,7 @@ use std::collections::VecDeque; use rustc_data_structures::fx::FxIndexSet; use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::{self, Body, Local, Location}; -use rustc_middle::ty::{RegionVid, TyCtxt}; +use rustc_middle::ty::{RegionUtilitiesExt, RegionVid, TyCtxt}; use crate::def_use::{self, DefUse}; use crate::region_infer::{Cause, RegionInferenceContext}; diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index f9c91c3371516..cb906bc35081e 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -15,8 +15,8 @@ use rustc_middle::bug; use rustc_middle::hir::place::PlaceBase; use rustc_middle::mir::{AnnotationSource, ConstraintCategory, ReturnConstraint}; use rustc_middle::ty::{ - self, FnSigKind, GenericArgs, Region, RegionVid, Ty, TyCtxt, TypeFoldable, TypeVisitor, - fold_regions, + self, FnSigKind, GenericArgs, Region, RegionUtilitiesExt, RegionVid, Ty, TyCtxt, TypeFoldable, + TypeVisitor, fold_regions, }; use rustc_span::{Ident, Span, kw}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; diff --git a/compiler/rustc_borrowck/src/diagnostics/region_name.rs b/compiler/rustc_borrowck/src/diagnostics/region_name.rs index 963f902b71fcb..f07603f6f69c4 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_name.rs @@ -6,7 +6,9 @@ use rustc_errors::{Diag, EmissionGuarantee}; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_middle::ty::print::RegionHighlightMode; -use rustc_middle::ty::{self, GenericArgKind, GenericArgsRef, RegionVid, Ty, Unnormalized}; +use rustc_middle::ty::{ + self, GenericArgKind, GenericArgsRef, RegionUtilitiesExt, RegionVid, Ty, Unnormalized, +}; use rustc_middle::{bug, span_bug}; use rustc_span::{DUMMY_SP, Span, Symbol, kw, sym}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; diff --git a/compiler/rustc_borrowck/src/diagnostics/var_name.rs b/compiler/rustc_borrowck/src/diagnostics/var_name.rs index b51604fb2903a..09199a87d8af6 100644 --- a/compiler/rustc_borrowck/src/diagnostics/var_name.rs +++ b/compiler/rustc_borrowck/src/diagnostics/var_name.rs @@ -1,7 +1,7 @@ use rustc_index::IndexSlice; use rustc_middle::mir::visit::{PlaceContext, VisitPlacesWith, Visitor}; use rustc_middle::mir::{Body, Local, Place}; -use rustc_middle::ty::{self, RegionVid, TyCtxt}; +use rustc_middle::ty::{self, RegionUtilitiesExt, RegionVid, TyCtxt}; use rustc_span::{Span, Symbol}; use tracing::debug; diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index acdeea91a189f..fa06c972204a1 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -37,7 +37,8 @@ use rustc_infer::infer::{ use rustc_middle::mir::*; use rustc_middle::query::Providers; use rustc_middle::ty::{ - self, ParamEnv, RegionVid, Ty, TyCtxt, TypeFoldable, TypeVisitable, TypingMode, fold_regions, + self, ParamEnv, RegionUtilitiesExt, RegionVid, Ty, TyCtxt, TypeFoldable, TypeVisitable, + TypingMode, fold_regions, }; use rustc_middle::{bug, span_bug}; use rustc_mir_dataflow::impls::{EverInitializedPlaces, MaybeUninitializedPlaces}; diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index dd6eb17947577..94710b3a3f662 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -12,7 +12,7 @@ use rustc_index::IndexSlice; use rustc_middle::mir::pretty::PrettyPrintMirOptions; use rustc_middle::mir::{Body, MirDumper, PassWhere, Promoted}; use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_middle::ty::{self, TyCtxt}; +use rustc_middle::ty::{self, RegionExt, TyCtxt}; use rustc_mir_dataflow::move_paths::MoveData; use rustc_mir_dataflow::points::DenseLocationMap; use rustc_session::config::MirIncludeSpans; diff --git a/compiler/rustc_borrowck/src/polonius/dump.rs b/compiler/rustc_borrowck/src/polonius/dump.rs index 5285f724b02ec..7e674f5fc9550 100644 --- a/compiler/rustc_borrowck/src/polonius/dump.rs +++ b/compiler/rustc_borrowck/src/polonius/dump.rs @@ -4,7 +4,7 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet}; use rustc_index::IndexVec; use rustc_middle::mir::pretty::{MirDumper, PassWhere, PrettyPrintMirOptions}; use rustc_middle::mir::{Body, Location}; -use rustc_middle::ty::{RegionVid, TyCtxt}; +use rustc_middle::ty::{RegionUtilitiesExt, RegionVid, TyCtxt}; use rustc_mir_dataflow::points::PointIndex; use rustc_session::config::MirIncludeSpans; diff --git a/compiler/rustc_borrowck/src/polonius/liveness_constraints.rs b/compiler/rustc_borrowck/src/polonius/liveness_constraints.rs index b6f8b4a79f39b..26cec60a0f24a 100644 --- a/compiler/rustc_borrowck/src/polonius/liveness_constraints.rs +++ b/compiler/rustc_borrowck/src/polonius/liveness_constraints.rs @@ -4,7 +4,7 @@ use rustc_hir::def_id::DefId; use rustc_middle::ty::relate::{ self, Relate, RelateResult, TypeRelation, relate_args_with_variances, }; -use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeVisitable}; +use rustc_middle::ty::{self, RegionUtilitiesExt, RegionVid, Ty, TyCtxt, TypeVisitable}; use super::{ConstraintDirection, PoloniusContext}; use crate::universal_regions::UniversalRegions; diff --git a/compiler/rustc_borrowck/src/region_infer/graphviz.rs b/compiler/rustc_borrowck/src/region_infer/graphviz.rs index ceb33d82deba8..d434e808d513a 100644 --- a/compiler/rustc_borrowck/src/region_infer/graphviz.rs +++ b/compiler/rustc_borrowck/src/region_infer/graphviz.rs @@ -7,7 +7,7 @@ use std::io::{self, Write}; use itertools::Itertools; use rustc_graphviz as dot; -use rustc_middle::ty::UniverseIndex; +use rustc_middle::ty::{RegionUtilitiesExt, UniverseIndex}; use super::*; diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index 2a759387788a7..1bb8993fc316d 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -16,7 +16,9 @@ use rustc_middle::mir::{ TerminatorKind, }; use rustc_middle::traits::{ObligationCause, ObligationCauseCode}; -use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, UniverseIndex, fold_regions}; +use rustc_middle::ty::{ + self, RegionExt, RegionVid, Ty, TyCtxt, TypeFoldable, UniverseIndex, fold_regions, +}; use rustc_mir_dataflow::points::DenseLocationMap; use rustc_span::hygiene::DesugaringKind; use rustc_span::{DUMMY_SP, Span}; diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs index 1348f30b4c980..101e49fbcb130 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs @@ -11,8 +11,9 @@ use rustc_macros::extension; use rustc_middle::mir::{Body, ConstraintCategory}; use rustc_middle::ty::{ self, DefiningScopeKind, DefinitionSiteHiddenType, FallibleTypeFolder, Flags, GenericArg, - GenericArgsRef, OpaqueTypeKey, ProvisionalHiddenType, Region, RegionVid, Ty, TyCtxt, - TypeFoldable, TypeSuperFoldable, TypeVisitableExt, Unnormalized, fold_regions, + GenericArgsRef, OpaqueTypeKey, ProvisionalHiddenType, Region, RegionExt, RegionUtilitiesExt, + RegionVid, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitableExt, Unnormalized, + fold_regions, }; use rustc_mir_dataflow::points::DenseLocationMap; use rustc_span::Span; diff --git a/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs index bca2de041b657..ef3a9376ac8c5 100644 --- a/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs +++ b/compiler/rustc_borrowck/src/type_check/constraint_conversion.rs @@ -8,7 +8,8 @@ use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound}; use rustc_infer::traits::query::type_op::DeeplyNormalize; use rustc_middle::bug; use rustc_middle::ty::{ - self, GenericArgKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, elaborate, fold_regions, + self, GenericArgKind, RegionExt, RegionUtilitiesExt, Ty, TyCtxt, TypeFoldable, + TypeVisitableExt, elaborate, fold_regions, }; use rustc_span::Span; use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput}; diff --git a/compiler/rustc_borrowck/src/type_check/liveness/mod.rs b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs index 442c37e26ec18..07deb46c51fcd 100644 --- a/compiler/rustc_borrowck/src/type_check/liveness/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/liveness/mod.rs @@ -4,7 +4,9 @@ use rustc_middle::mir::visit::{TyContext, Visitor}; use rustc_middle::mir::{Body, Local, Location, SourceInfo}; use rustc_middle::span_bug; use rustc_middle::ty::relate::Relate; -use rustc_middle::ty::{GenericArgsRef, Region, RegionVid, Ty, TyCtxt, TypeVisitable}; +use rustc_middle::ty::{ + GenericArgsRef, Region, RegionUtilitiesExt, RegionVid, Ty, TyCtxt, TypeVisitable, +}; use rustc_mir_dataflow::move_paths::MoveData; use rustc_mir_dataflow::points::DenseLocationMap; use tracing::debug; diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index 8998ced10bf9e..823e7f0d98895 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -27,7 +27,8 @@ use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::cast::CastTy; use rustc_middle::ty::{ self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, CoroutineArgsExt, - GenericArgsRef, Ty, TyCtxt, TypeVisitableExt, UserArgs, UserTypeAnnotationIndex, fold_regions, + GenericArgsRef, RegionUtilitiesExt, Ty, TyCtxt, TypeVisitableExt, UserArgs, + UserTypeAnnotationIndex, fold_regions, }; use rustc_mir_dataflow::move_paths::MoveData; use rustc_mir_dataflow::points::DenseLocationMap; diff --git a/compiler/rustc_borrowck/src/type_check/relate_tys.rs b/compiler/rustc_borrowck/src/type_check/relate_tys.rs index f18884df0b44d..88fcbbba9b434 100644 --- a/compiler/rustc_borrowck/src/type_check/relate_tys.rs +++ b/compiler/rustc_borrowck/src/type_check/relate_tys.rs @@ -12,7 +12,7 @@ use rustc_middle::traits::ObligationCause; use rustc_middle::traits::query::NoSolution; use rustc_middle::ty::relate::combine::{combine_ty_args, super_combine_consts, super_combine_tys}; use rustc_middle::ty::relate::relate_args_invariantly; -use rustc_middle::ty::{self, FnMutDelegate, Ty, TyCtxt, TypeVisitableExt}; +use rustc_middle::ty::{self, FnMutDelegate, RegionUtilitiesExt, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::{bug, span_bug}; use rustc_span::{Span, Symbol, sym}; use tracing::{debug, instrument}; diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index 804d2757cf998..19aae3331c5ec 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -26,8 +26,8 @@ use rustc_macros::extension; use rustc_middle::mir::RETURN_PLACE; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::{ - self, GenericArgs, GenericArgsRef, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty, - TyCtxt, TypeFoldable, TypeVisitableExt, fold_regions, + self, GenericArgs, GenericArgsRef, InlineConstArgs, InlineConstArgsParts, RegionExt, + RegionUtilitiesExt, RegionVid, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, fold_regions, }; use rustc_middle::{bug, span_bug}; use rustc_span::{ErrorGuaranteed, kw, sym}; diff --git a/compiler/rustc_hir_analysis/src/check/always_applicable.rs b/compiler/rustc_hir_analysis/src/check/always_applicable.rs index 689911000ea8c..9ef5e0310d543 100644 --- a/compiler/rustc_hir_analysis/src/check/always_applicable.rs +++ b/compiler/rustc_hir_analysis/src/check/always_applicable.rs @@ -11,7 +11,7 @@ use rustc_infer::infer::{RegionResolutionError, TyCtxtInferExt}; use rustc_infer::traits::{ObligationCause, ObligationCauseCode}; use rustc_middle::span_bug; use rustc_middle::ty::util::CheckRegions; -use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt, TypingMode}; +use rustc_middle::ty::{self, GenericArgsRef, RegionExt, Ty, TyCtxt, TypeVisitableExt, TypingMode}; use rustc_trait_selection::regions::InferCtxtRegionExt; use rustc_trait_selection::traits::{self, ObligationCtxt}; diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 234231ed37fed..6d297c0552c50 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -14,9 +14,9 @@ use rustc_infer::infer::{self, BoundRegionConversionTime, InferCtxt, TyCtxtInfer use rustc_infer::traits::util; use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::{ - self, BottomUpFolder, GenericArgs, GenericParamDefKind, Generics, Ty, TyCtxt, TypeFoldable, - TypeFolder, TypeSuperFoldable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, - Unnormalized, Upcast, + self, BottomUpFolder, GenericArgs, GenericParamDefKind, Generics, RegionExt, + RegionUtilitiesExt, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitable, + TypeVisitableExt, TypeVisitor, TypingMode, Unnormalized, Upcast, }; use rustc_middle::{bug, span_bug}; use rustc_span::{BytePos, DUMMY_SP, Span}; diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index 3225e00b24b26..45f21b4e01350 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -88,8 +88,8 @@ use rustc_middle::query::Providers; use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::print::with_types_for_signature; use rustc_middle::ty::{ - self, GenericArgs, GenericArgsRef, OutlivesPredicate, Region, Ty, TyCtxt, TypingMode, - Unnormalized, + self, GenericArgs, GenericArgsRef, OutlivesPredicate, Region, RegionUtilitiesExt, Ty, TyCtxt, + TypingMode, Unnormalized, }; use rustc_middle::{bug, span_bug}; use rustc_session::errors::feature_err; diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 63753aee383a0..65539d3c85e2b 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -22,9 +22,9 @@ use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::traits::solve::NoSolution; use rustc_middle::ty::trait_def::TraitSpecializationKind; use rustc_middle::ty::{ - self, AdtKind, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFlags, - TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, - Unnormalized, Upcast, + self, AdtKind, GenericArgKind, GenericArgs, GenericParamDefKind, RegionExt, RegionUtilitiesExt, + Ty, TyCtxt, TypeFlags, TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, + TypeVisitor, TypingMode, Unnormalized, Upcast, }; use rustc_middle::{bug, span_bug}; use rustc_session::errors::feature_err; diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 8c182f9165e13..f509ffbea7a5d 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -34,8 +34,8 @@ use rustc_middle::hir::nested_filter; use rustc_middle::query::Providers; use rustc_middle::ty::util::{Discr, IntTypeExt}; use rustc_middle::ty::{ - self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, TypeVisitableExt, TypingMode, Unnormalized, - fold_regions, + self, AdtKind, Const, IsSuggestable, RegionExt, Ty, TyCtxt, TypeVisitableExt, TypingMode, + Unnormalized, fold_regions, }; use rustc_middle::{bug, span_bug}; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index ad46f011a79cb..f083b2ebb7659 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -7,7 +7,8 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::find_attr; use rustc_middle::ty::{ - self, GenericPredicates, ImplTraitInTraitData, Ty, TyCtxt, TypeVisitable, TypeVisitor, Upcast, + self, GenericPredicates, ImplTraitInTraitData, RegionExt, Ty, TyCtxt, TypeVisitable, + TypeVisitor, Upcast, }; use rustc_middle::{bug, span_bug}; use rustc_span::{DUMMY_SP, Ident, Span}; diff --git a/compiler/rustc_hir_analysis/src/delegation.rs b/compiler/rustc_hir_analysis/src/delegation.rs index be8a8e228c47a..a18f47594261d 100644 --- a/compiler/rustc_hir_analysis/src/delegation.rs +++ b/compiler/rustc_hir_analysis/src/delegation.rs @@ -9,7 +9,8 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::{DelegationGenerics, HirId, PathSegment}; use rustc_middle::ty::{ - self, EarlyBinder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, + self, EarlyBinder, RegionExt, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, + TypeVisitableExt, }; use rustc_span::{ErrorGuaranteed, Span, kw}; diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 473a32bac03a9..ece439299f9e2 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -39,8 +39,8 @@ use rustc_middle::middle::stability::AllowUnstable; use rustc_middle::ty::print::PrintPolyTraitRefExt as _; use rustc_middle::ty::{ self, Const, FnSigKind, GenericArgKind, GenericArgsRef, GenericParamDefKind, LitToConstInput, - Ty, TyCtxt, TypeSuperFoldable, TypeVisitableExt, TypingMode, Unnormalized, Upcast, - const_lit_matches_ty, fold_regions, + RegionExt, RegionUtilitiesExt, Ty, TyCtxt, TypeSuperFoldable, TypeVisitableExt, TypingMode, + Unnormalized, Upcast, const_lit_matches_ty, fold_regions, }; use rustc_middle::{bug, span_bug}; use rustc_session::errors::feature_err; diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs index 1fb126fe3d69f..8882e49339180 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs @@ -72,7 +72,8 @@ use rustc_infer::traits::ObligationCause; use rustc_infer::traits::specialization_graph::Node; use rustc_middle::ty::trait_def::TraitSpecializationKind; use rustc_middle::ty::{ - self, GenericArg, GenericArgs, GenericArgsRef, TyCtxt, TypeVisitableExt, TypingMode, + self, GenericArg, GenericArgs, GenericArgsRef, RegionUtilitiesExt, TyCtxt, TypeVisitableExt, + TypingMode, }; use rustc_span::{ErrorGuaranteed, Span}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index d773420512590..537f2cb90297e 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -31,7 +31,9 @@ use rustc_middle::ty::print::{ PrintTraitRefExt as _, with_crate_prefix, with_forced_trimmed_paths, with_no_visible_paths_if_doc_hidden, }; -use rustc_middle::ty::{self, GenericArgKind, IsSuggestable, Ty, TyCtxt, TypeVisitableExt}; +use rustc_middle::ty::{ + self, GenericArgKind, IsSuggestable, RegionExt, Ty, TyCtxt, TypeVisitableExt, +}; use rustc_span::def_id::DefIdSet; use rustc_span::{ DUMMY_SP, ErrorGuaranteed, ExpnKind, FileName, Ident, MacroKind, Span, Symbol, edit_distance, diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index a575ba79df45c..4ac6a10dfdba1 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -10,8 +10,8 @@ use rustc_data_structures::sso::SsoHashMap; use rustc_index::Idx; use rustc_middle::bug; use rustc_middle::ty::{ - self, BoundVar, Flags, GenericArg, InferConst, List, Ty, TyCtxt, TypeFlags, TypeFoldable, - TypeFolder, TypeSuperFoldable, TypeVisitableExt, TypingModeEqWrapper, + self, BoundVar, Flags, GenericArg, InferConst, List, RegionUtilitiesExt, Ty, TyCtxt, TypeFlags, + TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, TypingModeEqWrapper, }; use smallvec::SmallVec; use tracing::debug; diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index bc159ee8a004c..0280be5f75c4e 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -14,7 +14,9 @@ use rustc_index::{Idx, IndexVec}; use rustc_middle::arena::ArenaAllocatable; use rustc_middle::bug; use rustc_middle::infer::canonical::CanonicalVarKind; -use rustc_middle::ty::{self, BoundVar, GenericArg, GenericArgKind, Ty, TyCtxt, TypeFoldable}; +use rustc_middle::ty::{ + self, BoundVar, GenericArg, GenericArgKind, RegionUtilitiesExt, Ty, TyCtxt, TypeFoldable, +}; use tracing::{debug, instrument}; use crate::infer::canonical::instantiate::{CanonicalExt, instantiate_value}; diff --git a/compiler/rustc_infer/src/infer/free_regions.rs b/compiler/rustc_infer/src/infer/free_regions.rs index 8fa5361121c67..26b7576b613f4 100644 --- a/compiler/rustc_infer/src/infer/free_regions.rs +++ b/compiler/rustc_infer/src/infer/free_regions.rs @@ -4,7 +4,7 @@ //! and use that to decide when one free region outlives another, and so forth. use rustc_data_structures::transitive_relation::TransitiveRelation; -use rustc_middle::ty::{Region, TyCtxt}; +use rustc_middle::ty::{Region, RegionUtilitiesExt, TyCtxt}; use tracing::debug; /// Combines a `FreeRegionMap` and a `TyCtxt`. diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/indexed_edges.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/indexed_edges.rs index 382998e55d2e2..a9a027ebed2a8 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/indexed_edges.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/indexed_edges.rs @@ -1,4 +1,5 @@ use rustc_index::IndexVec; +use rustc_middle::ty::RegionUtilitiesExt; use rustc_type_ir::RegionVid; use crate::infer::SubregionOrigin; diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index e6af7b30f4ad3..9c2caedabe9d2 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -8,7 +8,7 @@ use rustc_data_structures::unord::UnordSet; use rustc_index::{IndexSlice, IndexVec}; use rustc_middle::ty::{ self, ReBound, ReEarlyParam, ReErased, ReError, ReLateParam, RePlaceholder, ReStatic, ReVar, - Region, RegionVid, Ty, TyCtxt, TypeFoldable, fold_regions, + Region, RegionUtilitiesExt, RegionVid, Ty, TyCtxt, TypeFoldable, fold_regions, }; use rustc_middle::{bug, span_bug}; use rustc_span::Span; diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 05043f8617a92..0ee54df939945 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -30,8 +30,9 @@ use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::{ self, BoundVarReplacerDelegate, ConstVid, FloatVid, GenericArg, GenericArgKind, GenericArgs, GenericArgsRef, GenericParamDefKind, InferConst, IntVid, OpaqueTypeKey, ProvisionalHiddenType, - PseudoCanonicalInput, Term, TermKind, Ty, TyCtxt, TyVid, TypeFoldable, TypeFolder, - TypeSuperFoldable, TypeVisitable, TypeVisitableExt, TypingEnv, TypingMode, fold_regions, + PseudoCanonicalInput, RegionExt, RegionUtilitiesExt, Term, TermKind, Ty, TyCtxt, TyVid, + TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitable, TypeVisitableExt, TypingEnv, + TypingMode, fold_regions, }; use rustc_span::{DUMMY_SP, Span, Symbol}; use snapshot::undo_log::InferCtxtUndoLogs; diff --git a/compiler/rustc_infer/src/infer/region_constraints/mod.rs b/compiler/rustc_infer/src/infer/region_constraints/mod.rs index 03bcb5215ee1a..da345ac4c5f30 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/mod.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/mod.rs @@ -8,7 +8,9 @@ use rustc_data_structures::undo_log::UndoLogs; use rustc_data_structures::unify as ut; use rustc_index::IndexVec; use rustc_macros::{TypeFoldable, TypeVisitable}; -use rustc_middle::ty::{self, ReBound, ReStatic, ReVar, Region, RegionVid, Ty, TyCtxt}; +use rustc_middle::ty::{ + self, ReBound, ReStatic, ReVar, Region, RegionExt, RegionUtilitiesExt, RegionVid, Ty, TyCtxt, +}; use rustc_middle::{bug, span_bug}; use tracing::{debug, instrument}; diff --git a/compiler/rustc_lint/src/impl_trait_overcaptures.rs b/compiler/rustc_lint/src/impl_trait_overcaptures.rs index 65dfa8b93de78..c2edbf6f05ddb 100644 --- a/compiler/rustc_lint/src/impl_trait_overcaptures.rs +++ b/compiler/rustc_lint/src/impl_trait_overcaptures.rs @@ -16,8 +16,8 @@ use rustc_middle::ty::relate::{ structurally_relate_tys, }; use rustc_middle::ty::{ - self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, - Unnormalized, + self, RegionExt, RegionUtilitiesExt, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, + TypeVisitableExt, TypeVisitor, Unnormalized, }; use rustc_middle::{bug, span_bug}; use rustc_session::lint::fcw; diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index c25f5b402eb0d..d618620cee953 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -65,6 +65,7 @@ use crate::thir::Thir; use crate::traits; use crate::traits::solve::{ExternalConstraints, ExternalConstraintsData, PredefinedOpaques}; use crate::ty::predicate::ExistentialPredicateStableCmpExt as _; +use crate::ty::region::{RegionExt, RegionUtilitiesExt}; use crate::ty::{ self, AdtDef, AdtDefData, AdtKind, Binder, Clause, Clauses, Const, FnSigKind, GenericArg, GenericArgs, GenericArgsRef, GenericParamDefKind, List, ListWithCachedTypeInfo, ParamConst, diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index daae5c6037f2a..92bb6d13f44ef 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -4,9 +4,7 @@ use std::fmt::Write; use std::ops::ControlFlow; use rustc_data_structures::fx::FxIndexMap; -use rustc_errors::{ - Applicability, Diag, DiagArgValue, IntoDiagArg, into_diag_arg_using_display, listify, pluralize, -}; +use rustc_errors::{Applicability, Diag, DiagArgValue, IntoDiagArg, listify, pluralize}; use rustc_hir::def::{DefKind, Namespace}; use rustc_hir::def_id::DefId; use rustc_hir::{self as hir, AmbigArg, LangItem, PredicateOrigin, WherePredicateKind}; diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 3d9148d6ed7ba..c146e7c982de9 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -2,6 +2,7 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_hir::def_id::DefId; use rustc_type_ir::data_structures::DelayedMap; +use crate::ty::region::RegionExt; use crate::ty::{ self, Binder, BoundTy, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index 87e206d5f0712..0d30468aceb0e 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -7,6 +7,7 @@ use tracing::instrument; use super::{Clause, InstantiatedPredicates, ParamConst, ParamTy, Ty, TyCtxt, Unnormalized}; use crate::ty; +use crate::ty::region::RegionExt; use crate::ty::{EarlyBinder, GenericArgsRef}; #[derive(Clone, Debug, TyEncodable, TyDecodable, StableHash)] diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 93da73e1e4505..0dd26d820fa66 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -102,7 +102,8 @@ pub use self::predicate::{ TraitRef, TypeOutlivesPredicate, }; pub use self::region::{ - EarlyParamRegion, LateParamRegion, LateParamRegionKind, Region, RegionKind, RegionVid, + EarlyParamRegion, LateParamRegion, LateParamRegionKind, Region, RegionExt, RegionKind, + RegionUtilitiesExt, RegionVid, }; pub use self::sty::{ AliasTy, AliasTyKind, Article, Binder, BoundConst, BoundRegion, BoundRegionKind, BoundTy, diff --git a/compiler/rustc_middle/src/ty/opaque_types.rs b/compiler/rustc_middle/src/ty/opaque_types.rs index 2b024b7b6cbb3..31ca9c0a54db4 100644 --- a/compiler/rustc_middle/src/ty/opaque_types.rs +++ b/compiler/rustc_middle/src/ty/opaque_types.rs @@ -5,7 +5,8 @@ use tracing::{debug, instrument, trace}; use crate::error::ConstNotUsedTraitAlias; use crate::ty::{ - self, GenericArg, GenericArgKind, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, + self, GenericArg, GenericArgKind, RegionExt, Ty, TyCtxt, TypeFoldable, TypeFolder, + TypeSuperFoldable, }; pub type OpaqueTypeKey<'tcx> = rustc_type_ir::OpaqueTypeKey>; @@ -133,7 +134,7 @@ impl<'tcx> TypeFolder> for ReverseMapper<'tcx> { self.span, format!( "lifetime `{r}` is part of concrete type but not used in \ - parameter list of the `impl Trait` type alias" + parameter list of the `impl Trait` type alias", ), ) .emit(); diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index ea9825298fc96..1f252e24da232 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -24,6 +24,7 @@ use smallvec::SmallVec; use super::*; use crate::mir::interpret::{AllocRange, GlobalAlloc, Pointer, Provenance, Scalar}; use crate::query::{IntoQueryKey, Providers}; +use crate::ty::region::{RegionExt, RegionUtilitiesExt}; use crate::ty::{ ConstInt, Expr, GenericArgKind, ParamConst, ScalarInt, Term, TermKind, TraitPredicate, TypeFoldable, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, diff --git a/compiler/rustc_mir_transform/src/promote_consts.rs b/compiler/rustc_mir_transform/src/promote_consts.rs index 041ff45c11d7e..e0393a9e6085f 100644 --- a/compiler/rustc_mir_transform/src/promote_consts.rs +++ b/compiler/rustc_mir_transform/src/promote_consts.rs @@ -21,7 +21,7 @@ use rustc_hir::def::DefKind; use rustc_index::{IndexSlice, IndexVec}; use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; -use rustc_middle::ty::{self, GenericArgs, List, Ty, TyCtxt, TypeVisitableExt}; +use rustc_middle::ty::{self, GenericArgs, List, RegionUtilitiesExt, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::{bug, mir, span_bug}; use rustc_span::{Span, Spanned}; use tracing::{debug, instrument}; diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 46a7e092e6bc9..991713034d866 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -17,8 +17,8 @@ use rustc_middle::bug; use rustc_middle::ty::layout::IntegerExt; use rustc_middle::ty::print::{Print, PrintError, Printer}; use rustc_middle::ty::{ - self, FloatTy, GenericArg, GenericArgKind, Instance, IntTy, ReifyReason, Ty, TyCtxt, - TypeVisitable, TypeVisitableExt, UintTy, Unnormalized, + self, FloatTy, GenericArg, GenericArgKind, Instance, IntTy, RegionUtilitiesExt, ReifyReason, + Ty, TyCtxt, TypeVisitable, TypeVisitableExt, UintTy, Unnormalized, }; use rustc_span::sym; diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index 21951cee6d5ab..7354476bce005 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -64,8 +64,8 @@ use rustc_middle::traits::PatternOriginExpr; use rustc_middle::ty::error::{ExpectedFound, TypeError, TypeErrorToStringExt}; use rustc_middle::ty::print::{PrintTraitRefExt as _, WrapBinderMode, with_forced_trimmed_paths}; use rustc_middle::ty::{ - self, List, ParamEnv, Region, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, TypeVisitable, - TypeVisitableExt, Unnormalized, + self, List, ParamEnv, Region, RegionUtilitiesExt, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, + TypeVisitable, TypeVisitableExt, Unnormalized, }; use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Pos, Span, sym}; use tracing::{debug, instrument}; diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mismatched_static_lifetime.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mismatched_static_lifetime.rs index 711aab43d9e7b..4acae5c520d2b 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mismatched_static_lifetime.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/mismatched_static_lifetime.rs @@ -6,7 +6,7 @@ use rustc_errors::{ErrorGuaranteed, MultiSpan}; use rustc_hir as hir; use rustc_hir::intravisit::VisitorExt; use rustc_middle::bug; -use rustc_middle::ty::TypeVisitor; +use rustc_middle::ty::{RegionUtilitiesExt, TypeVisitor}; use tracing::debug; use crate::error_reporting::infer::nice_region_error::NiceRegionError; diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/named_anon_conflict.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/named_anon_conflict.rs index 73a04d78519c8..3bf952737d5ed 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/named_anon_conflict.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/named_anon_conflict.rs @@ -2,6 +2,7 @@ //! where one region is named and the other is anonymous. use rustc_errors::Diag; +use rustc_middle::ty::RegionUtilitiesExt; use tracing::debug; use crate::error_reporting::infer::nice_region_error::NiceRegionError; diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs index 9cf016019bb09..4e5a6b4c02449 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/placeholder_error.rs @@ -7,7 +7,9 @@ use rustc_hir::def_id::{CRATE_DEF_ID, DefId}; use rustc_middle::bug; use rustc_middle::ty::error::ExpectedFound; use rustc_middle::ty::print::{FmtPrinter, Print, PrintTraitRefExt as _, RegionHighlightMode}; -use rustc_middle::ty::{self, GenericArgsRef, RePlaceholder, Region, TyCtxt}; +use rustc_middle::ty::{ + self, GenericArgsRef, RePlaceholder, Region, RegionExt, RegionUtilitiesExt, TyCtxt, +}; use tracing::{debug, instrument}; use crate::error_reporting::infer::nice_region_error::NiceRegionError; diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs index b227cd065eab9..63d3f83cdb8a8 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/static_impl_trait.rs @@ -8,7 +8,7 @@ use rustc_hir::{ self as hir, AmbigArg, GenericBound, GenericParam, GenericParamKind, Item, ItemKind, Lifetime, LifetimeKind, LifetimeParamKind, MissingLifetimeKind, Node, TyKind, }; -use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor}; +use rustc_middle::ty::{self, RegionUtilitiesExt, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor}; use rustc_span::def_id::LocalDefId; use rustc_span::{Ident, Span}; use tracing::debug; diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/trait_impl_difference.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/trait_impl_difference.rs index 7e6f566e242a3..fc441485e18ae 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/trait_impl_difference.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/trait_impl_difference.rs @@ -10,7 +10,7 @@ use rustc_middle::hir::nested_filter; use rustc_middle::traits::ObligationCauseCode; use rustc_middle::ty::error::ExpectedFound; use rustc_middle::ty::print::RegionHighlightMode; -use rustc_middle::ty::{self, TyCtxt, TypeVisitable}; +use rustc_middle::ty::{self, RegionUtilitiesExt, TyCtxt, TypeVisitable}; use rustc_span::{Ident, Span}; use tracing::debug; diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs index 2e9dcae700d2a..31c5d90a963e9 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/region.rs @@ -12,7 +12,7 @@ use rustc_middle::bug; use rustc_middle::traits::ObligationCauseCode; use rustc_middle::ty::error::TypeError; use rustc_middle::ty::{ - self, IsSuggestable, Region, Ty, TyCtxt, TypeVisitableExt as _, Upcast as _, + self, IsSuggestable, Region, RegionUtilitiesExt, Ty, TyCtxt, TypeVisitableExt as _, Upcast as _, }; use rustc_span::{BytePos, ErrorGuaranteed, Span, Symbol, kw, sym}; use tracing::{debug, instrument}; diff --git a/compiler/rustc_trait_selection/src/opaque_types.rs b/compiler/rustc_trait_selection/src/opaque_types.rs index 28b9bf21eee59..b46d84b5dc5b9 100644 --- a/compiler/rustc_trait_selection/src/opaque_types.rs +++ b/compiler/rustc_trait_selection/src/opaque_types.rs @@ -4,8 +4,8 @@ use rustc_hir::def_id::LocalDefId; use rustc_infer::infer::outlives::env::OutlivesEnvironment; use rustc_infer::infer::{InferCtxt, TyCtxtInferExt}; use rustc_middle::ty::{ - self, DefiningScopeKind, GenericArgKind, GenericArgs, OpaqueTypeKey, Ty, TyCtxt, - TypeVisitableExt, TypingMode, fold_regions, + self, DefiningScopeKind, GenericArgKind, GenericArgs, OpaqueTypeKey, RegionUtilitiesExt, Ty, + TyCtxt, TypeVisitableExt, TypingMode, fold_regions, }; use rustc_span::{ErrorGuaranteed, Span}; diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index ef99b7772d6be..ee32ebcf59d8b 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -8,7 +8,7 @@ use rustc_data_structures::fx::{FxIndexMap, FxIndexSet, IndexEntry}; use rustc_data_structures::unord::UnordSet; use rustc_hir::def_id::CRATE_DEF_ID; use rustc_infer::infer::DefineOpaqueTypes; -use rustc_middle::ty::{Region, RegionVid}; +use rustc_middle::ty::{Region, RegionUtilitiesExt, RegionVid}; use tracing::debug; use super::*; diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 49cc2833cd978..eeace787142d1 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -20,8 +20,8 @@ use rustc_middle::traits::solve::{CandidateSource, Certainty, Goal}; use rustc_middle::traits::specialization_graph::OverlapMode; use rustc_middle::ty::fast_reject::DeepRejectCtxt; use rustc_middle::ty::{ - self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, - Unnormalized, + self, RegionUtilitiesExt, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, + TypeVisitor, TypingMode, Unnormalized, }; pub use rustc_next_trait_solver::coherence::*; use rustc_next_trait_solver::solve::SolverDelegateEvalExt; diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index 659229a58d539..4d02d383ba971 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -5,7 +5,7 @@ use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; use rustc_middle::query::Providers; -use rustc_middle::ty::{self, Ty, TyCtxt, Unnormalized, fold_regions}; +use rustc_middle::ty::{self, RegionExt, Ty, TyCtxt, Unnormalized, fold_regions}; use rustc_middle::{bug, span_bug}; use rustc_span::Span; diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 258b9db60960d..994f54b5efe3a 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -6,8 +6,8 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::bug; use rustc_middle::query::Providers; use rustc_middle::ty::{ - self, SizedTraitKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, Unnormalized, - Upcast, fold_regions, + self, RegionExt, SizedTraitKind, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, + Unnormalized, Upcast, fold_regions, }; use rustc_span::DUMMY_SP; use rustc_span::def_id::{CRATE_DEF_ID, DefId, LocalDefId}; From a09e971e7afba40a96ed36c2c9d041dfe95a34ef Mon Sep 17 00:00:00 2001 From: James Barford-Evans Date: Mon, 20 Apr 2026 13:59:43 +0100 Subject: [PATCH 6/9] Use `Region` instead of `I::Region` --- .../src/canonical/canonicalizer.rs | 4 ++-- .../rustc_next_trait_solver/src/coherence.rs | 4 ++-- .../src/placeholder.rs | 4 ++-- .../rustc_next_trait_solver/src/resolve.rs | 4 ++-- .../src/solve/assembly/mod.rs | 4 ++-- .../src/solve/assembly/structural_traits.rs | 8 ++++---- .../src/solve/eval_ctxt/mod.rs | 12 ++++++------ .../rustc_next_trait_solver/src/solve/mod.rs | 4 ++-- .../src/solve/normalizes_to/mod.rs | 2 +- .../src/solve/trait_goals.rs | 14 +++++++------- compiler/rustc_type_ir/src/binder.rs | 12 ++++++------ compiler/rustc_type_ir/src/canonical.rs | 2 +- compiler/rustc_type_ir/src/elaborate.rs | 4 ++-- compiler/rustc_type_ir/src/error.rs | 6 +++--- compiler/rustc_type_ir/src/flags.rs | 4 ++-- compiler/rustc_type_ir/src/fold.rs | 16 ++++++++-------- compiler/rustc_type_ir/src/generic_arg.rs | 4 ++-- compiler/rustc_type_ir/src/infer_ctxt.rs | 19 ++++++++----------- compiler/rustc_type_ir/src/inherent.rs | 16 ++++++++-------- compiler/rustc_type_ir/src/lib.rs | 4 +++- compiler/rustc_type_ir/src/opaque_ty.rs | 4 ++-- compiler/rustc_type_ir/src/outlives.rs | 6 +++--- compiler/rustc_type_ir/src/predicate.rs | 8 ++++---- compiler/rustc_type_ir/src/predicate_kind.rs | 4 ++-- compiler/rustc_type_ir/src/relate.rs | 4 ++-- .../src/relate/solver_relating.rs | 4 ++-- compiler/rustc_type_ir/src/ty_kind.rs | 6 +++--- compiler/rustc_type_ir/src/ty_kind/closure.rs | 12 ++++++------ compiler/rustc_type_ir/src/visit.rs | 8 ++++---- 29 files changed, 101 insertions(+), 102 deletions(-) diff --git a/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs b/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs index 824c78094a69b..b923eefc6fd6a 100644 --- a/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs +++ b/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs @@ -3,7 +3,7 @@ use rustc_type_ir::inherent::*; use rustc_type_ir::solve::{Goal, QueryInput}; use rustc_type_ir::{ self as ty, Canonical, CanonicalParamEnvCacheEntry, CanonicalVarKind, Flags, InferCtxtLike, - Interner, PlaceholderConst, PlaceholderType, TypeFlags, TypeFoldable, TypeFolder, + Interner, PlaceholderConst, PlaceholderType, Region, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, }; @@ -409,7 +409,7 @@ impl, I: Interner> TypeFolder for Canonicaliz self.delegate.cx() } - fn fold_region(&mut self, r: I::Region) -> I::Region { + fn fold_region(&mut self, r: Region) -> Region { // We canonicalize free regions from the input into placeholder regions so that // region constraints created in nested contexts can be propagated back to the // caller, instead of unifying them. diff --git a/compiler/rustc_next_trait_solver/src/coherence.rs b/compiler/rustc_next_trait_solver/src/coherence.rs index 589d055192029..77569e5ec02c7 100644 --- a/compiler/rustc_next_trait_solver/src/coherence.rs +++ b/compiler/rustc_next_trait_solver/src/coherence.rs @@ -4,7 +4,7 @@ use std::ops::ControlFlow; use derive_where::derive_where; use rustc_type_ir::inherent::*; use rustc_type_ir::{ - self as ty, InferCtxtLike, Interner, TrivialTypeTraversalImpls, TypeVisitable, + self as ty, InferCtxtLike, Interner, Region, TrivialTypeTraversalImpls, TypeVisitable, TypeVisitableExt, TypeVisitor, }; use tracing::instrument; @@ -317,7 +317,7 @@ where { type Result = ControlFlow>; - fn visit_region(&mut self, _r: I::Region) -> Self::Result { + fn visit_region(&mut self, _r: Region) -> Self::Result { ControlFlow::Continue(()) } diff --git a/compiler/rustc_next_trait_solver/src/placeholder.rs b/compiler/rustc_next_trait_solver/src/placeholder.rs index b5bb488c43b89..3e2228997c5d7 100644 --- a/compiler/rustc_next_trait_solver/src/placeholder.rs +++ b/compiler/rustc_next_trait_solver/src/placeholder.rs @@ -4,7 +4,7 @@ use rustc_type_ir::data_structures::IndexMap; use rustc_type_ir::inherent::*; use rustc_type_ir::{ self as ty, InferCtxtLike, Interner, PlaceholderConst, PlaceholderRegion, PlaceholderType, - TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, + Region, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, }; use tracing::debug; @@ -91,7 +91,7 @@ where t } - fn fold_region(&mut self, r: I::Region) -> I::Region { + fn fold_region(&mut self, r: Region) -> Region { match r.kind() { ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), _) if debruijn.as_usize() diff --git a/compiler/rustc_next_trait_solver/src/resolve.rs b/compiler/rustc_next_trait_solver/src/resolve.rs index c3c57eccd6eff..ab3415a2bbc70 100644 --- a/compiler/rustc_next_trait_solver/src/resolve.rs +++ b/compiler/rustc_next_trait_solver/src/resolve.rs @@ -1,7 +1,7 @@ use rustc_type_ir::data_structures::DelayedMap; use rustc_type_ir::inherent::*; use rustc_type_ir::{ - self as ty, InferCtxtLike, Interner, TypeFoldable, TypeFolder, TypeSuperFoldable, + self as ty, InferCtxtLike, Interner, Region, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, }; @@ -72,7 +72,7 @@ impl, I: Interner> TypeFolder for EagerResolv } } - fn fold_region(&mut self, r: I::Region) -> I::Region { + fn fold_region(&mut self, r: Region) -> Region { match r.kind() { ty::ReVar(vid) => self.delegate.opportunistic_resolve_lt_var(vid), _ => r, diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index 5a73c99616815..880577893bee4 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -11,7 +11,7 @@ use rustc_type_ir::lang_items::SolverTraitLangItem; use rustc_type_ir::search_graph::CandidateHeadUsages; use rustc_type_ir::solve::{AliasBoundKind, MaybeInfo, SizedTraitKind, StalledOnCoroutines}; use rustc_type_ir::{ - self as ty, AliasTy, Interner, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable, + self as ty, AliasTy, Interner, Region, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Unnormalized, Upcast, elaborate, }; @@ -1370,7 +1370,7 @@ where } } - fn visit_region(&mut self, r: I::Region) -> Self::Result { + fn visit_region(&mut self, r: Region) -> Self::Result { match self.ecx.eager_resolve_region(r).kind() { ty::ReStatic | ty::ReError(_) | ty::ReBound(..) => ControlFlow::Continue(()), ty::RePlaceholder(p) => { diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs index 0bbc6f483104f..56305e3583370 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs @@ -8,7 +8,7 @@ use rustc_type_ir::lang_items::{SolverLangItem, SolverTraitLangItem}; use rustc_type_ir::solve::SizedTraitKind; use rustc_type_ir::solve::inspect::ProbeKind; use rustc_type_ir::{ - self as ty, Binder, FallibleTypeFolder, Interner, Movability, Mutability, TypeFoldable, + self as ty, Binder, FallibleTypeFolder, Interner, Movability, Mutability, Region, TypeFoldable, TypeSuperFoldable, Unnormalized, Upcast as _, elaborate, }; use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic}; @@ -435,7 +435,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable, ) -> Result<(ty::Binder>, Vec), NoSolution> { match self_ty.kind() { ty::CoroutineClosure(def_id, args) => { @@ -613,7 +613,7 @@ fn fn_item_to_async_callable( fn coroutine_closure_to_certain_coroutine( cx: I, goal_kind: ty::ClosureKind, - goal_region: I::Region, + goal_region: Region, def_id: I::CoroutineClosureId, args: ty::CoroutineClosureArgs, sig: ty::CoroutineClosureSignature, @@ -637,7 +637,7 @@ fn coroutine_closure_to_certain_coroutine( fn coroutine_closure_to_ambiguous_coroutine( cx: I, goal_kind: ty::ClosureKind, - goal_region: I::Region, + goal_region: Region, def_id: I::CoroutineClosureId, args: ty::CoroutineClosureArgs, sig: ty::CoroutineClosureSignature, diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs index 615cc9e8f81d2..e02bc965161d2 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs @@ -10,7 +10,7 @@ use rustc_type_ir::relate::solver_relating::RelateExt; use rustc_type_ir::search_graph::{CandidateHeadUsages, PathKind}; use rustc_type_ir::solve::{MaybeInfo, OpaqueTypesJank}; use rustc_type_ir::{ - self as ty, CanonicalVarValues, InferCtxtLike, Interner, TypeFoldable, TypeFolder, + self as ty, CanonicalVarValues, InferCtxtLike, Interner, Region, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, }; @@ -798,7 +798,7 @@ where } } - pub(super) fn next_region_var(&mut self) -> I::Region { + pub(super) fn next_region_var(&mut self) -> Region { let region = self.delegate.next_region_infer(); self.inspect.add_var_value(region); region @@ -1099,7 +1099,7 @@ where self.delegate.shallow_resolve(ty) } - pub(super) fn eager_resolve_region(&self, r: I::Region) -> I::Region { + pub(super) fn eager_resolve_region(&self, r: Region) -> Region { if let ty::ReVar(vid) = r.kind() { self.delegate.opportunistic_resolve_lt_var(vid) } else { @@ -1115,14 +1115,14 @@ where args } - pub(super) fn register_ty_outlives(&self, ty: I::Ty, lt: I::Region) { + pub(super) fn register_ty_outlives(&self, ty: I::Ty, lt: Region) { self.delegate.register_ty_outlives(ty, lt, self.origin_span); } pub(super) fn register_region_outlives( &self, - a: I::Region, - b: I::Region, + a: Region, + b: Region, vis: VisibleForLeakCheck, ) { // `'a: 'b` ==> `'b <= 'a` diff --git a/compiler/rustc_next_trait_solver/src/solve/mod.rs b/compiler/rustc_next_trait_solver/src/solve/mod.rs index 6f05df707ad84..0701540570a7a 100644 --- a/compiler/rustc_next_trait_solver/src/solve/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/mod.rs @@ -24,7 +24,7 @@ mod trait_goals; use derive_where::derive_where; use rustc_type_ir::inherent::*; pub use rustc_type_ir::solve::*; -use rustc_type_ir::{self as ty, Interner, TyVid, TypingMode}; +use rustc_type_ir::{self as ty, Interner, Region, TyVid, TypingMode}; use tracing::instrument; pub use self::eval_ctxt::{ @@ -98,7 +98,7 @@ where #[instrument(level = "trace", skip(self))] fn compute_region_outlives_goal( &mut self, - goal: Goal>, + goal: Goal>>, ) -> QueryResult { let ty::OutlivesPredicate(a, b) = goal.predicate; self.register_region_outlives(a, b, VisibleForLeakCheck::Yes); diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs index d93b7843b2251..c7bd58175ee8b 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs @@ -7,7 +7,7 @@ use rustc_type_ir::fast_reject::DeepRejectCtxt; use rustc_type_ir::inherent::*; use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem}; use rustc_type_ir::{ - self as ty, FieldInfo, Interner, NormalizesTo, PredicateKind, Unnormalized, Upcast as _, + self as ty, FieldInfo, Interner, NormalizesTo, PredicateKind, Region, Unnormalized, Upcast as _, }; use tracing::instrument; diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index b97d895bec15f..cc9830d9a4433 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -9,8 +9,8 @@ use rustc_type_ir::solve::{ SizedTraitKind, }; use rustc_type_ir::{ - self as ty, FieldInfo, Interner, Movability, PredicatePolarity, TraitPredicate, TraitRef, - TypeVisitableExt as _, TypingMode, Unnormalized, Upcast as _, elaborate, + self as ty, FieldInfo, Interner, Movability, PredicatePolarity, Region, TraitPredicate, + TraitRef, TypeVisitableExt as _, TypingMode, Unnormalized, Upcast as _, elaborate, }; use tracing::{debug, instrument, trace}; @@ -944,9 +944,9 @@ where &mut self, goal: Goal, a_data: I::BoundExistentialPredicates, - a_region: I::Region, + a_region: Region, b_data: I::BoundExistentialPredicates, - b_region: I::Region, + b_region: Region, ) -> Vec> { let cx = self.cx(); let Goal { predicate: (a_ty, _b_ty), .. } = goal; @@ -992,7 +992,7 @@ where &mut self, goal: Goal, b_data: I::BoundExistentialPredicates, - b_region: I::Region, + b_region: Region, ) -> Result, NoSolution> { let cx = self.cx(); let Goal { predicate: (a_ty, _), .. } = goal; @@ -1034,9 +1034,9 @@ where goal: Goal, source: CandidateSource, a_data: I::BoundExistentialPredicates, - a_region: I::Region, + a_region: Region, b_data: I::BoundExistentialPredicates, - b_region: I::Region, + b_region: Region, upcast_principal: Option>>, ) -> Result, NoSolution> { let param_env = goal.param_env; diff --git a/compiler/rustc_type_ir/src/binder.rs b/compiler/rustc_type_ir/src/binder.rs index a277741488e4e..a813596d7b006 100644 --- a/compiler/rustc_type_ir/src/binder.rs +++ b/compiler/rustc_type_ir/src/binder.rs @@ -16,7 +16,7 @@ use crate::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldabl use crate::inherent::*; use crate::lift::Lift; use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor}; -use crate::{self as ty, DebruijnIndex, Interner, UniverseIndex, Unnormalized}; +use crate::{self as ty, DebruijnIndex, Interner, Region, UniverseIndex, Unnormalized}; /// `Binder` is a binder for higher-ranked lifetimes or types. It is part of the /// compiler's representation for things like `for<'a> Fn(&'a isize)` @@ -339,7 +339,7 @@ impl TypeVisitor for ValidateBoundVars { c.super_visit_with(self) } - fn visit_region(&mut self, r: I::Region) -> Self::Result { + fn visit_region(&mut self, r: Region) -> Self::Result { match r.kind() { ty::ReBound(index, br) if index == ty::BoundVarIndexKind::Bound(self.binder_index) => { let idx = br.var().as_usize(); @@ -708,7 +708,7 @@ impl<'a, I: Interner> TypeFolder for ArgFolder<'a, I> { t } - fn fold_region(&mut self, r: I::Region) -> I::Region { + fn fold_region(&mut self, r: Region) -> Region { // Note: This routine only handles regions that are bound on // type declarations and other outer declarations, not those // bound in *fn types*. Region instantiation of the bound @@ -846,7 +846,7 @@ impl<'a, I: Interner> ArgFolder<'a, I> { fn region_param_expected( &self, ebr: I::EarlyParamRegion, - r: I::Region, + r: Region, kind: ty::GenericArgKind, ) -> ! { panic!( @@ -861,7 +861,7 @@ impl<'a, I: Interner> ArgFolder<'a, I> { #[cold] #[inline(never)] - fn region_param_out_of_range(&self, ebr: I::EarlyParamRegion, r: I::Region) -> ! { + fn region_param_out_of_range(&self, ebr: I::EarlyParamRegion, r: Region) -> ! { panic!( "region parameter `{:?}` ({:?}/{}) out of range when instantiating args={:?}", ebr, @@ -922,7 +922,7 @@ impl<'a, I: Interner> ArgFolder<'a, I> { } } - fn shift_region_through_binders(&self, region: I::Region) -> I::Region { + fn shift_region_through_binders(&self, region: Region) -> Region { if self.binders_passed == 0 || !region.has_escaping_bound_vars() { region } else { diff --git a/compiler/rustc_type_ir/src/canonical.rs b/compiler/rustc_type_ir/src/canonical.rs index 59aa6a3a44941..3dd4989370ba7 100644 --- a/compiler/rustc_type_ir/src/canonical.rs +++ b/compiler/rustc_type_ir/src/canonical.rs @@ -11,7 +11,7 @@ use rustc_type_ir_macros::{ use crate::data_structures::HashMap; use crate::inherent::*; -use crate::{self as ty, Interner, TypingModeEqWrapper, UniverseIndex}; +use crate::{self as ty, Interner, Region, TypingModeEqWrapper, UniverseIndex}; #[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, V)] #[derive_where(Copy; I: Interner, V: Copy)] diff --git a/compiler/rustc_type_ir/src/elaborate.rs b/compiler/rustc_type_ir/src/elaborate.rs index be3661518d7d9..855b9534c0e12 100644 --- a/compiler/rustc_type_ir/src/elaborate.rs +++ b/compiler/rustc_type_ir/src/elaborate.rs @@ -6,7 +6,7 @@ use crate::data_structures::HashSet; use crate::inherent::*; use crate::lang_items::SolverTraitLangItem; use crate::outlives::{Component, push_outlives_components}; -use crate::{self as ty, Interner, Unnormalized, Upcast as _}; +use crate::{self as ty, Interner, Region, Unnormalized, Upcast as _}; /// "Elaboration" is the process of identifying all the predicates that /// are implied by a source predicate. Currently, this basically means @@ -249,7 +249,7 @@ impl> Elaborator { fn elaborate_component_to_clause( cx: I, component: Component, - outlives_region: I::Region, + outlives_region: Region, ) -> Option> { match component { Component::Region(r) => { diff --git a/compiler/rustc_type_ir/src/error.rs b/compiler/rustc_type_ir/src/error.rs index 15fbd985d9630..745ca462fbc32 100644 --- a/compiler/rustc_type_ir/src/error.rs +++ b/compiler/rustc_type_ir/src/error.rs @@ -3,7 +3,7 @@ use rustc_abi::ExternAbi; use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic}; use crate::solve::NoSolution; -use crate::{self as ty, Interner}; +use crate::{self as ty, Interner, Region}; #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(TypeFoldable_Generic, TypeVisitable_Generic, GenericTypeVisitable)] @@ -33,8 +33,8 @@ pub enum TypeError { ArraySize(ExpectedFound), ArgCount, - RegionsDoesNotOutlive(I::Region, I::Region), - RegionsInsufficientlyPolymorphic(ty::BoundRegion, I::Region), + RegionsDoesNotOutlive(Region, Region), + RegionsInsufficientlyPolymorphic(ty::BoundRegion, Region), RegionsPlaceholderMismatch, Sorts(ExpectedFound), diff --git a/compiler/rustc_type_ir/src/flags.rs b/compiler/rustc_type_ir/src/flags.rs index 50c30f4252703..9851c404d6c15 100644 --- a/compiler/rustc_type_ir/src/flags.rs +++ b/compiler/rustc_type_ir/src/flags.rs @@ -1,6 +1,6 @@ use crate::inherent::*; use crate::visit::Flags; -use crate::{self as ty, Interner}; +use crate::{self as ty, Interner, Region}; bitflags::bitflags! { /// Flags that we track on types. These flags are propagated upwards @@ -446,7 +446,7 @@ impl FlagComputation { } } - fn add_region(&mut self, r: I::Region) { + fn add_region(&mut self, r: Region) { self.add_flags(r.flags()); if let ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), _) = r.kind() { self.add_bound_var(debruijn); diff --git a/compiler/rustc_type_ir/src/fold.rs b/compiler/rustc_type_ir/src/fold.rs index d1a50599e8b9c..0fc87caec7dba 100644 --- a/compiler/rustc_type_ir/src/fold.rs +++ b/compiler/rustc_type_ir/src/fold.rs @@ -55,7 +55,7 @@ use tracing::{debug, instrument}; use crate::inherent::*; use crate::visit::{TypeVisitable, TypeVisitableExt as _}; -use crate::{self as ty, BoundVarIndexKind, Interner, TypeFlags}; +use crate::{self as ty, BoundVarIndexKind, Interner, Region, TypeFlags}; /// This trait is implemented for every type that can be folded, /// providing the skeleton of the traversal. @@ -141,7 +141,7 @@ pub trait TypeFolder: Sized { // The default region folder is a no-op because `Region` is non-recursive // and has no `super_fold_with` method to call. - fn fold_region(&mut self, r: I::Region) -> I::Region { + fn fold_region(&mut self, r: Region) -> Region { r } @@ -183,7 +183,7 @@ pub trait FallibleTypeFolder: Sized { // The default region folder is a no-op because `Region` is non-recursive // and has no `super_fold_with` method to call. - fn try_fold_region(&mut self, r: I::Region) -> Result { + fn try_fold_region(&mut self, r: Region) -> Result, Self::Error> { Ok(r) } @@ -396,7 +396,7 @@ impl TypeFolder for Shifter { t } - fn fold_region(&mut self, r: I::Region) -> I::Region { + fn fold_region(&mut self, r: Region) -> Region { match r.kind() { ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), br) if debruijn >= self.current_index => @@ -439,7 +439,7 @@ impl TypeFolder for Shifter { } } -pub fn shift_region(cx: I, region: I::Region, amount: u32) -> I::Region { +pub fn shift_region(cx: I, region: Region, amount: u32) -> Region { match region.kind() { ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), br) if amount > 0 => { Region::new_bound(cx, debruijn.shifted_in(amount), br) @@ -466,7 +466,7 @@ where pub fn fold_regions( cx: I, value: T, - f: impl FnMut(I::Region, ty::DebruijnIndex) -> I::Region, + f: impl FnMut(Region, ty::DebruijnIndex) -> Region, ) -> T where T: TypeFoldable, @@ -505,7 +505,7 @@ impl RegionFolder { impl TypeFolder for RegionFolder where I: Interner, - F: FnMut(I::Region, ty::DebruijnIndex) -> I::Region, + F: FnMut(Region, ty::DebruijnIndex) -> Region, { fn cx(&self) -> I { self.cx @@ -519,7 +519,7 @@ where } #[instrument(skip(self), level = "debug", ret)] - fn fold_region(&mut self, r: I::Region) -> I::Region { + fn fold_region(&mut self, r: Region) -> Region { match r.kind() { ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), _) if debruijn < self.current_index => diff --git a/compiler/rustc_type_ir/src/generic_arg.rs b/compiler/rustc_type_ir/src/generic_arg.rs index cbd9522e7a3f9..29a0f67e244b7 100644 --- a/compiler/rustc_type_ir/src/generic_arg.rs +++ b/compiler/rustc_type_ir/src/generic_arg.rs @@ -3,7 +3,7 @@ use derive_where::derive_where; use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash_NoContext}; use rustc_type_ir_macros::GenericTypeVisitable; -use crate::Interner; +use crate::{Interner, Region}; #[derive_where(Clone, Copy, PartialEq, Debug; I: Interner)] #[derive(GenericTypeVisitable)] @@ -12,7 +12,7 @@ use crate::Interner; derive(Decodable_NoContext, Encodable_NoContext, StableHash_NoContext) )] pub enum GenericArgKind { - Lifetime(I::Region), + Lifetime(Region), Type(I::Ty), Const(I::Const), } diff --git a/compiler/rustc_type_ir/src/infer_ctxt.rs b/compiler/rustc_type_ir/src/infer_ctxt.rs index 1b6bdf8c34dd8..875595d34d88d 100644 --- a/compiler/rustc_type_ir/src/infer_ctxt.rs +++ b/compiler/rustc_type_ir/src/infer_ctxt.rs @@ -9,7 +9,7 @@ use crate::inherent::*; use crate::relate::RelateResult; use crate::relate::combine::PredicateEmittingRelation; use crate::solve::VisibleForLeakCheck; -use crate::{self as ty, Interner, TyVid}; +use crate::{self as ty, Interner, Region, TyVid}; /// The current typing mode of an inference context. We unfortunately have some /// slightly different typing rules depending on the current context. See the @@ -253,14 +253,11 @@ pub trait InferCtxtLike: Sized { &self, vid: ty::ConstVid, ) -> ::Const; - fn opportunistic_resolve_lt_var( - &self, - vid: ty::RegionVid, - ) -> ::Region; + fn opportunistic_resolve_lt_var(&self, vid: ty::RegionVid) -> Region; fn is_changed_arg(&self, arg: ::GenericArg) -> bool; - fn next_region_infer(&self) -> ::Region; + fn next_region_infer(&self) -> Region; fn next_ty_infer(&self) -> ::Ty; fn next_const_infer(&self) -> ::Const; fn fresh_args_for_item( @@ -322,16 +319,16 @@ pub trait InferCtxtLike: Sized { fn sub_regions( &self, - sub: ::Region, - sup: ::Region, + sub: Region, + sup: Region, vis: VisibleForLeakCheck, span: ::Span, ); fn equate_regions( &self, - a: ::Region, - b: ::Region, + a: Region, + b: Region, vis: VisibleForLeakCheck, span: ::Span, ); @@ -339,7 +336,7 @@ pub trait InferCtxtLike: Sized { fn register_ty_outlives( &self, ty: ::Ty, - r: ::Region, + r: Region, span: ::Span, ); diff --git a/compiler/rustc_type_ir/src/inherent.rs b/compiler/rustc_type_ir/src/inherent.rs index 6db48047bc3cb..5f4c5957de971 100644 --- a/compiler/rustc_type_ir/src/inherent.rs +++ b/compiler/rustc_type_ir/src/inherent.rs @@ -14,7 +14,7 @@ use crate::relate::Relate; use crate::solve::{AdtDestructorKind, SizedTraitKind}; use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable}; use crate::{ - self as ty, ClauseKind, CollectAndApply, FieldInfo, Interner, PredicateKind, UpcastFrom, + self as ty, ClauseKind, CollectAndApply, FieldInfo, Interner, PredicateKind, Region, UpcastFrom, }; #[rust_analyzer::prefer_underscore_import] @@ -79,7 +79,7 @@ pub trait Ty>: fn new_foreign(interner: I, def_id: I::ForeignId) -> Self; - fn new_dynamic(interner: I, preds: I::BoundExistentialPredicates, region: I::Region) -> Self; + fn new_dynamic(interner: I, preds: I::BoundExistentialPredicates, region: Region) -> Self; fn new_coroutine(interner: I, def_id: I::CoroutineId, args: I::GenericArgs) -> Self; @@ -101,7 +101,7 @@ pub trait Ty>: fn new_ptr(interner: I, ty: Self, mutbl: Mutability) -> Self; - fn new_ref(interner: I, region: I::Region, ty: Self, mutbl: Mutability) -> Self; + fn new_ref(interner: I, region: Region, ty: Self, mutbl: Mutability) -> Self; fn new_array_with_const_len(interner: I, ty: Self, len: I::Const) -> Self; @@ -290,7 +290,7 @@ pub trait GenericArg>: + TypeVisitable + Relate + From - + From + + From> + From + From { @@ -318,11 +318,11 @@ pub trait GenericArg>: self.as_const().expect("expected a const") } - fn as_region(&self) -> Option { + fn as_region(&self) -> Option> { if let ty::GenericArgKind::Lifetime(c) = self.kind() { Some(c) } else { None } } - fn expect_region(&self) -> I::Region { + fn expect_region(&self) -> Region { self.as_region().expect("expected a const") } @@ -398,7 +398,7 @@ pub trait GenericArgs>: fn type_at(self, i: usize) -> I::Ty; - fn region_at(self, i: usize) -> I::Region; + fn region_at(self, i: usize) -> Region; fn const_at(self, i: usize) -> I::Const; @@ -444,7 +444,7 @@ pub trait Predicate>: + UpcastFrom>> + UpcastFrom> + UpcastFrom> - + UpcastFrom> + + UpcastFrom>> + IntoKind>> + Elaboratable { diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index 09b8d0eaf6d80..fca08a001f44a 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -5,7 +5,7 @@ #![allow(rustc::usage_of_type_ir_inherent)] #![allow(rustc::usage_of_type_ir_traits)] #![cfg_attr(feature = "nightly", allow(internal_features))] -#![cfg_attr(feature = "nightly", feature(associated_type_defaults, rustc_attrs, negative_impls))] +#![cfg_attr(feature = "nightly", feature(associated_type_defaults, negative_impls, rustc_attrs))] // tidy-alphabetical-end extern crate self as rustc_type_ir; @@ -31,6 +31,7 @@ pub mod outlives; pub mod relate; pub mod search_graph; pub mod solve; +pub mod sty; pub mod walk; // These modules are not `pub` since they are glob-imported. @@ -79,6 +80,7 @@ pub use predicate_kind::*; pub use region_kind::*; pub use rustc_ast_ir::{FloatTy, IntTy, Movability, Mutability, Pinnedness, UintTy}; use rustc_type_ir_macros::GenericTypeVisitable; +pub use sty::*; pub use ty_info::*; pub use ty_kind::*; pub use unnormalized::Unnormalized; diff --git a/compiler/rustc_type_ir/src/opaque_ty.rs b/compiler/rustc_type_ir/src/opaque_ty.rs index 782a7d30b675b..6c0ce1718f231 100644 --- a/compiler/rustc_type_ir/src/opaque_ty.rs +++ b/compiler/rustc_type_ir/src/opaque_ty.rs @@ -4,7 +4,7 @@ use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash_NoContex use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic}; use crate::inherent::*; -use crate::{self as ty, Interner}; +use crate::{self as ty, Interner, Region}; #[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] @@ -34,7 +34,7 @@ impl OpaqueTypeKey { pub fn fold_captured_lifetime_args( self, cx: I, - mut f: impl FnMut(I::Region) -> I::Region, + mut f: impl FnMut(Region) -> Region, ) -> Self { let Self { def_id, args } = self; let variances = cx.variances_of(def_id.into()); diff --git a/compiler/rustc_type_ir/src/outlives.rs b/compiler/rustc_type_ir/src/outlives.rs index 56f40d3f78288..c9d94bb8ac7ef 100644 --- a/compiler/rustc_type_ir/src/outlives.rs +++ b/compiler/rustc_type_ir/src/outlives.rs @@ -8,11 +8,11 @@ use smallvec::{SmallVec, smallvec}; use crate::data_structures::SsoHashSet; use crate::inherent::*; use crate::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt as _, TypeVisitor}; -use crate::{self as ty, Interner}; +use crate::{self as ty, Interner, Region}; #[derive_where(Debug; I: Interner)] pub enum Component { - Region(I::Region), + Region(Region), Param(I::ParamTy), Placeholder(ty::PlaceholderType), UnresolvedInferenceVariable(ty::InferTy), @@ -210,7 +210,7 @@ impl TypeVisitor for OutlivesCollector<'_, I> { } } - fn visit_region(&mut self, lt: I::Region) -> Self::Result { + fn visit_region(&mut self, lt: Region) -> Self::Result { if !lt.is_bound() { self.out.push(Component::Region(lt)); } diff --git a/compiler/rustc_type_ir/src/predicate.rs b/compiler/rustc_type_ir/src/predicate.rs index 90240e241bc90..bc2f3168b0658 100644 --- a/compiler/rustc_type_ir/src/predicate.rs +++ b/compiler/rustc_type_ir/src/predicate.rs @@ -12,7 +12,7 @@ use crate::inherent::*; use crate::lift::Lift; use crate::upcast::{Upcast, UpcastFrom}; use crate::visit::TypeVisitableExt as _; -use crate::{self as ty, AliasTyKind, Interner}; +use crate::{self as ty, AliasTyKind, Interner, Region}; /// `A: 'region` #[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, A)] @@ -22,7 +22,7 @@ use crate::{self as ty, AliasTyKind, Interner}; feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, StableHash_NoContext) )] -pub struct OutlivesPredicate(pub A, pub I::Region); +pub struct OutlivesPredicate(pub A, pub Region); impl Eq for OutlivesPredicate {} @@ -31,7 +31,7 @@ impl Eq for OutlivesPredicate {} impl Lift for OutlivesPredicate where A: Lift, - I::Region: Lift, + Region: Lift>, { type Lifted = OutlivesPredicate; @@ -50,7 +50,7 @@ where feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, StableHash_NoContext) )] -pub struct RegionEqPredicate(pub I::Region, pub I::Region); +pub struct RegionEqPredicate(pub Region, pub Region); impl RegionEqPredicate { /// Decompose `'a == 'b` into `['a: 'b, 'b: 'a]` diff --git a/compiler/rustc_type_ir/src/predicate_kind.rs b/compiler/rustc_type_ir/src/predicate_kind.rs index e905c1849a31d..e2d6c0db9f8bc 100644 --- a/compiler/rustc_type_ir/src/predicate_kind.rs +++ b/compiler/rustc_type_ir/src/predicate_kind.rs @@ -5,7 +5,7 @@ use derive_where::derive_where; use rustc_macros::{Decodable_NoContext, Encodable_NoContext, StableHash, StableHash_NoContext}; use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic}; -use crate::{self as ty, Interner}; +use crate::{self as ty, Interner, Region}; /// A clause is something that can appear in where bounds or be inferred /// by implied bounds. @@ -22,7 +22,7 @@ pub enum ClauseKind { Trait(ty::TraitPredicate), /// `where 'a: 'r` - RegionOutlives(ty::OutlivesPredicate), + RegionOutlives(ty::OutlivesPredicate>), /// `where T: 'r` TypeOutlives(ty::OutlivesPredicate), diff --git a/compiler/rustc_type_ir/src/relate.rs b/compiler/rustc_type_ir/src/relate.rs index 425436dabafb2..86f3415a52023 100644 --- a/compiler/rustc_type_ir/src/relate.rs +++ b/compiler/rustc_type_ir/src/relate.rs @@ -7,7 +7,7 @@ use tracing::{instrument, trace}; use crate::error::{ExpectedFound, TypeError}; use crate::fold::TypeFoldable; use crate::inherent::*; -use crate::{self as ty, Interner}; +use crate::{self as ty, Interner, Region}; pub mod combine; pub mod solver_relating; @@ -100,7 +100,7 @@ pub trait TypeRelation: Sized { fn tys(&mut self, a: I::Ty, b: I::Ty) -> RelateResult; - fn regions(&mut self, a: I::Region, b: I::Region) -> RelateResult; + fn regions(&mut self, a: Region, b: Region) -> RelateResult>; fn consts(&mut self, a: I::Const, b: I::Const) -> RelateResult; diff --git a/compiler/rustc_type_ir/src/relate/solver_relating.rs b/compiler/rustc_type_ir/src/relate/solver_relating.rs index a643d22c17643..324509999ba85 100644 --- a/compiler/rustc_type_ir/src/relate/solver_relating.rs +++ b/compiler/rustc_type_ir/src/relate/solver_relating.rs @@ -5,7 +5,7 @@ use crate::data_structures::DelayedSet; use crate::relate::combine::combine_ty_args; pub use crate::relate::*; use crate::solve::{Goal, VisibleForLeakCheck}; -use crate::{self as ty, InferCtxtLike, Interner}; +use crate::{self as ty, InferCtxtLike, Interner, Region}; pub trait RelateExt: InferCtxtLike { fn relate>( @@ -253,7 +253,7 @@ where } #[instrument(skip(self), level = "trace")] - fn regions(&mut self, a: I::Region, b: I::Region) -> RelateResult { + fn regions(&mut self, a: Region, b: Region) -> RelateResult> { match self.ambient_variance { // Subtype(&'a u8, &'b u8) => Outlives('a: 'b) => SubRegion('b, 'a) ty::Covariant => self.infcx.sub_regions(b, a, VisibleForLeakCheck::Yes, self.span), diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index a08bd00eeed65..873bba2ba6c16 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -19,7 +19,7 @@ pub use self::closure::*; use crate::inherent::*; #[cfg(feature = "nightly")] use crate::visit::TypeVisitable; -use crate::{self as ty, BoundVarIndexKind, FloatTy, IntTy, Interner, UintTy}; +use crate::{self as ty, BoundVarIndexKind, FloatTy, IntTy, Interner, Region, UintTy}; mod closure; @@ -151,7 +151,7 @@ pub enum TyKind { /// A reference; a pointer with an associated lifetime. Written as /// `&'a mut T` or `&'a T`. - Ref(I::Region, I::Ty, Mutability), + Ref(Region, I::Ty, Mutability), /// The anonymous type of a function declaration/definition. /// @@ -195,7 +195,7 @@ pub enum TyKind { UnsafeBinder(UnsafeBinderInner), /// A trait object. Written as `dyn for<'b> Trait<'b, Assoc = u32> + Send + 'a`. - Dynamic(I::BoundExistentialPredicates, I::Region), + Dynamic(I::BoundExistentialPredicates, Region), /// The anonymous type of a closure. Used to represent the type of `|a| a`. /// diff --git a/compiler/rustc_type_ir/src/ty_kind/closure.rs b/compiler/rustc_type_ir/src/ty_kind/closure.rs index 3b8ed0a15994d..6d72cc96346f8 100644 --- a/compiler/rustc_type_ir/src/ty_kind/closure.rs +++ b/compiler/rustc_type_ir/src/ty_kind/closure.rs @@ -9,7 +9,7 @@ use crate::data_structures::DelayedMap; use crate::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable, shift_region}; use crate::inherent::*; use crate::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor}; -use crate::{self as ty, FnSigKind, Interner}; +use crate::{self as ty, FnSigKind, Interner, Region}; /// A closure can be modeled as a struct that looks like: /// ```ignore (illustrative) @@ -343,7 +343,7 @@ impl TypeVisitor for HasRegionsBoundAt { ControlFlow::Continue(()) } - fn visit_region(&mut self, r: I::Region) -> Self::Result { + fn visit_region(&mut self, r: Region) -> Self::Result { if matches!(r.kind(), ty::ReBound(ty::BoundVarIndexKind::Bound(binder), _) if self.binder == binder) { ControlFlow::Break(()) @@ -415,7 +415,7 @@ impl CoroutineClosureSignature { parent_args: I::GenericArgsSlice, coroutine_def_id: I::CoroutineId, goal_kind: ty::ClosureKind, - env_region: I::Region, + env_region: Region, closure_tupled_upvars_ty: I::Ty, coroutine_captures_by_ref_ty: I::Ty, ) -> I::Ty { @@ -452,7 +452,7 @@ impl CoroutineClosureSignature { tupled_inputs_ty: I::Ty, closure_tupled_upvars_ty: I::Ty, coroutine_captures_by_ref_ty: I::Ty, - env_region: I::Region, + env_region: Region, ) -> I::Ty { match kind { ty::ClosureKind::Fn | ty::ClosureKind::FnMut => { @@ -491,7 +491,7 @@ impl CoroutineClosureSignature { struct FoldEscapingRegions { interner: I, debruijn: ty::DebruijnIndex, - region: I::Region, + region: Region, // Depends on `debruijn` because we may have types with regions of different // debruijn depths depending on the binders we've entered. @@ -525,7 +525,7 @@ impl TypeFolder for FoldEscapingRegions { result } - fn fold_region(&mut self, r: ::Region) -> ::Region { + fn fold_region(&mut self, r: Region) -> Region { if let ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), _) = r.kind() { assert!( debruijn <= self.debruijn, diff --git a/compiler/rustc_type_ir/src/visit.rs b/compiler/rustc_type_ir/src/visit.rs index a078b860be774..e99df9bcb7559 100644 --- a/compiler/rustc_type_ir/src/visit.rs +++ b/compiler/rustc_type_ir/src/visit.rs @@ -52,7 +52,7 @@ use smallvec::SmallVec; use thin_vec::ThinVec; use crate::inherent::*; -use crate::{self as ty, Interner, TypeFlags}; +use crate::{self as ty, Interner, Region, TypeFlags}; /// This trait is implemented for every type that can be visited, /// providing the skeleton of the traversal. @@ -104,7 +104,7 @@ pub trait TypeVisitor: Sized { // The default region visitor is a no-op because `Region` is non-recursive // and has no `super_visit_with` method to call. - fn visit_region(&mut self, r: I::Region) -> Self::Result { + fn visit_region(&mut self, r: Region) -> Self::Result { if let ty::ReError(guar) = r.kind() { self.visit_error(guar) } else { @@ -447,7 +447,7 @@ impl TypeVisitor for HasTypeFlagsVisitor { } #[inline] - fn visit_region(&mut self, r: I::Region) -> Self::Result { + fn visit_region(&mut self, r: Region) -> Self::Result { // Note: no `super_visit_with` call, as usual for `Region`. let flags = r.flags(); if flags.intersects(self.flags) { @@ -555,7 +555,7 @@ impl TypeVisitor for HasEscapingVarsVisitor { } #[inline] - fn visit_region(&mut self, r: I::Region) -> Self::Result { + fn visit_region(&mut self, r: Region) -> Self::Result { // If the region is bound by `outer_index` or anything outside // of outer index, then it escapes the binders we have // visited. From 57142b275b936941ffc825c9ec037efde968d6a8 Mon Sep 17 00:00:00 2001 From: James Barford-Evans Date: Mon, 20 Apr 2026 14:00:48 +0100 Subject: [PATCH 7/9] Update Region outside of `./compiler` --- src/librustdoc/clean/auto_trait.rs | 2 +- src/librustdoc/clean/mod.rs | 3 ++- src/tools/clippy/clippy_lints/src/eta_reduction.rs | 1 + .../clippy/clippy_lints/src/operators/identity_op.rs | 1 + .../clippy/clippy_lints/src/returns/let_and_return.rs | 2 +- src/tools/clippy/clippy_utils/src/lib.rs | 1 + src/tools/rust-analyzer/Cargo.lock | 1 + .../crates/hir-ty/src/next_solver/interner.rs | 7 ++++++- src/tools/rust-analyzer/crates/intern/Cargo.toml | 2 ++ src/tools/rust-analyzer/crates/intern/src/intern.rs | 9 +++++++++ src/tools/rust-analyzer/crates/intern/src/lib.rs | 2 ++ 11 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 554b81b14cd3d..562f1f2dc3831 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -3,7 +3,7 @@ use rustc_data_structures::thin_vec::ThinVec; use rustc_hir as hir; use rustc_infer::infer::region_constraints::{ConstraintKind, RegionConstraintData}; use rustc_middle::bug; -use rustc_middle::ty::{self, Region, Ty, fold_regions}; +use rustc_middle::ty::{self, Region, RegionUtilitiesExt, Ty, fold_regions}; use rustc_span::def_id::DefId; use rustc_span::symbol::{Symbol, kw}; use rustc_trait_selection::traits::auto_trait::{self, RegionTarget}; diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index f020a26a23bc2..5fadc4ee2eccc 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -47,7 +47,8 @@ use rustc_hir_analysis::{lower_const_arg_for_rustdoc, lower_ty}; use rustc_middle::metadata::Reexport; use rustc_middle::middle::resolve_bound_vars as rbv; use rustc_middle::ty::{ - self, AdtKind, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt, TypingMode, Unnormalized, + self, AdtKind, GenericArgsRef, RegionUtilitiesExt, Ty, TyCtxt, TypeVisitableExt, TypingMode, + Unnormalized, }; use rustc_middle::{bug, span_bug}; use rustc_span::ExpnKind; diff --git a/src/tools/clippy/clippy_lints/src/eta_reduction.rs b/src/tools/clippy/clippy_lints/src/eta_reduction.rs index 6248ba6e44da5..d9265230cefab 100644 --- a/src/tools/clippy/clippy_lints/src/eta_reduction.rs +++ b/src/tools/clippy/clippy_lints/src/eta_reduction.rs @@ -10,6 +10,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind}; use rustc_middle::ty::{ + RegionUtilitiesExt, self, Binder, ClosureKind, FnSig, GenericArg, GenericArgKind, List, Region, Ty, TypeVisitableExt, TypeckResults, }; use rustc_session::declare_lint_pass; diff --git a/src/tools/clippy/clippy_lints/src/operators/identity_op.rs b/src/tools/clippy/clippy_lints/src/operators/identity_op.rs index 2e0beb2d4e821..49b34faa2c770 100644 --- a/src/tools/clippy/clippy_lints/src/operators/identity_op.rs +++ b/src/tools/clippy/clippy_lints/src/operators/identity_op.rs @@ -7,6 +7,7 @@ use rustc_hir::def::{DefKind, Res}; use rustc_hir::{BinOpKind, Expr, ExprKind, Node, Path, QPath}; use rustc_lint::LateContext; use rustc_middle::ty; +use rustc_middle::ty::RegionUtilitiesExt; use rustc_span::{Span, SyntaxContext, kw}; use super::IDENTITY_OP; diff --git a/src/tools/clippy/clippy_lints/src/returns/let_and_return.rs b/src/tools/clippy/clippy_lints/src/returns/let_and_return.rs index 2ec921ed21c7d..829dd74ea43fc 100644 --- a/src/tools/clippy/clippy_lints/src/returns/let_and_return.rs +++ b/src/tools/clippy/clippy_lints/src/returns/let_and_return.rs @@ -8,7 +8,7 @@ use core::ops::ControlFlow; use rustc_errors::Applicability; use rustc_hir::{Block, Expr, PatKind, StmtKind}; use rustc_lint::{LateContext, LintContext}; -use rustc_middle::ty::GenericArgKind; +use rustc_middle::ty::{GenericArgKind, RegionUtilitiesExt}; use rustc_span::edition::Edition; use super::LET_AND_RETURN; diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 522d35bd6093e..de589d68363f0 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -109,6 +109,7 @@ use rustc_middle::mir::{AggregateKind, Operand, RETURN_PLACE, Rvalue, StatementK use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, DerefAdjustKind, PointerCoercion}; use rustc_middle::ty::layout::IntegerExt; use rustc_middle::ty::{ + RegionUtilitiesExt, self as rustc_ty, Binder, BorrowKind, ClosureKind, EarlyBinder, GenericArgKind, GenericArgsRef, IntTy, Ty, TyCtxt, TypeFlags, TypeVisitableExt, TypeckResults, UintTy, UpvarCapture, }; diff --git a/src/tools/rust-analyzer/Cargo.lock b/src/tools/rust-analyzer/Cargo.lock index e6575c28c1dd0..0a4164e074554 100644 --- a/src/tools/rust-analyzer/Cargo.lock +++ b/src/tools/rust-analyzer/Cargo.lock @@ -1215,6 +1215,7 @@ version = "0.0.0" dependencies = [ "dashmap", "hashbrown 0.14.5", + "ra-ap-rustc_type_ir", "rayon", "rustc-hash 2.1.1", "triomphe", diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/interner.rs b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/interner.rs index cfb55e2e00a05..f75a90240d47f 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/interner.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/interner.rs @@ -54,7 +54,8 @@ use crate::{ use super::{ Binder, BoundExistentialPredicates, BoundTy, BoundTyKind, Clause, ClauseKind, Clauses, Const, ErrorGuaranteed, ExprConst, ExternalConstraints, GenericArg, GenericArgs, ParamConst, ParamEnv, - ParamTy, PredefinedOpaques, Predicate, SolverDefId, Term, Ty, TyKind, Tys, ValTree, ValueConst, + ParamTy, PredefinedOpaques, Predicate, RegionKind, SolverDefId, Term, Ty, TyKind, Tys, ValTree, + ValueConst, abi::Safety, fold::{BoundVarReplacer, BoundVarReplacerDelegate, FnMutDelegate}, generics::{Generics, generics}, @@ -1069,7 +1070,11 @@ impl<'db> Interner for DbInterner<'db> { type Region = Region<'db>; type EarlyParamRegion = EarlyParamRegion; + type LateParamRegion = LateParamRegion<'db>; + type BoundRegion = BoundRegion; + type PlaceholderRegion = PlaceholderRegion; + type InternedRegionKind = InternedRef<'db, RegionKind<'db>>; type RegionAssumptions = RegionAssumptions<'db>; diff --git a/src/tools/rust-analyzer/crates/intern/Cargo.toml b/src/tools/rust-analyzer/crates/intern/Cargo.toml index 39320ebd1cfef..ae58d5f3ac905 100644 --- a/src/tools/rust-analyzer/crates/intern/Cargo.toml +++ b/src/tools/rust-analyzer/crates/intern/Cargo.toml @@ -20,6 +20,8 @@ rustc-hash.workspace = true triomphe.workspace = true rayon.workspace = true +ra-ap-rustc_type_ir.workspace = true + [lints] workspace = true diff --git a/src/tools/rust-analyzer/crates/intern/src/intern.rs b/src/tools/rust-analyzer/crates/intern/src/intern.rs index a96dfcfa9fe3c..b6c7f705e501f 100644 --- a/src/tools/rust-analyzer/crates/intern/src/intern.rs +++ b/src/tools/rust-analyzer/crates/intern/src/intern.rs @@ -34,6 +34,7 @@ use std::{ use dashmap::{DashMap, SharedValue}; use hashbrown::raw::RawTable; use rustc_hash::FxBuildHasher; +use rustc_type_ir::inherent::IntoKind; use triomphe::{Arc, ArcBorrow}; type InternMap = DashMap, (), FxBuildHasher>; @@ -318,6 +319,14 @@ impl Display for InternedRef<'_, T> { } } +impl IntoKind for InternedRef<'_, T> { + type Kind = T; + + fn kind(self) -> Self::Kind { + self.arc.get().clone() + } +} + pub struct InternStorage { map: OnceLock>, } diff --git a/src/tools/rust-analyzer/crates/intern/src/lib.rs b/src/tools/rust-analyzer/crates/intern/src/lib.rs index 0c0b12427d212..46006e815fb63 100644 --- a/src/tools/rust-analyzer/crates/intern/src/lib.rs +++ b/src/tools/rust-analyzer/crates/intern/src/lib.rs @@ -7,6 +7,8 @@ mod intern; mod intern_slice; mod symbol; +extern crate ra_ap_rustc_type_ir as rustc_type_ir; + pub use self::gc::{GarbageCollector, GcInternedSliceVisit, GcInternedVisit}; pub use self::intern::{InternStorage, Internable, Interned, InternedRef, impl_internable}; pub use self::intern_slice::{ From 622e495b7e061094a7268726e82ab8c82627421f Mon Sep 17 00:00:00 2001 From: James Barford-Evans Date: Mon, 20 Apr 2026 14:56:45 +0100 Subject: [PATCH 8/9] Undo rust-analyser changes --- src/tools/rust-analyzer/Cargo.lock | 1 - .../crates/hir-ty/src/next_solver/interner.rs | 4 +--- src/tools/rust-analyzer/crates/intern/Cargo.toml | 2 -- src/tools/rust-analyzer/crates/intern/src/intern.rs | 9 --------- src/tools/rust-analyzer/crates/intern/src/lib.rs | 2 -- 5 files changed, 1 insertion(+), 17 deletions(-) diff --git a/src/tools/rust-analyzer/Cargo.lock b/src/tools/rust-analyzer/Cargo.lock index 0a4164e074554..e6575c28c1dd0 100644 --- a/src/tools/rust-analyzer/Cargo.lock +++ b/src/tools/rust-analyzer/Cargo.lock @@ -1215,7 +1215,6 @@ version = "0.0.0" dependencies = [ "dashmap", "hashbrown 0.14.5", - "ra-ap-rustc_type_ir", "rayon", "rustc-hash 2.1.1", "triomphe", diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/interner.rs b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/interner.rs index f75a90240d47f..35c3ac0d8e7f4 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/interner.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/interner.rs @@ -54,8 +54,7 @@ use crate::{ use super::{ Binder, BoundExistentialPredicates, BoundTy, BoundTyKind, Clause, ClauseKind, Clauses, Const, ErrorGuaranteed, ExprConst, ExternalConstraints, GenericArg, GenericArgs, ParamConst, ParamEnv, - ParamTy, PredefinedOpaques, Predicate, RegionKind, SolverDefId, Term, Ty, TyKind, Tys, ValTree, - ValueConst, + ParamTy, PredefinedOpaques, Predicate, SolverDefId, Term, Ty, TyKind, Tys, ValTree, ValueConst, abi::Safety, fold::{BoundVarReplacer, BoundVarReplacerDelegate, FnMutDelegate}, generics::{Generics, generics}, @@ -1074,7 +1073,6 @@ impl<'db> Interner for DbInterner<'db> { type LateParamRegion = LateParamRegion<'db>; type BoundRegion = BoundRegion; type PlaceholderRegion = PlaceholderRegion; - type InternedRegionKind = InternedRef<'db, RegionKind<'db>>; type RegionAssumptions = RegionAssumptions<'db>; diff --git a/src/tools/rust-analyzer/crates/intern/Cargo.toml b/src/tools/rust-analyzer/crates/intern/Cargo.toml index ae58d5f3ac905..39320ebd1cfef 100644 --- a/src/tools/rust-analyzer/crates/intern/Cargo.toml +++ b/src/tools/rust-analyzer/crates/intern/Cargo.toml @@ -20,8 +20,6 @@ rustc-hash.workspace = true triomphe.workspace = true rayon.workspace = true -ra-ap-rustc_type_ir.workspace = true - [lints] workspace = true diff --git a/src/tools/rust-analyzer/crates/intern/src/intern.rs b/src/tools/rust-analyzer/crates/intern/src/intern.rs index b6c7f705e501f..a96dfcfa9fe3c 100644 --- a/src/tools/rust-analyzer/crates/intern/src/intern.rs +++ b/src/tools/rust-analyzer/crates/intern/src/intern.rs @@ -34,7 +34,6 @@ use std::{ use dashmap::{DashMap, SharedValue}; use hashbrown::raw::RawTable; use rustc_hash::FxBuildHasher; -use rustc_type_ir::inherent::IntoKind; use triomphe::{Arc, ArcBorrow}; type InternMap = DashMap, (), FxBuildHasher>; @@ -319,14 +318,6 @@ impl Display for InternedRef<'_, T> { } } -impl IntoKind for InternedRef<'_, T> { - type Kind = T; - - fn kind(self) -> Self::Kind { - self.arc.get().clone() - } -} - pub struct InternStorage { map: OnceLock>, } diff --git a/src/tools/rust-analyzer/crates/intern/src/lib.rs b/src/tools/rust-analyzer/crates/intern/src/lib.rs index 46006e815fb63..0c0b12427d212 100644 --- a/src/tools/rust-analyzer/crates/intern/src/lib.rs +++ b/src/tools/rust-analyzer/crates/intern/src/lib.rs @@ -7,8 +7,6 @@ mod intern; mod intern_slice; mod symbol; -extern crate ra_ap_rustc_type_ir as rustc_type_ir; - pub use self::gc::{GarbageCollector, GcInternedSliceVisit, GcInternedVisit}; pub use self::intern::{InternStorage, Internable, Interned, InternedRef, impl_internable}; pub use self::intern_slice::{ From cdf38d3a09d62754592f0573468a52845ef90bf6 Mon Sep 17 00:00:00 2001 From: James Barford-Evans Date: Wed, 6 May 2026 15:56:46 +0100 Subject: [PATCH 9/9] Updates from new code coming in --- .../src/ty/context/impl_interner.rs | 9 +++++--- compiler/rustc_middle/src/ty/region.rs | 23 +------------------ .../rustc_next_trait_solver/src/normalize.rs | 4 ++-- .../src/placeholder.rs | 2 +- compiler/rustc_type_ir/src/binder.rs | 4 ++-- compiler/rustc_type_ir/src/sty/mod.rs | 4 ++-- 6 files changed, 14 insertions(+), 32 deletions(-) diff --git a/compiler/rustc_middle/src/ty/context/impl_interner.rs b/compiler/rustc_middle/src/ty/context/impl_interner.rs index ae358423bc51a..a220610e6ad4d 100644 --- a/compiler/rustc_middle/src/ty/context/impl_interner.rs +++ b/compiler/rustc_middle/src/ty/context/impl_interner.rs @@ -1,6 +1,7 @@ //! Implementation of [`rustc_type_ir::Interner`] for [`TyCtxt`]. use std::{debug_assert_matches, fmt}; +use rustc_data_structures::intern::Interned; use rustc_errors::ErrorGuaranteed; use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind}; @@ -8,7 +9,9 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::lang_items::LangItem; use rustc_span::{DUMMY_SP, Span, Symbol}; use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem}; -use rustc_type_ir::{CollectAndApply, Interner, TypeFoldable, Unnormalized, search_graph}; +use rustc_type_ir::{ + BoundVar, CollectAndApply, DebruijnIndex, Interner, TypeFoldable, Unnormalized, search_graph, +}; use crate::dep_graph::{DepKind, DepNodeIndex}; use crate::infer::canonical::CanonicalVarKinds; @@ -17,8 +20,8 @@ use crate::traits::solve::{ self, CanonicalInput, ExternalConstraints, ExternalConstraintsData, QueryResult, inspect, }; use crate::ty::{ - self, Clause, Const, List, ParamTy, Pattern, PolyExistentialPredicate, Predicate, Region, Ty, - TyCtxt, + self, BoundRegion, Clause, Const, List, ParamTy, Pattern, PolyExistentialPredicate, Predicate, + Region, RegionKind, Ty, TyCtxt, }; #[allow(rustc::usage_of_ty_tykind)] diff --git a/compiler/rustc_middle/src/ty/region.rs b/compiler/rustc_middle/src/ty/region.rs index 5799d16af4d16..7a4161b14c918 100644 --- a/compiler/rustc_middle/src/ty/region.rs +++ b/compiler/rustc_middle/src/ty/region.rs @@ -1,6 +1,6 @@ use rustc_errors::MultiSpan; use rustc_hir::def_id::DefId; -use rustc_macros::{HashStable, TyDecodable, TyEncodable, extension}; +use rustc_macros::{StableHash, TyDecodable, TyEncodable, extension}; use rustc_span::{DUMMY_SP, ErrorGuaranteed, Symbol, kw, sym}; pub use rustc_type_ir::RegionVid; use rustc_type_ir::{Region as IrRegion, RegionKind as IrRegionKind}; @@ -11,27 +11,6 @@ use crate::ty::{self, BoundVar, TyCtxt, TypeFlags}; pub type Region<'tcx> = IrRegion>; pub type RegionKind<'tcx> = IrRegionKind>; -impl<'tcx> rustc_type_ir::inherent::IntoKind for Region<'tcx> { - type Kind = RegionKind<'tcx>; - - fn kind(self) -> RegionKind<'tcx> { - *self.0.0 - } -} - -impl<'tcx> rustc_type_ir::Flags for Region<'tcx> { - fn flags(&self) -> TypeFlags { - self.type_flags() - } - - fn outer_exclusive_binder(&self) -> ty::DebruijnIndex { - match self.kind() { - ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), _) => debruijn.shifted_in(1), - _ => ty::INNERMOST, - } - } -} - #[extension(pub trait RegionExt<'tcx>)] impl<'tcx> Region<'tcx> { #[inline] diff --git a/compiler/rustc_next_trait_solver/src/normalize.rs b/compiler/rustc_next_trait_solver/src/normalize.rs index 7506591d6fb5d..ee88fc9333a14 100644 --- a/compiler/rustc_next_trait_solver/src/normalize.rs +++ b/compiler/rustc_next_trait_solver/src/normalize.rs @@ -2,7 +2,7 @@ use rustc_type_ir::data_structures::ensure_sufficient_stack; use rustc_type_ir::inherent::*; use rustc_type_ir::solve::{Goal, NoSolution}; use rustc_type_ir::{ - self as ty, Binder, FallibleTypeFolder, InferConst, InferCtxtLike, InferTy, Interner, + self as ty, Binder, FallibleTypeFolder, InferConst, InferCtxtLike, InferTy, Interner, Region, TypeFoldable, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, UniverseIndex, }; @@ -90,7 +90,7 @@ where c.super_visit_with(self) } - fn visit_region(&mut self, r: I::Region) { + fn visit_region(&mut self, r: Region) { if let ty::ReVar(vid) = r.kind() { self.max_universe = self.max_universe.max(self.infcx.universe_of_lt(vid).unwrap()); } diff --git a/compiler/rustc_next_trait_solver/src/placeholder.rs b/compiler/rustc_next_trait_solver/src/placeholder.rs index 3e2228997c5d7..04247a17edcca 100644 --- a/compiler/rustc_next_trait_solver/src/placeholder.rs +++ b/compiler/rustc_next_trait_solver/src/placeholder.rs @@ -224,7 +224,7 @@ where t } - fn fold_region(&mut self, r0: I::Region) -> I::Region { + fn fold_region(&mut self, r0: Region) -> Region { let r1 = match r0.kind() { ty::ReVar(vid) => self.infcx.opportunistic_resolve_lt_var(vid), _ => r0, diff --git a/compiler/rustc_type_ir/src/binder.rs b/compiler/rustc_type_ir/src/binder.rs index a813596d7b006..53e4ec278f3a4 100644 --- a/compiler/rustc_type_ir/src/binder.rs +++ b/compiler/rustc_type_ir/src/binder.rs @@ -961,8 +961,8 @@ pub enum BoundVarIndexKind { impl Lift for BoundVarIndexKind { type Lifted = BoundVarIndexKind; - fn lift_to_interner(self, _interner: U) -> Option { - Some(self) + fn lift_to_interner(self, _interner: U) -> Self::Lifted { + self } } diff --git a/compiler/rustc_type_ir/src/sty/mod.rs b/compiler/rustc_type_ir/src/sty/mod.rs index 7822f3d86ec75..b9a15c65c9761 100644 --- a/compiler/rustc_type_ir/src/sty/mod.rs +++ b/compiler/rustc_type_ir/src/sty/mod.rs @@ -4,7 +4,7 @@ use derive_where::derive_where; #[cfg(feature = "nightly")] use rustc_data_structures::intern::Interned; #[cfg(feature = "nightly")] -use rustc_macros::HashStable_NoContext; +use rustc_macros::StableHash_NoContext; #[cfg(feature = "nightly")] use rustc_serialize::{Decodable, Encodable}; use tracing::debug; @@ -19,7 +19,7 @@ use crate::{ /// Use this rather than `RegionKind`, whenever possible. #[derive_where(Clone, Copy, PartialEq, Eq, Hash; I: Interner)] -#[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] +#[cfg_attr(feature = "nightly", derive(StableHash_NoContext))] #[cfg_attr(feature = "nightly", rustc_pass_by_value)] pub struct Region(pub I::InternedRegionKind);