about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChayim Refael Friedman <chayimfr@gmail.com>2025-08-26 19:33:46 +0300
committerChayim Refael Friedman <chayimfr@gmail.com>2025-08-26 19:33:46 +0300
commit83f22cc0f87263c0aa3057d55b994d75c6151834 (patch)
tree0d27c958e1a11e43571e2edad1014cd68c8715f2
parent7375e2c961ac9f2fe4b6d685c5a73346c6e7f777 (diff)
downloadrust-83f22cc0f87263c0aa3057d55b994d75c6151834.tar.gz
rust-83f22cc0f87263c0aa3057d55b994d75c6151834.zip
Remove `SolverDefId::ForeignId`
Replace it with normal `SolverDefId::TypeAliasId`.

The split caused a very funny bug where code was getting `TypeAliasId` where it expected `ForeignId`, because `TypeAliasId` had a `From` impl from `hir_def::TypeAliasId` and `ForeignId` had not, plus a careless `into()`.

I could've fixed this specific bug but opted to remove the split instead; currently, it just provides more room for bugs, as we don't have typed IDs for the solver anyway, and even when we'll have (hopefully), that doesn't seem like a very useful distinction, for example in hir-def foreign types are just `TypeAliasId` with some flags.

Constructing a test for this isn't trivial; the trivial test (creating a foreign type, even proving a trait bound for it) fails to fail before the change, probably because we don't use the new solver everywhere yet so we don't trigger this specific code path.
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/display.rs2
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs2
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/next_solver/def_id.rs2
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/next_solver/interner.rs1
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/next_solver/mapping.rs4
5 files changed, 4 insertions, 7 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs
index ae0113fcbd7..0df727a8e5c 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/display.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/display.rs
@@ -1473,7 +1473,7 @@ impl<'db> HirDisplay for crate::next_solver::Ty<'db> {
             }
             TyKind::Foreign(type_alias) => {
                 let alias = match type_alias {
-                    SolverDefId::ForeignId(id) => id,
+                    SolverDefId::TypeAliasId(id) => id,
                     _ => unreachable!(),
                 };
                 let type_alias = db.type_alias_signature(alias);
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs b/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs
index 49438151bbf..8bd71df7c19 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/method_resolution.rs
@@ -155,7 +155,7 @@ impl TyFingerprint {
                 rustc_ast_ir::Mutability::Not => TyFingerprint::RawPtr(Mutability::Not),
             },
             TyKind::Foreign(def) => {
-                let SolverDefId::ForeignId(def) = def else { unreachable!() };
+                let SolverDefId::TypeAliasId(def) = def else { unreachable!() };
                 TyFingerprint::ForeignType(crate::to_foreign_def_id(def))
             }
             TyKind::Dynamic(bounds, _, _) => {
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/def_id.rs b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/def_id.rs
index 64eab2d6b81..c9632ddcd4b 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/def_id.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/def_id.rs
@@ -26,7 +26,6 @@ pub enum SolverDefId {
     StaticId(StaticId),
     TraitId(TraitId),
     TypeAliasId(TypeAliasId),
-    ForeignId(TypeAliasId),
     InternedClosureId(InternedClosureId),
     InternedCoroutineId(InternedCoroutineId),
     InternedOpaqueTyId(InternedOpaqueTyId),
@@ -73,7 +72,6 @@ impl TryFrom<SolverDefId> for GenericDefId {
             SolverDefId::StaticId(static_id) => GenericDefId::StaticId(static_id),
             SolverDefId::TraitId(trait_id) => GenericDefId::TraitId(trait_id),
             SolverDefId::TypeAliasId(type_alias_id) => GenericDefId::TypeAliasId(type_alias_id),
-            SolverDefId::ForeignId(_) => return Err(value),
             SolverDefId::InternedClosureId(_) => return Err(value),
             SolverDefId::InternedCoroutineId(_) => return Err(value),
             SolverDefId::InternedOpaqueTyId(_) => return Err(value),
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 4fe0b54d684..11c79ff742d 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
@@ -1148,7 +1148,6 @@ impl<'db> rustc_type_ir::Interner for DbInterner<'db> {
         let container = match def_id {
             SolverDefId::FunctionId(it) => it.lookup(self.db()).container,
             SolverDefId::TypeAliasId(it) => it.lookup(self.db()).container,
-            SolverDefId::ForeignId(it) => it.lookup(self.db()).container,
             SolverDefId::ConstId(it) => it.lookup(self.db()).container,
             SolverDefId::InternedClosureId(it) => {
                 return self
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/mapping.rs b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/mapping.rs
index 8f6296b1454..de2671e28fb 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/mapping.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/next_solver/mapping.rs
@@ -271,7 +271,7 @@ impl<'db> ChalkToNextSolver<'db, Ty<'db>> for chalk_ir::Ty<Interner> {
                     )
                 }
                 chalk_ir::TyKind::Foreign(foreign_def_id) => rustc_type_ir::TyKind::Foreign(
-                    SolverDefId::ForeignId(crate::from_foreign_def_id(*foreign_def_id)),
+                    SolverDefId::TypeAliasId(crate::from_foreign_def_id(*foreign_def_id)),
                 ),
                 chalk_ir::TyKind::Error => rustc_type_ir::TyKind::Error(ErrorGuaranteed),
                 chalk_ir::TyKind::Placeholder(placeholder_index) => {
@@ -1262,7 +1262,7 @@ pub(crate) fn convert_ty_for_result<'db>(interner: DbInterner<'db>, ty: Ty<'db>)
 
         rustc_type_ir::TyKind::Foreign(foreign) => {
             let def_id = match foreign {
-                SolverDefId::ForeignId(id) => id,
+                SolverDefId::TypeAliasId(id) => id,
                 _ => unreachable!(),
             };
             TyKind::Foreign(to_foreign_def_id(def_id))