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
21 changes: 15 additions & 6 deletions compiler/rustc_middle/src/ty/context/impl_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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, search_graph};

use crate::dep_graph::{DepKind, DepNodeIndex};
Expand Down Expand Up @@ -40,6 +40,11 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
type AdtId = DefId;
type ImplId = DefId;
type UnevaluatedConstId = DefId;
type ProjectionTyId = DefId;
type ProjectionId = DefId;
type OpaqueId = DefId;
type FreeAliasId = DefId;
type ImplTyAliasId = DefId;
type Span = Span;

type GenericArgs = ty::GenericArgsRef<'tcx>;
Expand Down Expand Up @@ -290,7 +295,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::ProjectionId) -> Self::TraitId {
self.parent(def_id)
}

fn impl_ty_alias_parent(self, def_id: Self::ImplTyAliasId) -> Self::ImplId {
self.parent(def_id)
}

Expand Down Expand Up @@ -436,7 +445,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 @@ -448,7 +457,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 @@ -468,7 +477,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 @@ -747,7 +756,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
4 changes: 2 additions & 2 deletions compiler/rustc_next_trait_solver/src/delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>::ProjectionId,
impl_def_id: <Self::Interner as Interner>::ImplId,
) -> Result<
Option<<Self::Interner as Interner>::DefId>,
Option<<Self::Interner as Interner>::ImplTyAliasId>,
<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 @@ -102,7 +102,7 @@ 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)]))
Ok(ty::Binder::dummy(vec![cx.type_of(def_id.into()).instantiate(cx, args)]))
}
}
}
Expand Down Expand Up @@ -535,7 +535,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 @@ -590,7 +591,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 @@ -636,7 +638,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 @@ -907,7 +910,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
4 changes: 2 additions & 2 deletions compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,9 +1124,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::ProjectionId,
impl_def_id: I::ImplId,
) -> Result<Option<I::DefId>, I::ErrorGuaranteed> {
) -> Result<Option<I::ImplTyAliasId>, I::ErrorGuaranteed> {
self.delegate.fetch_eligible_assoc_item(goal_trait_ref, trait_assoc_def_id, impl_def_id)
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_next_trait_solver/src/solve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ where
}
}

fn opaque_type_is_rigid(&self, def_id: I::DefId) -> bool {
fn opaque_type_is_rigid(&self, def_id: I::OpaqueId) -> bool {
match self.typing_mode() {
// Opaques are never rigid outside of analysis mode.
TypingMode::Coherence | TypingMode::PostAnalysis => false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ where
let cx = self.cx();
let inherent = goal.predicate.alias;

let impl_def_id = cx.parent(inherent.def_id);
let impl_args = self.fresh_args_for_item(impl_def_id);
let impl_def_id = cx.impl_ty_alias_parent(inherent.def_id.try_into().unwrap());
let impl_args = self.fresh_args_for_item(impl_def_id.into());

// Equate impl header and add impl where clauses
self.eq(
goal.param_env,
inherent.self_ty(),
cx.type_of(impl_def_id).instantiate(cx, impl_args),
cx.type_of(impl_def_id.into()).instantiate(cx, impl_args),
)?;

// Equate IAT with the RHS of the project goal
Expand Down
108 changes: 57 additions & 51 deletions compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod opaque_types;

use rustc_type_ir::fast_reject::DeepRejectCtxt;
use rustc_type_ir::inherent::*;
use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem};
use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverProjectionLangItem, SolverTraitLangItem};
use rustc_type_ir::solve::SizedTraitKind;
use rustc_type_ir::{self as ty, FieldInfo, Interner, NormalizesTo, PredicateKind, Upcast as _};
use tracing::instrument;
Expand Down Expand Up @@ -273,7 +273,7 @@ where

let target_item_def_id = match ecx.fetch_eligible_assoc_item(
goal_trait_ref,
goal.predicate.def_id(),
goal.predicate.def_id().try_into().unwrap(),
impl_def_id,
) {
Ok(Some(target_item_def_id)) => target_item_def_id,
Expand Down Expand Up @@ -350,7 +350,7 @@ where
}
}

let target_container_def_id = cx.parent(target_item_def_id);
let target_container_def_id = cx.impl_ty_alias_parent(target_item_def_id);

// Getting the right args here is complex, e.g. given:
// - a goal `<Vec<u32> as Trait<i32>>::Assoc<u64>`
Expand All @@ -367,10 +367,10 @@ where
impl_def_id,
impl_args,
impl_trait_ref,
target_container_def_id,
target_container_def_id.into(),
)?;

