Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions compiler/rustc_middle/src/ty/context/impl_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_hir::def::{CtorKind, CtorOf, DefKind};
use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::lang_items::LangItem;
use rustc_span::{DUMMY_SP, Span, Symbol};
use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverProjectionLangItem, SolverTraitLangItem};
use rustc_type_ir::{CollectAndApply, Interner, TypeFoldable, Unnormalized, search_graph};

use crate::dep_graph::{DepKind, DepNodeIndex};
Expand Down Expand Up @@ -39,6 +39,17 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
type AdtId = DefId;
type ImplId = DefId;
type UnevaluatedConstId = DefId;
type DefinitionAssocTyId = DefId;
type DefinitionAssocConstId = DefId;
type DefinitionAssocTermId = DefId;
type OpaqueTyId = DefId;
type LocalOpaqueTyId = LocalDefId;
type FreeTyAliasId = DefId;
type FreeConstAliasId = DefId;
type FreeTermAliasId = DefId;
type ImplOrTraitAssocTyId = DefId;
type ImplOrTraitAssocConstId = DefId;
type ImplOrTraitAssocTermId = DefId;
type Span = Span;

type GenericArgs = ty::GenericArgsRef<'tcx>;
Expand Down Expand Up @@ -285,7 +296,11 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
self.mk_type_list_from_iter(args)
}

fn parent(self, def_id: DefId) -> DefId {
fn projection_parent(self, def_id: Self::DefinitionAssocTermId) -> Self::TraitId {
self.parent(def_id)
}

fn impl_or_trait_assoc_term_parent(self, def_id: Self::ImplOrTraitAssocTyId) -> Self::ImplId {
self.parent(def_id)
}

Expand Down Expand Up @@ -443,7 +458,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
!self.codegen_fn_attrs(def_id).target_features.is_empty()
}

fn require_lang_item(self, lang_item: SolverLangItem) -> DefId {
fn require_projection_lang_item(self, lang_item: SolverProjectionLangItem) -> DefId {
self.require_lang_item(solver_lang_item_to_lang_item(lang_item), DUMMY_SP)
}

Expand All @@ -455,7 +470,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
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_projection_lang_item(self, def_id: DefId, lang_item: SolverProjectionLangItem) -> bool {
self.is_lang_item(def_id, solver_lang_item_to_lang_item(lang_item))
}

Expand All @@ -475,7 +490,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
self.is_sizedness_trait(def_id)
}

