about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2025-02-02 23:06:56 +0100
committerGitHub <noreply@github.com>2025-02-02 23:06:56 +0100
commit04299454762744d18f2e323b30dd35bfd90109e2 (patch)
tree2ae46fc99db798d16dde04f3156526b2e577a54f /compiler/rustc_middle/src
parentdc4d38740e914d9abb045e33c0fc08df43b8cdbc (diff)
parent000f8c4e824d35fbcdd1b7d1ebce05eae6cb93b2 (diff)
downloadrust-04299454762744d18f2e323b30dd35bfd90109e2.tar.gz
rust-04299454762744d18f2e323b30dd35bfd90109e2.zip
Rollup merge of #136425 - nnethercote:mv-rustc_middle-infer, r=lcnr
Move `rustc_middle::infer::unify_key`

`rustc_infer` is a much better place for it.

r? `@lcnr`
Diffstat (limited to 'compiler/rustc_middle/src')
-rw-r--r--compiler/rustc_middle/src/infer/mod.rs1
-rw-r--r--compiler/rustc_middle/src/infer/unify_key.rs174
2 files changed, 0 insertions, 175 deletions
diff --git a/compiler/rustc_middle/src/infer/mod.rs b/compiler/rustc_middle/src/infer/mod.rs
index 3dfcf90cb93..73e8971c3bd 100644
--- a/compiler/rustc_middle/src/infer/mod.rs
+++ b/compiler/rustc_middle/src/infer/mod.rs
@@ -1,2 +1 @@
 pub mod canonical;
