Rollup merge of #146111 - ChayimFriedman2:more-ns-specific-defid, r=lcnr

Migrate more things in the new solver to specific `DefId`s

Continuation of https://github.com/rust-lang/rust/pull/145377. I migrated the rest of the types, except aliases.

Aliases are problematic because opaques and associated types share the same type in the new solver. `@jackh726,` `@lcnr,` `@ShoyuVanilla` I'd like to hear ideas here. Anyway, even if we do nothing with them we already got a substantial improvement.

r? types
This commit is contained in:
Matthias Krüger
2025-09-08 16:34:55 +02:00
committed by GitHub
17 changed files with 154 additions and 80 deletions

View File

@@ -52,7 +52,7 @@ use rustc_session::{Limit, Session};
use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId}; use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId};
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
use rustc_type_ir::TyKind::*; use rustc_type_ir::TyKind::*;
use rustc_type_ir::lang_items::{SolverLangItem, SolverTraitLangItem}; use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
pub use rustc_type_ir::lift::Lift; pub use rustc_type_ir::lift::Lift;
use rustc_type_ir::{ use rustc_type_ir::{
CollectAndApply, Interner, TypeFlags, TypeFoldable, WithCachedTypeInfo, elaborate, search_graph, CollectAndApply, Interner, TypeFlags, TypeFoldable, WithCachedTypeInfo, elaborate, search_graph,
@@ -94,6 +94,13 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
type DefId = DefId; type DefId = DefId;
type LocalDefId = LocalDefId; type LocalDefId = LocalDefId;
type TraitId = DefId; type TraitId = DefId;
type ForeignId = DefId;
type FunctionId = DefId;
type ClosureId = DefId;
type CoroutineClosureId = DefId;
type CoroutineId = DefId;
type AdtId = DefId;
type ImplId = DefId;
type Span = Span; type Span = Span;
type GenericArgs = ty::GenericArgsRef<'tcx>; type GenericArgs = ty::GenericArgsRef<'tcx>;
@@ -492,6 +499,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
self.require_lang_item(solver_trait_lang_item_to_lang_item(lang_item), DUMMY_SP) self.require_lang_item(solver_trait_lang_item_to_lang_item(lang_item), DUMMY_SP)
} }
fn require_adt_lang_item(self, lang_item: SolverAdtLangItem) -> DefId {
self.require_lang_item(solver_adt_lang_item_to_lang_item(lang_item), DUMMY_SP)
}
fn is_lang_item(self, def_id: DefId, lang_item: SolverLangItem) -> bool { fn is_lang_item(self, def_id: DefId, lang_item: SolverLangItem) -> bool {
self.is_lang_item(def_id, solver_lang_item_to_lang_item(lang_item)) self.is_lang_item(def_id, solver_lang_item_to_lang_item(lang_item))
} }
@@ -500,6 +511,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
self.is_lang_item(def_id, solver_trait_lang_item_to_lang_item(lang_item)) self.is_lang_item(def_id, solver_trait_lang_item_to_lang_item(lang_item))
} }
fn is_adt_lang_item(self, def_id: DefId, lang_item: SolverAdtLangItem) -> bool {
self.is_lang_item(def_id, solver_adt_lang_item_to_lang_item(lang_item))
}
fn is_default_trait(self, def_id: DefId) -> bool { fn is_default_trait(self, def_id: DefId) -> bool {
self.is_default_trait(def_id) self.is_default_trait(def_id)
} }
@@ -512,6 +527,10 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
lang_item_to_solver_trait_lang_item(self.lang_items().from_def_id(def_id)?) lang_item_to_solver_trait_lang_item(self.lang_items().from_def_id(def_id)?)
} }
fn as_adt_lang_item(self, def_id: DefId) -> Option<SolverAdtLangItem> {
lang_item_to_solver_adt_lang_item(self.lang_items().from_def_id(def_id)?)
}
fn associated_type_def_ids(self, def_id: DefId) -> impl IntoIterator<Item = DefId> { fn associated_type_def_ids(self, def_id: DefId) -> impl IntoIterator<Item = DefId> {
self.associated_items(def_id) self.associated_items(def_id)
.in_definition_order() .in_definition_order()
@@ -783,6 +802,13 @@ bidirectional_lang_item_map! {
DynMetadata, DynMetadata,
FutureOutput, FutureOutput,
Metadata, Metadata,
// tidy-alphabetical-end
}
bidirectional_lang_item_map! {
SolverAdtLangItem, lang_item_to_solver_adt_lang_item, solver_adt_lang_item_to_lang_item;
// tidy-alphabetical-start
Option, Option,
Poll, Poll,
// tidy-alphabetical-end // tidy-alphabetical-end

View File

@@ -435,7 +435,21 @@ where
} }
} }
ty::Error(_) => ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)), ty::Error(_) => ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)),
ty::Closure(did, ..) | ty::CoroutineClosure(did, ..) | ty::Coroutine(did, ..) => { ty::Closure(did, ..) => {
if self.def_id_is_local(did) {
ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty))
} else {
self.found_non_local_ty(ty)
}
}
ty::CoroutineClosure(did, ..) => {
if self.def_id_is_local(did) {
ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty))
} else {
self.found_non_local_ty(ty)
}
}
ty::Coroutine(did, ..) => {
if self.def_id_is_local(did) { if self.def_id_is_local(did) {
ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)) ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty))
} else { } else {

View File

@@ -76,7 +76,7 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
&self, &self,
goal_trait_ref: ty::TraitRef<Self::Interner>, goal_trait_ref: ty::TraitRef<Self::Interner>,
trait_assoc_def_id: <Self::Interner as Interner>::DefId, trait_assoc_def_id: <Self::Interner as Interner>::DefId,
impl_def_id: <Self::Interner as Interner>::DefId, impl_def_id: <Self::Interner as Interner>::ImplId,
) -> Result< ) -> Result<
Option<<Self::Interner as Interner>::DefId>, Option<<Self::Interner as Interner>::DefId>,
<Self::Interner as Interner>::ErrorGuaranteed, <Self::Interner as Interner>::ErrorGuaranteed,

