From cf0f1318f186d542cc3ebd5c6d76e27403490664 Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Sun, 23 Nov 2025 16:19:48 +0200 Subject: [PATCH] Upgrade rustc crates Major changes: - `GoalSource::InstantiateHigherRanked` was removed. - `Interner::UnevaluatedConstId` was introduced, allowing further simplifications due to better typing. Generally we don't represent unevaluated consts like we should, but it's still better. - `PatternKind::NotNull` was introduced. --- Cargo.lock | 44 ++++++++--------- Cargo.toml | 16 +++--- crates/hir-ty/src/consteval.rs | 20 ++++---- crates/hir-ty/src/display.rs | 9 +--- crates/hir-ty/src/infer/unify.rs | 18 +------ crates/hir-ty/src/lower.rs | 8 +-- crates/hir-ty/src/mir/eval.rs | 10 ++-- crates/hir-ty/src/next_solver/def_id.rs | 49 +++++++++++++++++++ .../hir-ty/src/next_solver/fulfill/errors.rs | 11 ++--- crates/hir-ty/src/next_solver/interner.rs | 30 +++++++----- crates/hir-ty/src/next_solver/solver.rs | 9 ++-- 11 files changed, 125 insertions(+), 99 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c1dbe6a7a5e0..891deadeebf7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2025,9 +2025,9 @@ checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "ra-ap-rustc_abi" -version = "0.137.0" +version = "0.139.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4ce5c9ea794353e02beae390c4674f74ffb23a2ad9de763469fdcef5c1026ef" +checksum = "ce480c45c05462cf6b700468118201b00132613a968a1849da5f7a555c0f1db9" dependencies = [ "bitflags 2.9.4", "ra-ap-rustc_hashes", @@ -2037,24 +2037,24 @@ dependencies = [ [[package]] name = "ra-ap-rustc_ast_ir" -version = "0.137.0" +version = "0.139.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1696b77af9bbfe1fcc7a09c907561061c6ef4c8bd6d5f1675b927bc62d349103" +checksum = "453da2376de406d740ca28412a31ae3d5a6039cd45698c1c2fb01b577dff64ae" [[package]] name = "ra-ap-rustc_hashes" -version = "0.137.0" +version = "0.139.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c055d8b0d8a592d8cf9547495189f52c1ee5c691d28df1628253a816214e8521" +checksum = "bf411a55deaa3ea348594c8273fb2d1200265bf87b881b40c62b32f75caf8323" dependencies = [ "rustc-stable-hash", ] [[package]] name = "ra-ap-rustc_index" -version = "0.137.0" +version = "0.139.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a08a03e3d4a452144b68f48130eda3a2894d4d79e99ddb44bdb4e0ab8c384e10" +checksum = "1d0dd4cf1417ea8a809e9e7bf296c6ce6e05b75b043483872d1bd2951a08142c" dependencies = [ "ra-ap-rustc_index_macros", "smallvec", @@ -2062,9 +2062,9 @@ dependencies = [ [[package]] name = "ra-ap-rustc_index_macros" -version = "0.137.0" +version = "0.139.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1e0446b4d65a8ce19d8fd12826c4bf2365ffa4b8fe0ee94daf5968fe36e920c" +checksum = "a1b0d218fb91f8969716a962142c722d88b3cd3fd1f7ef03093261bf37e85dfd" dependencies = [ "proc-macro2", "quote", @@ -2073,9 +2073,9 @@ dependencies = [ [[package]] name = "ra-ap-rustc_lexer" -version = "0.137.0" +version = "0.139.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac80365383a3c749f38af567fdcfaeff3fa6ea5df3846852abbce73e943921b9" +checksum = "5ec7c26e92c44d5433b29cf661faf0027e263b70a411d0f28996bd67e3bdb57e" dependencies = [ "memchr", "unicode-properties", @@ -2084,9 +2084,9 @@ dependencies = [ [[package]] name = "ra-ap-rustc_next_trait_solver" -version = "0.137.0" +version = "0.139.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a39b419d2d6f7fdec7e0981b7fb7d5beb5dda7140064f1199704ec9dadbb6f73" +checksum = "029686fdbc8a058cf3d81ad157e1cdc81a37b9de0400289ccb86a62465484313" dependencies = [ "derive-where", "ra-ap-rustc_index", @@ -2097,9 +2097,9 @@ dependencies = [ [[package]] name = "ra-ap-rustc_parse_format" -version = "0.137.0" +version = "0.139.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b743b0c8f795842e41b1720bbc5af6e896129fb9acf04e9785774bfb0dc5947c" +checksum = "509d279f1e87acc33476da3fbd05a6054e9ffeb4427cb38ba01b9d2656aec268" dependencies = [ "ra-ap-rustc_lexer", "rustc-literal-escaper 0.0.5", @@ -2107,9 +2107,9 @@ dependencies = [ [[package]] name = "ra-ap-rustc_pattern_analysis" -version = "0.137.0" +version = "0.139.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf944dce80137195528f89a576f70153c2060a6f8ca49c3fa9f55f9da14ab937" +checksum = "9bb2c9930854314b03bd7aab060a14bca6f194b76381a4c309e3905ec3a02bbc" dependencies = [ "ra-ap-rustc_index", "rustc-hash 2.1.1", @@ -2120,9 +2120,9 @@ dependencies = [ [[package]] name = "ra-ap-rustc_type_ir" -version = "0.137.0" +version = "0.139.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bfe2722b20bc889a9d7711bd3a1f4f7b082940491241615aa643c17e0deffec" +checksum = "0e4a92a3e4dbdebb0d4c9caceb52eff45c4df784d21fb2da90dac50e218f95c0" dependencies = [ "arrayvec", "bitflags 2.9.4", @@ -2140,9 +2140,9 @@ dependencies = [ [[package]] name = "ra-ap-rustc_type_ir_macros" -version = "0.137.0" +version = "0.139.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fad1527df26aaa77367393fae86f42818b33e02b3737a19f3846d1c7671e7f9" +checksum = "ca368eca2472367f2e6fdfb431c8342e99d848e4ce89cb20dd3b3bdcc43cbc28" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 63223f831222..8ff7e0e8a2a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,14 +86,14 @@ vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" } vfs = { path = "./crates/vfs", version = "0.0.0" } edition = { path = "./crates/edition", version = "0.0.0" } -ra-ap-rustc_lexer = { version = "0.137", default-features = false } -ra-ap-rustc_parse_format = { version = "0.137", default-features = false } -ra-ap-rustc_index = { version = "0.137", default-features = false } -ra-ap-rustc_abi = { version = "0.137", default-features = false } -ra-ap-rustc_pattern_analysis = { version = "0.137", default-features = false } -ra-ap-rustc_ast_ir = { version = "0.137", default-features = false } -ra-ap-rustc_type_ir = { version = "0.137", default-features = false } -ra-ap-rustc_next_trait_solver = { version = "0.137", default-features = false } +ra-ap-rustc_lexer = { version = "0.139", default-features = false } +ra-ap-rustc_parse_format = { version = "0.139", default-features = false } +ra-ap-rustc_index = { version = "0.139", default-features = false } +ra-ap-rustc_abi = { version = "0.139", default-features = false } +ra-ap-rustc_pattern_analysis = { version = "0.139", default-features = false } +ra-ap-rustc_ast_ir = { version = "0.139", default-features = false } +ra-ap-rustc_type_ir = { version = "0.139", default-features = false } +ra-ap-rustc_next_trait_solver = { version = "0.139", default-features = false } # local crates that aren't published to crates.io. These should not have versions. diff --git a/crates/hir-ty/src/consteval.rs b/crates/hir-ty/src/consteval.rs index 621ebc7bd549..61f29b4ab747 100644 --- a/crates/hir-ty/src/consteval.rs +++ b/crates/hir-ty/src/consteval.rs @@ -5,7 +5,7 @@ mod tests; use base_db::Crate; use hir_def::{ - ConstId, EnumVariantId, StaticId, + ConstId, EnumVariantId, GeneralConstId, StaticId, expr_store::Body, hir::{Expr, ExprId}, type_ref::LiteralConstRef, @@ -21,8 +21,8 @@ use crate::{ infer::InferenceContext, mir::{MirEvalError, MirLowerError}, next_solver::{ - Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArg, GenericArgs, - SolverDefId, Ty, ValueConst, + Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArg, GenericArgs, Ty, + ValueConst, }, }; @@ -139,17 +139,16 @@ pub fn try_const_usize<'db>(db: &'db dyn HirDatabase, c: Const<'db>) -> Option None, ConstKind::Bound(_, _) => None, ConstKind::Placeholder(_) => None, - ConstKind::Unevaluated(unevaluated_const) => match unevaluated_const.def { - SolverDefId::ConstId(id) => { + ConstKind::Unevaluated(unevaluated_const) => match unevaluated_const.def.0 { + GeneralConstId::ConstId(id) => { let subst = unevaluated_const.args; let ec = db.const_eval(id, subst, None).ok()?; try_const_usize(db, ec) } - SolverDefId::StaticId(id) => { + GeneralConstId::StaticId(id) => { let ec = db.const_eval_static(id).ok()?; try_const_usize(db, ec) } - _ => unreachable!(), }, ConstKind::Value(val) => Some(u128::from_le_bytes(pad16(&val.value.inner().memory, false))), ConstKind::Error(_) => None, @@ -163,17 +162,16 @@ pub fn try_const_isize<'db>(db: &'db dyn HirDatabase, c: &Const<'db>) -> Option< ConstKind::Infer(_) => None, ConstKind::Bound(_, _) => None, ConstKind::Placeholder(_) => None, - ConstKind::Unevaluated(unevaluated_const) => match unevaluated_const.def { - SolverDefId::ConstId(id) => { + ConstKind::Unevaluated(unevaluated_const) => match unevaluated_const.def.0 { + GeneralConstId::ConstId(id) => { let subst = unevaluated_const.args; let ec = db.const_eval(id, subst, None).ok()?; try_const_isize(db, &ec) } - SolverDefId::StaticId(id) => { + GeneralConstId::StaticId(id) => { let ec = db.const_eval_static(id).ok()?; try_const_isize(db, &ec) } - _ => unreachable!(), }, ConstKind::Value(val) => Some(i128::from_le_bytes(pad16(&val.value.inner().memory, true))), ConstKind::Error(_) => None, diff --git a/crates/hir-ty/src/display.rs b/crates/hir-ty/src/display.rs index 3b37dc805662..6767bd05b336 100644 --- a/crates/hir-ty/src/display.rs +++ b/crates/hir-ty/src/display.rs @@ -10,8 +10,7 @@ use std::{ use base_db::Crate; use either::Either; use hir_def::{ - FindPathConfig, GeneralConstId, GenericDefId, HasModule, LocalFieldId, Lookup, ModuleDefId, - ModuleId, TraitId, + FindPathConfig, GenericDefId, HasModule, LocalFieldId, Lookup, ModuleDefId, ModuleId, TraitId, db::DefDatabase, expr_store::{ExpressionStore, path::Path}, find_path::{self, PrefixKind}, @@ -700,11 +699,7 @@ impl<'db> HirDisplay<'db> for Const<'db> { const_bytes.ty, ), ConstKind::Unevaluated(unev) => { - let c = match unev.def { - SolverDefId::ConstId(id) => GeneralConstId::ConstId(id), - SolverDefId::StaticId(id) => GeneralConstId::StaticId(id), - _ => unreachable!(), - }; + let c = unev.def.0; write!(f, "{}", c.name(f.db))?; hir_fmt_generics(f, unev.args.as_slice(), c.generic_def(f.db), None)?; Ok(()) diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs index 5bb71bc50310..0b566497c4b6 100644 --- a/crates/hir-ty/src/infer/unify.rs +++ b/crates/hir-ty/src/infer/unify.rs @@ -9,7 +9,7 @@ use rustc_hash::FxHashSet; use rustc_type_ir::{ TyVid, TypeFoldable, TypeVisitableExt, UpcastFrom, inherent::{Const as _, GenericArg as _, IntoKind, SliceLike, Ty as _}, - solve::{Certainty, GoalSource}, + solve::Certainty, }; use smallvec::SmallVec; use triomphe::Arc; @@ -62,21 +62,7 @@ impl<'a, 'db> ProofTreeVisitor<'db> for NestedObligationsForSelfTy<'a, 'db> { let db = self.ctx.interner(); let goal = inspect_goal.goal(); - if self.ctx.predicate_has_self_ty(goal.predicate, self.self_ty) - // We do not push the instantiated forms of goals as it would cause any - // aliases referencing bound vars to go from having escaping bound vars to - // being able to be normalized to an inference variable. - // - // This is mostly just a hack as arbitrary nested goals could still contain - // such aliases while having a different `GoalSource`. Closure signature inference - // however can't really handle *every* higher ranked `Fn` goal also being present - // in the form of `?c: Fn<(>::Assoc)`. - // - // This also just better matches the behaviour of the old solver where we do not - // encounter instantiated forms of goals, only nested goals that referred to bound - // vars from instantiated goals. - && !matches!(inspect_goal.source(), GoalSource::InstantiateHigherRanked) - { + if self.ctx.predicate_has_self_ty(goal.predicate, self.self_ty) { self.obligations_for_self_ty.push(Obligation::new( db, self.root_cause.clone(), diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs index a20c299d0cbb..3f187d205da6 100644 --- a/crates/hir-ty/src/lower.rs +++ b/crates/hir-ty/src/lower.rs @@ -15,9 +15,9 @@ use base_db::Crate; use either::Either; use hir_def::{ AdtId, AssocItemId, CallableDefId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, - FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, ItemContainerId, LifetimeParamId, - LocalFieldId, Lookup, StaticId, StructId, TypeAliasId, TypeOrConstParamId, TypeParamId, - UnionId, VariantId, + FunctionId, GeneralConstId, GenericDefId, GenericParamId, HasModule, ImplId, ItemContainerId, + LifetimeParamId, LocalFieldId, Lookup, StaticId, StructId, TypeAliasId, TypeOrConstParamId, + TypeParamId, UnionId, VariantId, builtin_type::BuiltinType, expr_store::{ExpressionStore, HygieneId, path::Path}, hir::generics::{ @@ -335,7 +335,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> { Some(Const::new( self.interner, rustc_type_ir::ConstKind::Unevaluated(UnevaluatedConst::new( - SolverDefId::ConstId(c), + GeneralConstId::ConstId(c).into(), args, )), )) diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs index 08f42410a7f2..da15ca695ea8 100644 --- a/crates/hir-ty/src/mir/eval.rs +++ b/crates/hir-ty/src/mir/eval.rs @@ -42,8 +42,8 @@ use crate::{ layout::{Layout, LayoutError, RustcEnumVariantIdx}, method_resolution::{is_dyn_method, lookup_impl_const}, next_solver::{ - Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArgs, Region, - SolverDefId, Ty, TyKind, TypingMode, UnevaluatedConst, ValueConst, + Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArgs, Region, Ty, TyKind, + TypingMode, UnevaluatedConst, ValueConst, infer::{DbInternerInferExt, InferCtxt, traits::ObligationCause}, obligation_ctxt::ObligationCtxt, }, @@ -1917,11 +1917,7 @@ impl<'db> Evaluator<'db> { let value = match konst.kind() { ConstKind::Value(value) => value, ConstKind::Unevaluated(UnevaluatedConst { def: const_id, args: subst }) => 'b: { - let mut id = match const_id { - SolverDefId::ConstId(it) => GeneralConstId::from(it), - SolverDefId::StaticId(it) => it.into(), - _ => unreachable!("unevaluated consts should be consts or statics"), - }; + let mut id = const_id.0; let mut subst = subst; if let hir_def::GeneralConstId::ConstId(c) = id { let (c, s) = lookup_impl_const(&self.infcx, self.trait_env.clone(), c, subst); diff --git a/crates/hir-ty/src/next_solver/def_id.rs b/crates/hir-ty/src/next_solver/def_id.rs index 2c30922246c2..b6167b4a097c 100644 --- a/crates/hir-ty/src/next_solver/def_id.rs +++ b/crates/hir-ty/src/next_solver/def_id.rs @@ -334,6 +334,55 @@ declare_id_wrapper!(CoroutineIdWrapper, InternedCoroutineId); declare_id_wrapper!(AdtIdWrapper, AdtId); declare_id_wrapper!(ImplIdWrapper, ImplId); +#[derive(Clone, Copy, PartialEq, Eq, Hash)] +pub struct GeneralConstIdWrapper(pub GeneralConstId); + +impl std::fmt::Debug for GeneralConstIdWrapper { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + std::fmt::Debug::fmt(&self.0, f) + } +} +impl From for GeneralConstId { + #[inline] + fn from(value: GeneralConstIdWrapper) -> GeneralConstId { + value.0 + } +} +impl From for GeneralConstIdWrapper { + #[inline] + fn from(value: GeneralConstId) -> GeneralConstIdWrapper { + Self(value) + } +} +impl From for SolverDefId { + #[inline] + fn from(value: GeneralConstIdWrapper) -> SolverDefId { + match value.0 { + GeneralConstId::ConstId(id) => SolverDefId::ConstId(id), + GeneralConstId::StaticId(id) => SolverDefId::StaticId(id), + } + } +} +impl TryFrom for GeneralConstIdWrapper { + type Error = (); + #[inline] + fn try_from(value: SolverDefId) -> Result { + match value { + SolverDefId::ConstId(it) => Ok(Self(it.into())), + SolverDefId::StaticId(it) => Ok(Self(it.into())), + _ => Err(()), + } + } +} +impl<'db> inherent::DefId> for GeneralConstIdWrapper { + fn as_local(self) -> Option { + Some(self.into()) + } + fn is_local(self) -> bool { + true + } +} + #[derive(Clone, Copy, PartialEq, Eq, Hash)] pub struct CallableIdWrapper(pub CallableDefId); diff --git a/crates/hir-ty/src/next_solver/fulfill/errors.rs b/crates/hir-ty/src/next_solver/fulfill/errors.rs index 82dbf9403cab..8495af4b755e 100644 --- a/crates/hir-ty/src/next_solver/fulfill/errors.rs +++ b/crates/hir-ty/src/next_solver/fulfill/errors.rs @@ -98,7 +98,7 @@ pub(super) fn fulfillment_error_for_no_solution<'db>( PredicateKind::Clause(ClauseKind::ConstArgHasType(ct, expected_ty)) => { let ct_ty = match ct.kind() { ConstKind::Unevaluated(uv) => { - infcx.interner.type_of(uv.def).instantiate(infcx.interner, uv.args) + infcx.interner.type_of(uv.def.into()).instantiate(infcx.interner, uv.args) } ConstKind::Param(param_ct) => param_ct.find_const_ty_from_env(obligation.param_env), ConstKind::Value(cv) => cv.ty, @@ -286,7 +286,6 @@ impl<'db> BestObligation<'db> { nested_goal.source(), GoalSource::ImplWhereBound | GoalSource::AliasBoundConstCondition - | GoalSource::InstantiateHigherRanked | GoalSource::AliasWellFormed ) && nested_goal.result().is_err() }) @@ -555,8 +554,6 @@ impl<'db> ProofTreeVisitor<'db> for BestObligation<'db> { ChildMode::Host(_parent_host_pred), GoalSource::ImplWhereBound | GoalSource::AliasBoundConstCondition, ) => make_obligation(), - // Skip over a higher-ranked predicate. - (_, GoalSource::InstantiateHigherRanked) => self.obligation.clone(), (ChildMode::PassThrough, _) | (_, GoalSource::AliasWellFormed | GoalSource::AliasBoundConstCondition) => { make_obligation() @@ -620,7 +617,7 @@ impl<'db> NextSolverError<'db> { } mod wf { - use hir_def::ItemContainerId; + use hir_def::{GeneralConstId, ItemContainerId}; use rustc_type_ir::inherent::{ AdtDef, BoundExistentialPredicates, GenericArgs as _, IntoKind, SliceLike, Term as _, Ty as _, @@ -1054,14 +1051,14 @@ mod wf { predicate, )); - if let SolverDefId::ConstId(uv_def) = uv.def + if let GeneralConstId::ConstId(uv_def) = uv.def.0 && let ItemContainerId::ImplId(impl_) = uv_def.loc(self.interner().db).container && self.interner().db.impl_signature(impl_).target_trait.is_none() { return; // Subtree is handled by above function } else { - let obligations = self.nominal_obligations(uv.def, uv.args); + let obligations = self.nominal_obligations(uv.def.into(), uv.args); self.out.extend(obligations); } } diff --git a/crates/hir-ty/src/next_solver/interner.rs b/crates/hir-ty/src/next_solver/interner.rs index b77b30541ed9..a3c984f6c981 100644 --- a/crates/hir-ty/src/next_solver/interner.rs +++ b/crates/hir-ty/src/next_solver/interner.rs @@ -20,7 +20,7 @@ use rustc_index::bit_set::DenseBitSet; use rustc_type_ir::{ AliasTermKind, AliasTyKind, BoundVar, CollectAndApply, CoroutineWitnessTypes, DebruijnIndex, EarlyBinder, FlagComputation, Flags, GenericArgKind, ImplPolarity, InferTy, Interner, TraitRef, - TypeVisitableExt, UniverseIndex, Upcast, Variance, + TypeFlags, TypeVisitableExt, UniverseIndex, Upcast, Variance, elaborate::elaborate, error::TypeError, fast_reject, @@ -36,9 +36,9 @@ use crate::{ method_resolution::TraitImpls, next_solver::{ AdtIdWrapper, BoundConst, CallableIdWrapper, CanonicalVarKind, ClosureIdWrapper, - CoroutineIdWrapper, Ctor, FnSig, FxIndexMap, ImplIdWrapper, OpaqueTypeKey, - RegionAssumptions, SimplifiedType, SolverContext, SolverDefIds, TraitIdWrapper, - TypeAliasIdWrapper, util::explicit_item_bounds, + CoroutineIdWrapper, Ctor, FnSig, FxIndexMap, GeneralConstIdWrapper, ImplIdWrapper, + OpaqueTypeKey, RegionAssumptions, SimplifiedType, SolverContext, SolverDefIds, + TraitIdWrapper, TypeAliasIdWrapper, util::explicit_item_bounds, }, }; @@ -770,7 +770,7 @@ impl<'db> Pattern<'db> { } impl<'db> Flags for Pattern<'db> { - fn flags(&self) -> rustc_type_ir::TypeFlags { + fn flags(&self) -> TypeFlags { match self.inner() { PatternKind::Range { start, end } => { FlagComputation::for_const_kind(&start.kind()).flags @@ -783,6 +783,7 @@ impl<'db> Flags for Pattern<'db> { } flags } + PatternKind::NotNull => TypeFlags::empty(), } } @@ -798,6 +799,7 @@ impl<'db> Flags for Pattern<'db> { } idx } + PatternKind::NotNull => rustc_type_ir::INNERMOST, } } } @@ -835,7 +837,10 @@ impl<'db> rustc_type_ir::relate::Relate> for Pattern<'db> { )?; Ok(Pattern::new(tcx, PatternKind::Or(pats))) } - (PatternKind::Range { .. } | PatternKind::Or(_), _) => Err(TypeError::Mismatch), + (PatternKind::NotNull, PatternKind::NotNull) => Ok(a), + (PatternKind::Range { .. } | PatternKind::Or(_) | PatternKind::NotNull, _) => { + Err(TypeError::Mismatch) + } } } } @@ -878,6 +883,7 @@ impl<'db> Interner for DbInterner<'db> { type CoroutineId = CoroutineIdWrapper; type AdtId = AdtIdWrapper; type ImplId = ImplIdWrapper; + type UnevaluatedConstId = GeneralConstIdWrapper; type Span = Span; type GenericArgs = GenericArgs<'db>; @@ -1597,12 +1603,11 @@ impl<'db> Interner for DbInterner<'db> { ) } - fn associated_type_def_ids(self, def_id: Self::DefId) -> impl IntoIterator { - let trait_ = match def_id { - SolverDefId::TraitId(id) => id, - _ => unreachable!(), - }; - trait_.trait_items(self.db()).associated_types().map(|id| id.into()) + fn associated_type_def_ids( + self, + def_id: Self::TraitId, + ) -> impl IntoIterator { + def_id.0.trait_items(self.db()).associated_types().map(|id| id.into()) } fn for_each_relevant_impl( @@ -2216,6 +2221,7 @@ TrivialTypeTraversalImpls! { CoroutineIdWrapper, AdtIdWrapper, ImplIdWrapper, + GeneralConstIdWrapper, Pattern<'db>, Safety, FnAbi, diff --git a/crates/hir-ty/src/next_solver/solver.rs b/crates/hir-ty/src/next_solver/solver.rs index 68b6ebf7e9be..b5ed770e161d 100644 --- a/crates/hir-ty/src/next_solver/solver.rs +++ b/crates/hir-ty/src/next_solver/solver.rs @@ -1,6 +1,6 @@ //! Defining `SolverContext` for next-trait-solver. -use hir_def::AssocItemId; +use hir_def::{AssocItemId, GeneralConstId}; use rustc_next_trait_solver::delegate::SolverDelegate; use rustc_type_ir::{ AliasTyKind, GenericArgKind, InferCtxtLike, Interner, PredicatePolarity, TypeFlags, @@ -233,17 +233,16 @@ impl<'db> SolverDelegate for SolverContext<'db> { _param_env: ParamEnv<'db>, uv: rustc_type_ir::UnevaluatedConst, ) -> Option<::Const> { - match uv.def { - SolverDefId::ConstId(c) => { + match uv.def.0 { + GeneralConstId::ConstId(c) => { let subst = uv.args; let ec = self.cx().db.const_eval(c, subst, None).ok()?; Some(ec) } - SolverDefId::StaticId(c) => { + GeneralConstId::StaticId(c) => { let ec = self.cx().db.const_eval_static(c).ok()?; Some(ec) } - _ => unreachable!(), } }