if !cx.check_args_compatible(target_item_def_id, target_args) {
if !cx.check_args_compatible(target_item_def_id.into(), target_args) {
return error_response(
ecx,
cx.delay_bug("associated item has mismatched arguments"),
Expand All @@ -380,10 +380,10 @@ where
// Finally we construct the actual value of the associated type.
let term = match goal.predicate.alias.kind(cx) {
ty::AliasTermKind::ProjectionTy => {
cx.type_of(target_item_def_id).map_bound(|ty| ty.into())
cx.type_of(target_item_def_id.into()).map_bound(|ty| ty.into())
}
ty::AliasTermKind::ProjectionConst => {
cx.const_of_item(target_item_def_id).map_bound(|ct| ct.into())
cx.const_of_item(target_item_def_id.into()).map_bound(|ct| ct.into())
}
kind => panic!("expected projection, found {kind:?}"),
};
Expand Down Expand Up @@ -486,6 +486,7 @@ where
goal_kind: ty::ClosureKind,
) -> Result<Candidate<I>, NoSolution> {
let cx = ecx.cx();
let def_id = goal.predicate.def_id().try_into().unwrap();

let env_region = match goal_kind {
ty::ClosureKind::Fn | ty::ClosureKind::FnMut => goal.predicate.alias.args.region_at(2),
Expand Down Expand Up @@ -513,41 +514,42 @@ where
[output_coroutine_ty],
);

let (projection_term, term) =
if cx.is_lang_item(goal.predicate.def_id(), SolverLangItem::CallOnceFuture) {
(
ty::AliasTerm::new(
cx,
goal.predicate.def_id(),
[goal.predicate.self_ty(), tupled_inputs_ty],
),
output_coroutine_ty.into(),
)
} else if cx.is_lang_item(goal.predicate.def_id(), SolverLangItem::CallRefFuture) {
(
ty::AliasTerm::new(
cx,
goal.predicate.def_id(),
[
I::GenericArg::from(goal.predicate.self_ty()),
tupled_inputs_ty.into(),
env_region.into(),
],
),
output_coroutine_ty.into(),
)
} else if cx.is_lang_item(goal.predicate.def_id(), SolverLangItem::AsyncFnOnceOutput) {
(
ty::AliasTerm::new(
cx,
goal.predicate.def_id(),
[goal.predicate.self_ty(), tupled_inputs_ty],
),
coroutine_return_ty.into(),
)
} else {
panic!("no such associated type in `AsyncFn*`: {:?}", goal.predicate.def_id())
};
let (projection_term, term) = if cx
.is_projection_lang_item(def_id, SolverProjectionLangItem::CallOnceFuture)
{
(
ty::AliasTerm::new(
cx,
goal.predicate.def_id(),
[goal.predicate.self_ty(), tupled_inputs_ty],
),
output_coroutine_ty.into(),
)
} else if cx.is_projection_lang_item(def_id, SolverProjectionLangItem::CallRefFuture) {
(
ty::AliasTerm::new(
cx,
goal.predicate.def_id(),
[
I::GenericArg::from(goal.predicate.self_ty()),
tupled_inputs_ty.into(),
env_region.into(),
],
),
output_coroutine_ty.into(),
)
} else if cx.is_projection_lang_item(def_id, SolverProjectionLangItem::AsyncFnOnceOutput) {
(
ty::AliasTerm::new(
cx,
goal.predicate.def_id(),
[goal.predicate.self_ty(), tupled_inputs_ty],
),
coroutine_return_ty.into(),
)
} else {
panic!("no such associated type in `AsyncFn*`: {:?}", goal.predicate.def_id())
};
let pred = ty::ProjectionPredicate { projection_term, term }.upcast(cx);

Self::probe_and_consider_implied_clause(
Expand Down Expand Up @@ -621,8 +623,8 @@ where
goal: Goal<I, Self>,
) -> Result<Candidate<I>, NoSolution> {
let cx = ecx.cx();
let metadata_def_id = cx.require_lang_item(SolverLangItem::Metadata);
assert_eq!(metadata_def_id, goal.predicate.def_id());
let metadata_def_id = cx.require_projection_lang_item(SolverProjectionLangItem::Metadata);
assert_eq!(Into::<I::DefId>::into(metadata_def_id), goal.predicate.def_id());
let metadata_ty = match goal.predicate.self_ty().kind() {
ty::Bool
| ty::Char
Expand All @@ -648,8 +650,9 @@ where
ty::Str | ty::Slice(_) => Ty::new_usize(cx),

ty::Dynamic(_, _) => {
let dyn_metadata = cx.require_lang_item(SolverLangItem::DynMetadata);
cx.type_of(dyn_metadata)
let dyn_metadata =
cx.require_projection_lang_item(SolverProjectionLangItem::DynMetadata);
cx.type_of(dyn_metadata.into())
.instantiate(cx, &[I::GenericArg::from(goal.predicate.self_ty())])
}

Expand Down Expand Up @@ -836,10 +839,12 @@ where
}

let coroutine = args.as_coroutine();
let def_id = goal.predicate.def_id().try_into().unwrap();

let term = if cx.is_lang_item(goal.predicate.def_id(), SolverLangItem::CoroutineReturn) {
let term = if cx.is_projection_lang_item(def_id, SolverProjectionLangItem::CoroutineReturn)
{
coroutine.return_ty().into()
} else if cx.is_lang_item(goal.predicate.def_id(), SolverLangItem::CoroutineYield) {
} else if cx.is_projection_lang_item(def_id, SolverProjectionLangItem::CoroutineYield) {
coroutine.yield_ty().into()
} else {
panic!("unexpected associated item `{:?}` for `{self_ty:?}`", goal.predicate.def_id())
Expand Down Expand Up @@ -963,9 +968,10 @@ where
else {
return Err(NoSolution);
};
let ty = match ecx.cx().as_lang_item(goal.predicate.def_id()) {
Some(SolverLangItem::FieldBase) => base,
Some(SolverLangItem::FieldType) => ty,
let ty = match ecx.cx().as_projection_lang_item(goal.predicate.def_id().try_into().unwrap())
{
Some(SolverProjectionLangItem::FieldBase) => base,
Some(SolverProjectionLangItem::FieldType) => ty,
_ => panic!("unexpected associated type {:?} in `Field`", goal.predicate),
};
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_next_trait_solver/src/solve/trait_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ where
goal.predicate.self_ty().kind()
{
debug_assert!(ecx.opaque_type_is_rigid(def_id));
for item_bound in cx.item_self_bounds(def_id).skip_binder() {
for item_bound in cx.item_self_bounds(def_id.into()).skip_binder() {
if item_bound
.as_trait_clause()
.is_some_and(|b| b.def_id() == goal.predicate.def_id())
Expand Down
Loading
Loading