View File

@@ -186,7 +186,7 @@ where
fn consider_impl_candidate( fn consider_impl_candidate(
ecx: &mut EvalCtxt<'_, D>, ecx: &mut EvalCtxt<'_, D>,
goal: Goal<I, Self>, goal: Goal<I, Self>,
impl_def_id: I::DefId, impl_def_id: I::ImplId,
) -> Result<Candidate<I>, NoSolution>; ) -> Result<Candidate<I>, NoSolution>;
/// If the predicate contained an error, we want to avoid emitting unnecessary trait /// If the predicate contained an error, we want to avoid emitting unnecessary trait

View File

@@ -605,7 +605,7 @@ fn coroutine_closure_to_certain_coroutine<I: Interner>(
cx: I, cx: I,
goal_kind: ty::ClosureKind, goal_kind: ty::ClosureKind,
goal_region: I::Region, goal_region: I::Region,
def_id: I::DefId, def_id: I::CoroutineClosureId,
args: ty::CoroutineClosureArgs<I>, args: ty::CoroutineClosureArgs<I>,
sig: ty::CoroutineClosureSignature<I>, sig: ty::CoroutineClosureSignature<I>,
) -> I::Ty { ) -> I::Ty {
@@ -629,7 +629,7 @@ fn coroutine_closure_to_ambiguous_coroutine<I: Interner>(
cx: I, cx: I,
goal_kind: ty::ClosureKind, goal_kind: ty::ClosureKind,
goal_region: I::Region, goal_region: I::Region,
def_id: I::DefId, def_id: I::CoroutineClosureId,
args: ty::CoroutineClosureArgs<I>, args: ty::CoroutineClosureArgs<I>,
sig: ty::CoroutineClosureSignature<I>, sig: ty::CoroutineClosureSignature<I>,
) -> I::Ty { ) -> I::Ty {
@@ -664,7 +664,7 @@ fn coroutine_closure_to_ambiguous_coroutine<I: Interner>(
pub(in crate::solve) fn extract_fn_def_from_const_callable<I: Interner>( pub(in crate::solve) fn extract_fn_def_from_const_callable<I: Interner>(
cx: I, cx: I,
self_ty: I::Ty, self_ty: I::Ty,
) -> Result<(ty::Binder<I, (I::FnInputTys, I::Ty)>, I::DefId, I::GenericArgs), NoSolution> { ) -> Result<(ty::Binder<I, (I::FnInputTys, I::Ty)>, I::FunctionId, I::GenericArgs), NoSolution> {
match self_ty.kind() { match self_ty.kind() {
ty::FnDef(def_id, args) => { ty::FnDef(def_id, args) => {
let sig = cx.fn_sig(def_id); let sig = cx.fn_sig(def_id);

View File

@@ -123,7 +123,7 @@ where
fn consider_impl_candidate( fn consider_impl_candidate(
ecx: &mut EvalCtxt<'_, D>, ecx: &mut EvalCtxt<'_, D>,
goal: Goal<I, Self>, goal: Goal<I, Self>,
impl_def_id: I::DefId, impl_def_id: I::ImplId,
) -> Result<Candidate<I>, NoSolution> { ) -> Result<Candidate<I>, NoSolution> {
let cx = ecx.cx(); let cx = ecx.cx();
@@ -152,20 +152,20 @@ where
} }
ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| { ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
let impl_args = ecx.fresh_args_for_item(impl_def_id); let impl_args = ecx.fresh_args_for_item(impl_def_id.into());
ecx.record_impl_args(impl_args); ecx.record_impl_args(impl_args);
let impl_trait_ref = impl_trait_ref.instantiate(cx, impl_args); let impl_trait_ref = impl_trait_ref.instantiate(cx, impl_args);
ecx.eq(goal.param_env, goal.predicate.trait_ref, impl_trait_ref)?; ecx.eq(goal.param_env, goal.predicate.trait_ref, impl_trait_ref)?;
let where_clause_bounds = cx let where_clause_bounds = cx
.predicates_of(impl_def_id) .predicates_of(impl_def_id.into())
.iter_instantiated(cx, impl_args) .iter_instantiated(cx, impl_args)
.map(|pred| goal.with(cx, pred)); .map(|pred| goal.with(cx, pred));
ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds); ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds);
// For this impl to be `const`, we need to check its `[const]` bounds too. // For this impl to be `const`, we need to check its `[const]` bounds too.
let const_conditions = cx let const_conditions = cx
.const_conditions(impl_def_id) .const_conditions(impl_def_id.into())
.iter_instantiated(cx, impl_args) .iter_instantiated(cx, impl_args)
.map(|bound_trait_ref| { .map(|bound_trait_ref| {
goal.with( goal.with(
@@ -240,7 +240,7 @@ where
ty::TraitRef::new(cx, cx.require_trait_lang_item(SolverTraitLangItem::Sized), [output]) ty::TraitRef::new(cx, cx.require_trait_lang_item(SolverTraitLangItem::Sized), [output])
}); });
let requirements = cx let requirements = cx
.const_conditions(def_id) .const_conditions(def_id.into())
.iter_instantiated(cx, args) .iter_instantiated(cx, args)
.map(|trait_ref| { .map(|trait_ref| {
( (

View File

@@ -1092,7 +1092,7 @@ where
&self, &self,
goal_trait_ref: ty::TraitRef<I>, goal_trait_ref: ty::TraitRef<I>,
trait_assoc_def_id: I::DefId, trait_assoc_def_id: I::DefId,
impl_def_id: I::DefId, impl_def_id: I::ImplId,
) -> Result<Option<I::DefId>, I::ErrorGuaranteed> { ) -> Result<Option<I::DefId>, I::ErrorGuaranteed> {
self.delegate.fetch_eligible_assoc_item(goal_trait_ref, trait_assoc_def_id, impl_def_id) self.delegate.fetch_eligible_assoc_item(goal_trait_ref, trait_assoc_def_id, impl_def_id)
} }

View File

@@ -5,7 +5,7 @@ mod opaque_types;
use rustc_type_ir::fast_reject::DeepRejectCtxt; use rustc_type_ir::fast_reject::DeepRejectCtxt;
use rustc_type_ir::inherent::*; use rustc_type_ir::inherent::*;
use rustc_type_ir::lang_items::{SolverLangItem, SolverTraitLangItem}; use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
use rustc_type_ir::solve::SizedTraitKind; use rustc_type_ir::solve::SizedTraitKind;
use rustc_type_ir::{self as ty, Interner, NormalizesTo, PredicateKind, Upcast as _}; use rustc_type_ir::{self as ty, Interner, NormalizesTo, PredicateKind, Upcast as _};
use tracing::instrument; use tracing::instrument;
@@ -193,7 +193,7 @@ where
fn consider_impl_candidate( fn consider_impl_candidate(
ecx: &mut EvalCtxt<'_, D>, ecx: &mut EvalCtxt<'_, D>,
goal: Goal<I, NormalizesTo<I>>, goal: Goal<I, NormalizesTo<I>>,
impl_def_id: I::DefId, impl_def_id: I::ImplId,
) -> Result<Candidate<I>, NoSolution> { ) -> Result<Candidate<I>, NoSolution> {
let cx = ecx.cx(); let cx = ecx.cx();
@@ -217,13 +217,13 @@ where
}; };
ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| { ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
let impl_args = ecx.fresh_args_for_item(impl_def_id); let impl_args = ecx.fresh_args_for_item(impl_def_id.into());
let impl_trait_ref = impl_trait_ref.instantiate(cx, impl_args); let impl_trait_ref = impl_trait_ref.instantiate(cx, impl_args);
ecx.eq(goal.param_env, goal_trait_ref, impl_trait_ref)?; ecx.eq(goal.param_env, goal_trait_ref, impl_trait_ref)?;
let where_clause_bounds = cx let where_clause_bounds = cx
.predicates_of(impl_def_id) .predicates_of(impl_def_id.into())
.iter_instantiated(cx, impl_args) .iter_instantiated(cx, impl_args)
.map(|pred| goal.with(cx, pred)); .map(|pred| goal.with(cx, pred));
ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds); ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds);
@@ -824,10 +824,10 @@ where
// coroutine yield ty `Poll<Option<I>>`. // coroutine yield ty `Poll<Option<I>>`.
let wrapped_expected_ty = Ty::new_adt( let wrapped_expected_ty = Ty::new_adt(
cx, cx,
cx.adt_def(cx.require_lang_item(SolverLangItem::Poll)), cx.adt_def(cx.require_adt_lang_item(SolverAdtLangItem::Poll)),
cx.mk_args(&[Ty::new_adt( cx.mk_args(&[Ty::new_adt(
cx, cx,
cx.adt_def(cx.require_lang_item(SolverLangItem::Option)), cx.adt_def(cx.require_adt_lang_item(SolverAdtLangItem::Option)),
cx.mk_args(&[expected_ty.into()]), cx.mk_args(&[expected_ty.into()]),
) )
.into()]), .into()]),
@@ -979,7 +979,7 @@ where
fn translate_args( fn translate_args(
&mut self, &mut self,
goal: Goal<I, ty::NormalizesTo<I>>, goal: Goal<I, ty::NormalizesTo<I>>,
impl_def_id: I::DefId, impl_def_id: I::ImplId,
impl_args: I::GenericArgs, impl_args: I::GenericArgs,
impl_trait_ref: rustc_type_ir::TraitRef<I>, impl_trait_ref: rustc_type_ir::TraitRef<I>,
target_container_def_id: I::DefId, target_container_def_id: I::DefId,
@@ -988,14 +988,15 @@ where
Ok(if target_container_def_id == impl_trait_ref.def_id.into() { Ok(if target_container_def_id == impl_trait_ref.def_id.into() {
// Default value from the trait definition. No need to rebase. // Default value from the trait definition. No need to rebase.
goal.predicate.alias.args goal.predicate.alias.args
} else if target_container_def_id == impl_def_id { } else if target_container_def_id == impl_def_id.into() {
// Same impl, no need to fully translate, just a rebase from // Same impl, no need to fully translate, just a rebase from
// the trait is sufficient. // the trait is sufficient.
goal.predicate.alias.args.rebase_onto(cx, impl_trait_ref.def_id.into(), impl_args) goal.predicate.alias.args.rebase_onto(cx, impl_trait_ref.def_id.into(), impl_args)
} else { } else {
let target_args = self.fresh_args_for_item(target_container_def_id); let target_args = self.fresh_args_for_item(target_container_def_id);
let target_trait_ref = let target_trait_ref = cx
cx.impl_trait_ref(target_container_def_id).instantiate(cx, target_args); .impl_trait_ref(target_container_def_id.try_into().unwrap())
.instantiate(cx, target_args);
// Relate source impl to target impl by equating trait refs. // Relate source impl to target impl by equating trait refs.
self.eq(goal.param_env, impl_trait_ref, target_trait_ref)?; self.eq(goal.param_env, impl_trait_ref, target_trait_ref)?;
// Also add predicates since they may be needed to constrain the // Also add predicates since they may be needed to constrain the

View File

@@ -54,7 +54,7 @@ where
fn consider_impl_candidate( fn consider_impl_candidate(
ecx: &mut EvalCtxt<'_, D>, ecx: &mut EvalCtxt<'_, D>,
goal: Goal<I, TraitPredicate<I>>, goal: Goal<I, TraitPredicate<I>>,
impl_def_id: I::DefId, impl_def_id: I::ImplId,
) -> Result<Candidate<I>, NoSolution> { ) -> Result<Candidate<I>, NoSolution> {
let cx = ecx.cx(); let cx = ecx.cx();
@@ -91,13 +91,13 @@ where
}; };
ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| { ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
let impl_args = ecx.fresh_args_for_item(impl_def_id); let impl_args = ecx.fresh_args_for_item(impl_def_id.into());
ecx.record_impl_args(impl_args); ecx.record_impl_args(impl_args);
let impl_trait_ref = impl_trait_ref.instantiate(cx, impl_args); let impl_trait_ref = impl_trait_ref.instantiate(cx, impl_args);
ecx.eq(goal.param_env, goal.predicate.trait_ref, impl_trait_ref)?; ecx.eq(goal.param_env, goal.predicate.trait_ref, impl_trait_ref)?;
let where_clause_bounds = cx let where_clause_bounds = cx
.predicates_of(impl_def_id) .predicates_of(impl_def_id.into())
.iter_instantiated(cx, impl_args) .iter_instantiated(cx, impl_args)
.map(|pred| goal.with(cx, pred)); .map(|pred| goal.with(cx, pred));
ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds); ecx.add_goals(GoalSource::ImplWhereBound, where_clause_bounds);

View File

@@ -122,7 +122,7 @@ pub fn simplify_type<I: Interner>(
ty::Int(int_type) => Some(SimplifiedType::Int(int_type)), ty::Int(int_type) => Some(SimplifiedType::Int(int_type)),
ty::Uint(uint_type) => Some(SimplifiedType::Uint(uint_type)), ty::Uint(uint_type) => Some(SimplifiedType::Uint(uint_type)),
ty::Float(float_type) => Some(SimplifiedType::Float(float_type)), ty::Float(float_type) => Some(SimplifiedType::Float(float_type)),
ty::Adt(def, _) => Some(SimplifiedType::Adt(def.def_id())), ty::Adt(def, _) => Some(SimplifiedType::Adt(def.def_id().into())),
ty::Str => Some(SimplifiedType::Str), ty::Str => Some(SimplifiedType::Str),
ty::Array(..) => Some(SimplifiedType::Array), ty::Array(..) => Some(SimplifiedType::Array),
ty::Slice(..) => Some(SimplifiedType::Slice), ty::Slice(..) => Some(SimplifiedType::Slice),
@@ -135,11 +135,11 @@ pub fn simplify_type<I: Interner>(
_ => Some(SimplifiedType::MarkerTraitObject), _ => Some(SimplifiedType::MarkerTraitObject),
}, },
ty::Ref(_, _, mutbl) => Some(SimplifiedType::Ref(mutbl)), ty::Ref(_, _, mutbl) => Some(SimplifiedType::Ref(mutbl)),
ty::FnDef(def_id, _) | ty::Closure(def_id, _) | ty::CoroutineClosure(def_id, _) => { ty::FnDef(def_id, _) => Some(SimplifiedType::Closure(def_id.into())),
Some(SimplifiedType::Closure(def_id)) ty::Closure(def_id, _) => Some(SimplifiedType::Closure(def_id.into())),
} ty::CoroutineClosure(def_id, _) => Some(SimplifiedType::Closure(def_id.into())),
ty::Coroutine(def_id, _) => Some(SimplifiedType::Coroutine(def_id)), ty::Coroutine(def_id, _) => Some(SimplifiedType::Coroutine(def_id.into())),
ty::CoroutineWitness(def_id, _) => Some(SimplifiedType::CoroutineWitness(def_id)), ty::CoroutineWitness(def_id, _) => Some(SimplifiedType::CoroutineWitness(def_id.into())),
ty::Never => Some(SimplifiedType::Never), ty::Never => Some(SimplifiedType::Never),
ty::Tuple(tys) => Some(SimplifiedType::Tuple(tys.len())), ty::Tuple(tys) => Some(SimplifiedType::Tuple(tys.len())),
ty::FnPtr(sig_tys, _hdr) => { ty::FnPtr(sig_tys, _hdr) => {
@@ -161,7 +161,7 @@ pub fn simplify_type<I: Interner>(
} }
TreatParams::AsRigid | TreatParams::InstantiateWithInfer => None, TreatParams::AsRigid | TreatParams::InstantiateWithInfer => None,
}, },
ty::Foreign(def_id) => Some(SimplifiedType::Foreign(def_id)), ty::Foreign(def_id) => Some(SimplifiedType::Foreign(def_id.into())),
ty::Error(_) => Some(SimplifiedType::Error), ty::Error(_) => Some(SimplifiedType::Error),
ty::Bound(..) | ty::Infer(_) => None, ty::Bound(..) | ty::Infer(_) => None,
} }

View File

@@ -74,7 +74,7 @@ pub trait Ty<I: Interner<Ty = Self>>:
fn new_adt(interner: I, adt_def: I::AdtDef, args: I::GenericArgs) -> Self; fn new_adt(interner: I, adt_def: I::AdtDef, args: I::GenericArgs) -> Self;
fn new_foreign(interner: I, def_id: I::DefId) -> Self; fn new_foreign(interner: I, def_id: I::ForeignId) -> Self;
fn new_dynamic( fn new_dynamic(
interner: I, interner: I,
@@ -83,17 +83,21 @@ pub trait Ty<I: Interner<Ty = Self>>:
kind: ty::DynKind, kind: ty::DynKind,
) -> Self; ) -> Self;
fn new_coroutine(interner: I, def_id: I::DefId, args: I::GenericArgs) -> Self; fn new_coroutine(interner: I, def_id: I::CoroutineId, args: I::GenericArgs) -> Self;
fn new_coroutine_closure(interner: I, def_id: I::DefId, args: I::GenericArgs) -> Self; fn new_coroutine_closure(
interner: I,
def_id: I::CoroutineClosureId,
args: I::GenericArgs,
) -> Self;
fn new_closure(interner: I, def_id: I::DefId, args: I::GenericArgs) -> Self; fn new_closure(interner: I, def_id: I::ClosureId, args: I::GenericArgs) -> Self;
fn new_coroutine_witness(interner: I, def_id: I::DefId, args: I::GenericArgs) -> Self; fn new_coroutine_witness(interner: I, def_id: I::CoroutineId, args: I::GenericArgs) -> Self;
fn new_coroutine_witness_for_coroutine( fn new_coroutine_witness_for_coroutine(
interner: I, interner: I,
def_id: I::DefId, def_id: I::CoroutineId,
coroutine_args: I::GenericArgs, coroutine_args: I::GenericArgs,
) -> Self; ) -> Self;
@@ -112,7 +116,7 @@ pub trait Ty<I: Interner<Ty = Self>>:
It: Iterator<Item = T>, It: Iterator<Item = T>,
T: CollectAndApply<Self, Self>; T: CollectAndApply<Self, Self>;
fn new_fn_def(interner: I, def_id: I::DefId, args: I::GenericArgs) -> Self; fn new_fn_def(interner: I, def_id: I::FunctionId, args: I::GenericArgs) -> Self;
fn new_fn_ptr(interner: I, sig: ty::Binder<I, ty::FnSig<I>>) -> Self; fn new_fn_ptr(interner: I, sig: ty::Binder<I, ty::FnSig<I>>) -> Self;
@@ -599,7 +603,7 @@ pub trait ParamLike: Copy + Debug + Hash + Eq {
} }
pub trait AdtDef<I: Interner>: Copy + Debug + Hash + Eq { pub trait AdtDef<I: Interner>: Copy + Debug + Hash + Eq {
fn def_id(self) -> I::DefId; fn def_id(self) -> I::AdtId;
fn is_struct(self) -> bool; fn is_struct(self) -> bool;
@@ -646,6 +650,16 @@ pub trait DefId<I: Interner>: Copy + Debug + Hash + Eq + TypeFoldable<I> {
fn as_local(self) -> Option<I::LocalDefId>; fn as_local(self) -> Option<I::LocalDefId>;
} }
pub trait SpecificDefId<I: Interner>:
DefId<I> + Into<I::DefId> + TryFrom<I::DefId, Error: std::fmt::Debug>
{
}
impl<I: Interner, T: DefId<I> + Into<I::DefId> + TryFrom<I::DefId, Error: std::fmt::Debug>>
SpecificDefId<I> for T
{
}
pub trait BoundExistentialPredicates<I: Interner>: pub trait BoundExistentialPredicates<I: Interner>:
Copy + Debug + Hash + Eq + Relate<I> + SliceLike<Item = ty::Binder<I, ty::ExistentialPredicate<I>>> Copy + Debug + Hash + Eq + Relate<I> + SliceLike<Item = ty::Binder<I, ty::ExistentialPredicate<I>>>
{ {

View File

@@ -9,7 +9,7 @@ use rustc_index::bit_set::DenseBitSet;
use crate::fold::TypeFoldable; use crate::fold::TypeFoldable;
use crate::inherent::*; use crate::inherent::*;
use crate::ir_print::IrPrint; use crate::ir_print::IrPrint;
use crate::lang_items::{SolverLangItem, SolverTraitLangItem}; use crate::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
use crate::relate::Relate; use crate::relate::Relate;
use crate::solve::{ use crate::solve::{
CanonicalInput, ExternalConstraintsData, PredefinedOpaquesData, QueryResult, inspect, CanonicalInput, ExternalConstraintsData, PredefinedOpaquesData, QueryResult, inspect,
@@ -41,13 +41,20 @@ pub trait Interner:
type DefId: DefId<Self>; type DefId: DefId<Self>;
type LocalDefId: Copy + Debug + Hash + Eq + Into<Self::DefId> + TypeFoldable<Self>; type LocalDefId: Copy + Debug + Hash + Eq + Into<Self::DefId> + TypeFoldable<Self>;
/// A `DefId` of a trait. // Various more specific `DefId`s.
/// //
/// In rustc this is just a `DefId`, but rust-analyzer uses different types for different items. // rustc just defines them all to be `DefId`, but rust-analyzer uses different types so this is convenient for it.
/// //
/// Note: The `TryFrom<DefId>` always succeeds (in rustc), so don't use it to check if some `DefId` // Note: The `TryFrom<DefId>` always succeeds (in rustc), so don't use it to check if some `DefId`
/// is a trait! // is of some specific type!
type TraitId: DefId<Self> + Into<Self::DefId> + TryFrom<Self::DefId, Error: std::fmt::Debug>; type TraitId: SpecificDefId<Self>;
type ForeignId: SpecificDefId<Self>;
type FunctionId: SpecificDefId<Self>;
type ClosureId: SpecificDefId<Self>;
type CoroutineClosureId: SpecificDefId<Self>;
type CoroutineId: SpecificDefId<Self>;
type AdtId: SpecificDefId<Self>;
type ImplId: SpecificDefId<Self>;
type Span: Span<Self>; type Span: Span<Self>;
type GenericArgs: GenericArgs<Self>; type GenericArgs: GenericArgs<Self>;
@@ -199,7 +206,7 @@ pub trait Interner:
-> ty::EarlyBinder<Self, Self::Ty>; -> ty::EarlyBinder<Self, Self::Ty>;
type AdtDef: AdtDef<Self>; type AdtDef: AdtDef<Self>;
fn adt_def(self, adt_def_id: Self::DefId) -> Self::AdtDef; fn adt_def(self, adt_def_id: Self::AdtId) -> Self::AdtDef;
fn alias_ty_kind(self, alias: ty::AliasTy<Self>) -> ty::AliasTyKind; fn alias_ty_kind(self, alias: ty::AliasTy<Self>) -> ty::AliasTyKind;
@@ -240,17 +247,17 @@ pub trait Interner:
fn coroutine_hidden_types( fn coroutine_hidden_types(
self, self,
def_id: Self::DefId, def_id: Self::CoroutineId,
) -> ty::EarlyBinder<Self, ty::Binder<Self, ty::CoroutineWitnessTypes<Self>>>; ) -> ty::EarlyBinder<Self, ty::Binder<Self, ty::CoroutineWitnessTypes<Self>>>;
fn fn_sig( fn fn_sig(
self, self,
def_id: Self::DefId, def_id: Self::FunctionId,
) -> ty::EarlyBinder<Self, ty::Binder<Self, ty::FnSig<Self>>>; ) -> ty::EarlyBinder<Self, ty::Binder<Self, ty::FnSig<Self>>>;
fn coroutine_movability(self, def_id: Self::DefId) -> Movability; fn coroutine_movability(self, def_id: Self::CoroutineId) -> Movability;
fn coroutine_for_closure(self, def_id: Self::DefId) -> Self::DefId; fn coroutine_for_closure(self, def_id: Self::CoroutineClosureId) -> Self::CoroutineId;
fn generics_require_sized_self(self, def_id: Self::DefId) -> bool; fn generics_require_sized_self(self, def_id: Self::DefId) -> bool;
@@ -293,11 +300,11 @@ pub trait Interner:
/// and filtering them to the outlives predicates. This is purely for performance. /// and filtering them to the outlives predicates. This is purely for performance.
fn impl_super_outlives( fn impl_super_outlives(
self, self,
impl_def_id: Self::DefId, impl_def_id: Self::ImplId,
) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>; ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;
fn impl_is_const(self, def_id: Self::DefId) -> bool; fn impl_is_const(self, def_id: Self::ImplId) -> bool;
fn fn_is_const(self, def_id: Self::DefId) -> bool; fn fn_is_const(self, def_id: Self::FunctionId) -> bool;
fn alias_has_const_conditions(self, def_id: Self::DefId) -> bool; fn alias_has_const_conditions(self, def_id: Self::DefId) -> bool;
fn const_conditions( fn const_conditions(
self, self,
@@ -308,42 +315,49 @@ pub trait Interner:
def_id: Self::DefId, def_id: Self::DefId,
) -> ty::EarlyBinder<Self, impl IntoIterator<Item = ty::Binder<Self, ty::TraitRef<Self>>>>; ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = ty::Binder<Self, ty::TraitRef<Self>>>>;
fn impl_self_is_guaranteed_unsized(self, def_id: Self::DefId) -> bool; fn impl_self_is_guaranteed_unsized(self, def_id: Self::ImplId) -> bool;
fn has_target_features(self, def_id: Self::DefId) -> bool; fn has_target_features(self, def_id: Self::FunctionId) -> bool;
fn require_lang_item(self, lang_item: SolverLangItem) -> Self::DefId; fn require_lang_item(self, lang_item: SolverLangItem) -> Self::DefId;
fn require_trait_lang_item(self, lang_item: SolverTraitLangItem) -> Self::TraitId; fn require_trait_lang_item(self, lang_item: SolverTraitLangItem) -> Self::TraitId;
fn require_adt_lang_item(self, lang_item: SolverAdtLangItem) -> Self::AdtId;
fn is_lang_item(self, def_id: Self::DefId, lang_item: SolverLangItem) -> bool; fn is_lang_item(self, def_id: Self::DefId, lang_item: SolverLangItem) -> bool;
fn is_trait_lang_item(self, def_id: Self::TraitId, lang_item: SolverTraitLangItem) -> bool; fn is_trait_lang_item(self, def_id: Self::TraitId, lang_item: SolverTraitLangItem) -> bool;
fn is_adt_lang_item(self, def_id: Self::AdtId, lang_item: SolverAdtLangItem) -> bool;
fn is_default_trait(self, def_id: Self::TraitId) -> bool; fn is_default_trait(self, def_id: Self::TraitId) -> bool;
fn as_lang_item(self, def_id: Self::DefId) -> Option<SolverLangItem>; fn as_lang_item(self, def_id: Self::DefId) -> Option<SolverLangItem>;
fn as_trait_lang_item(self, def_id: Self::TraitId) -> Option<SolverTraitLangItem>; fn as_trait_lang_item(self, def_id: Self::TraitId) -> Option<SolverTraitLangItem>;
fn as_adt_lang_item(self, def_id: Self::AdtId) -> Option<SolverAdtLangItem>;
fn associated_type_def_ids(self, def_id: Self::DefId) -> impl IntoIterator<Item = Self::DefId>; fn associated_type_def_ids(self, def_id: Self::DefId) -> impl IntoIterator<Item = Self::DefId>;
fn for_each_relevant_impl( fn for_each_relevant_impl(
self, self,
trait_def_id: Self::TraitId, trait_def_id: Self::TraitId,
self_ty: Self::Ty, self_ty: Self::Ty,
f: impl FnMut(Self::DefId), f: impl FnMut(Self::ImplId),
); );
fn has_item_definition(self, def_id: Self::DefId) -> bool; fn has_item_definition(self, def_id: Self::DefId) -> bool;
fn impl_specializes(self, impl_def_id: Self::DefId, victim_def_id: Self::DefId) -> bool; fn impl_specializes(self, impl_def_id: Self::ImplId, victim_def_id: Self::ImplId) -> bool;
fn impl_is_default(self, impl_def_id: Self::DefId) -> bool; fn impl_is_default(self, impl_def_id: Self::ImplId) -> bool;
fn impl_trait_ref(self, impl_def_id: Self::DefId) -> ty::EarlyBinder<Self, ty::TraitRef<Self>>; fn impl_trait_ref(self, impl_def_id: Self::ImplId)
-> ty::EarlyBinder<Self, ty::TraitRef<Self>>;
fn impl_polarity(self, impl_def_id: Self::DefId) -> ty::ImplPolarity; fn impl_polarity(self, impl_def_id: Self::ImplId) -> ty::ImplPolarity;
fn trait_is_auto(self, trait_def_id: Self::TraitId) -> bool; fn trait_is_auto(self, trait_def_id: Self::TraitId) -> bool;
@@ -364,13 +378,13 @@ pub trait Interner:
fn delay_bug(self, msg: impl ToString) -> Self::ErrorGuaranteed; fn delay_bug(self, msg: impl ToString) -> Self::ErrorGuaranteed;
fn is_general_coroutine(self, coroutine_def_id: Self::DefId) -> bool; fn is_general_coroutine(self, coroutine_def_id: Self::CoroutineId) -> bool;
fn coroutine_is_async(self, coroutine_def_id: Self::DefId) -> bool; fn coroutine_is_async(self, coroutine_def_id: Self::CoroutineId) -> bool;
fn coroutine_is_gen(self, coroutine_def_id: Self::DefId) -> bool; fn coroutine_is_gen(self, coroutine_def_id: Self::CoroutineId) -> bool;
fn coroutine_is_async_gen(self, coroutine_def_id: Self::DefId) -> bool; fn coroutine_is_async_gen(self, coroutine_def_id: Self::CoroutineId) -> bool;
type UnsizingParams: Deref<Target = DenseBitSet<u32>>; type UnsizingParams: Deref<Target = DenseBitSet<u32>>;
fn unsizing_params_for_adt(self, adt_def_id: Self::DefId) -> Self::UnsizingParams; fn unsizing_params_for_adt(self, adt_def_id: Self::AdtId) -> Self::UnsizingParams;
fn anonymize_bound_vars<T: TypeFoldable<Self>>( fn anonymize_bound_vars<T: TypeFoldable<Self>>(
self, self,

View File

@@ -11,6 +11,11 @@ pub enum SolverLangItem {
DynMetadata, DynMetadata,
FutureOutput, FutureOutput,
Metadata, Metadata,
// tidy-alphabetical-end
}
pub enum SolverAdtLangItem {
// tidy-alphabetical-start
Option, Option,
Poll, Poll,
// tidy-alphabetical-end // tidy-alphabetical-end

View File

@@ -405,7 +405,7 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>(
Ok(if a_args.is_empty() { Ok(if a_args.is_empty() {
a a
} else { } else {
let args = relation.relate_item_args(a_def.def_id(), a_args, b_args)?; let args = relation.relate_item_args(a_def.def_id().into(), a_args, b_args)?;
if args == a_args { a } else { Ty::new_adt(cx, a_def, args) } if args == a_args { a } else { Ty::new_adt(cx, a_def, args) }
}) })
} }
@@ -524,7 +524,7 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>(
Ok(if a_args.is_empty() { Ok(if a_args.is_empty() {
a a
} else { } else {
let args = relation.relate_item_args(a_def_id, a_args, b_args)?; let args = relation.relate_item_args(a_def_id.into(), a_args, b_args)?;
if args == a_args { a } else { Ty::new_fn_def(cx, a_def_id, args) } if args == a_args { a } else { Ty::new_fn_def(cx, a_def_id, args) }
}) })
} }

View File

@@ -136,7 +136,7 @@ pub enum CandidateSource<I: Interner> {
/// let y = x.clone(); /// let y = x.clone();
/// } /// }
/// ``` /// ```
Impl(I::DefId), Impl(I::ImplId),
/// A builtin impl generated by the compiler. When adding a new special /// A builtin impl generated by the compiler. When adding a new special
/// trait, try to use actual impls whenever possible. Builtin impls should /// trait, try to use actual impls whenever possible. Builtin impls should
/// only be used in cases where the impl cannot be manually be written. /// only be used in cases where the impl cannot be manually be written.

View File

@@ -101,7 +101,7 @@ pub enum TyKind<I: Interner> {
Adt(I::AdtDef, I::GenericArgs), Adt(I::AdtDef, I::GenericArgs),
/// An unsized FFI type that is opaque to Rust. Written as `extern type T`. /// An unsized FFI type that is opaque to Rust. Written as `extern type T`.
Foreign(I::DefId), Foreign(I::ForeignId),
/// The pointee of a string slice. Written as `str`. /// The pointee of a string slice. Written as `str`.
Str, Str,
@@ -137,7 +137,7 @@ pub enum TyKind<I: Interner> {
/// fn foo() -> i32 { 1 } /// fn foo() -> i32 { 1 }
/// let bar = foo; // bar: fn() -> i32 {foo} /// let bar = foo; // bar: fn() -> i32 {foo}
/// ``` /// ```
FnDef(I::DefId, I::GenericArgs), FnDef(I::FunctionId, I::GenericArgs),
/// A pointer to a function. Written as `fn() -> i32`. /// A pointer to a function. Written as `fn() -> i32`.
/// ///
@@ -172,21 +172,21 @@ pub enum TyKind<I: Interner> {
/// Closure args contain both the - potentially instantiated - generic parameters /// Closure args contain both the - potentially instantiated - generic parameters
/// of its parent and some synthetic parameters. See the documentation for /// of its parent and some synthetic parameters. See the documentation for
/// `ClosureArgs` for more details. /// `ClosureArgs` for more details.
Closure(I::DefId, I::GenericArgs), Closure(I::ClosureId, I::GenericArgs),
/// The anonymous type of a closure. Used to represent the type of `async |a| a`. /// The anonymous type of a closure. Used to represent the type of `async |a| a`.
/// ///
/// Coroutine-closure args contain both the - potentially instantiated - generic /// Coroutine-closure args contain both the - potentially instantiated - generic
/// parameters of its parent and some synthetic parameters. See the documentation /// parameters of its parent and some synthetic parameters. See the documentation
/// for `CoroutineClosureArgs` for more details. /// for `CoroutineClosureArgs` for more details.
CoroutineClosure(I::DefId, I::GenericArgs), CoroutineClosure(I::CoroutineClosureId, I::GenericArgs),
/// The anonymous type of a coroutine. Used to represent the type of /// The anonymous type of a coroutine. Used to represent the type of
/// `|a| yield a`. /// `|a| yield a`.
/// ///
/// For more info about coroutine args, visit the documentation for /// For more info about coroutine args, visit the documentation for
/// `CoroutineArgs`. /// `CoroutineArgs`.
Coroutine(I::DefId, I::GenericArgs), Coroutine(I::CoroutineId, I::GenericArgs),
/// A type representing the types stored inside a coroutine. /// A type representing the types stored inside a coroutine.
/// This should only appear as part of the `CoroutineArgs`. /// This should only appear as part of the `CoroutineArgs`.
@@ -211,7 +211,7 @@ pub enum TyKind<I: Interner> {
/// } /// }
/// # ; /// # ;
/// ``` /// ```
CoroutineWitness(I::DefId, I::GenericArgs), CoroutineWitness(I::CoroutineId, I::GenericArgs),
/// The never type `!`. /// The never type `!`.
Never, Never,

View File

@@ -391,7 +391,7 @@ impl<I: Interner> CoroutineClosureSignature<I> {
cx: I, cx: I,
parent_args: I::GenericArgsSlice, parent_args: I::GenericArgsSlice,
coroutine_kind_ty: I::Ty, coroutine_kind_ty: I::Ty,
coroutine_def_id: I::DefId, coroutine_def_id: I::CoroutineId,
tupled_upvars_ty: I::Ty, tupled_upvars_ty: I::Ty,
) -> I::Ty { ) -> I::Ty {
let coroutine_args = ty::CoroutineArgs::new( let coroutine_args = ty::CoroutineArgs::new(
@@ -418,7 +418,7 @@ impl<I: Interner> CoroutineClosureSignature<I> {
self, self,
cx: I, cx: I,
parent_args: I::GenericArgsSlice, parent_args: I::GenericArgsSlice,
coroutine_def_id: I::DefId, coroutine_def_id: I::CoroutineId,
goal_kind: ty::ClosureKind, goal_kind: ty::ClosureKind,
env_region: I::Region, env_region: I::Region,
closure_tupled_upvars_ty: I::Ty, closure_tupled_upvars_ty: I::Ty,