Skip to content

Commit 869fb46

Browse files
committed
Auto merge of rust-lang#147723 - ChayimFriedman2:ns-types, r=BoxyUwU
Make `UnevaluatedConst` have a specific ID type in the new solver For the benefit of rust-analyzer. r? types
2 parents 19abae7 + 4efd70d commit 869fb46

File tree

8 files changed

+18
-10
lines changed

8 files changed

+18
-10
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
101101
type CoroutineId = DefId;
102102
type AdtId = DefId;
103103
type ImplId = DefId;
104+
type UnevaluatedConstId = DefId;
104105
type Span = Span;
105106

106107
type GenericArgs = ty::GenericArgsRef<'tcx>;

compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@ where
870870

871871
// FIXME(associated_const_equality): Also add associated consts to
872872
// the requirements here.
873-
for associated_type_def_id in cx.associated_type_def_ids(trait_ref.def_id.into()) {
873+
for associated_type_def_id in cx.associated_type_def_ids(trait_ref.def_id) {
874874
// associated types that require `Self: Sized` do not show up in the built-in
875875
// implementation of `Trait for dyn Trait`, and can be dropped here.
876876
if cx.generics_require_sized_self(associated_type_def_id) {

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ where
218218
return self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes);
219219
}
220220
ty::ConstKind::Unevaluated(uv) => {
221-
self.cx().type_of(uv.def).instantiate(self.cx(), uv.args)
221+
self.cx().type_of(uv.def.into()).instantiate(self.cx(), uv.args)
222222
}
223223
ty::ConstKind::Expr(_) => unimplemented!(
224224
"`feature(generic_const_exprs)` is not supported in the new trait solver"

compiler/rustc_next_trait_solver/src/solve/normalizes_to/anon_const.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ where
1616
) -> QueryResult<I> {
1717
if let Some(normalized_const) = self.evaluate_const(
1818
goal.param_env,
19-
ty::UnevaluatedConst::new(goal.predicate.alias.def_id, goal.predicate.alias.args),
19+
ty::UnevaluatedConst::new(
20+
goal.predicate.alias.def_id.try_into().unwrap(),
21+
goal.predicate.alias.args,
22+
),
2023
) {
2124
self.instantiate_normalizes_to_term(goal, normalized_const.into());
2225
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)

compiler/rustc_type_ir/src/const_kind.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,15 @@ impl<I: Interner> fmt::Debug for ConstKind<I> {
7272
derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext)
7373
)]
7474
pub struct UnevaluatedConst<I: Interner> {
75-
pub def: I::DefId,
75+
pub def: I::UnevaluatedConstId,
7676
pub args: I::GenericArgs,
7777
}
7878

7979
impl<I: Interner> Eq for UnevaluatedConst<I> {}
8080

8181
impl<I: Interner> UnevaluatedConst<I> {
8282
#[inline]
83-
pub fn new(def: I::DefId, args: I::GenericArgs) -> UnevaluatedConst<I> {
83+
pub fn new(def: I::UnevaluatedConstId, args: I::GenericArgs) -> UnevaluatedConst<I> {
8484
UnevaluatedConst { def, args }
8585
}
8686
}

compiler/rustc_type_ir/src/interner.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub trait Interner:
5353
type CoroutineId: SpecificDefId<Self>;
5454
type AdtId: SpecificDefId<Self>;
5555
type ImplId: SpecificDefId<Self>;
56+
type UnevaluatedConstId: SpecificDefId<Self>;
5657
type Span: Span<Self>;
5758

5859
type GenericArgs: GenericArgs<Self>;
@@ -341,7 +342,10 @@ pub trait Interner:
341342

342343
fn as_adt_lang_item(self, def_id: Self::AdtId) -> Option<SolverAdtLangItem>;
343344

344-
fn associated_type_def_ids(self, def_id: Self::DefId) -> impl IntoIterator<Item = Self::DefId>;
345+
fn associated_type_def_ids(
346+
self,
347+
def_id: Self::TraitId,
348+
) -> impl IntoIterator<Item = Self::DefId>;
345349

346350
fn for_each_relevant_impl(
347351
self,

compiler/rustc_type_ir/src/predicate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ impl<I: Interner> AliasTerm<I> {
655655
| AliasTermKind::UnevaluatedConst
656656
| AliasTermKind::ProjectionConst => I::Const::new_unevaluated(
657657
interner,
658-
ty::UnevaluatedConst::new(self.def_id, self.args),
658+
ty::UnevaluatedConst::new(self.def_id.try_into().unwrap(), self.args),
659659
)
660660
.into(),
661661
}
@@ -747,7 +747,7 @@ impl<I: Interner> From<ty::AliasTy<I>> for AliasTerm<I> {
747747

748748
impl<I: Interner> From<ty::UnevaluatedConst<I>> for AliasTerm<I> {
749749
fn from(ct: ty::UnevaluatedConst<I>) -> Self {
750-
AliasTerm { args: ct.args, def_id: ct.def, _use_alias_term_new_instead: () }
750+
AliasTerm { args: ct.args, def_id: ct.def.into(), _use_alias_term_new_instead: () }
751751
}
752752
}
753753

compiler/rustc_type_ir/src/relate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,8 @@ pub fn structurally_relate_consts<I: Interner, R: TypeRelation<I>>(
608608
// be stabilized.
609609
(ty::ConstKind::Unevaluated(au), ty::ConstKind::Unevaluated(bu)) if au.def == bu.def => {
610610
if cfg!(debug_assertions) {
611-
let a_ty = cx.type_of(au.def).instantiate(cx, au.args);
612-
let b_ty = cx.type_of(bu.def).instantiate(cx, bu.args);
611+
let a_ty = cx.type_of(au.def.into()).instantiate(cx, au.args);
612+
let b_ty = cx.type_of(bu.def.into()).instantiate(cx, bu.args);
613613
assert_eq!(a_ty, b_ty);
614614
}
615615

0 commit comments

Comments
 (0)