-pub mod unify_key;
diff --git a/compiler/rustc_middle/src/infer/unify_key.rs b/compiler/rustc_middle/src/infer/unify_key.rs
deleted file mode 100644
index 7f9211043d6..00000000000
--- a/compiler/rustc_middle/src/infer/unify_key.rs
+++ /dev/null
@@ -1,174 +0,0 @@
-use std::cmp;
-use std::marker::PhantomData;
-
-use rustc_data_structures::unify::{NoError, UnifyKey, UnifyValue};
-use rustc_span::Span;
-use rustc_span::def_id::DefId;
-
-use crate::ty::{self, Ty, TyCtxt};
-
-pub trait ToType {
-    fn to_type<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx>;
-}
-
-#[derive(Copy, Clone, Debug)]
-pub enum RegionVariableValue<'tcx> {
-    Known { value: ty::Region<'tcx> },
-    Unknown { universe: ty::UniverseIndex },
-}
-
-#[derive(PartialEq, Copy, Clone, Debug)]
-pub struct RegionVidKey<'tcx> {
-    pub vid: ty::RegionVid,
-    pub phantom: PhantomData<RegionVariableValue<'tcx>>,
-}
-
-impl<'tcx> From<ty::RegionVid> for RegionVidKey<'tcx> {
-    fn from(vid: ty::RegionVid) -> Self {
-        RegionVidKey { vid, phantom: PhantomData }
-    }
-}
-
-impl<'tcx> UnifyKey for RegionVidKey<'tcx> {
-    type Value = RegionVariableValue<'tcx>;
-    #[inline]
-    fn index(&self) -> u32 {
-        self.vid.as_u32()
-    }
-    #[inline]
-    fn from_index(i: u32) -> Self {
-        RegionVidKey::from(ty::RegionVid::from_u32(i))
-    }
-    fn tag() -> &'static str {
-        "RegionVidKey"
-    }
-}
-
-pub struct RegionUnificationError;
-impl<'tcx> UnifyValue for RegionVariableValue<'tcx> {
-    type Error = RegionUnificationError;
-
-    fn unify_values(value1: &Self, value2: &Self) -> Result<Self, Self::Error> {
-        match (*value1, *value2) {
-            (RegionVariableValue::Known { .. }, RegionVariableValue::Known { .. }) => {
-                Err(RegionUnificationError)
-            }
-
-            (RegionVariableValue::Known { value }, RegionVariableValue::Unknown { universe })
-            | (RegionVariableValue::Unknown { universe }, RegionVariableValue::Known { value }) => {
-                let universe_of_value = match value.kind() {
-                    ty::ReStatic
-                    | ty::ReErased
-                    | ty::ReLateParam(..)
-                    | ty::ReEarlyParam(..)
-                    | ty::ReError(_) => ty::UniverseIndex::ROOT,
-                    ty::RePlaceholder(placeholder) => placeholder.universe,
-                    ty::ReVar(..) | ty::ReBound(..) => bug!("not a universal region"),
-                };
-
-                if universe.can_name(universe_of_value) {
-                    Ok(RegionVariableValue::Known { value })
-                } else {
-                    Err(RegionUnificationError)
-                }
-            }
-
-            (
-                RegionVariableValue::Unknown { universe: a },
-                RegionVariableValue::Unknown { universe: b },
-            ) => {
-                // If we unify two unconstrained regions then whatever
-                // value they wind up taking (which must be the same value) must
-                // be nameable by both universes. Therefore, the resulting
-                // universe is the minimum of the two universes, because that is
-                // the one which contains the fewest names in scope.
-                Ok(RegionVariableValue::Unknown { universe: a.min(b) })
-            }
-        }
-    }
-}
-
-// Generic consts.
-
-#[derive(Copy, Clone, Debug)]
-pub struct ConstVariableOrigin {
-    pub span: Span,
-    /// `DefId` of the const parameter this was instantiated for, if any.
-    ///
-    /// This should only be used for diagnostics.
-    pub param_def_id: Option<DefId>,
-}
-
-#[derive(Copy, Clone, Debug)]
-pub enum ConstVariableValue<'tcx> {
-    Known { value: ty::Const<'tcx> },
-    Unknown { origin: ConstVariableOrigin, universe: ty::UniverseIndex },
-}
-
-impl<'tcx> ConstVariableValue<'tcx> {
-    /// If this value is known, returns the const it is known to be.
-    /// Otherwise, `None`.
-    pub fn known(&self) -> Option<ty::Const<'tcx>> {
-        match *self {
-            ConstVariableValue::Unknown { .. } => None,
-            ConstVariableValue::Known { value } => Some(value),
-        }
-    }
-}
-
-#[derive(PartialEq, Copy, Clone, Debug)]
-pub struct ConstVidKey<'tcx> {
-    pub vid: ty::ConstVid,
-    pub phantom: PhantomData<ty::Const<'tcx>>,
-}
-
-impl<'tcx> From<ty::ConstVid> for ConstVidKey<'tcx> {
-    fn from(vid: ty::ConstVid) -> Self {
-        ConstVidKey { vid, phantom: PhantomData }
-    }
-}
-
-impl<'tcx> UnifyKey for ConstVidKey<'tcx> {
-    type Value = ConstVariableValue<'tcx>;
-    #[inline]
-    fn index(&self) -> u32 {
-        self.vid.as_u32()
-    }
-    #[inline]
-    fn from_index(i: u32) -> Self {
-        ConstVidKey::from(ty::ConstVid::from_u32(i))
-    }
-    fn tag() -> &'static str {
-        "ConstVidKey"
-    }
-}
-
-impl<'tcx> UnifyValue for ConstVariableValue<'tcx> {
-    type Error = NoError;
-
-    fn unify_values(&value1: &Self, &value2: &Self) -> Result<Self, Self::Error> {
-        match (value1, value2) {
-            (ConstVariableValue::Known { .. }, ConstVariableValue::Known { .. }) => {
-                bug!("equating two const variables, both of which have known values")
-            }
-
-            // If one side is known, prefer that one.
-            (ConstVariableValue::Known { .. }, ConstVariableValue::Unknown { .. }) => Ok(value1),
-            (ConstVariableValue::Unknown { .. }, ConstVariableValue::Known { .. }) => Ok(value2),
-
-            // If both sides are *unknown*, it hardly matters, does it?
-            (
-                ConstVariableValue::Unknown { origin, universe: universe1 },
-                ConstVariableValue::Unknown { origin: _, universe: universe2 },
-            ) => {
-                // If we unify two unbound variables, ?T and ?U, then whatever
-                // value they wind up taking (which must be the same value) must
-                // be nameable by both universes. Therefore, the resulting
-                // universe is the minimum of the two universes, because that is
-                // the one which contains the fewest names in scope.
-                let universe = cmp::min(universe1, universe2);
-                Ok(ConstVariableValue::Unknown { origin, universe })
-            }
-        }
-    }
-}