fn as_lang_item(self, def_id: DefId) -> Option<SolverLangItem> {
fn as_projection_lang_item(self, def_id: DefId) -> Option<SolverProjectionLangItem> {
lang_item_to_solver_lang_item(self.lang_items().from_def_id(def_id)?)
}

Expand Down Expand Up @@ -754,7 +769,7 @@ macro_rules! bidirectional_lang_item_map {
}

bidirectional_lang_item_map! {
SolverLangItem, fn lang_item_to_solver_lang_item, fn solver_lang_item_to_lang_item;
SolverProjectionLangItem, fn lang_item_to_solver_lang_item, fn solver_lang_item_to_lang_item;

// tidy-alphabetical-start
AsyncFnKindUpvars,
Expand Down Expand Up @@ -788,7 +803,6 @@ bidirectional_lang_item_map! {
AsyncFnKindHelper,
AsyncFnMut,
AsyncFnOnce,
AsyncFnOnceOutput,
AsyncIterator,
BikeshedGuaranteedNoDrop,
Clone,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_next_trait_solver/src/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {

fn add_item_bounds_for_hidden_type(
&self,
def_id: <Self::Interner as Interner>::DefId,
def_id: <Self::Interner as Interner>::OpaqueTyId,
args: <Self::Interner as Interner>::GenericArgs,
param_env: <Self::Interner as Interner>::ParamEnv,
hidden_ty: <Self::Interner as Interner>::Ty,
Expand All @@ -77,10 +77,10 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
fn fetch_eligible_assoc_item(
&self,
goal_trait_ref: ty::TraitRef<Self::Interner>,
trait_assoc_def_id: <Self::Interner as Interner>::DefId,
trait_assoc_def_id: <Self::Interner as Interner>::DefinitionAssocTermId,
impl_def_id: <Self::Interner as Interner>::ImplId,
) -> Result<
Option<<Self::Interner as Interner>::DefId>,
Option<<Self::Interner as Interner>::ImplOrTraitAssocTermId>,
<Self::Interner as Interner>::ErrorGuaranteed,
>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use derive_where::derive_where;
use rustc_type_ir::data_structures::HashMap;
use rustc_type_ir::inherent::*;
use rustc_type_ir::lang_items::{SolverLangItem, SolverTraitLangItem};
use rustc_type_ir::lang_items::{SolverProjectionLangItem, SolverTraitLangItem};
use rustc_type_ir::solve::SizedTraitKind;
use rustc_type_ir::solve::inspect::ProbeKind;
use rustc_type_ir::{
Expand Down Expand Up @@ -106,7 +106,9 @@ where
// We can resolve the `impl Trait` to its concrete type,
// which enforces a DAG between the functions requiring
// the auto trait bounds in question.
Ok(ty::Binder::dummy(vec![cx.type_of(def_id).instantiate(cx, args).skip_norm_wip()]))
Ok(ty::Binder::dummy(vec![
cx.type_of(def_id.into()).instantiate(cx, args).skip_norm_wip(),
]))
}
}
}
Expand Down Expand Up @@ -541,7 +543,8 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I:
);
}

let future_output_def_id = cx.require_lang_item(SolverLangItem::FutureOutput);
let future_output_def_id =
cx.require_projection_lang_item(SolverProjectionLangItem::FutureOutput);
let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
Ok((
bound_sig.rebind(AsyncCallableRelevantTypes {
Expand Down Expand Up @@ -596,7 +599,8 @@ fn fn_item_to_async_callable<I: Interner>(
let nested = vec![
bound_sig.rebind(ty::TraitRef::new(cx, future_trait_def_id, [sig.output()])).upcast(cx),
];
let future_output_def_id = cx.require_lang_item(SolverLangItem::FutureOutput);
let future_output_def_id =
cx.require_projection_lang_item(SolverProjectionLangItem::FutureOutput);
let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]);
Ok((
bound_sig.rebind(AsyncCallableRelevantTypes {
Expand Down Expand Up @@ -642,7 +646,8 @@ fn coroutine_closure_to_ambiguous_coroutine<I: Interner>(
args: ty::CoroutineClosureArgs<I>,
sig: ty::CoroutineClosureSignature<I>,
) -> I::Ty {
let upvars_projection_def_id = cx.require_lang_item(SolverLangItem::AsyncFnKindUpvars);
let upvars_projection_def_id =
cx.require_projection_lang_item(SolverProjectionLangItem::AsyncFnKindUpvars);
let tupled_upvars_ty = Ty::new_projection(
cx,
upvars_projection_def_id,
Expand Down Expand Up @@ -920,7 +925,10 @@ where
// show up in the bounds, but just ones that come from substituting
// `Self` with the dyn type.
let proj = proj.with_self_ty(cx, trait_ref.self_ty());
replace_projection_with.entry(proj.def_id()).or_default().push(bound.rebind(proj));
replace_projection_with
.entry(proj.def_id().into())
.or_default()
.push(bound.rebind(proj));
}
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,9 +1152,9 @@ where
pub(super) fn fetch_eligible_assoc_item(
&self,
goal_trait_ref: ty::TraitRef<I>,
trait_assoc_def_id: I::DefId,
trait_assoc_def_id: I::DefinitionAssocTermId,
impl_def_id: I::ImplId,
) -> Result<Option<I::DefId>, I::ErrorGuaranteed> {
) -> Result<Option<I::ImplOrTraitAssocTermId>, I::ErrorGuaranteed> {
self.delegate.fetch_eligible_assoc_item(goal_trait_ref, trait_assoc_def_id, impl_def_id)
}

Expand All @@ -1169,7 +1169,7 @@ where

pub(super) fn add_item_bounds_for_hidden_type(
&mut self,
opaque_def_id: I::DefId,
opaque_def_id: I::OpaqueTyId,
opaque_args: I::GenericArgs,
param_env: I::ParamEnv,
hidden_ty: I::Ty,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_next_trait_solver/src/solve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ where
}
}

fn opaque_type_is_rigid(&self, def_id: I::DefId) -> bool {
fn opaque_type_is_rigid(&self, def_id: I::OpaqueTyId) -> bool {
match self.typing_mode() {
// Opaques are never rigid outside of analysis mode.
TypingMode::Coherence | TypingMode::PostAnalysis => false,
Expand All @@ -366,7 +366,7 @@ where
TypingMode::Analysis { defining_opaque_types_and_generators: non_rigid_opaques }
| TypingMode::Borrowck { defining_opaque_types: non_rigid_opaques }
| TypingMode::PostBorrowckAnalysis { defined_opaque_types: non_rigid_opaques } => {
!def_id.as_local().is_some_and(|def_id| non_rigid_opaques.contains(&def_id))
!def_id.as_local().is_some_and(|def_id| non_rigid_opaques.contains(&def_id.into()))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ where
pub(super) fn normalize_anon_const(
&mut self,
goal: Goal<I, ty::NormalizesTo<I>>,
def_id: I::UnevaluatedConstId,
) -> QueryResult<I> {
if let Some(normalized_const) = self.evaluate_const(
goal.param_env,
ty::UnevaluatedConst::new(
goal.predicate.alias.def_id().try_into().unwrap(),
goal.predicate.alias.args,
),
ty::UnevaluatedConst::new(def_id, goal.predicate.alias.args),
) {
self.instantiate_normalizes_to_term(goal, normalized_const.into());
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ where
pub(super) fn normalize_inherent_associated_term(
&mut self,
goal: Goal<I, ty::NormalizesTo<I>>,
def_id: I::ImplOrTraitAssocTermId,
) -> QueryResult<I> {
let cx = self.cx();
let inherent = goal.predicate.alias;

let impl_def_id = cx.parent(inherent.def_id());
let impl_def_id = cx.impl_or_trait_assoc_term_parent(def_id);
let impl_args = self.fresh_args_for_item(impl_def_id);

// Equate impl header and add impl where clauses
Expand All @@ -46,19 +47,16 @@ where
// to be very careful when changing the impl where-clauses to be productive.
self.add_goals(
GoalSource::Misc,
cx.predicates_of(inherent.def_id())
cx.predicates_of(def_id.into())
.iter_instantiated(cx, inherent_args)
.map(Unnormalized::skip_norm_wip)
.map(|pred| goal.with(cx, pred)),
);

let normalized = if inherent.kind(cx).is_type() {
cx.type_of(inherent.def_id()).instantiate(cx, inherent_args).skip_norm_wip().into()
cx.type_of(def_id.into()).instantiate(cx, inherent_args).skip_norm_wip().into()
} else {
cx.const_of_item(inherent.def_id())
.instantiate(cx, inherent_args)
.skip_norm_wip()
.into()
cx.const_of_item(def_id.into()).instantiate(cx, inherent_args).skip_norm_wip().into()
};
self.instantiate_normalizes_to_term(goal, normalized);
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
Expand Down
Loading
Loading