Skip to content

Commit 17e0cc3

Browse files
committed
Create Ty type alias in rustc_type_ir
1 parent 9df8317 commit 17e0cc3

File tree

33 files changed

+292
-282
lines changed

33 files changed

+292
-282
lines changed

‎compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub(super) struct Canonicalizer<'a, D: SolverDelegate<Interner = I>, I: Interner
7878

7979
/// We can simply cache based on the ty itself, because we use
8080
/// `ty::BoundVarIndexKind::Canonical`.
81-
cache: HashMap<I::Ty, I::Ty>,
81+
cache: HashMap<ty::Ty<I>, ty::Ty<I>>,
8282
}
8383

8484
impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
@@ -316,7 +316,7 @@ impl<'a, D: SolverDelegate<Interner = I>, I: Interner> Canonicalizer<'a, D, I> {
316316
(max_universe, self.variables, var_kinds)
317317
}
318318

319-
fn inner_fold_ty(&mut self, t: I::Ty) -> I::Ty {
319+
fn inner_fold_ty(&mut self, t: ty::Ty<I>) -> ty::Ty<I> {
320320
let kind = match t.kind() {
321321
ty::Infer(i) => match i {
322322
ty::TyVar(vid) => {
@@ -475,7 +475,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
475475
Region::new_canonical_bound(self.cx(), var)
476476
}
477477

478-
fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
478+
fn fold_ty(&mut self, t: ty::Ty<I>) -> ty::Ty<I> {
479479
if !t.flags().intersects(NEEDS_CANONICAL) {
480480
t
481481
} else if let Some(&ty) = self.cache.get(&t) {

‎compiler/rustc_next_trait_solver/src/canonical/mod.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_index::IndexVec;
1616
use rustc_type_ir::inherent::*;
1717
use rustc_type_ir::relate::solver_relating::RelateExt;
1818
use rustc_type_ir::{
19-
self as ty, Canonical, CanonicalVarKind, CanonicalVarValues, InferCtxtLike, Interner,
19+
self as ty, Canonical, CanonicalVarKind, CanonicalVarValues, InferCtxtLike, Interner, Ty,
2020
TypeFoldable,
2121
};
2222
use tracing::instrument;
@@ -53,7 +53,7 @@ impl<I: Interner, T> ResponseT<I> for inspect::State<I, T> {
5353
pub(super) fn canonicalize_goal<D, I>(
5454
delegate: &D,
5555
goal: Goal<I, I::Predicate>,
56-
opaque_types: &[(ty::OpaqueTypeKey<I>, I::Ty)],
56+
opaque_types: &[(ty::OpaqueTypeKey<I>, Ty<I>)],
5757
) -> (Vec<I::GenericArg>, CanonicalInput<I, I::Predicate>)
5858
where
5959
D: SolverDelegate<Interner = I>,
@@ -264,7 +264,7 @@ fn register_region_constraints<D, I>(
264264

265265
fn register_new_opaque_types<D, I>(
266266
delegate: &D,
267-
opaque_types: &[(ty::OpaqueTypeKey<I>, I::Ty)],
267+
opaque_types: &[(ty::OpaqueTypeKey<I>, Ty<I>)],
268268
span: I::Span,
269269
) where
270270
D: SolverDelegate<Interner = I>,

‎compiler/rustc_next_trait_solver/src/coherence.rs‎

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub enum Conflict {
4747
pub fn trait_ref_is_knowable<Infcx, I, E>(
4848
infcx: &Infcx,
4949
trait_ref: ty::TraitRef<I>,
50-
mut lazily_normalize_ty: impl FnMut(I::Ty) -> Result<I::Ty, E>,
50+
mut lazily_normalize_ty: impl FnMut(ty::Ty<I>) -> Result<ty::Ty<I>, E>,
5151
) -> Result<Result<(), Conflict>, E>
5252
where
5353
Infcx: InferCtxtLike<Interner = I>,
@@ -115,14 +115,14 @@ impl From<bool> for IsFirstInputType {
115115

116116
#[derive_where(Debug; I: Interner, T: Debug)]
117117
pub enum OrphanCheckErr<I: Interner, T> {
118-
NonLocalInputType(Vec<(I::Ty, IsFirstInputType)>),
118+
NonLocalInputType(Vec<(ty::Ty<I>, IsFirstInputType)>),
119119
UncoveredTyParams(UncoveredTyParams<I, T>),
120120
}
121121

122122
#[derive_where(Debug; I: Interner, T: Debug)]
123123
pub struct UncoveredTyParams<I: Interner, T> {
124124
pub uncovered: T,
125-
pub local_ty: Option<I::Ty>,
125+
pub local_ty: Option<ty::Ty<I>>,
126126
}
127127

128128
/// Checks whether a trait-ref is potentially implementable by a crate.
@@ -222,8 +222,8 @@ pub fn orphan_check_trait_ref<Infcx, I, E: Debug>(
222222
infcx: &Infcx,
223223
trait_ref: ty::TraitRef<I>,
224224
in_crate: InCrate,
225-
lazily_normalize_ty: impl FnMut(I::Ty) -> Result<I::Ty, E>,
226-
) -> Result<Result<(), OrphanCheckErr<I, I::Ty>>, E>
225+
lazily_normalize_ty: impl FnMut(ty::Ty<I>) -> Result<ty::Ty<I>, E>,
226+
) -> Result<Result<(), OrphanCheckErr<I, ty::Ty<I>>>, E>
227227
where
228228
Infcx: InferCtxtLike<Interner = I>,
229229
I: Interner,
@@ -262,14 +262,14 @@ struct OrphanChecker<'a, Infcx, I: Interner, F> {
262262
lazily_normalize_ty: F,
263263
/// Ignore orphan check failures and exclusively search for the first local type.
264264
search_first_local_ty: bool,
265-
non_local_tys: Vec<(I::Ty, IsFirstInputType)>,
265+
non_local_tys: Vec<(ty::Ty<I>, IsFirstInputType)>,
266266
}
267267

268268
impl<'a, Infcx, I, F, E> OrphanChecker<'a, Infcx, I, F>
269269
where
270270
Infcx: InferCtxtLike<Interner = I>,
271271
I: Interner,
272-
F: FnOnce(I::Ty) -> Result<I::Ty, E>,
272+
F: FnOnce(ty::Ty<I>) -> Result<ty::Ty<I>, E>,
273273
{
274274
fn new(infcx: &'a Infcx, in_crate: InCrate, lazily_normalize_ty: F) -> Self {
275275
OrphanChecker {
@@ -282,12 +282,15 @@ where
282282
}
283283
}
284284

285-
fn found_non_local_ty(&mut self, t: I::Ty) -> ControlFlow<OrphanCheckEarlyExit<I, E>> {
285+
fn found_non_local_ty(&mut self, t: ty::Ty<I>) -> ControlFlow<OrphanCheckEarlyExit<I, E>> {
286286
self.non_local_tys.push((t, self.in_self_ty.into()));
287287
ControlFlow::Continue(())
288288
}
289289

290-
fn found_uncovered_ty_param(&mut self, ty: I::Ty) -> ControlFlow<OrphanCheckEarlyExit<I, E>> {
290+
fn found_uncovered_ty_param(
291+
&mut self,
292+
ty: ty::Ty<I>,
293+
) -> ControlFlow<OrphanCheckEarlyExit<I, E>> {
291294
if self.search_first_local_ty {
292295
return ControlFlow::Continue(());
293296
}
@@ -305,23 +308,23 @@ where
305308

306309
enum OrphanCheckEarlyExit<I: Interner, E> {
307310
NormalizationFailure(E),
308-
UncoveredTyParam(I::Ty),
309-
LocalTy(I::Ty),
311+
UncoveredTyParam(ty::Ty<I>),
312+
LocalTy(ty::Ty<I>),
310313
}
311314

312315
impl<'a, Infcx, I, F, E> TypeVisitor<I> for OrphanChecker<'a, Infcx, I, F>
313316
where
314317
Infcx: InferCtxtLike<Interner = I>,
315318
I: Interner,
316-
F: FnMut(I::Ty) -> Result<I::Ty, E>,
319+
F: FnMut(ty::Ty<I>) -> Result<ty::Ty<I>, E>,
317320
{
318321
type Result = ControlFlow<OrphanCheckEarlyExit<I, E>>;
319322

320323
fn visit_region(&mut self, _r: I::Region) -> Self::Result {
321324
ControlFlow::Continue(())
322325
}
323326

324-
fn visit_ty(&mut self, ty: I::Ty) -> Self::Result {
327+
fn visit_ty(&mut self, ty: ty::Ty<I>) -> Self::Result {
325328
let ty = self.infcx.shallow_resolve(ty);
326329
let ty = match (self.lazily_normalize_ty)(ty) {
327330
Ok(norm_ty) if norm_ty.is_ty_var() => ty,

‎compiler/rustc_next_trait_solver/src/delegate.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ops::Deref;
22

33
use rustc_type_ir::solve::{Certainty, Goal, NoSolution};
4-
use rustc_type_ir::{self as ty, InferCtxtLike, Interner, TypeFoldable};
4+
use rustc_type_ir::{self as ty, InferCtxtLike, Interner, Ty, TypeFoldable};
55

66
pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
77
type Infcx: InferCtxtLike<Interner = Self::Interner>;
@@ -70,7 +70,7 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
7070
def_id: <Self::Interner as Interner>::DefId,
7171
args: <Self::Interner as Interner>::GenericArgs,
7272
param_env: <Self::Interner as Interner>::ParamEnv,
73-
hidden_ty: <Self::Interner as Interner>::Ty,
73+
hidden_ty: Ty<Self::Interner>,
7474
goals: &mut Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>,
7575
);
7676

@@ -86,8 +86,8 @@ pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
8686

8787
fn is_transmutable(
8888
&self,
89-
src: <Self::Interner as Interner>::Ty,
90-
dst: <Self::Interner as Interner>::Ty,
89+
src: Ty<Self::Interner>,
90+
dst: Ty<Self::Interner>,
9191
assume: <Self::Interner as Interner>::Const,
9292
) -> Result<Certainty, NoSolution>;
9393
}

‎compiler/rustc_next_trait_solver/src/placeholder.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ where
113113
}
114114
}
115115

116-
fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
116+
fn fold_ty(&mut self, t: ty::Ty<I>) -> ty::Ty<I> {
117117
match t.kind() {
118118
ty::Bound(ty::BoundVarIndexKind::Bound(debruijn), _)
119119
if debruijn.as_usize() + 1

‎compiler/rustc_next_trait_solver/src/resolve.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_type_ir::data_structures::DelayedMap;
22
use rustc_type_ir::inherent::*;
33
use rustc_type_ir::{
4-
self as ty, InferCtxtLike, Interner, TypeFoldable, TypeFolder, TypeSuperFoldable,
4+
self as ty, InferCtxtLike, Interner, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable,
55
TypeVisitableExt,
66
};
77

@@ -19,7 +19,7 @@ where
1919
delegate: &'a D,
2020
/// We're able to use a cache here as the folder does not have any
2121
/// mutable state.
22-
cache: DelayedMap<I::Ty, I::Ty>,
22+
cache: DelayedMap<Ty<I>, Ty<I>>,
2323
}
2424

2525
pub fn eager_resolve_vars<D: SolverDelegate, T: TypeFoldable<D::Interner>>(
@@ -45,7 +45,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for EagerResolv
4545
self.delegate.cx()
4646
}
4747

48-
fn fold_ty(&mut self, t: I::Ty) -> I::Ty {
48+
fn fold_ty(&mut self, t: Ty<I>) -> Ty<I> {
4949
match t.kind() {
5050
ty::Infer(ty::TyVar(vid)) => {
5151
let resolved = self.delegate.opportunistic_resolve_ty_var(vid);

‎compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ where
4646
D: SolverDelegate<Interner = I>,
4747
I: Interner,
4848
{
49-
fn self_ty(self) -> I::Ty;
49+
fn self_ty(self) -> ty::Ty<I>;
5050

5151
fn trait_ref(self, cx: I) -> ty::TraitRef<I>;
5252

53-
fn with_replaced_self_ty(self, cx: I, self_ty: I::Ty) -> Self;
53+
fn with_replaced_self_ty(self, cx: I, self_ty: ty::Ty<I>) -> Self;
5454

5555
fn trait_def_id(self, cx: I) -> I::TraitId;
5656

@@ -683,7 +683,7 @@ where
683683
// hitting another overflow error something. Add a depth parameter needed later.
684684
fn assemble_alias_bound_candidates_recur<G: GoalKind<D>>(
685685
&mut self,
686-
self_ty: I::Ty,
686+
self_ty: ty::Ty<I>,
687687
goal: Goal<I, G>,
688688
candidates: &mut Vec<Candidate<I>>,
689689
consider_self_bounds: AliasBoundKind,
@@ -1017,13 +1017,13 @@ where
10171017
struct ReplaceOpaque<I: Interner> {
10181018
cx: I,
10191019
alias_ty: ty::AliasTy<I>,
1020-
self_ty: I::Ty,
1020+
self_ty: ty::Ty<I>,
10211021
}
10221022
impl<I: Interner> TypeFolder<I> for ReplaceOpaque<I> {
10231023
fn cx(&self) -> I {
10241024
self.cx
10251025
}
1026-
fn fold_ty(&mut self, ty: I::Ty) -> I::Ty {
1026+
fn fold_ty(&mut self, ty: ty::Ty<I>) -> ty::Ty<I> {
10271027
if let ty::Alias(ty::Opaque, alias_ty) = ty.kind() {
10281028
if alias_ty == self.alias_ty {
10291029
return self.self_ty;
@@ -1280,7 +1280,7 @@ where
12801280
ControlFlow::Continue(())
12811281
}
12821282

1283-
fn visit_ty(&mut self, ty: I::Ty) -> Self::Result {
1283+
fn visit_ty(&mut self, ty: ty::Ty<I>) -> Self::Result {
12841284
let ty = self.ecx.replace_bound_vars(ty, &mut self.universes);
12851285
let Ok(ty) = self.ecx.structurally_normalize_ty(self.param_env, ty) else {
12861286
return ControlFlow::Break(Err(NoSolution));

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use crate::solve::{AdtDestructorKind, EvalCtxt, Goal, NoSolution};
2121
#[instrument(level = "trace", skip(ecx), ret)]
2222
pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<D, I>(
2323
ecx: &EvalCtxt<'_, D>,
24-
ty: I::Ty,
25-
) -> Result<ty::Binder<I, Vec<I::Ty>>, NoSolution>
24+
ty: ty::Ty<I>,
25+
) -> Result<ty::Binder<I, Vec<ty::Ty<I>>>, NoSolution>
2626
where
2727
D: SolverDelegate<Interner = I>,
2828
I: Interner,
@@ -108,8 +108,8 @@ where
108108
pub(in crate::solve) fn instantiate_constituent_tys_for_sizedness_trait<D, I>(
109109
ecx: &EvalCtxt<'_, D>,
110110
sizedness: SizedTraitKind,
111-
ty: I::Ty,
112-
) -> Result<ty::Binder<I, Vec<I::Ty>>, NoSolution>
111+
ty: ty::Ty<I>,
112+
) -> Result<ty::Binder<I, Vec<ty::Ty<I>>>, NoSolution>
113113
where
114114
D: SolverDelegate<Interner = I>,
115115
I: Interner,
@@ -186,8 +186,8 @@ where
186186
#[instrument(level = "trace", skip(ecx), ret)]
187187
pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait<D, I>(
188188
ecx: &EvalCtxt<'_, D>,
189-
ty: I::Ty,
190-
) -> Result<ty::Binder<I, Vec<I::Ty>>, NoSolution>
189+
ty: ty::Ty<I>,
190+
) -> Result<ty::Binder<I, Vec<ty::Ty<I>>>, NoSolution>
191191
where
192192
D: SolverDelegate<Interner = I>,
193193
I: Interner,
@@ -268,9 +268,9 @@ where
268268
// Returns a binder of the tupled inputs types and output type from a builtin callable type.
269269
pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Interner>(
270270
cx: I,
271-
self_ty: I::Ty,
271+
self_ty: ty::Ty<I>,
272272
goal_kind: ty::ClosureKind,
273-
) -> Result<Option<ty::Binder<I, (I::Ty, I::Ty)>>, NoSolution> {
273+
) -> Result<Option<ty::Binder<I, (ty::Ty<I>, ty::Ty<I>)>>, NoSolution> {
274274
match self_ty.kind() {
275275
// keep this in sync with assemble_fn_pointer_candidates until the old solver is removed.
276276
ty::FnDef(def_id, args) => {
@@ -408,13 +408,13 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable<I: Intern
408408
#[derive_where(Clone, Copy, Debug; I: Interner)]
409409
#[derive(TypeVisitable_Generic, TypeFoldable_Generic)]
410410
pub(in crate::solve) struct AsyncCallableRelevantTypes<I: Interner> {
411-
pub tupled_inputs_ty: I::Ty,
411+
pub tupled_inputs_ty: ty::Ty<I>,
412412
/// Type returned by calling the closure
413413
/// i.e. `f()`.
414-
pub output_coroutine_ty: I::Ty,
414+
pub output_coroutine_ty: ty::Ty<I>,
415415
/// Type returned by `await`ing the output
416416
/// i.e. `f().await`.
417-
pub coroutine_return_ty: I::Ty,
417+
pub coroutine_return_ty: ty::Ty<I>,
418418
}
419419

420420
// Returns a binder of the tupled inputs types, output type, and coroutine type
@@ -424,7 +424,7 @@ pub(in crate::solve) struct AsyncCallableRelevantTypes<I: Interner> {
424424
// know the kind already, we can short-circuit this check.
425425
pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable<I: Interner>(
426426
cx: I,
427-
self_ty: I::Ty,
427+
self_ty: ty::Ty<I>,
428428
goal_kind: ty::ClosureKind,
429429
env_region: I::Region,
430430
) -> Result<(ty::Binder<I, AsyncCallableRelevantTypes<I>>, Vec<I::Predicate>), NoSolution> {
@@ -608,7 +608,7 @@ fn coroutine_closure_to_certain_coroutine<I: Interner>(
608608
def_id: I::CoroutineClosureId,
609609
args: ty::CoroutineClosureArgs<I>,
610610
sig: ty::CoroutineClosureSignature<I>,
611-
) -> I::Ty {
611+
) -> ty::Ty<I> {
612612
sig.to_coroutine_given_kind_and_upvars(
613613
cx,
614614
args.parent_args(),
@@ -632,7 +632,7 @@ fn coroutine_closure_to_ambiguous_coroutine<I: Interner>(
632632
def_id: I::CoroutineClosureId,
633633
args: ty::CoroutineClosureArgs<I>,
634634
sig: ty::CoroutineClosureSignature<I>,
635-
) -> I::Ty {
635+
) -> ty::Ty<I> {
636636
let upvars_projection_def_id = cx.require_lang_item(SolverLangItem::AsyncFnKindUpvars);
637637
let tupled_upvars_ty = Ty::new_projection(
638638
cx,
@@ -664,8 +664,8 @@ fn coroutine_closure_to_ambiguous_coroutine<I: Interner>(
664664
#[instrument(level = "trace", skip(cx), ret)]
665665
pub(in crate::solve) fn extract_fn_def_from_const_callable<I: Interner>(
666666
cx: I,
667-
self_ty: I::Ty,
668-
) -> Result<(ty::Binder<I, (I::Ty, I::Ty)>, I::DefId, I::GenericArgs), NoSolution> {
667+
self_ty: ty::Ty<I>,
668+
) -> Result<(ty::Binder<I, (ty::Ty<I>, ty::Ty<I>)>, I::DefId, I::GenericArgs), NoSolution> {
669669
match self_ty.kind() {
670670
ty::FnDef(def_id, args) => {
671671
let sig = cx.fn_sig(def_id);
@@ -742,7 +742,7 @@ pub(in crate::solve) fn extract_fn_def_from_const_callable<I: Interner>(
742742
// the old solver, for as long as that exists.
743743
pub(in crate::solve) fn const_conditions_for_destruct<I: Interner>(
744744
cx: I,
745-
self_ty: I::Ty,
745+
self_ty: ty::Ty<I>,
746746
) -> Result<Vec<ty::TraitRef<I>>, NoSolution> {
747747
let destruct_def_id = cx.require_trait_lang_item(SolverTraitLangItem::Destruct);
748748

@@ -923,7 +923,7 @@ where
923923
struct ReplaceProjectionWith<'a, 'b, I: Interner, D: SolverDelegate<Interner = I>> {
924924
ecx: &'a mut EvalCtxt<'b, D>,
925925
param_env: I::ParamEnv,
926-
self_ty: I::Ty,
926+
self_ty: ty::Ty<I>,
927927
mapping: &'a HashMap<I::DefId, Vec<ty::Binder<I, ty::ProjectionPredicate<I>>>>,
928928
nested: Vec<Goal<I, I::Predicate>>,
929929
}
@@ -1009,7 +1009,7 @@ where
10091009
self.ecx.cx()
10101010
}
10111011

1012-
fn try_fold_ty(&mut self, ty: I::Ty) -> Result<I::Ty, Ambiguous> {
1012+
fn try_fold_ty(&mut self, ty: ty::Ty<I>) -> Result<ty::Ty<I>, Ambiguous> {
10131013
if let ty::Alias(ty::Projection, alias_ty) = ty.kind()
10141014
&& let Some(term) = self.try_eagerly_replace_alias(alias_ty.into())?
10151015
{

0 commit comments

Comments
 (0)