From 0c5d075580562d45dddeda30ab40972bfaf32480 Mon Sep 17 00:00:00 2001 From: James Barford-Evans Date: Mon, 23 Mar 2026 18:09:15 +0000 Subject: [PATCH 1/2] Create `Ty` type alias in `rustc_type_ir` --- .../src/canonical/canonicalizer.rs | 12 ++- .../src/canonical/mod.rs | 6 +- .../rustc_next_trait_solver/src/coherence.rs | 30 +++--- .../rustc_next_trait_solver/src/delegate.rs | 8 +- .../src/placeholder.rs | 8 +- .../rustc_next_trait_solver/src/resolve.rs | 6 +- .../src/solve/assembly/mod.rs | 16 +-- .../src/solve/assembly/structural_traits.rs | 78 ++++++++------- .../src/solve/effect_goals.rs | 6 +- .../src/solve/eval_ctxt/mod.rs | 28 +++--- .../rustc_next_trait_solver/src/solve/mod.rs | 10 +- .../src/solve/normalizes_to/mod.rs | 34 ++++--- .../src/solve/trait_goals.rs | 30 +++--- compiler/rustc_type_ir/src/binder.rs | 16 +-- compiler/rustc_type_ir/src/error.rs | 8 +- compiler/rustc_type_ir/src/fast_reject.rs | 14 +-- compiler/rustc_type_ir/src/flags.rs | 4 +- compiler/rustc_type_ir/src/fold.rs | 14 +-- compiler/rustc_type_ir/src/generic_arg.rs | 6 +- compiler/rustc_type_ir/src/infer_ctxt.rs | 34 +++---- compiler/rustc_type_ir/src/inherent.rs | 39 ++++---- compiler/rustc_type_ir/src/lib.rs | 6 +- compiler/rustc_type_ir/src/outlives.rs | 8 +- compiler/rustc_type_ir/src/predicate.rs | 60 ++++++------ compiler/rustc_type_ir/src/predicate_kind.rs | 6 +- compiler/rustc_type_ir/src/relate.rs | 58 +++++------ compiler/rustc_type_ir/src/relate/combine.rs | 22 +++-- .../src/relate/solver_relating.rs | 16 +-- compiler/rustc_type_ir/src/solve/mod.rs | 4 +- compiler/rustc_type_ir/src/sty/mod.rs | 3 + compiler/rustc_type_ir/src/ty_kind.rs | 52 +++++----- compiler/rustc_type_ir/src/ty_kind/closure.rs | 98 ++++++++++--------- compiler/rustc_type_ir/src/visit.rs | 8 +- 33 files changed, 391 insertions(+), 357 deletions(-) create mode 100644 compiler/rustc_type_ir/src/sty/mod.rs diff --git a/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs b/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs index ce2be24adc586..72c4f8622471b 100644 --- a/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs +++ b/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs @@ -1,9 +1,11 @@ use rustc_type_ir::data_structures::{HashMap, ensure_sufficient_stack}; +#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] +use rustc_type_ir::inherent::Ty as _; use rustc_type_ir::inherent::*; use rustc_type_ir::solve::{Goal, QueryInput}; use rustc_type_ir::{ self as ty, Canonical, CanonicalParamEnvCacheEntry, CanonicalVarKind, Flags, InferCtxtLike, - Interner, PlaceholderConst, PlaceholderType, TypeFlags, TypeFoldable, TypeFolder, + Interner, PlaceholderConst, PlaceholderType, Ty, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, }; @@ -78,7 +80,7 @@ pub(super) struct Canonicalizer<'a, D: SolverDelegate, I: Interner /// We can simply cache based on the ty itself, because we use /// `ty::BoundVarIndexKind::Canonical`. - cache: HashMap, + cache: HashMap, Ty>, } impl<'a, D: SolverDelegate, I: Interner> Canonicalizer<'a, D, I> { @@ -316,7 +318,7 @@ impl<'a, D: SolverDelegate, I: Interner> Canonicalizer<'a, D, I> { (max_universe, self.variables, var_kinds) } - fn inner_fold_ty(&mut self, t: I::Ty) -> I::Ty { + fn inner_fold_ty(&mut self, t: Ty) -> Ty { let kind = match t.kind() { ty::Infer(i) => match i { ty::TyVar(vid) => { @@ -400,7 +402,7 @@ impl<'a, D: SolverDelegate, I: Interner> Canonicalizer<'a, D, I> { let var = self.get_or_insert_bound_var(t, kind); - Ty::new_canonical_bound(self.cx(), var) + I::Ty::new_canonical_bound(self.cx(), var) } } @@ -475,7 +477,7 @@ impl, I: Interner> TypeFolder for Canonicaliz Region::new_canonical_bound(self.cx(), var) } - fn fold_ty(&mut self, t: I::Ty) -> I::Ty { + fn fold_ty(&mut self, t: Ty) -> Ty { if !t.flags().intersects(NEEDS_CANONICAL) { t } else if let Some(&ty) = self.cache.get(&t) { diff --git a/compiler/rustc_next_trait_solver/src/canonical/mod.rs b/compiler/rustc_next_trait_solver/src/canonical/mod.rs index 1f64f09fe787f..cd42bf8b57b60 100644 --- a/compiler/rustc_next_trait_solver/src/canonical/mod.rs +++ b/compiler/rustc_next_trait_solver/src/canonical/mod.rs @@ -16,7 +16,7 @@ use rustc_index::IndexVec; use rustc_type_ir::inherent::*; use rustc_type_ir::relate::solver_relating::RelateExt; use rustc_type_ir::{ - self as ty, Canonical, CanonicalVarKind, CanonicalVarValues, InferCtxtLike, Interner, + self as ty, Canonical, CanonicalVarKind, CanonicalVarValues, InferCtxtLike, Interner, Ty, TypeFoldable, }; use tracing::instrument; @@ -53,7 +53,7 @@ impl ResponseT for inspect::State { pub(super) fn canonicalize_goal( delegate: &D, goal: Goal, - opaque_types: &[(ty::OpaqueTypeKey, I::Ty)], + opaque_types: &[(ty::OpaqueTypeKey, Ty)], ) -> (Vec, CanonicalInput) where D: SolverDelegate, @@ -264,7 +264,7 @@ fn register_region_constraints( fn register_new_opaque_types( delegate: &D, - opaque_types: &[(ty::OpaqueTypeKey, I::Ty)], + opaque_types: &[(ty::OpaqueTypeKey, Ty)], span: I::Span, ) where D: SolverDelegate, diff --git a/compiler/rustc_next_trait_solver/src/coherence.rs b/compiler/rustc_next_trait_solver/src/coherence.rs index c370fd24a1bb3..1f69add30c540 100644 --- a/compiler/rustc_next_trait_solver/src/coherence.rs +++ b/compiler/rustc_next_trait_solver/src/coherence.rs @@ -2,9 +2,11 @@ use std::fmt::Debug; use std::ops::ControlFlow; use derive_where::derive_where; +#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] +use rustc_type_ir::inherent::Ty as _; use rustc_type_ir::inherent::*; use rustc_type_ir::{ - self as ty, InferCtxtLike, Interner, TrivialTypeTraversalImpls, TypeVisitable, + self as ty, InferCtxtLike, Interner, TrivialTypeTraversalImpls, Ty, TypeVisitable, TypeVisitableExt, TypeVisitor, }; use tracing::instrument; @@ -47,7 +49,7 @@ pub enum Conflict { pub fn trait_ref_is_knowable( infcx: &Infcx, trait_ref: ty::TraitRef, - mut lazily_normalize_ty: impl FnMut(I::Ty) -> Result, + mut lazily_normalize_ty: impl FnMut(Ty) -> Result, E>, ) -> Result, E> where Infcx: InferCtxtLike, @@ -115,14 +117,14 @@ impl From for IsFirstInputType { #[derive_where(Debug; I: Interner, T: Debug)] pub enum OrphanCheckErr { - NonLocalInputType(Vec<(I::Ty, IsFirstInputType)>), + NonLocalInputType(Vec<(Ty, IsFirstInputType)>), UncoveredTyParams(UncoveredTyParams), } #[derive_where(Debug; I: Interner, T: Debug)] pub struct UncoveredTyParams { pub uncovered: T, - pub local_ty: Option, + pub local_ty: Option>, } /// Checks whether a trait-ref is potentially implementable by a crate. @@ -222,8 +224,8 @@ pub fn orphan_check_trait_ref( infcx: &Infcx, trait_ref: ty::TraitRef, in_crate: InCrate, - lazily_normalize_ty: impl FnMut(I::Ty) -> Result, -) -> Result>, E> + lazily_normalize_ty: impl FnMut(Ty) -> Result, E>, +) -> Result>>, E> where Infcx: InferCtxtLike, I: Interner, @@ -262,14 +264,14 @@ struct OrphanChecker<'a, Infcx, I: Interner, F> { lazily_normalize_ty: F, /// Ignore orphan check failures and exclusively search for the first local type. search_first_local_ty: bool, - non_local_tys: Vec<(I::Ty, IsFirstInputType)>, + non_local_tys: Vec<(Ty, IsFirstInputType)>, } impl<'a, Infcx, I, F, E> OrphanChecker<'a, Infcx, I, F> where Infcx: InferCtxtLike, I: Interner, - F: FnOnce(I::Ty) -> Result, + F: FnOnce(Ty) -> Result, E>, { fn new(infcx: &'a Infcx, in_crate: InCrate, lazily_normalize_ty: F) -> Self { OrphanChecker { @@ -282,12 +284,12 @@ where } } - fn found_non_local_ty(&mut self, t: I::Ty) -> ControlFlow> { + fn found_non_local_ty(&mut self, t: Ty) -> ControlFlow> { self.non_local_tys.push((t, self.in_self_ty.into())); ControlFlow::Continue(()) } - fn found_uncovered_ty_param(&mut self, ty: I::Ty) -> ControlFlow> { + fn found_uncovered_ty_param(&mut self, ty: Ty) -> ControlFlow> { if self.search_first_local_ty { return ControlFlow::Continue(()); } @@ -305,15 +307,15 @@ where enum OrphanCheckEarlyExit { NormalizationFailure(E), - UncoveredTyParam(I::Ty), - LocalTy(I::Ty), + UncoveredTyParam(Ty), + LocalTy(Ty), } impl<'a, Infcx, I, F, E> TypeVisitor for OrphanChecker<'a, Infcx, I, F> where Infcx: InferCtxtLike, I: Interner, - F: FnMut(I::Ty) -> Result, + F: FnMut(Ty) -> Result, E>, { type Result = ControlFlow>; @@ -321,7 +323,7 @@ where ControlFlow::Continue(()) } - fn visit_ty(&mut self, ty: I::Ty) -> Self::Result { + fn visit_ty(&mut self, ty: Ty) -> Self::Result { let ty = self.infcx.shallow_resolve(ty); let ty = match (self.lazily_normalize_ty)(ty) { Ok(norm_ty) if norm_ty.is_ty_var() => ty, diff --git a/compiler/rustc_next_trait_solver/src/delegate.rs b/compiler/rustc_next_trait_solver/src/delegate.rs index 9d5aa8bc124b6..1714ae3dd6b2e 100644 --- a/compiler/rustc_next_trait_solver/src/delegate.rs +++ b/compiler/rustc_next_trait_solver/src/delegate.rs @@ -1,7 +1,7 @@ use std::ops::Deref; use rustc_type_ir::solve::{Certainty, Goal, NoSolution}; -use rustc_type_ir::{self as ty, InferCtxtLike, Interner, TypeFoldable}; +use rustc_type_ir::{self as ty, InferCtxtLike, Interner, Ty, TypeFoldable}; pub trait SolverDelegate: Deref + Sized { type Infcx: InferCtxtLike; @@ -70,7 +70,7 @@ pub trait SolverDelegate: Deref + Sized { def_id: ::DefId, args: ::GenericArgs, param_env: ::ParamEnv, - hidden_ty: ::Ty, + hidden_ty: Ty, goals: &mut Vec::Predicate>>, ); @@ -86,8 +86,8 @@ pub trait SolverDelegate: Deref + Sized { fn is_transmutable( &self, - src: ::Ty, - dst: ::Ty, + src: Ty, + dst: Ty, assume: ::Const, ) -> Result; } diff --git a/compiler/rustc_next_trait_solver/src/placeholder.rs b/compiler/rustc_next_trait_solver/src/placeholder.rs index 83f3bdf01dc83..bf3983aa3b333 100644 --- a/compiler/rustc_next_trait_solver/src/placeholder.rs +++ b/compiler/rustc_next_trait_solver/src/placeholder.rs @@ -1,9 +1,11 @@ use core::panic; use rustc_type_ir::data_structures::IndexMap; +#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] +use rustc_type_ir::inherent::Ty as _; use rustc_type_ir::inherent::*; use rustc_type_ir::{ - self as ty, InferCtxtLike, Interner, PlaceholderConst, PlaceholderRegion, PlaceholderType, + self as ty, InferCtxtLike, Interner, PlaceholderConst, PlaceholderRegion, PlaceholderType, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, }; @@ -113,7 +115,7 @@ where } } - fn fold_ty(&mut self, t: I::Ty) -> I::Ty { + fn fold_ty(&mut self, t: Ty) -> Ty { match t.kind() { ty::Bound(ty::BoundVarIndexKind::Bound(debruijn), _) if debruijn.as_usize() + 1 @@ -130,7 +132,7 @@ where let universe = self.universe_for(debruijn); let p = PlaceholderType::new(universe, bound_ty); self.mapped_types.insert(p, bound_ty); - Ty::new_placeholder(self.cx(), p) + I::Ty::new_placeholder(self.cx(), p) } _ if t.has_vars_bound_at_or_above(self.current_index) => t.super_fold_with(self), _ => t, diff --git a/compiler/rustc_next_trait_solver/src/resolve.rs b/compiler/rustc_next_trait_solver/src/resolve.rs index c3c57eccd6eff..86bf05bdb57cc 100644 --- a/compiler/rustc_next_trait_solver/src/resolve.rs +++ b/compiler/rustc_next_trait_solver/src/resolve.rs @@ -1,7 +1,7 @@ use rustc_type_ir::data_structures::DelayedMap; use rustc_type_ir::inherent::*; use rustc_type_ir::{ - self as ty, InferCtxtLike, Interner, TypeFoldable, TypeFolder, TypeSuperFoldable, + self as ty, InferCtxtLike, Interner, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, }; @@ -19,7 +19,7 @@ where delegate: &'a D, /// We're able to use a cache here as the folder does not have any /// mutable state. - cache: DelayedMap, + cache: DelayedMap, Ty>, } pub fn eager_resolve_vars>( @@ -45,7 +45,7 @@ impl, I: Interner> TypeFolder for EagerResolv self.delegate.cx() } - fn fold_ty(&mut self, t: I::Ty) -> I::Ty { + fn fold_ty(&mut self, t: Ty) -> Ty { match t.kind() { ty::Infer(ty::TyVar(vid)) => { let resolved = self.delegate.opportunistic_resolve_ty_var(vid); diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index 32b1e93bf98be..bd5d6d61211e7 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -6,13 +6,15 @@ use std::cell::Cell; use std::ops::ControlFlow; use derive_where::derive_where; +#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] +use rustc_type_ir::inherent::Ty as _; use rustc_type_ir::inherent::*; use rustc_type_ir::lang_items::SolverTraitLangItem; use rustc_type_ir::search_graph::CandidateHeadUsages; use rustc_type_ir::solve::Certainty::Maybe; use rustc_type_ir::solve::{AliasBoundKind, SizedTraitKind}; use rustc_type_ir::{ - self as ty, Interner, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable, + self as ty, Interner, Ty, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Upcast, elaborate, }; @@ -46,11 +48,11 @@ where D: SolverDelegate, I: Interner, { - fn self_ty(self) -> I::Ty; + fn self_ty(self) -> Ty; fn trait_ref(self, cx: I) -> ty::TraitRef; - fn with_replaced_self_ty(self, cx: I, self_ty: I::Ty) -> Self; + fn with_replaced_self_ty(self, cx: I, self_ty: Ty) -> Self; fn trait_def_id(self, cx: I) -> I::TraitId; @@ -683,7 +685,7 @@ where // hitting another overflow error something. Add a depth parameter needed later. fn assemble_alias_bound_candidates_recur>( &mut self, - self_ty: I::Ty, + self_ty: Ty, goal: Goal, candidates: &mut Vec>, consider_self_bounds: AliasBoundKind, @@ -1017,13 +1019,13 @@ where struct ReplaceOpaque { cx: I, alias_ty: ty::AliasTy, - self_ty: I::Ty, + self_ty: Ty, } impl TypeFolder for ReplaceOpaque { fn cx(&self) -> I { self.cx } - fn fold_ty(&mut self, ty: I::Ty) -> I::Ty { + fn fold_ty(&mut self, ty: Ty) -> Ty { if let ty::Alias(ty::Opaque, alias_ty) = ty.kind() { if alias_ty == self.alias_ty { return self.self_ty; @@ -1280,7 +1282,7 @@ where ControlFlow::Continue(()) } - fn visit_ty(&mut self, ty: I::Ty) -> Self::Result { + fn visit_ty(&mut self, ty: Ty) -> Self::Result { let ty = self.ecx.replace_bound_vars(ty, &mut self.universes); let Ok(ty) = self.ecx.structurally_normalize_ty(self.param_env, ty) else { return ControlFlow::Break(Err(NoSolution)); diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs index cd74e87b670f1..320c85128e66e 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs @@ -3,12 +3,14 @@ use derive_where::derive_where; use rustc_type_ir::data_structures::HashMap; +#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] +use rustc_type_ir::inherent::Ty as _; use rustc_type_ir::inherent::*; use rustc_type_ir::lang_items::{SolverLangItem, SolverTraitLangItem}; use rustc_type_ir::solve::SizedTraitKind; use rustc_type_ir::solve::inspect::ProbeKind; use rustc_type_ir::{ - self as ty, FallibleTypeFolder, Interner, Movability, Mutability, TypeFoldable, + self as ty, FallibleTypeFolder, Interner, Movability, Mutability, Ty, TypeFoldable, TypeSuperFoldable, Upcast as _, elaborate, }; use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic}; @@ -21,8 +23,8 @@ use crate::solve::{AdtDestructorKind, EvalCtxt, Goal, NoSolution}; #[instrument(level = "trace", skip(ecx), ret)] pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait( ecx: &EvalCtxt<'_, D>, - ty: I::Ty, -) -> Result>, NoSolution> + ty: Ty, +) -> Result>>, NoSolution> where D: SolverDelegate, I: Interner, @@ -45,7 +47,7 @@ where ty::Foreign(..) => Ok(ty::Binder::dummy(vec![])), // Treat `str` like it's defined as `struct str([u8]);` - ty::Str => Ok(ty::Binder::dummy(vec![Ty::new_slice(cx, Ty::new_u8(cx))])), + ty::Str => Ok(ty::Binder::dummy(vec![I::Ty::new_slice(cx, I::Ty::new_u8(cx))])), ty::Dynamic(..) | ty::Param(..) @@ -77,7 +79,7 @@ where ty::Coroutine(def_id, args) => Ok(ty::Binder::dummy(vec![ args.as_coroutine().tupled_upvars_ty(), - Ty::new_coroutine_witness_for_coroutine(ecx.cx(), def_id, args), + I::Ty::new_coroutine_witness_for_coroutine(ecx.cx(), def_id, args), ])), ty::CoroutineWitness(def_id, args) => Ok(ecx @@ -108,8 +110,8 @@ where pub(in crate::solve) fn instantiate_constituent_tys_for_sizedness_trait( ecx: &EvalCtxt<'_, D>, sizedness: SizedTraitKind, - ty: I::Ty, -) -> Result>, NoSolution> + ty: Ty, +) -> Result>>, NoSolution> where D: SolverDelegate, I: Interner, @@ -186,8 +188,8 @@ where #[instrument(level = "trace", skip(ecx), ret)] pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait( ecx: &EvalCtxt<'_, D>, - ty: I::Ty, -) -> Result>, NoSolution> + ty: Ty, +) -> Result>>, NoSolution> where D: SolverDelegate, I: Interner, @@ -246,7 +248,7 @@ where if ecx.cx().features().coroutine_clone() { Ok(ty::Binder::dummy(vec![ args.as_coroutine().tupled_upvars_ty(), - Ty::new_coroutine_witness_for_coroutine(ecx.cx(), def_id, args), + I::Ty::new_coroutine_witness_for_coroutine(ecx.cx(), def_id, args), ])) } else { Err(NoSolution) @@ -268,17 +270,18 @@ where // Returns a binder of the tupled inputs types and output type from a builtin callable type. pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable( cx: I, - self_ty: I::Ty, + self_ty: Ty, goal_kind: ty::ClosureKind, -) -> Result>, NoSolution> { +) -> Result, Ty)>>, NoSolution> { match self_ty.kind() { // keep this in sync with assemble_fn_pointer_candidates until the old solver is removed. ty::FnDef(def_id, args) => { let sig = cx.fn_sig(def_id); if sig.skip_binder().is_fn_trait_compatible() && !cx.has_target_features(def_id) { Ok(Some( - sig.instantiate(cx, args) - .map_bound(|sig| (Ty::new_tup(cx, sig.inputs().as_slice()), sig.output())), + sig.instantiate(cx, args).map_bound(|sig| { + (I::Ty::new_tup(cx, sig.inputs().as_slice()), sig.output()) + }), )) } else { Err(NoSolution) @@ -289,7 +292,9 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable { - pub tupled_inputs_ty: I::Ty, + pub tupled_inputs_ty: Ty, /// Type returned by calling the closure /// i.e. `f()`. - pub output_coroutine_ty: I::Ty, + pub output_coroutine_ty: Ty, /// Type returned by `await`ing the output /// i.e. `f().await`. - pub coroutine_return_ty: I::Ty, + pub coroutine_return_ty: Ty, } // Returns a binder of the tupled inputs types, output type, and coroutine type @@ -424,7 +429,7 @@ pub(in crate::solve) struct AsyncCallableRelevantTypes { // know the kind already, we can short-circuit this check. pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable( cx: I, - self_ty: I::Ty, + self_ty: Ty, goal_kind: ty::ClosureKind, env_region: I::Region, ) -> Result<(ty::Binder>, Vec), NoSolution> { @@ -455,7 +460,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable( 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_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]); + let future_output_ty = I::Ty::new_projection(cx, future_output_def_id, [sig.output()]); Ok(( bound_sig.rebind(AsyncCallableRelevantTypes { - tupled_inputs_ty: Ty::new_tup(cx, sig.inputs().as_slice()), + tupled_inputs_ty: I::Ty::new_tup(cx, sig.inputs().as_slice()), output_coroutine_ty: sig.output(), coroutine_return_ty: future_output_ty, }), @@ -608,7 +613,7 @@ fn coroutine_closure_to_certain_coroutine( def_id: I::CoroutineClosureId, args: ty::CoroutineClosureArgs, sig: ty::CoroutineClosureSignature, -) -> I::Ty { +) -> Ty { sig.to_coroutine_given_kind_and_upvars( cx, args.parent_args(), @@ -632,14 +637,14 @@ fn coroutine_closure_to_ambiguous_coroutine( def_id: I::CoroutineClosureId, args: ty::CoroutineClosureArgs, sig: ty::CoroutineClosureSignature, -) -> I::Ty { +) -> Ty { let upvars_projection_def_id = cx.require_lang_item(SolverLangItem::AsyncFnKindUpvars); - let tupled_upvars_ty = Ty::new_projection( + let tupled_upvars_ty = I::Ty::new_projection( cx, upvars_projection_def_id, [ I::GenericArg::from(args.kind_ty()), - Ty::from_closure_kind(cx, goal_kind).into(), + I::Ty::from_closure_kind(cx, goal_kind).into(), goal_region.into(), sig.tupled_inputs_ty.into(), args.tupled_upvars_ty().into(), @@ -649,7 +654,7 @@ fn coroutine_closure_to_ambiguous_coroutine( sig.to_coroutine( cx, args.parent_args(), - Ty::from_closure_kind(cx, goal_kind), + I::Ty::from_closure_kind(cx, goal_kind), cx.coroutine_for_closure(def_id), tupled_upvars_ty, ) @@ -664,8 +669,8 @@ fn coroutine_closure_to_ambiguous_coroutine( #[instrument(level = "trace", skip(cx), ret)] pub(in crate::solve) fn extract_fn_def_from_const_callable( cx: I, - self_ty: I::Ty, -) -> Result<(ty::Binder, I::DefId, I::GenericArgs), NoSolution> { + self_ty: Ty, +) -> Result<(ty::Binder, Ty)>, I::DefId, I::GenericArgs), NoSolution> { match self_ty.kind() { ty::FnDef(def_id, args) => { let sig = cx.fn_sig(def_id); @@ -674,8 +679,9 @@ pub(in crate::solve) fn extract_fn_def_from_const_callable( && cx.fn_is_const(def_id) { Ok(( - sig.instantiate(cx, args) - .map_bound(|sig| (Ty::new_tup(cx, sig.inputs().as_slice()), sig.output())), + sig.instantiate(cx, args).map_bound(|sig| { + (I::Ty::new_tup(cx, sig.inputs().as_slice()), sig.output()) + }), def_id.into(), args, )) @@ -742,7 +748,7 @@ pub(in crate::solve) fn extract_fn_def_from_const_callable( // the old solver, for as long as that exists. pub(in crate::solve) fn const_conditions_for_destruct( cx: I, - self_ty: I::Ty, + self_ty: Ty, ) -> Result>, NoSolution> { let destruct_def_id = cx.require_trait_lang_item(SolverTraitLangItem::Destruct); @@ -923,7 +929,7 @@ where struct ReplaceProjectionWith<'a, 'b, I: Interner, D: SolverDelegate> { ecx: &'a mut EvalCtxt<'b, D>, param_env: I::ParamEnv, - self_ty: I::Ty, + self_ty: Ty, mapping: &'a HashMap>>>, nested: Vec>, } @@ -1009,7 +1015,7 @@ where self.ecx.cx() } - fn try_fold_ty(&mut self, ty: I::Ty) -> Result { + fn try_fold_ty(&mut self, ty: Ty) -> Result, Ambiguous> { if let ty::Alias(ty::Projection, alias_ty) = ty.kind() && let Some(term) = self.try_eagerly_replace_alias(alias_ty.into())? { diff --git a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs index 4b1e4b2de571d..9a0a82acbc931 100644 --- a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs @@ -13,7 +13,7 @@ use super::assembly::{Candidate, structural_traits}; use crate::delegate::SolverDelegate; use crate::solve::{ BuiltinImplSource, CandidateSource, Certainty, EvalCtxt, Goal, GoalSource, NoSolution, - QueryResult, assembly, + QueryResult, Ty, assembly, }; impl assembly::GoalKind for ty::HostEffectPredicate @@ -21,7 +21,7 @@ where D: SolverDelegate, I: Interner, { - fn self_ty(self) -> I::Ty { + fn self_ty(self) -> Ty { self.self_ty() } @@ -29,7 +29,7 @@ where self.trait_ref } - fn with_replaced_self_ty(self, cx: I, self_ty: I::Ty) -> Self { + fn with_replaced_self_ty(self, cx: I, self_ty: Ty) -> Self { self.with_replaced_self_ty(cx, self_ty) } diff --git a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs index 6841fe1c5124e..d6ed220909732 100644 --- a/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs @@ -10,7 +10,7 @@ use rustc_type_ir::relate::solver_relating::RelateExt; use rustc_type_ir::search_graph::{CandidateHeadUsages, PathKind}; use rustc_type_ir::solve::OpaqueTypesJank; use rustc_type_ir::{ - self as ty, CanonicalVarValues, InferCtxtLike, Interner, TypeFoldable, TypeFolder, + self as ty, CanonicalVarValues, InferCtxtLike, Interner, Ty, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, }; @@ -781,7 +781,7 @@ where region } - pub(super) fn next_ty_infer(&mut self) -> I::Ty { + pub(super) fn next_ty_infer(&mut self) -> Ty { let ty = self.delegate.next_ty_infer(); self.inspect.add_var_value(ty); ty @@ -829,7 +829,7 @@ where term: I::Term, universe_of_term: ty::UniverseIndex, delegate: &'a D, - cache: HashSet, + cache: HashSet>, } impl, I: Interner> ContainsTermOrNotNameable<'_, D, I> { @@ -846,7 +846,7 @@ where for ContainsTermOrNotNameable<'_, D, I> { type Result = ControlFlow<()>; - fn visit_ty(&mut self, t: I::Ty) -> Self::Result { + fn visit_ty(&mut self, t: Ty) -> Self::Result { if self.cache.contains(&t) { return ControlFlow::Continue(()); } @@ -1072,7 +1072,7 @@ where self.delegate.resolve_vars_if_possible(value) } - pub(super) fn shallow_resolve(&self, ty: I::Ty) -> I::Ty { + pub(super) fn shallow_resolve(&self, ty: Ty) -> Ty { self.delegate.shallow_resolve(ty) } @@ -1092,7 +1092,7 @@ where args } - pub(super) fn register_ty_outlives(&self, ty: I::Ty, lt: I::Region) { + pub(super) fn register_ty_outlives(&self, ty: Ty, lt: I::Region) { self.delegate.register_ty_outlives(ty, lt, self.origin_span); } @@ -1134,8 +1134,8 @@ where pub(super) fn register_hidden_type_in_storage( &mut self, opaque_type_key: ty::OpaqueTypeKey, - hidden_ty: I::Ty, - ) -> Option { + hidden_ty: Ty, + ) -> Option> { self.delegate.register_hidden_type_in_storage(opaque_type_key, hidden_ty, self.origin_span) } @@ -1144,7 +1144,7 @@ where opaque_def_id: I::DefId, opaque_args: I::GenericArgs, param_env: I::ParamEnv, - hidden_ty: I::Ty, + hidden_ty: Ty, ) { let mut goals = Vec::new(); self.delegate.add_item_bounds_for_hidden_type( @@ -1170,8 +1170,8 @@ where pub(super) fn is_transmutable( &mut self, - src: I::Ty, - dst: I::Ty, + src: Ty, + dst: Ty, assume: I::Const, ) -> Result { self.delegate.is_transmutable(dst, src, assume) @@ -1195,7 +1195,7 @@ where pub(crate) fn opaques_with_sub_unified_hidden_type( &self, - self_ty: I::Ty, + self_ty: Ty, ) -> Vec> { if let ty::Infer(ty::TyVar(vid)) = self_ty.kind() { self.delegate.opaques_with_sub_unified_hidden_type(vid) @@ -1389,7 +1389,7 @@ where ecx: &'me mut EvalCtxt<'a, D>, param_env: I::ParamEnv, normalization_goal_source: GoalSource, - cache: HashMap, + cache: HashMap, Ty>, } impl<'me, 'a, D, I> ReplaceAliasWithInfer<'me, 'a, D, I> @@ -1421,7 +1421,7 @@ where self.ecx.cx() } - fn fold_ty(&mut self, ty: I::Ty) -> I::Ty { + fn fold_ty(&mut self, ty: Ty) -> Ty { match ty.kind() { ty::Alias(..) if !ty.has_escaping_bound_vars() => { let infer_ty = self.ecx.next_ty_infer(); diff --git a/compiler/rustc_next_trait_solver/src/solve/mod.rs b/compiler/rustc_next_trait_solver/src/solve/mod.rs index 58bd7cf663d98..71b28cf1ad277 100644 --- a/compiler/rustc_next_trait_solver/src/solve/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/mod.rs @@ -24,7 +24,7 @@ mod trait_goals; use derive_where::derive_where; use rustc_type_ir::inherent::*; pub use rustc_type_ir::solve::*; -use rustc_type_ir::{self as ty, Interner, TyVid, TypingMode}; +use rustc_type_ir::{self as ty, Interner, Ty, TyVid, TypingMode}; use tracing::instrument; pub use self::eval_ctxt::{ @@ -88,7 +88,7 @@ where #[instrument(level = "trace", skip(self))] fn compute_type_outlives_goal( &mut self, - goal: Goal>, + goal: Goal>>, ) -> QueryResult { let ty::OutlivesPredicate(ty, lt) = goal.predicate; self.register_ty_outlives(ty, lt); @@ -205,7 +205,7 @@ where #[instrument(level = "trace", skip(self), ret)] fn compute_const_arg_has_type_goal( &mut self, - goal: Goal, + goal: Goal)>, ) -> QueryResult { let (ct, ty) = goal.predicate; let ct = self.structurally_normalize_const(goal.param_env, ct)?; @@ -315,8 +315,8 @@ where fn structurally_normalize_ty( &mut self, param_env: I::ParamEnv, - ty: I::Ty, - ) -> Result { + ty: Ty, + ) -> Result, NoSolution> { self.structurally_normalize_term(param_env, ty.into()).map(|term| term.expect_ty()) } diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs index 13f2ad8f82eba..376a817370496 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs @@ -4,10 +4,14 @@ mod inherent; mod opaque_types; use rustc_type_ir::fast_reject::DeepRejectCtxt; +#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] +use rustc_type_ir::inherent::Ty as _; use rustc_type_ir::inherent::*; use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem}; use rustc_type_ir::solve::SizedTraitKind; -use rustc_type_ir::{self as ty, FieldInfo, Interner, NormalizesTo, PredicateKind, Upcast as _}; +use rustc_type_ir::{ + self as ty, FieldInfo, Interner, NormalizesTo, PredicateKind, Ty, Upcast as _, +}; use tracing::instrument; use crate::delegate::SolverDelegate; @@ -125,7 +129,7 @@ where D: SolverDelegate, I: Interner, { - fn self_ty(self) -> I::Ty { + fn self_ty(self) -> Ty { self.self_ty() } @@ -133,7 +137,7 @@ where self.alias.trait_ref(cx) } - fn with_replaced_self_ty(self, cx: I, self_ty: I::Ty) -> Self { + fn with_replaced_self_ty(self, cx: I, self_ty: Ty) -> Self { self.with_replaced_self_ty(cx, self_ty) } @@ -263,7 +267,7 @@ where let error_response = |ecx: &mut EvalCtxt<'_, D>, guar| { let error_term = match goal.predicate.alias.kind(cx) { - ty::AliasTermKind::ProjectionTy => Ty::new_error(cx, guar).into(), + ty::AliasTermKind::ProjectionTy => I::Ty::new_error(cx, guar).into(), ty::AliasTermKind::ProjectionConst => Const::new_error(cx, guar).into(), kind => panic!("expected projection, found {kind:?}"), }; @@ -641,11 +645,11 @@ where | ty::Coroutine(..) | ty::CoroutineWitness(..) | ty::Never - | ty::Foreign(..) => Ty::new_unit(cx), + | ty::Foreign(..) => I::Ty::new_unit(cx), - ty::Error(e) => Ty::new_error(cx, e), + ty::Error(e) => I::Ty::new_error(cx, e), - ty::Str | ty::Slice(_) => Ty::new_usize(cx), + ty::Str | ty::Slice(_) => I::Ty::new_usize(cx), ty::Dynamic(_, _) => { let dyn_metadata = cx.require_lang_item(SolverLangItem::DynMetadata); @@ -666,7 +670,7 @@ where [I::GenericArg::from(goal.predicate.self_ty())], ); ecx.add_goal(GoalSource::Misc, goal.with(cx, sized_predicate)); - ecx.instantiate_normalizes_to_term(goal, Ty::new_unit(cx).into()); + ecx.instantiate_normalizes_to_term(goal, I::Ty::new_unit(cx).into()); ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) }); // In case the dummy alias-bound candidate does not apply, we instead treat this projection @@ -683,16 +687,16 @@ where } ty::Adt(def, args) if def.is_struct() => match def.struct_tail_ty(cx) { - None => Ty::new_unit(cx), + None => I::Ty::new_unit(cx), Some(tail_ty) => { - Ty::new_projection(cx, metadata_def_id, [tail_ty.instantiate(cx, args)]) + I::Ty::new_projection(cx, metadata_def_id, [tail_ty.instantiate(cx, args)]) } }, - ty::Adt(_, _) => Ty::new_unit(cx), + ty::Adt(_, _) => I::Ty::new_unit(cx), ty::Tuple(elements) => match elements.last() { - None => Ty::new_unit(cx), - Some(tail_ty) => Ty::new_projection(cx, metadata_def_id, [tail_ty]), + None => I::Ty::new_unit(cx), + Some(tail_ty) => I::Ty::new_projection(cx, metadata_def_id, [tail_ty]), }, ty::UnsafeBinder(_) => { @@ -803,10 +807,10 @@ where let expected_ty = ecx.next_ty_infer(); // Take `AsyncIterator` and turn it into the corresponding // coroutine yield ty `Poll>`. - let wrapped_expected_ty = Ty::new_adt( + let wrapped_expected_ty = I::Ty::new_adt( cx, cx.adt_def(cx.require_adt_lang_item(SolverAdtLangItem::Poll)), - cx.mk_args(&[Ty::new_adt( + cx.mk_args(&[I::Ty::new_adt( cx, cx.adt_def(cx.require_adt_lang_item(SolverAdtLangItem::Option)), cx.mk_args(&[expected_ty.into()]), diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index 6589a12c4cc2d..478241648e25a 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -2,13 +2,15 @@ use rustc_type_ir::data_structures::IndexSet; use rustc_type_ir::fast_reject::DeepRejectCtxt; +#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] +use rustc_type_ir::inherent::Ty as _; use rustc_type_ir::inherent::*; use rustc_type_ir::lang_items::SolverTraitLangItem; use rustc_type_ir::solve::{ AliasBoundKind, CandidatePreferenceMode, CanonicalResponse, SizedTraitKind, }; use rustc_type_ir::{ - self as ty, FieldInfo, Interner, Movability, PredicatePolarity, TraitPredicate, TraitRef, + self as ty, FieldInfo, Interner, Movability, PredicatePolarity, TraitPredicate, TraitRef, Ty, TypeVisitableExt as _, TypingMode, Upcast as _, elaborate, }; use tracing::{debug, instrument, trace}; @@ -29,7 +31,7 @@ where D: SolverDelegate, I: Interner, { - fn self_ty(self) -> I::Ty { + fn self_ty(self) -> Ty { self.self_ty() } @@ -37,7 +39,7 @@ where self.trait_ref } - fn with_replaced_self_ty(self, cx: I, self_ty: I::Ty) -> Self { + fn with_replaced_self_ty(self, cx: I, self_ty: Ty) -> Self { self.with_replaced_self_ty(cx, self_ty) } @@ -929,7 +931,7 @@ where /// ``` fn consider_builtin_dyn_upcast_candidates( &mut self, - goal: Goal, + goal: Goal, Ty)>, a_data: I::BoundExistentialPredicates, a_region: I::Region, b_data: I::BoundExistentialPredicates, @@ -977,7 +979,7 @@ where fn consider_builtin_unsize_to_dyn_candidate( &mut self, - goal: Goal, + goal: Goal, Ty)>, b_data: I::BoundExistentialPredicates, b_region: I::Region, ) -> Result, NoSolution> { @@ -1018,7 +1020,7 @@ where fn consider_builtin_upcast_to_principal( &mut self, - goal: Goal, + goal: Goal, Ty)>, source: CandidateSource, a_data: I::BoundExistentialPredicates, a_region: I::Region, @@ -1132,9 +1134,9 @@ where /// `#[rustc_deny_explicit_impl]` in this case. fn consider_builtin_array_unsize( &mut self, - goal: Goal, - a_elem_ty: I::Ty, - b_elem_ty: I::Ty, + goal: Goal, Ty)>, + a_elem_ty: Ty, + b_elem_ty: Ty, ) -> Result, NoSolution> { self.eq(goal.param_env, a_elem_ty, b_elem_ty)?; self.probe_builtin_trait_candidate(BuiltinImplSource::Misc) @@ -1156,7 +1158,7 @@ where /// ``` fn consider_builtin_struct_unsize( &mut self, - goal: Goal, + goal: Goal, Ty)>, def: I::AdtDef, a_args: I::GenericArgs, b_args: I::GenericArgs, @@ -1182,7 +1184,7 @@ where let new_a_args = cx.mk_args_from_iter(a_args.iter().enumerate().map(|(i, a)| { if unsizing_params.contains(i as u32) { b_args.get(i).unwrap() } else { a } })); - let unsized_a_ty = Ty::new_adt(cx, def, new_a_args); + let unsized_a_ty = I::Ty::new_adt(cx, def, new_a_args); // Finally, we require that `TailA: Unsize` for the tail field // types. @@ -1319,8 +1321,8 @@ where goal: Goal>, constituent_tys: impl Fn( &EvalCtxt<'_, D>, - I::Ty, - ) -> Result>, NoSolution>, + Ty, + ) -> Result>>, NoSolution>, ) -> Result, NoSolution> { self.probe_trait_candidate(source).enter(|ecx| { let goals = @@ -1542,7 +1544,7 @@ where self.merge_trait_candidates(candidate_preference_mode, candidates, failed_candidate_info) } - fn try_stall_coroutine(&mut self, self_ty: I::Ty) -> Option, NoSolution>> { + fn try_stall_coroutine(&mut self, self_ty: Ty) -> Option, NoSolution>> { if let ty::Coroutine(def_id, _) = self_ty.kind() { match self.typing_mode() { TypingMode::Analysis { diff --git a/compiler/rustc_type_ir/src/binder.rs b/compiler/rustc_type_ir/src/binder.rs index 0b0f0fd2f4249..6528aa7526b21 100644 --- a/compiler/rustc_type_ir/src/binder.rs +++ b/compiler/rustc_type_ir/src/binder.rs @@ -16,7 +16,7 @@ use crate::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldabl use crate::inherent::*; use crate::lift::Lift; use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor}; -use crate::{self as ty, DebruijnIndex, Interner, UniverseIndex}; +use crate::{self as ty, DebruijnIndex, Interner, Ty, UniverseIndex}; /// `Binder` is a binder for higher-ranked lifetimes or types. It is part of the /// compiler's representation for things like `for<'a> Fn(&'a isize)` @@ -274,7 +274,7 @@ pub struct ValidateBoundVars { // We only cache types because any complex const will have to step through // a type at some point anyways. We may encounter the same variable at // different levels of binding, so this can't just be `Ty`. - visited: SsoHashSet<(ty::DebruijnIndex, I::Ty)>, + visited: SsoHashSet<(ty::DebruijnIndex, Ty)>, } impl ValidateBoundVars { @@ -297,7 +297,7 @@ impl TypeVisitor for ValidateBoundVars { result } - fn visit_ty(&mut self, t: I::Ty) -> Self::Result { + fn visit_ty(&mut self, t: Ty) -> Self::Result { if t.outer_exclusive_binder() < self.binder_index || !self.visited.insert((self.binder_index, t)) { @@ -724,7 +724,7 @@ impl<'a, I: Interner> TypeFolder for ArgFolder<'a, I> { } } - fn fold_ty(&mut self, t: I::Ty) -> I::Ty { + fn fold_ty(&mut self, t: Ty) -> Ty { if !t.has_param() { return t; } @@ -753,7 +753,7 @@ impl<'a, I: Interner> TypeFolder for ArgFolder<'a, I> { } impl<'a, I: Interner> ArgFolder<'a, I> { - fn ty_for_param(&self, p: I::ParamTy, source_ty: I::Ty) -> I::Ty { + fn ty_for_param(&self, p: I::ParamTy, source_ty: Ty) -> Ty { // Look up the type in the args. It really should be in there. let opt_ty = self.args.get(p.index() as usize).map(|arg| arg.kind()); let ty = match opt_ty { @@ -767,7 +767,7 @@ impl<'a, I: Interner> ArgFolder<'a, I> { #[cold] #[inline(never)] - fn type_param_expected(&self, p: I::ParamTy, ty: I::Ty, kind: ty::GenericArgKind) -> ! { + fn type_param_expected(&self, p: I::ParamTy, ty: Ty, kind: ty::GenericArgKind) -> ! { panic!( "expected type for `{:?}` ({:?}/{}) but found {:?} when instantiating, args={:?}", p, @@ -780,7 +780,7 @@ impl<'a, I: Interner> ArgFolder<'a, I> { #[cold] #[inline(never)] - fn type_param_out_of_range(&self, p: I::ParamTy, ty: I::Ty) -> ! { + fn type_param_out_of_range(&self, p: I::ParamTy, ty: Ty) -> ! { panic!( "type parameter `{:?}` ({:?}/{}) out of range when instantiating, args={:?}", p, @@ -1277,7 +1277,7 @@ impl PlaceholderConst { Self { universe: ui, bound, _tcx: PhantomData } } - pub fn find_const_ty_from_env(self, env: I::ParamEnv) -> I::Ty { + pub fn find_const_ty_from_env(self, env: I::ParamEnv) -> Ty { let mut candidates = env.caller_bounds().iter().filter_map(|clause| { // `ConstArgHasType` are never desugared to be higher ranked. match clause.kind().skip_binder() { diff --git a/compiler/rustc_type_ir/src/error.rs b/compiler/rustc_type_ir/src/error.rs index eba4c7c6644ac..ef542af7f1f9a 100644 --- a/compiler/rustc_type_ir/src/error.rs +++ b/compiler/rustc_type_ir/src/error.rs @@ -2,7 +2,7 @@ use derive_where::derive_where; use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic}; use crate::solve::NoSolution; -use crate::{self as ty, Interner}; +use crate::{self as ty, Interner, Ty}; #[derive(Clone, Copy, Debug, PartialEq, Eq)] #[derive(TypeFoldable_Generic, TypeVisitable_Generic, GenericTypeVisitable)] @@ -36,15 +36,15 @@ pub enum TypeError { RegionsInsufficientlyPolymorphic(ty::BoundRegion, I::Region), RegionsPlaceholderMismatch, - Sorts(ExpectedFound), - ArgumentSorts(ExpectedFound, usize), + Sorts(ExpectedFound>), + ArgumentSorts(ExpectedFound>, usize), Traits(ExpectedFound), VariadicMismatch(ExpectedFound), /// Instantiating a type variable with the given type would have /// created a cycle (because it appears somewhere within that /// type). - CyclicTy(I::Ty), + CyclicTy(Ty), CyclicConst(I::Const), ProjectionMismatched(ExpectedFound), ExistentialMismatch(ExpectedFound), diff --git a/compiler/rustc_type_ir/src/fast_reject.rs b/compiler/rustc_type_ir/src/fast_reject.rs index ed6416a7f55f2..884d6bce4b71c 100644 --- a/compiler/rustc_type_ir/src/fast_reject.rs +++ b/compiler/rustc_type_ir/src/fast_reject.rs @@ -11,9 +11,11 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHas #[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext}; +#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] +use crate::inherent::Ty as _; use crate::inherent::*; use crate::visit::TypeVisitableExt as _; -use crate::{self as ty, Interner}; +use crate::{self as ty, Interner, Ty}; /// See `simplify_type`. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -113,7 +115,7 @@ pub enum TreatParams { /// ¹ meaning that if the outermost layers are different, then the whole types are also different. pub fn simplify_type( cx: I, - ty: I::Ty, + ty: Ty, treat_params: TreatParams, ) -> Option> { match ty.kind() { @@ -236,11 +238,11 @@ impl bool { + pub fn types_may_unify(self, lhs: Ty, rhs: Ty) -> bool { self.types_may_unify_inner(lhs, rhs, Self::STARTING_DEPTH) } - pub fn types_may_unify_with_depth(self, lhs: I::Ty, rhs: I::Ty, depth_limit: usize) -> bool { + pub fn types_may_unify_with_depth(self, lhs: Ty, rhs: Ty, depth_limit: usize) -> bool { self.types_may_unify_inner(lhs, rhs, depth_limit) } @@ -268,7 +270,7 @@ impl bool { + fn types_may_unify_inner(self, lhs: Ty, rhs: Ty, depth: usize) -> bool { if lhs == rhs { return true; } @@ -527,7 +529,7 @@ impl bool { + fn var_and_ty_may_unify(self, var: ty::InferTy, ty: Ty) -> bool { if !ty.is_known_rigid() { return true; } diff --git a/compiler/rustc_type_ir/src/flags.rs b/compiler/rustc_type_ir/src/flags.rs index 7e905da0785f8..6962a7ab1d727 100644 --- a/compiler/rustc_type_ir/src/flags.rs +++ b/compiler/rustc_type_ir/src/flags.rs @@ -1,6 +1,6 @@ use crate::inherent::*; use crate::visit::Flags; -use crate::{self as ty, Interner}; +use crate::{self as ty, Interner, Ty}; bitflags::bitflags! { /// Flags that we track on types. These flags are propagated upwards @@ -430,7 +430,7 @@ impl FlagComputation { } } - fn add_ty(&mut self, ty: I::Ty) { + fn add_ty(&mut self, ty: Ty) { self.add_flags(ty.flags()); self.add_exclusive_binder(ty.outer_exclusive_binder()); } diff --git a/compiler/rustc_type_ir/src/fold.rs b/compiler/rustc_type_ir/src/fold.rs index d1a50599e8b9c..4e8e0a4ed4015 100644 --- a/compiler/rustc_type_ir/src/fold.rs +++ b/compiler/rustc_type_ir/src/fold.rs @@ -53,9 +53,11 @@ use rustc_index::{Idx, IndexVec}; use thin_vec::ThinVec; use tracing::{debug, instrument}; +#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] +use crate::inherent::Ty as _; use crate::inherent::*; use crate::visit::{TypeVisitable, TypeVisitableExt as _}; -use crate::{self as ty, BoundVarIndexKind, Interner, TypeFlags}; +use crate::{self as ty, BoundVarIndexKind, Interner, Ty, TypeFlags}; /// This trait is implemented for every type that can be folded, /// providing the skeleton of the traversal. @@ -135,7 +137,7 @@ pub trait TypeFolder: Sized { t.super_fold_with(self) } - fn fold_ty(&mut self, t: I::Ty) -> I::Ty { + fn fold_ty(&mut self, t: Ty) -> Ty { t.super_fold_with(self) } @@ -177,7 +179,7 @@ pub trait FallibleTypeFolder: Sized { t.try_super_fold_with(self) } - fn try_fold_ty(&mut self, t: I::Ty) -> Result { + fn try_fold_ty(&mut self, t: Ty) -> Result, Self::Error> { t.try_super_fold_with(self) } @@ -408,13 +410,13 @@ impl TypeFolder for Shifter { } } - fn fold_ty(&mut self, ty: I::Ty) -> I::Ty { + fn fold_ty(&mut self, ty: Ty) -> Ty { match ty.kind() { ty::Bound(BoundVarIndexKind::Bound(debruijn), bound_ty) if debruijn >= self.current_index => { let debruijn = debruijn.shifted_in(self.amount); - Ty::new_bound(self.cx, debruijn, bound_ty) + I::Ty::new_bound(self.cx, debruijn, bound_ty) } _ if ty.has_vars_bound_at_or_above(self.current_index) => ty.super_fold_with(self), @@ -538,7 +540,7 @@ where } } - fn fold_ty(&mut self, t: I::Ty) -> I::Ty { + fn fold_ty(&mut self, t: Ty) -> Ty { if t.has_type_flags( TypeFlags::HAS_FREE_REGIONS | TypeFlags::HAS_RE_BOUND | TypeFlags::HAS_RE_ERASED, ) { diff --git a/compiler/rustc_type_ir/src/generic_arg.rs b/compiler/rustc_type_ir/src/generic_arg.rs index 5d612740fdd84..22a4ebd03b69c 100644 --- a/compiler/rustc_type_ir/src/generic_arg.rs +++ b/compiler/rustc_type_ir/src/generic_arg.rs @@ -3,7 +3,7 @@ use derive_where::derive_where; use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext}; use rustc_type_ir_macros::GenericTypeVisitable; -use crate::Interner; +use crate::{Interner, Ty}; #[derive_where(Clone, Copy, PartialEq, Debug; I: Interner)] #[derive(GenericTypeVisitable)] @@ -13,7 +13,7 @@ use crate::Interner; )] pub enum GenericArgKind { Lifetime(I::Region), - Type(I::Ty), + Type(Ty), Const(I::Const), } @@ -26,7 +26,7 @@ impl Eq for GenericArgKind {} derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) )] pub enum TermKind { - Ty(I::Ty), + Ty(Ty), Const(I::Const), } diff --git a/compiler/rustc_type_ir/src/infer_ctxt.rs b/compiler/rustc_type_ir/src/infer_ctxt.rs index feafcee7bad9e..843d1eb37b7d9 100644 --- a/compiler/rustc_type_ir/src/infer_ctxt.rs +++ b/compiler/rustc_type_ir/src/infer_ctxt.rs @@ -6,7 +6,7 @@ use crate::fold::TypeFoldable; use crate::inherent::*; use crate::relate::RelateResult; use crate::relate::combine::PredicateEmittingRelation; -use crate::{self as ty, Interner, TyVid}; +use crate::{self as ty, Interner, Ty, TyVid}; /// The current typing mode of an inference context. We unfortunately have some /// slightly different typing rules depending on the current context. See the @@ -161,12 +161,9 @@ pub trait InferCtxtLike: Sized { fn sub_unification_table_root_var(&self, var: ty::TyVid) -> ty::TyVid; fn root_const_var(&self, var: ty::ConstVid) -> ty::ConstVid; - fn opportunistic_resolve_ty_var(&self, vid: ty::TyVid) -> ::Ty; - fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> ::Ty; - fn opportunistic_resolve_float_var( - &self, - vid: ty::FloatVid, - ) -> ::Ty; + fn opportunistic_resolve_ty_var(&self, vid: ty::TyVid) -> Ty; + fn opportunistic_resolve_int_var(&self, vid: ty::IntVid) -> Ty; + fn opportunistic_resolve_float_var(&self, vid: ty::FloatVid) -> Ty; fn opportunistic_resolve_ct_var( &self, vid: ty::ConstVid, @@ -179,7 +176,7 @@ pub trait InferCtxtLike: Sized { fn is_changed_arg(&self, arg: ::GenericArg) -> bool; fn next_region_infer(&self) -> ::Region; - fn next_ty_infer(&self) -> ::Ty; + fn next_ty_infer(&self) -> Ty; fn next_const_infer(&self) -> ::Const; fn fresh_args_for_item( &self, @@ -209,7 +206,7 @@ pub trait InferCtxtLike: Sized { target_is_expected: bool, target_vid: ty::TyVid, instantiation_variance: ty::Variance, - source_ty: ::Ty, + source_ty: Ty, ) -> RelateResult; fn instantiate_int_var_raw(&self, vid: ty::IntVid, value: ty::IntVarValue); fn instantiate_float_var_raw(&self, vid: ty::FloatVid, value: ty::FloatVarValue); @@ -223,10 +220,7 @@ pub trait InferCtxtLike: Sized { fn set_tainted_by_errors(&self, e: ::ErrorGuaranteed); - fn shallow_resolve( - &self, - ty: ::Ty, - ) -> ::Ty; + fn shallow_resolve(&self, ty: Ty) -> Ty; fn shallow_resolve_const( &self, ty: ::Const, @@ -254,7 +248,7 @@ pub trait InferCtxtLike: Sized { fn register_ty_outlives( &self, - ty: ::Ty, + ty: Ty, r: ::Region, span: ::Span, ); @@ -263,26 +257,26 @@ pub trait InferCtxtLike: Sized { fn opaque_types_storage_num_entries(&self) -> Self::OpaqueTypeStorageEntries; fn clone_opaque_types_lookup_table( &self, - ) -> Vec<(ty::OpaqueTypeKey, ::Ty)>; + ) -> Vec<(ty::OpaqueTypeKey, Ty)>; fn clone_duplicate_opaque_types( &self, - ) -> Vec<(ty::OpaqueTypeKey, ::Ty)>; + ) -> Vec<(ty::OpaqueTypeKey, Ty)>; fn clone_opaque_types_added_since( &self, prev_entries: Self::OpaqueTypeStorageEntries, - ) -> Vec<(ty::OpaqueTypeKey, ::Ty)>; + ) -> Vec<(ty::OpaqueTypeKey, Ty)>; fn opaques_with_sub_unified_hidden_type(&self, ty: TyVid) -> Vec>; fn register_hidden_type_in_storage( &self, opaque_type_key: ty::OpaqueTypeKey, - hidden_ty: ::Ty, + hidden_ty: Ty, span: ::Span, - ) -> Option<::Ty>; + ) -> Option>; fn add_duplicate_opaque_type( &self, opaque_type_key: ty::OpaqueTypeKey, - hidden_ty: ::Ty, + hidden_ty: Ty, span: ::Span, ); diff --git a/compiler/rustc_type_ir/src/inherent.rs b/compiler/rustc_type_ir/src/inherent.rs index 116fd100bf0a9..a4af4bc040be6 100644 --- a/compiler/rustc_type_ir/src/inherent.rs +++ b/compiler/rustc_type_ir/src/inherent.rs @@ -14,7 +14,8 @@ use crate::relate::Relate; use crate::solve::{AdtDestructorKind, SizedTraitKind}; use crate::visit::{Flags, TypeSuperVisitable, TypeVisitable}; use crate::{ - self as ty, ClauseKind, CollectAndApply, FieldInfo, Interner, PredicateKind, UpcastFrom, + self as ty, ClauseKind, CollectAndApply, FieldInfo, Interner, PredicateKind, Ty as IrTy, + UpcastFrom, }; pub trait Ty>: @@ -55,7 +56,7 @@ pub trait Ty>: fn new_alias(interner: I, kind: ty::AliasTyKind, alias_ty: ty::AliasTy) -> Self; fn new_projection_from_args(interner: I, def_id: I::DefId, args: I::GenericArgs) -> Self { - Ty::new_alias( + Self::new_alias( interner, ty::AliasTyKind::Projection, ty::AliasTy::new_from_args(interner, def_id, args), @@ -67,7 +68,7 @@ pub trait Ty>: def_id: I::DefId, args: impl IntoIterator>, ) -> Self { - Ty::new_alias( + Self::new_alias( interner, ty::AliasTyKind::Projection, ty::AliasTy::new(interner, def_id, args), @@ -108,7 +109,7 @@ pub trait Ty>: fn new_slice(interner: I, ty: Self) -> Self; - fn new_tup(interner: I, tys: &[I::Ty]) -> Self; + fn new_tup(interner: I, tys: &[IrTy]) -> Self; fn new_tup_from_iter(interner: I, iter: It) -> T::Output where @@ -121,7 +122,7 @@ pub trait Ty>: fn new_pat(interner: I, ty: Self, pat: I::Pat) -> Self; - fn new_unsafe_binder(interner: I, ty: ty::Binder) -> Self; + fn new_unsafe_binder(interner: I, ty: ty::Binder>) -> Self; fn tuple_fields(self) -> I::Tys; @@ -158,7 +159,7 @@ pub trait Ty>: self.kind().fn_sig(interner) } - fn discriminant_ty(self, interner: I) -> I::Ty; + fn discriminant_ty(self, interner: I) -> IrTy; fn is_known_rigid(self) -> bool { self.kind().is_known_rigid() @@ -198,11 +199,11 @@ pub trait Ty>: } pub trait Tys>: - Copy + Debug + Hash + Eq + SliceLike + TypeFoldable + Default + Copy + Debug + Hash + Eq + SliceLike> + TypeFoldable + Default { fn inputs(self) -> I::FnInputTys; - fn output(self) -> I::Ty; + fn output(self) -> IrTy; } pub trait Abi>: Copy + Debug + Hash + Eq { @@ -290,7 +291,7 @@ pub trait Const>: } pub trait ValueConst>: Copy + Debug + Hash + Eq { - fn ty(self) -> I::Ty; + fn ty(self) -> IrTy; fn valtree(self) -> I::ValTree; } @@ -310,7 +311,7 @@ pub trait GenericArg>: + IntoKind> + TypeVisitable + Relate - + From + + From> + From + From + From @@ -323,11 +324,11 @@ pub trait GenericArg>: } } - fn as_type(&self) -> Option { + fn as_type(&self) -> Option> { if let ty::GenericArgKind::Type(ty) = self.kind() { Some(ty) } else { None } } - fn expect_ty(&self) -> I::Ty { + fn expect_ty(&self) -> IrTy { self.as_type().expect("expected a type") } @@ -359,11 +360,11 @@ pub trait GenericArg>: pub trait Term>: Copy + Debug + Hash + Eq + IntoKind> + TypeFoldable + Relate { - fn as_type(&self) -> Option { + fn as_type(&self) -> Option> { if let ty::TermKind::Ty(ty) = self.kind() { Some(ty) } else { None } } - fn expect_ty(&self) -> I::Ty { + fn expect_ty(&self) -> IrTy { self.as_type().expect("expected a type, but found a const") } @@ -413,7 +414,7 @@ pub trait GenericArgs>: target: I::GenericArgs, ) -> I::GenericArgs; - fn type_at(self, i: usize) -> I::Ty; + fn type_at(self, i: usize) -> IrTy; fn region_at(self, i: usize) -> I::Region; @@ -459,7 +460,7 @@ pub trait Predicate>: + UpcastFrom> + UpcastFrom>> + UpcastFrom> - + UpcastFrom> + + UpcastFrom>> + UpcastFrom> + IntoKind>> + Elaboratable @@ -578,7 +579,7 @@ pub trait AdtDef: Copy + Debug + Hash + Eq { /// Returns the type of the struct tail. /// /// Expects the `AdtDef` to be a struct. If it is not, then this will panic. - fn struct_tail_ty(self, interner: I) -> Option>; + fn struct_tail_ty(self, interner: I) -> Option>>; fn is_phantom_data(self) -> bool; @@ -591,13 +592,13 @@ pub trait AdtDef: Copy + Debug + Hash + Eq { ) -> Option>; // FIXME: perhaps use `all_fields` and expose `FieldDef`. - fn all_field_tys(self, interner: I) -> ty::EarlyBinder>; + fn all_field_tys(self, interner: I) -> ty::EarlyBinder>>; fn sizedness_constraint( self, interner: I, sizedness: SizedTraitKind, - ) -> Option>; + ) -> Option>>; fn is_fundamental(self) -> bool; diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index a0b444024ca79..6c838cf8a48ac 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -31,6 +31,7 @@ pub mod outlives; pub mod relate; pub mod search_graph; pub mod solve; +pub mod sty; pub mod walk; // These modules are not `pub` since they are glob-imported. @@ -78,6 +79,7 @@ pub use predicate_kind::*; pub use region_kind::*; pub use rustc_ast_ir::{FloatTy, IntTy, Movability, Mutability, Pinnedness, UintTy}; use rustc_type_ir_macros::GenericTypeVisitable; +pub use sty::*; pub use ty_info::*; pub use ty_kind::*; pub use upcast::*; @@ -443,8 +445,8 @@ impl fmt::Display for ClosureKind { } pub struct FieldInfo { - pub base: I::Ty, - pub ty: I::Ty, + pub base: Ty, + pub ty: Ty, pub variant: Option, pub variant_idx: VariantIdx, pub name: I::Symbol, diff --git a/compiler/rustc_type_ir/src/outlives.rs b/compiler/rustc_type_ir/src/outlives.rs index 300e5c0b46956..cc79d6589e6fb 100644 --- a/compiler/rustc_type_ir/src/outlives.rs +++ b/compiler/rustc_type_ir/src/outlives.rs @@ -8,7 +8,7 @@ use smallvec::{SmallVec, smallvec}; use crate::data_structures::SsoHashSet; use crate::inherent::*; use crate::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt as _, TypeVisitor}; -use crate::{self as ty, Interner}; +use crate::{self as ty, Interner, Ty}; #[derive_where(Debug; I: Interner)] pub enum Component { @@ -55,7 +55,7 @@ pub enum Component { /// `ty0: 'a` to hold. Note that `ty0` must be a **fully resolved type**. pub fn push_outlives_components( cx: I, - ty: I::Ty, + ty: Ty, out: &mut SmallVec<[Component; 4]>, ) { ty.visit_with(&mut OutlivesCollector { cx, out, visited: Default::default() }); @@ -64,14 +64,14 @@ pub fn push_outlives_components( struct OutlivesCollector<'a, I: Interner> { cx: I, out: &'a mut SmallVec<[Component; 4]>, - visited: SsoHashSet, + visited: SsoHashSet>, } impl TypeVisitor for OutlivesCollector<'_, I> { #[cfg(not(feature = "nightly"))] type Result = (); - fn visit_ty(&mut self, ty: I::Ty) -> Self::Result { + fn visit_ty(&mut self, ty: Ty) -> Self::Result { if !self.visited.insert(ty) { return; } diff --git a/compiler/rustc_type_ir/src/predicate.rs b/compiler/rustc_type_ir/src/predicate.rs index 113192cc02eb8..b8ea99777aaba 100644 --- a/compiler/rustc_type_ir/src/predicate.rs +++ b/compiler/rustc_type_ir/src/predicate.rs @@ -10,11 +10,13 @@ use rustc_type_ir_macros::{ GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic, }; +#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] +use crate::inherent::Ty as _; use crate::inherent::*; use crate::lift::Lift; use crate::upcast::{Upcast, UpcastFrom}; use crate::visit::TypeVisitableExt as _; -use crate::{self as ty, Interner}; +use crate::{self as ty, Interner, Ty}; /// `A: 'region` #[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, A)] @@ -101,7 +103,7 @@ impl TraitRef { ) } - pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self { + pub fn with_replaced_self_ty(self, interner: I, self_ty: Ty) -> Self { TraitRef::new( interner, self.def_id, @@ -110,13 +112,13 @@ impl TraitRef { } #[inline] - pub fn self_ty(&self) -> I::Ty { + pub fn self_ty(&self) -> Ty { self.args.type_at(0) } } impl ty::Binder> { - pub fn self_ty(&self) -> ty::Binder { + pub fn self_ty(&self) -> ty::Binder> { self.map_bound_ref(|tr| tr.self_ty()) } @@ -152,7 +154,7 @@ pub struct TraitPredicate { impl Eq for TraitPredicate {} impl TraitPredicate { - pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self { + pub fn with_replaced_self_ty(self, interner: I, self_ty: Ty) -> Self { Self { trait_ref: self.trait_ref.with_replaced_self_ty(interner, self_ty), polarity: self.polarity, @@ -163,7 +165,7 @@ impl TraitPredicate { self.trait_ref.def_id } - pub fn self_ty(self) -> I::Ty { + pub fn self_ty(self) -> Ty { self.trait_ref.self_ty() } } @@ -174,7 +176,7 @@ impl ty::Binder> { self.skip_binder().def_id() } - pub fn self_ty(self) -> ty::Binder { + pub fn self_ty(self) -> ty::Binder> { self.map_bound(|trait_ref| trait_ref.self_ty()) } @@ -307,7 +309,7 @@ impl ty::Binder> { /// Given an existential predicate like `?Self: PartialEq` (e.g., derived from `dyn PartialEq`), /// and a concrete type `self_ty`, returns a full predicate where the existentially quantified variable `?Self` /// has been replaced with `self_ty` (e.g., `self_ty: PartialEq`, in our example). - pub fn with_self_ty(&self, cx: I, self_ty: I::Ty) -> I::Clause { + pub fn with_self_ty(&self, cx: I, self_ty: Ty) -> I::Clause { match self.skip_binder() { ExistentialPredicate::Trait(tr) => self.rebind(tr).with_self_ty(cx, self_ty).upcast(cx), ExistentialPredicate::Projection(p) => { @@ -384,7 +386,7 @@ impl ExistentialTraitRef { /// we convert the principal trait-ref into a normal trait-ref, /// you must give *some* self type. A common choice is `mk_err()` /// or some placeholder type. - pub fn with_self_ty(self, interner: I, self_ty: I::Ty) -> TraitRef { + pub fn with_self_ty(self, interner: I, self_ty: Ty) -> TraitRef { // otherwise the escaping vars would be captured by the binder // debug_assert!(!self_ty.has_escaping_bound_vars()); @@ -401,7 +403,7 @@ impl ty::Binder> { /// we convert the principal trait-ref into a normal trait-ref, /// you must give *some* self type. A common choice is `mk_err()` /// or some placeholder type. - pub fn with_self_ty(&self, cx: I, self_ty: I::Ty) -> ty::Binder> { + pub fn with_self_ty(&self, cx: I, self_ty: Ty) -> ty::Binder> { self.map_bound(|trait_ref| trait_ref.with_self_ty(cx, self_ty)) } } @@ -459,7 +461,7 @@ impl ExistentialProjection { ExistentialTraitRef::new_from_args(interner, def_id.try_into().unwrap(), args) } - pub fn with_self_ty(&self, interner: I, self_ty: I::Ty) -> ProjectionPredicate { + pub fn with_self_ty(&self, interner: I, self_ty: Ty) -> ProjectionPredicate { // otherwise the escaping regions would be captured by the binders debug_assert!(!self_ty.has_escaping_bound_vars()); @@ -487,7 +489,7 @@ impl ExistentialProjection { } impl ty::Binder> { - pub fn with_self_ty(&self, cx: I, self_ty: I::Ty) -> ty::Binder> { + pub fn with_self_ty(&self, cx: I, self_ty: Ty) -> ty::Binder> { self.map_bound(|p| p.with_self_ty(cx, self_ty)) } @@ -645,25 +647,25 @@ impl AliasTerm { pub fn to_term(self, interner: I) -> I::Term { match self.kind(interner) { - AliasTermKind::ProjectionTy => Ty::new_alias( + AliasTermKind::ProjectionTy => I::Ty::new_alias( interner, ty::AliasTyKind::Projection, ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () }, ) .into(), - AliasTermKind::InherentTy => Ty::new_alias( + AliasTermKind::InherentTy => I::Ty::new_alias( interner, ty::AliasTyKind::Inherent, ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () }, ) .into(), - AliasTermKind::OpaqueTy => Ty::new_alias( + AliasTermKind::OpaqueTy => I::Ty::new_alias( interner, ty::AliasTyKind::Opaque, ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () }, ) .into(), - AliasTermKind::FreeTy => Ty::new_alias( + AliasTermKind::FreeTy => I::Ty::new_alias( interner, ty::AliasTyKind::Free, ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () }, @@ -683,11 +685,11 @@ impl AliasTerm { /// The following methods work only with (trait) associated term projections. impl AliasTerm { - pub fn self_ty(self) -> I::Ty { + pub fn self_ty(self) -> Ty { self.args.type_at(0) } - pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self { + pub fn with_replaced_self_ty(self, interner: I, self_ty: Ty) -> Self { AliasTerm::new( interner, self.def_id, @@ -796,11 +798,11 @@ pub struct ProjectionPredicate { impl Eq for ProjectionPredicate {} impl ProjectionPredicate { - pub fn self_ty(self) -> I::Ty { + pub fn self_ty(self) -> Ty { self.projection_term.self_ty() } - pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> ProjectionPredicate { + pub fn with_replaced_self_ty(self, interner: I, self_ty: Ty) -> ProjectionPredicate { Self { projection_term: self.projection_term.with_replaced_self_ty(interner, self_ty), ..self @@ -859,11 +861,11 @@ pub struct NormalizesTo { impl Eq for NormalizesTo {} impl NormalizesTo { - pub fn self_ty(self) -> I::Ty { + pub fn self_ty(self) -> Ty { self.alias.self_ty() } - pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> NormalizesTo { + pub fn with_replaced_self_ty(self, interner: I, self_ty: Ty) -> NormalizesTo { Self { alias: self.alias.with_replaced_self_ty(interner, self_ty), ..self } } @@ -896,11 +898,11 @@ pub struct HostEffectPredicate { impl Eq for HostEffectPredicate {} impl HostEffectPredicate { - pub fn self_ty(self) -> I::Ty { + pub fn self_ty(self) -> Ty { self.trait_ref.self_ty() } - pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self { + pub fn with_replaced_self_ty(self, interner: I, self_ty: Ty) -> Self { Self { trait_ref: self.trait_ref.with_replaced_self_ty(interner, self_ty), ..self } } @@ -915,7 +917,7 @@ impl ty::Binder> { self.skip_binder().def_id() } - pub fn self_ty(self) -> ty::Binder { + pub fn self_ty(self) -> ty::Binder> { self.map_bound(|trait_ref| trait_ref.self_ty()) } @@ -936,8 +938,8 @@ impl ty::Binder> { )] pub struct SubtypePredicate { pub a_is_expected: bool, - pub a: I::Ty, - pub b: I::Ty, + pub a: Ty, + pub b: Ty, } impl Eq for SubtypePredicate {} @@ -950,8 +952,8 @@ impl Eq for SubtypePredicate {} derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) )] pub struct CoercePredicate { - pub a: I::Ty, - pub b: I::Ty, + pub a: Ty, + pub b: Ty, } impl Eq for CoercePredicate {} diff --git a/compiler/rustc_type_ir/src/predicate_kind.rs b/compiler/rustc_type_ir/src/predicate_kind.rs index 445e85a888fca..b6ff27fb238e6 100644 --- a/compiler/rustc_type_ir/src/predicate_kind.rs +++ b/compiler/rustc_type_ir/src/predicate_kind.rs @@ -5,7 +5,7 @@ use derive_where::derive_where; use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext}; use rustc_type_ir_macros::{GenericTypeVisitable, TypeFoldable_Generic, TypeVisitable_Generic}; -use crate::{self as ty, Interner}; +use crate::{self as ty, Interner, Ty}; /// A clause is something that can appear in where bounds or be inferred /// by implied bounds. @@ -25,7 +25,7 @@ pub enum ClauseKind { RegionOutlives(ty::OutlivesPredicate), /// `where T: 'r` - TypeOutlives(ty::OutlivesPredicate), + TypeOutlives(ty::OutlivesPredicate>), /// `where ::Name == X`, approximately. /// See the `ProjectionPredicate` struct for details. @@ -33,7 +33,7 @@ pub enum ClauseKind { /// Ensures that a const generic argument to a parameter `const N: u8` /// is of type `u8`. - ConstArgHasType(I::Const, I::Ty), + ConstArgHasType(I::Const, Ty), /// No syntax: `T` well-formed. WellFormed(I::Term), diff --git a/compiler/rustc_type_ir/src/relate.rs b/compiler/rustc_type_ir/src/relate.rs index d33c6036dadd8..cc7f5f715f0ba 100644 --- a/compiler/rustc_type_ir/src/relate.rs +++ b/compiler/rustc_type_ir/src/relate.rs @@ -6,8 +6,10 @@ use tracing::{instrument, trace}; use crate::error::{ExpectedFound, TypeError}; use crate::fold::TypeFoldable; +#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] +use crate::inherent::Ty as _; use crate::inherent::*; -use crate::{self as ty, Interner}; +use crate::{self as ty, Interner, Ty}; pub mod combine; pub mod solver_relating; @@ -44,7 +46,7 @@ pub enum VarianceDiagInfo { Invariant { /// The generic type containing the generic parameter /// that changes the variance (e.g. `*mut T`, `MyStruct`) - ty: I::Ty, + ty: Ty, /// The index of the generic parameter being used /// (e.g. `0` for `*mut T`, `1` for `MyStruct<'CovariantParam, 'InvariantParam>`) param_index: u32, @@ -75,13 +77,13 @@ pub trait TypeRelation: Sized { fn relate_ty_args( &mut self, - a_ty: I::Ty, - b_ty: I::Ty, + a_ty: Ty, + b_ty: Ty, ty_def_id: I::DefId, a_arg: I::GenericArgs, b_arg: I::GenericArgs, - mk: impl FnOnce(I::GenericArgs) -> I::Ty, - ) -> RelateResult; + mk: impl FnOnce(I::GenericArgs) -> Ty, + ) -> RelateResult>; /// Switch variance for the purpose of relating `a` and `b`. fn relate_with_variance>( @@ -98,7 +100,7 @@ pub trait TypeRelation: Sized { // additional hooks for other types in the future if needed // without making older code, which called `relate`, obsolete. - fn tys(&mut self, a: I::Ty, b: I::Ty) -> RelateResult; + fn tys(&mut self, a: Ty, b: Ty) -> RelateResult>; fn regions(&mut self, a: I::Region, b: I::Region) -> RelateResult; @@ -332,9 +334,9 @@ impl Relate for ty::ExistentialTraitRef { #[instrument(level = "trace", skip(relation), ret)] pub fn structurally_relate_tys>( relation: &mut R, - a: I::Ty, - b: I::Ty, -) -> RelateResult { + a: Ty, + b: Ty, +) -> RelateResult> { let cx = relation.cx(); match (a.kind(), b.kind()) { (ty::Infer(_), _) | (_, ty::Infer(_)) => { @@ -346,7 +348,7 @@ pub fn structurally_relate_tys>( panic!("bound types encountered in structurally_relate_tys") } - (ty::Error(guar), _) | (_, ty::Error(guar)) => Ok(Ty::new_error(cx, guar)), + (ty::Error(guar), _) | (_, ty::Error(guar)) => Ok(I::Ty::new_error(cx, guar)), (ty::Never, _) | (ty::Char, _) @@ -373,14 +375,14 @@ pub fn structurally_relate_tys>( Ok(a) } else { relation.relate_ty_args(a, b, a_def.def_id().into(), a_args, b_args, |args| { - Ty::new_adt(cx, a_def, args) + I::Ty::new_adt(cx, a_def, args) }) } } - (ty::Foreign(a_id), ty::Foreign(b_id)) if a_id == b_id => Ok(Ty::new_foreign(cx, a_id)), + (ty::Foreign(a_id), ty::Foreign(b_id)) if a_id == b_id => Ok(I::Ty::new_foreign(cx, a_id)), - (ty::Dynamic(a_obj, a_region), ty::Dynamic(b_obj, b_region)) => Ok(Ty::new_dynamic( + (ty::Dynamic(a_obj, a_region), ty::Dynamic(b_obj, b_region)) => Ok(I::Ty::new_dynamic( cx, relation.relate(a_obj, b_obj)?, relation.relate(a_region, b_region)?, @@ -391,7 +393,7 @@ pub fn structurally_relate_tys>( // the (anonymous) type of the same coroutine expression. So // all of their regions should be equated. let args = relate_args_invariantly(relation, a_args, b_args)?; - Ok(Ty::new_coroutine(cx, a_id, args)) + Ok(I::Ty::new_coroutine(cx, a_id, args)) } (ty::CoroutineWitness(a_id, a_args), ty::CoroutineWitness(b_id, b_args)) @@ -401,7 +403,7 @@ pub fn structurally_relate_tys>( // the (anonymous) type of the same coroutine expression. So // all of their regions should be equated. let args = relate_args_invariantly(relation, a_args, b_args)?; - Ok(Ty::new_coroutine_witness(cx, a_id, args)) + Ok(I::Ty::new_coroutine_witness(cx, a_id, args)) } (ty::Closure(a_id, a_args), ty::Closure(b_id, b_args)) if a_id == b_id => { @@ -409,14 +411,14 @@ pub fn structurally_relate_tys>( // the (anonymous) type of the same closure expression. So // all of their regions should be equated. let args = relate_args_invariantly(relation, a_args, b_args)?; - Ok(Ty::new_closure(cx, a_id, args)) + Ok(I::Ty::new_closure(cx, a_id, args)) } (ty::CoroutineClosure(a_id, a_args), ty::CoroutineClosure(b_id, b_args)) if a_id == b_id => { let args = relate_args_invariantly(relation, a_args, b_args)?; - Ok(Ty::new_coroutine_closure(cx, a_id, args)) + Ok(I::Ty::new_coroutine_closure(cx, a_id, args)) } (ty::RawPtr(a_ty, a_mutbl), ty::RawPtr(b_ty, b_mutbl)) => { @@ -433,7 +435,7 @@ pub fn structurally_relate_tys>( let ty = relation.relate_with_variance(variance, info, a_ty, b_ty)?; - Ok(Ty::new_ptr(cx, ty, a_mutbl)) + Ok(I::Ty::new_ptr(cx, ty, a_mutbl)) } (ty::Ref(a_r, a_ty, a_mutbl), ty::Ref(b_r, b_ty, b_mutbl)) => { @@ -451,13 +453,13 @@ pub fn structurally_relate_tys>( let r = relation.relate(a_r, b_r)?; let ty = relation.relate_with_variance(variance, info, a_ty, b_ty)?; - Ok(Ty::new_ref(cx, r, ty, a_mutbl)) + Ok(I::Ty::new_ref(cx, r, ty, a_mutbl)) } (ty::Array(a_t, sz_a), ty::Array(b_t, sz_b)) => { let t = relation.relate(a_t, b_t)?; match relation.relate(sz_a, sz_b) { - Ok(sz) => Ok(Ty::new_array_with_const_len(cx, t, sz)), + Ok(sz) => Ok(I::Ty::new_array_with_const_len(cx, t, sz)), Err(TypeError::ConstMismatch(_)) => { Err(TypeError::ArraySize(ExpectedFound::new(sz_a, sz_b))) } @@ -467,12 +469,12 @@ pub fn structurally_relate_tys>( (ty::Slice(a_t), ty::Slice(b_t)) => { let t = relation.relate(a_t, b_t)?; - Ok(Ty::new_slice(cx, t)) + Ok(I::Ty::new_slice(cx, t)) } (ty::Tuple(as_), ty::Tuple(bs)) => { if as_.len() == bs.len() { - Ok(Ty::new_tup_from_iter( + Ok(I::Ty::new_tup_from_iter( cx, iter::zip(as_.iter(), bs.iter()).map(|(a, b)| relation.relate(a, b)), )?) @@ -488,31 +490,31 @@ pub fn structurally_relate_tys>( Ok(a) } else { relation.relate_ty_args(a, b, a_def_id.into(), a_args, b_args, |args| { - Ty::new_fn_def(cx, a_def_id, args) + I::Ty::new_fn_def(cx, a_def_id, args) }) } } (ty::FnPtr(a_sig_tys, a_hdr), ty::FnPtr(b_sig_tys, b_hdr)) => { let fty = relation.relate(a_sig_tys.with(a_hdr), b_sig_tys.with(b_hdr))?; - Ok(Ty::new_fn_ptr(cx, fty)) + Ok(I::Ty::new_fn_ptr(cx, fty)) } // Alias tend to mostly already be handled downstream due to normalization. (ty::Alias(a_kind, a_data), ty::Alias(b_kind, b_data)) => { let alias_ty = relation.relate(a_data, b_data)?; assert_eq!(a_kind, b_kind); - Ok(Ty::new_alias(cx, a_kind, alias_ty)) + Ok(I::Ty::new_alias(cx, a_kind, alias_ty)) } (ty::Pat(a_ty, a_pat), ty::Pat(b_ty, b_pat)) => { let ty = relation.relate(a_ty, b_ty)?; let pat = relation.relate(a_pat, b_pat)?; - Ok(Ty::new_pat(cx, ty, pat)) + Ok(I::Ty::new_pat(cx, ty, pat)) } (ty::UnsafeBinder(a_binder), ty::UnsafeBinder(b_binder)) => { - Ok(Ty::new_unsafe_binder(cx, relation.binders(*a_binder, *b_binder)?)) + Ok(I::Ty::new_unsafe_binder(cx, relation.binders(*a_binder, *b_binder)?)) } _ => Err(TypeError::Sorts(ExpectedFound::new(a, b))), diff --git a/compiler/rustc_type_ir/src/relate/combine.rs b/compiler/rustc_type_ir/src/relate/combine.rs index 64b87fac77f94..de5d63c032128 100644 --- a/compiler/rustc_type_ir/src/relate/combine.rs +++ b/compiler/rustc_type_ir/src/relate/combine.rs @@ -7,11 +7,13 @@ use super::{ structurally_relate_consts, structurally_relate_tys, }; use crate::error::TypeError; +#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] +use crate::inherent::Ty as _; use crate::inherent::*; use crate::relate::VarianceDiagInfo; use crate::solve::Goal; use crate::visit::TypeVisitableExt as _; -use crate::{self as ty, InferCtxtLike, Interner, TypingMode, Upcast}; +use crate::{self as ty, InferCtxtLike, Interner, Ty, TypingMode, Upcast}; pub trait PredicateEmittingRelation::Interner>: TypeRelation @@ -39,15 +41,15 @@ where ); /// Register `AliasRelate` obligation(s) that both types must be related to each other. - fn register_alias_relate_predicate(&mut self, a: I::Ty, b: I::Ty); + fn register_alias_relate_predicate(&mut self, a: Ty, b: Ty); } pub fn super_combine_tys( infcx: &Infcx, relation: &mut R, - a: I::Ty, - b: I::Ty, -) -> RelateResult + a: Ty, + b: Ty, +) -> RelateResult> where Infcx: InferCtxtLike, I: Interner, @@ -60,7 +62,7 @@ where match (a.kind(), b.kind()) { (ty::Error(e), _) | (_, ty::Error(e)) => { infcx.set_tainted_by_errors(e); - return Ok(Ty::new_error(infcx.cx(), e)); + return Ok(I::Ty::new_error(infcx.cx(), e)); } // Relate integral variables to other types @@ -226,13 +228,13 @@ where pub fn combine_ty_args( infcx: &Infcx, relation: &mut R, - a_ty: I::Ty, - b_ty: I::Ty, + a_ty: Ty, + b_ty: Ty, variances: I::VariancesOf, a_args: I::GenericArgs, b_args: I::GenericArgs, - mk: impl FnOnce(I::GenericArgs) -> I::Ty, -) -> RelateResult + mk: impl FnOnce(I::GenericArgs) -> Ty, +) -> RelateResult> where Infcx: InferCtxtLike, I: Interner, diff --git a/compiler/rustc_type_ir/src/relate/solver_relating.rs b/compiler/rustc_type_ir/src/relate/solver_relating.rs index 82ee4f75fcb0a..1494d67d3c603 100644 --- a/compiler/rustc_type_ir/src/relate/solver_relating.rs +++ b/compiler/rustc_type_ir/src/relate/solver_relating.rs @@ -5,7 +5,7 @@ use crate::data_structures::DelayedSet; use crate::relate::combine::combine_ty_args; pub use crate::relate::*; use crate::solve::Goal; -use crate::{self as ty, InferCtxtLike, Interner}; +use crate::{self as ty, InferCtxtLike, Interner, Ty}; pub trait RelateExt: InferCtxtLike { fn relate>( @@ -104,7 +104,7 @@ pub struct SolverRelating<'infcx, Infcx, I: Interner> { /// constrain `?1` to `u32`. When using the cache entry from the /// first time we've related these types, this only happens when /// later proving the `Subtype(?0, ?1)` goal from the first relation. - cache: DelayedSet<(ty::Variance, I::Ty, I::Ty)>, + cache: DelayedSet<(ty::Variance, Ty, Ty)>, } impl<'infcx, Infcx, I> SolverRelating<'infcx, Infcx, I> @@ -142,13 +142,13 @@ where fn relate_ty_args( &mut self, - a_ty: I::Ty, - b_ty: I::Ty, + a_ty: Ty, + b_ty: Ty, def_id: I::DefId, a_args: I::GenericArgs, b_args: I::GenericArgs, - _: impl FnOnce(I::GenericArgs) -> I::Ty, - ) -> RelateResult { + _: impl FnOnce(I::GenericArgs) -> Ty, + ) -> RelateResult> { if self.ambient_variance == ty::Invariant { // Avoid fetching the variance if we are in an invariant // context; no need, and it can induce dependency cycles @@ -178,7 +178,7 @@ where } #[instrument(skip(self), level = "trace")] - fn tys(&mut self, a: I::Ty, b: I::Ty) -> RelateResult { + fn tys(&mut self, a: Ty, b: Ty) -> RelateResult> { if a == b { return Ok(a); } @@ -383,7 +383,7 @@ where self.goals.extend(obligations); } - fn register_alias_relate_predicate(&mut self, a: I::Ty, b: I::Ty) { + fn register_alias_relate_predicate(&mut self, a: Ty, b: Ty) { self.register_predicates([ty::Binder::dummy(match self.ambient_variance { ty::Covariant => ty::PredicateKind::AliasRelate( a.into(), diff --git a/compiler/rustc_type_ir/src/solve/mod.rs b/compiler/rustc_type_ir/src/solve/mod.rs index 72b7df22b30d5..23e6075452b18 100644 --- a/compiler/rustc_type_ir/src/solve/mod.rs +++ b/compiler/rustc_type_ir/src/solve/mod.rs @@ -11,7 +11,7 @@ use rustc_type_ir_macros::{ use crate::lang_items::SolverTraitLangItem; use crate::search_graph::PathKind; -use crate::{self as ty, Canonical, CanonicalVarValues, Interner, Upcast}; +use crate::{self as ty, Canonical, CanonicalVarValues, Interner, Ty, Upcast}; pub type CanonicalInput::Predicate> = ty::CanonicalQueryInput>; @@ -254,7 +254,7 @@ impl Eq for Response {} #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] pub struct ExternalConstraintsData { pub region_constraints: Vec>, - pub opaque_types: Vec<(ty::OpaqueTypeKey, I::Ty)>, + pub opaque_types: Vec<(ty::OpaqueTypeKey, Ty)>, pub normalization_nested_goals: NestedNormalizationGoals, } diff --git a/compiler/rustc_type_ir/src/sty/mod.rs b/compiler/rustc_type_ir/src/sty/mod.rs new file mode 100644 index 0000000000000..5b73d372384b8 --- /dev/null +++ b/compiler/rustc_type_ir/src/sty/mod.rs @@ -0,0 +1,3 @@ +/// This type is temporary and exists to cut down the bloat of further PR's +/// moving `struct Ty` from `rustc_middle` to `rustc_type_ir`. +pub type Ty = ::Ty; diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index 983d8f0820b6b..de8ae4a36f033 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -14,10 +14,12 @@ use rustc_type_ir_macros::{ use self::TyKind::*; pub use self::closure::*; +#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] +use crate::inherent::Ty as _; use crate::inherent::*; #[cfg(feature = "nightly")] use crate::visit::TypeVisitable; -use crate::{self as ty, BoundVarIndexKind, FloatTy, IntTy, Interner, UintTy}; +use crate::{self as ty, BoundVarIndexKind, FloatTy, IntTy, Interner, Ty, UintTy}; mod closure; @@ -100,7 +102,7 @@ pub enum TyKind { Str, /// An array with the given length. Written as `[T; N]`. - Array(I::Ty, I::Const), + Array(Ty, I::Const), /// A pattern newtype. /// @@ -109,17 +111,17 @@ pub enum TyKind { /// Only `Copy` and `Clone` will automatically get implemented for pattern types. /// Auto-traits treat this as if it were an aggregate with a single nested type. /// Only supports integer range patterns for now. - Pat(I::Ty, I::Pat), + Pat(Ty, I::Pat), /// The pointee of an array slice. Written as `[T]`. - Slice(I::Ty), + Slice(Ty), /// A raw pointer. Written as `*mut T` or `*const T` - RawPtr(I::Ty, Mutability), + RawPtr(Ty, Mutability), /// A reference; a pointer with an associated lifetime. Written as /// `&'a mut T` or `&'a T`. - Ref(I::Region, I::Ty, Mutability), + Ref(I::Region, Ty, Mutability), /// The anonymous type of a function declaration/definition. /// @@ -469,18 +471,18 @@ impl AliasTy { matches!(self.kind(interner), AliasTyKind::Opaque) } - pub fn to_ty(self, interner: I) -> I::Ty { - Ty::new_alias(interner, self.kind(interner), self) + pub fn to_ty(self, interner: I) -> Ty { + I::Ty::new_alias(interner, self.kind(interner), self) } } /// The following methods work only with (trait) associated type projections. impl AliasTy { - pub fn self_ty(self) -> I::Ty { + pub fn self_ty(self) -> Ty { self.args.type_at(0) } - pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self { + pub fn with_replaced_self_ty(self, interner: I, self_ty: Ty) -> Self { AliasTy::new( interner, self.def_id, @@ -735,7 +737,7 @@ impl fmt::Debug for InferTy { )] #[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] pub struct TypeAndMut { - pub ty: I::Ty, + pub ty: Ty, pub mutbl: Mutability, } @@ -765,7 +767,7 @@ impl FnSig { self.inputs_and_output.inputs() } - pub fn output(self) -> I::Ty { + pub fn output(self) -> Ty { self.inputs_and_output.output() } @@ -783,7 +785,7 @@ impl ty::Binder> { #[inline] #[track_caller] - pub fn input(self, index: usize) -> ty::Binder { + pub fn input(self, index: usize) -> ty::Binder> { self.map_bound(|fn_sig| fn_sig.inputs().get(index).unwrap()) } @@ -792,7 +794,7 @@ impl ty::Binder> { } #[inline] - pub fn output(self) -> ty::Binder { + pub fn output(self) -> ty::Binder> { self.map_bound(|fn_sig| fn_sig.output()) } @@ -856,21 +858,21 @@ impl fmt::Debug for FnSig { } // FIXME: this is a distinct type because we need to define `Encode`/`Decode` -// impls in this crate for `Binder`. +// impls in this crate for `Binder>`. #[derive_where(Clone, Copy, PartialEq, Hash; I: Interner)] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] #[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] -pub struct UnsafeBinderInner(ty::Binder); +pub struct UnsafeBinderInner(ty::Binder>); impl Eq for UnsafeBinderInner {} -impl From> for UnsafeBinderInner { - fn from(value: ty::Binder) -> Self { +impl From>> for UnsafeBinderInner { + fn from(value: ty::Binder>) -> Self { UnsafeBinderInner(value) } } -impl From> for ty::Binder { +impl From> for ty::Binder> { fn from(value: UnsafeBinderInner) -> Self { value.0 } @@ -883,7 +885,7 @@ impl fmt::Debug for UnsafeBinderInner { } impl Deref for UnsafeBinderInner { - type Target = ty::Binder; + type Target = ty::Binder>; fn deref(&self) -> &Self::Target { &self.0 @@ -894,7 +896,7 @@ impl Deref for UnsafeBinderInner { impl rustc_serialize::Encodable for UnsafeBinderInner where - I::Ty: rustc_serialize::Encodable, + Ty: rustc_serialize::Encodable, I::BoundVarKinds: rustc_serialize::Encodable, { fn encode(&self, e: &mut E) { @@ -907,7 +909,7 @@ where impl rustc_serialize::Decodable for UnsafeBinderInner where - I::Ty: TypeVisitable + rustc_serialize::Decodable, + Ty: TypeVisitable + rustc_serialize::Decodable, I::BoundVarKinds: rustc_serialize::Decodable, { fn decode(decoder: &mut D) -> Self { @@ -937,7 +939,7 @@ impl FnSigTys { self.inputs_and_output.inputs() } - pub fn output(self) -> I::Ty { + pub fn output(self) -> Ty { self.inputs_and_output.output() } } @@ -960,7 +962,7 @@ impl ty::Binder> { #[inline] #[track_caller] - pub fn input(self, index: usize) -> ty::Binder { + pub fn input(self, index: usize) -> ty::Binder> { self.map_bound(|sig_tys| sig_tys.inputs().get(index).unwrap()) } @@ -969,7 +971,7 @@ impl ty::Binder> { } #[inline] - pub fn output(self) -> ty::Binder { + pub fn output(self) -> ty::Binder> { self.map_bound(|sig_tys| sig_tys.output()) } } diff --git a/compiler/rustc_type_ir/src/ty_kind/closure.rs b/compiler/rustc_type_ir/src/ty_kind/closure.rs index e8f94c8e7cc92..d713b832a5213 100644 --- a/compiler/rustc_type_ir/src/ty_kind/closure.rs +++ b/compiler/rustc_type_ir/src/ty_kind/closure.rs @@ -7,9 +7,11 @@ use rustc_type_ir_macros::{ use crate::data_structures::DelayedMap; use crate::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable, shift_region}; +#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] +use crate::inherent::Ty as _; use crate::inherent::*; use crate::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor}; -use crate::{self as ty, Interner}; +use crate::{self as ty, Interner, Ty}; /// A closure can be modeled as a struct that looks like: /// ```ignore (illustrative) @@ -121,13 +123,13 @@ pub struct ClosureArgsParts { /// This is the args of the typeck root. pub parent_args: I::GenericArgsSlice, /// Represents the maximum calling capability of the closure. - pub closure_kind_ty: I::Ty, + pub closure_kind_ty: Ty, /// Captures the closure's signature. This closure signature is "tupled", and /// thus has a peculiar signature of `extern "rust-call" fn((Args, ...)) -> Ty`. - pub closure_sig_as_fn_ptr_ty: I::Ty, + pub closure_sig_as_fn_ptr_ty: Ty, /// The upvars captured by the closure. Remains an inference variable /// until the upvar analysis, which happens late in HIR typeck. - pub tupled_upvars_ty: I::Ty, + pub tupled_upvars_ty: Ty, } impl ClosureArgs { @@ -169,14 +171,14 @@ impl ClosureArgs { /// Returns the tuple type representing the upvars for this closure. #[inline] - pub fn tupled_upvars_ty(self) -> I::Ty { + pub fn tupled_upvars_ty(self) -> Ty { self.split().tupled_upvars_ty } /// Returns the closure kind for this closure; may return a type /// variable during inference. To get the closure kind during /// inference, use `infcx.closure_kind(args)`. - pub fn kind_ty(self) -> I::Ty { + pub fn kind_ty(self) -> Ty { self.split().closure_kind_ty } @@ -185,7 +187,7 @@ impl ClosureArgs { // FIXME(eddyb) this should be unnecessary, as the shallowly resolved // type is known at the time of the creation of `ClosureArgs`, // see `rustc_hir_analysis::check::closure`. - pub fn sig_as_fn_ptr_ty(self) -> I::Ty { + pub fn sig_as_fn_ptr_ty(self) -> Ty { self.split().closure_sig_as_fn_ptr_ty } @@ -223,7 +225,7 @@ pub struct CoroutineClosureArgsParts { /// This is the args of the typeck root. pub parent_args: I::GenericArgsSlice, /// Represents the maximum calling capability of the closure. - pub closure_kind_ty: I::Ty, + pub closure_kind_ty: Ty, /// Represents all of the relevant parts of the coroutine returned by this /// coroutine-closure. This signature parts type will have the general /// shape of `fn(tupled_inputs, resume_ty) -> (return_ty, yield_ty)`, where @@ -232,10 +234,10 @@ pub struct CoroutineClosureArgsParts { /// /// Use `coroutine_closure_sig` to break up this type rather than using it /// yourself. - pub signature_parts_ty: I::Ty, + pub signature_parts_ty: Ty, /// The upvars captured by the closure. Remains an inference variable /// until the upvar analysis, which happens late in HIR typeck. - pub tupled_upvars_ty: I::Ty, + pub tupled_upvars_ty: Ty, /// a function pointer that has the shape `for<'env> fn() -> (&'env T, ...)`. /// This allows us to represent the binder of the self-captures of the closure. /// @@ -243,7 +245,7 @@ pub struct CoroutineClosureArgsParts { /// from the closure's upvars, this will be `for<'env> fn() -> (&'env String,)`, /// while the `tupled_upvars_ty`, representing the by-move version of the same /// captures, will be `(String,)`. - pub coroutine_captures_by_ref_ty: I::Ty, + pub coroutine_captures_by_ref_ty: Ty, } impl CoroutineClosureArgs { @@ -277,11 +279,11 @@ impl CoroutineClosureArgs { } #[inline] - pub fn tupled_upvars_ty(self) -> I::Ty { + pub fn tupled_upvars_ty(self) -> Ty { self.split().tupled_upvars_ty } - pub fn kind_ty(self) -> I::Ty { + pub fn kind_ty(self) -> Ty { self.split().closure_kind_ty } @@ -289,7 +291,7 @@ impl CoroutineClosureArgs { self.kind_ty().to_opt_closure_kind().unwrap() } - pub fn signature_parts_ty(self) -> I::Ty { + pub fn signature_parts_ty(self) -> Ty { self.split().signature_parts_ty } @@ -314,7 +316,7 @@ impl CoroutineClosureArgs { }) } - pub fn coroutine_captures_by_ref_ty(self) -> I::Ty { + pub fn coroutine_captures_by_ref_ty(self) -> Ty { self.split().coroutine_captures_by_ref_ty } @@ -358,10 +360,10 @@ impl TypeVisitor for HasRegionsBoundAt { #[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] pub struct CoroutineClosureSignature { - pub tupled_inputs_ty: I::Ty, - pub resume_ty: I::Ty, - pub yield_ty: I::Ty, - pub return_ty: I::Ty, + pub tupled_inputs_ty: Ty, + pub resume_ty: Ty, + pub yield_ty: Ty, + pub return_ty: Ty, // Like the `fn_sig_as_fn_ptr_ty` of a regular closure, these types // never actually differ. But we save them rather than recreating them @@ -393,10 +395,10 @@ impl CoroutineClosureSignature { self, cx: I, parent_args: I::GenericArgsSlice, - coroutine_kind_ty: I::Ty, + coroutine_kind_ty: Ty, coroutine_def_id: I::CoroutineId, - tupled_upvars_ty: I::Ty, - ) -> I::Ty { + tupled_upvars_ty: Ty, + ) -> Ty { let coroutine_args = ty::CoroutineArgs::new( cx, ty::CoroutineArgsParts { @@ -409,7 +411,7 @@ impl CoroutineClosureSignature { }, ); - Ty::new_coroutine(cx, coroutine_def_id, coroutine_args.args) + I::Ty::new_coroutine(cx, coroutine_def_id, coroutine_args.args) } /// Given known upvars and a [`ClosureKind`](ty::ClosureKind), compute the coroutine @@ -424,9 +426,9 @@ impl CoroutineClosureSignature { coroutine_def_id: I::CoroutineId, goal_kind: ty::ClosureKind, env_region: I::Region, - closure_tupled_upvars_ty: I::Ty, - coroutine_captures_by_ref_ty: I::Ty, - ) -> I::Ty { + closure_tupled_upvars_ty: Ty, + coroutine_captures_by_ref_ty: Ty, + ) -> Ty { let tupled_upvars_ty = Self::tupled_upvars_by_closure_kind( cx, goal_kind, @@ -439,7 +441,7 @@ impl CoroutineClosureSignature { self.to_coroutine( cx, parent_args, - Ty::from_coroutine_closure_kind(cx, goal_kind), + I::Ty::from_coroutine_closure_kind(cx, goal_kind), coroutine_def_id, tupled_upvars_ty, ) @@ -457,11 +459,11 @@ impl CoroutineClosureSignature { pub fn tupled_upvars_by_closure_kind( cx: I, kind: ty::ClosureKind, - tupled_inputs_ty: I::Ty, - closure_tupled_upvars_ty: I::Ty, - coroutine_captures_by_ref_ty: I::Ty, + tupled_inputs_ty: Ty, + closure_tupled_upvars_ty: Ty, + coroutine_captures_by_ref_ty: Ty, env_region: I::Region, - ) -> I::Ty { + ) -> Ty { match kind { ty::ClosureKind::Fn | ty::ClosureKind::FnMut => { let ty::FnPtr(sig_tys, _) = coroutine_captures_by_ref_ty.kind() else { @@ -474,7 +476,7 @@ impl CoroutineClosureSignature { debruijn: ty::INNERMOST, cache: Default::default(), }); - Ty::new_tup_from_iter( + I::Ty::new_tup_from_iter( cx, tupled_inputs_ty .tuple_fields() @@ -482,7 +484,7 @@ impl CoroutineClosureSignature { .chain(coroutine_captures_by_ref_ty.tuple_fields().iter()), ) } - ty::ClosureKind::FnOnce => Ty::new_tup_from_iter( + ty::ClosureKind::FnOnce => I::Ty::new_tup_from_iter( cx, tupled_inputs_ty .tuple_fields() @@ -503,7 +505,7 @@ struct FoldEscapingRegions { // Depends on `debruijn` because we may have types with regions of different // debruijn depths depending on the binders we've entered. - cache: DelayedMap<(ty::DebruijnIndex, I::Ty), I::Ty>, + cache: DelayedMap<(ty::DebruijnIndex, Ty), Ty>, } impl TypeFolder for FoldEscapingRegions { @@ -511,7 +513,7 @@ impl TypeFolder for FoldEscapingRegions { self.interner } - fn fold_ty(&mut self, t: I::Ty) -> I::Ty { + fn fold_ty(&mut self, t: Ty) -> Ty { if !t.has_vars_bound_at_or_above(self.debruijn) { t } else if let Some(&t) = self.cache.get(&(self.debruijn, t)) { @@ -553,9 +555,9 @@ impl TypeFolder for FoldEscapingRegions { #[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] pub struct GenSig { - pub resume_ty: I::Ty, - pub yield_ty: I::Ty, - pub return_ty: I::Ty, + pub resume_ty: Ty, + pub yield_ty: Ty, + pub return_ty: Ty, } impl Eq for GenSig {} @@ -581,15 +583,15 @@ pub struct CoroutineArgsParts { /// kind: `i8`/`i16`/`i32`. /// /// For regular coroutines, this field will always just be `()`. - pub kind_ty: I::Ty, + pub kind_ty: Ty, - pub resume_ty: I::Ty, - pub yield_ty: I::Ty, - pub return_ty: I::Ty, + pub resume_ty: Ty, + pub yield_ty: Ty, + pub return_ty: Ty, /// The upvars captured by the closure. Remains an inference variable /// until the upvar analysis, which happens late in HIR typeck. - pub tupled_upvars_ty: I::Ty, + pub tupled_upvars_ty: Ty, } impl CoroutineArgs { @@ -619,7 +621,7 @@ impl CoroutineArgs { } // Returns the kind of the coroutine. See docs on the `kind_ty` field. - pub fn kind_ty(self) -> I::Ty { + pub fn kind_ty(self) -> Ty { self.split().kind_ty } @@ -638,22 +640,22 @@ impl CoroutineArgs { /// Returns the tuple type representing the upvars for this coroutine. #[inline] - pub fn tupled_upvars_ty(self) -> I::Ty { + pub fn tupled_upvars_ty(self) -> Ty { self.split().tupled_upvars_ty } /// Returns the type representing the resume type of the coroutine. - pub fn resume_ty(self) -> I::Ty { + pub fn resume_ty(self) -> Ty { self.split().resume_ty } /// Returns the type representing the yield type of the coroutine. - pub fn yield_ty(self) -> I::Ty { + pub fn yield_ty(self) -> Ty { self.split().yield_ty } /// Returns the type representing the return type of the coroutine. - pub fn return_ty(self) -> I::Ty { + pub fn return_ty(self) -> Ty { self.split().return_ty } diff --git a/compiler/rustc_type_ir/src/visit.rs b/compiler/rustc_type_ir/src/visit.rs index 6e62e1031a969..1ee4bff6b7a11 100644 --- a/compiler/rustc_type_ir/src/visit.rs +++ b/compiler/rustc_type_ir/src/visit.rs @@ -52,7 +52,7 @@ use smallvec::SmallVec; use thin_vec::ThinVec; use crate::inherent::*; -use crate::{self as ty, Interner, TypeFlags}; +use crate::{self as ty, Interner, Ty, TypeFlags}; /// This trait is implemented for every type that can be visited, /// providing the skeleton of the traversal. @@ -98,7 +98,7 @@ pub trait TypeVisitor: Sized { t.super_visit_with(self) } - fn visit_ty(&mut self, t: I::Ty) -> Self::Result { + fn visit_ty(&mut self, t: Ty) -> Self::Result { t.super_visit_with(self) } @@ -417,7 +417,7 @@ impl TypeVisitor for HasTypeFlagsVisitor { } #[inline] - fn visit_ty(&mut self, t: I::Ty) -> Self::Result { + fn visit_ty(&mut self, t: Ty) -> Self::Result { // Note: no `super_visit_with` call. let flags = t.flags(); if flags.intersects(self.flags) { @@ -522,7 +522,7 @@ impl TypeVisitor for HasEscapingVarsVisitor { } #[inline] - fn visit_ty(&mut self, t: I::Ty) -> Self::Result { + fn visit_ty(&mut self, t: Ty) -> Self::Result { // If the outer-exclusive-binder is *strictly greater* than // `outer_index`, that means that `t` contains some content // bound at `outer_index` or above (because From b95801f60e0cb8b97e82555d5940ba9decd33932 Mon Sep 17 00:00:00 2001 From: James Barford-Evans Date: Wed, 25 Mar 2026 09:15:42 +0000 Subject: [PATCH 2/2] Removing `use crate::inherent::Ty as _;` and adding `ty::Ty` --- .../src/canonical/canonicalizer.rs | 12 +-- .../rustc_next_trait_solver/src/coherence.rs | 33 ++++--- .../src/placeholder.rs | 8 +- .../src/solve/assembly/mod.rs | 16 ++- .../src/solve/assembly/structural_traits.rs | 78 +++++++-------- .../src/solve/normalizes_to/mod.rs | 34 +++---- .../src/solve/trait_goals.rs | 33 ++++--- compiler/rustc_type_ir/src/fast_reject.rs | 19 ++-- compiler/rustc_type_ir/src/fold.rs | 14 ++- compiler/rustc_type_ir/src/predicate.rs | 60 ++++++------ compiler/rustc_type_ir/src/relate.rs | 58 ++++++----- compiler/rustc_type_ir/src/relate/combine.rs | 22 ++--- compiler/rustc_type_ir/src/ty_kind.rs | 52 +++++----- compiler/rustc_type_ir/src/ty_kind/closure.rs | 98 +++++++++---------- 14 files changed, 257 insertions(+), 280 deletions(-) diff --git a/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs b/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs index 72c4f8622471b..5a0f149fd0550 100644 --- a/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs +++ b/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs @@ -1,11 +1,9 @@ use rustc_type_ir::data_structures::{HashMap, ensure_sufficient_stack}; -#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] -use rustc_type_ir::inherent::Ty as _; use rustc_type_ir::inherent::*; use rustc_type_ir::solve::{Goal, QueryInput}; use rustc_type_ir::{ self as ty, Canonical, CanonicalParamEnvCacheEntry, CanonicalVarKind, Flags, InferCtxtLike, - Interner, PlaceholderConst, PlaceholderType, Ty, TypeFlags, TypeFoldable, TypeFolder, + Interner, PlaceholderConst, PlaceholderType, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, }; @@ -80,7 +78,7 @@ pub(super) struct Canonicalizer<'a, D: SolverDelegate, I: Interner /// We can simply cache based on the ty itself, because we use /// `ty::BoundVarIndexKind::Canonical`. - cache: HashMap, Ty>, + cache: HashMap, ty::Ty>, } impl<'a, D: SolverDelegate, I: Interner> Canonicalizer<'a, D, I> { @@ -318,7 +316,7 @@ impl<'a, D: SolverDelegate, I: Interner> Canonicalizer<'a, D, I> { (max_universe, self.variables, var_kinds) } - fn inner_fold_ty(&mut self, t: Ty) -> Ty { + fn inner_fold_ty(&mut self, t: ty::Ty) -> ty::Ty { let kind = match t.kind() { ty::Infer(i) => match i { ty::TyVar(vid) => { @@ -402,7 +400,7 @@ impl<'a, D: SolverDelegate, I: Interner> Canonicalizer<'a, D, I> { let var = self.get_or_insert_bound_var(t, kind); - I::Ty::new_canonical_bound(self.cx(), var) + Ty::new_canonical_bound(self.cx(), var) } } @@ -477,7 +475,7 @@ impl, I: Interner> TypeFolder for Canonicaliz Region::new_canonical_bound(self.cx(), var) } - fn fold_ty(&mut self, t: Ty) -> Ty { + fn fold_ty(&mut self, t: ty::Ty) -> ty::Ty { if !t.flags().intersects(NEEDS_CANONICAL) { t } else if let Some(&ty) = self.cache.get(&t) { diff --git a/compiler/rustc_next_trait_solver/src/coherence.rs b/compiler/rustc_next_trait_solver/src/coherence.rs index 1f69add30c540..69cebb0a3dc64 100644 --- a/compiler/rustc_next_trait_solver/src/coherence.rs +++ b/compiler/rustc_next_trait_solver/src/coherence.rs @@ -2,11 +2,9 @@ use std::fmt::Debug; use std::ops::ControlFlow; use derive_where::derive_where; -#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] -use rustc_type_ir::inherent::Ty as _; use rustc_type_ir::inherent::*; use rustc_type_ir::{ - self as ty, InferCtxtLike, Interner, TrivialTypeTraversalImpls, Ty, TypeVisitable, + self as ty, InferCtxtLike, Interner, TrivialTypeTraversalImpls, TypeVisitable, TypeVisitableExt, TypeVisitor, }; use tracing::instrument; @@ -49,7 +47,7 @@ pub enum Conflict { pub fn trait_ref_is_knowable( infcx: &Infcx, trait_ref: ty::TraitRef, - mut lazily_normalize_ty: impl FnMut(Ty) -> Result, E>, + mut lazily_normalize_ty: impl FnMut(ty::Ty) -> Result, E>, ) -> Result, E> where Infcx: InferCtxtLike, @@ -117,14 +115,14 @@ impl From for IsFirstInputType { #[derive_where(Debug; I: Interner, T: Debug)] pub enum OrphanCheckErr { - NonLocalInputType(Vec<(Ty, IsFirstInputType)>), + NonLocalInputType(Vec<(ty::Ty, IsFirstInputType)>), UncoveredTyParams(UncoveredTyParams), } #[derive_where(Debug; I: Interner, T: Debug)] pub struct UncoveredTyParams { pub uncovered: T, - pub local_ty: Option>, + pub local_ty: Option>, } /// Checks whether a trait-ref is potentially implementable by a crate. @@ -224,8 +222,8 @@ pub fn orphan_check_trait_ref( infcx: &Infcx, trait_ref: ty::TraitRef, in_crate: InCrate, - lazily_normalize_ty: impl FnMut(Ty) -> Result, E>, -) -> Result>>, E> + lazily_normalize_ty: impl FnMut(ty::Ty) -> Result, E>, +) -> Result>>, E> where Infcx: InferCtxtLike, I: Interner, @@ -264,14 +262,14 @@ struct OrphanChecker<'a, Infcx, I: Interner, F> { lazily_normalize_ty: F, /// Ignore orphan check failures and exclusively search for the first local type. search_first_local_ty: bool, - non_local_tys: Vec<(Ty, IsFirstInputType)>, + non_local_tys: Vec<(ty::Ty, IsFirstInputType)>, } impl<'a, Infcx, I, F, E> OrphanChecker<'a, Infcx, I, F> where Infcx: InferCtxtLike, I: Interner, - F: FnOnce(Ty) -> Result, E>, + F: FnOnce(ty::Ty) -> Result, E>, { fn new(infcx: &'a Infcx, in_crate: InCrate, lazily_normalize_ty: F) -> Self { OrphanChecker { @@ -284,12 +282,15 @@ where } } - fn found_non_local_ty(&mut self, t: Ty) -> ControlFlow> { + fn found_non_local_ty(&mut self, t: ty::Ty) -> ControlFlow> { self.non_local_tys.push((t, self.in_self_ty.into())); ControlFlow::Continue(()) } - fn found_uncovered_ty_param(&mut self, ty: Ty) -> ControlFlow> { + fn found_uncovered_ty_param( + &mut self, + ty: ty::Ty, + ) -> ControlFlow> { if self.search_first_local_ty { return ControlFlow::Continue(()); } @@ -307,15 +308,15 @@ where enum OrphanCheckEarlyExit { NormalizationFailure(E), - UncoveredTyParam(Ty), - LocalTy(Ty), + UncoveredTyParam(ty::Ty), + LocalTy(ty::Ty), } impl<'a, Infcx, I, F, E> TypeVisitor for OrphanChecker<'a, Infcx, I, F> where Infcx: InferCtxtLike, I: Interner, - F: FnMut(Ty) -> Result, E>, + F: FnMut(ty::Ty) -> Result, E>, { type Result = ControlFlow>; @@ -323,7 +324,7 @@ where ControlFlow::Continue(()) } - fn visit_ty(&mut self, ty: Ty) -> Self::Result { + fn visit_ty(&mut self, ty: ty::Ty) -> Self::Result { let ty = self.infcx.shallow_resolve(ty); let ty = match (self.lazily_normalize_ty)(ty) { Ok(norm_ty) if norm_ty.is_ty_var() => ty, diff --git a/compiler/rustc_next_trait_solver/src/placeholder.rs b/compiler/rustc_next_trait_solver/src/placeholder.rs index bf3983aa3b333..fe7521c86e9be 100644 --- a/compiler/rustc_next_trait_solver/src/placeholder.rs +++ b/compiler/rustc_next_trait_solver/src/placeholder.rs @@ -1,11 +1,9 @@ use core::panic; use rustc_type_ir::data_structures::IndexMap; -#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] -use rustc_type_ir::inherent::Ty as _; use rustc_type_ir::inherent::*; use rustc_type_ir::{ - self as ty, InferCtxtLike, Interner, PlaceholderConst, PlaceholderRegion, PlaceholderType, Ty, + self as ty, InferCtxtLike, Interner, PlaceholderConst, PlaceholderRegion, PlaceholderType, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, }; @@ -115,7 +113,7 @@ where } } - fn fold_ty(&mut self, t: Ty) -> Ty { + fn fold_ty(&mut self, t: ty::Ty) -> ty::Ty { match t.kind() { ty::Bound(ty::BoundVarIndexKind::Bound(debruijn), _) if debruijn.as_usize() + 1 @@ -132,7 +130,7 @@ where let universe = self.universe_for(debruijn); let p = PlaceholderType::new(universe, bound_ty); self.mapped_types.insert(p, bound_ty); - I::Ty::new_placeholder(self.cx(), p) + Ty::new_placeholder(self.cx(), p) } _ if t.has_vars_bound_at_or_above(self.current_index) => t.super_fold_with(self), _ => t, diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index bd5d6d61211e7..f58318b83625d 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -6,15 +6,13 @@ use std::cell::Cell; use std::ops::ControlFlow; use derive_where::derive_where; -#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] -use rustc_type_ir::inherent::Ty as _; use rustc_type_ir::inherent::*; use rustc_type_ir::lang_items::SolverTraitLangItem; use rustc_type_ir::search_graph::CandidateHeadUsages; use rustc_type_ir::solve::Certainty::Maybe; use rustc_type_ir::solve::{AliasBoundKind, SizedTraitKind}; use rustc_type_ir::{ - self as ty, Interner, Ty, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable, + self as ty, Interner, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Upcast, elaborate, }; @@ -48,11 +46,11 @@ where D: SolverDelegate, I: Interner, { - fn self_ty(self) -> Ty; + fn self_ty(self) -> ty::Ty; fn trait_ref(self, cx: I) -> ty::TraitRef; - fn with_replaced_self_ty(self, cx: I, self_ty: Ty) -> Self; + fn with_replaced_self_ty(self, cx: I, self_ty: ty::Ty) -> Self; fn trait_def_id(self, cx: I) -> I::TraitId; @@ -685,7 +683,7 @@ where // hitting another overflow error something. Add a depth parameter needed later. fn assemble_alias_bound_candidates_recur>( &mut self, - self_ty: Ty, + self_ty: ty::Ty, goal: Goal, candidates: &mut Vec>, consider_self_bounds: AliasBoundKind, @@ -1019,13 +1017,13 @@ where struct ReplaceOpaque { cx: I, alias_ty: ty::AliasTy, - self_ty: Ty, + self_ty: ty::Ty, } impl TypeFolder for ReplaceOpaque { fn cx(&self) -> I { self.cx } - fn fold_ty(&mut self, ty: Ty) -> Ty { + fn fold_ty(&mut self, ty: ty::Ty) -> ty::Ty { if let ty::Alias(ty::Opaque, alias_ty) = ty.kind() { if alias_ty == self.alias_ty { return self.self_ty; @@ -1282,7 +1280,7 @@ where ControlFlow::Continue(()) } - fn visit_ty(&mut self, ty: Ty) -> Self::Result { + fn visit_ty(&mut self, ty: ty::Ty) -> Self::Result { let ty = self.ecx.replace_bound_vars(ty, &mut self.universes); let Ok(ty) = self.ecx.structurally_normalize_ty(self.param_env, ty) else { return ControlFlow::Break(Err(NoSolution)); diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs index 320c85128e66e..af25b3ed26e6a 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/structural_traits.rs @@ -3,14 +3,12 @@ use derive_where::derive_where; use rustc_type_ir::data_structures::HashMap; -#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] -use rustc_type_ir::inherent::Ty as _; use rustc_type_ir::inherent::*; use rustc_type_ir::lang_items::{SolverLangItem, SolverTraitLangItem}; use rustc_type_ir::solve::SizedTraitKind; use rustc_type_ir::solve::inspect::ProbeKind; use rustc_type_ir::{ - self as ty, FallibleTypeFolder, Interner, Movability, Mutability, Ty, TypeFoldable, + self as ty, FallibleTypeFolder, Interner, Movability, Mutability, TypeFoldable, TypeSuperFoldable, Upcast as _, elaborate, }; use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic}; @@ -23,8 +21,8 @@ use crate::solve::{AdtDestructorKind, EvalCtxt, Goal, NoSolution}; #[instrument(level = "trace", skip(ecx), ret)] pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait( ecx: &EvalCtxt<'_, D>, - ty: Ty, -) -> Result>>, NoSolution> + ty: ty::Ty, +) -> Result>>, NoSolution> where D: SolverDelegate, I: Interner, @@ -47,7 +45,7 @@ where ty::Foreign(..) => Ok(ty::Binder::dummy(vec![])), // Treat `str` like it's defined as `struct str([u8]);` - ty::Str => Ok(ty::Binder::dummy(vec![I::Ty::new_slice(cx, I::Ty::new_u8(cx))])), + ty::Str => Ok(ty::Binder::dummy(vec![Ty::new_slice(cx, Ty::new_u8(cx))])), ty::Dynamic(..) | ty::Param(..) @@ -79,7 +77,7 @@ where ty::Coroutine(def_id, args) => Ok(ty::Binder::dummy(vec![ args.as_coroutine().tupled_upvars_ty(), - I::Ty::new_coroutine_witness_for_coroutine(ecx.cx(), def_id, args), + Ty::new_coroutine_witness_for_coroutine(ecx.cx(), def_id, args), ])), ty::CoroutineWitness(def_id, args) => Ok(ecx @@ -110,8 +108,8 @@ where pub(in crate::solve) fn instantiate_constituent_tys_for_sizedness_trait( ecx: &EvalCtxt<'_, D>, sizedness: SizedTraitKind, - ty: Ty, -) -> Result>>, NoSolution> + ty: ty::Ty, +) -> Result>>, NoSolution> where D: SolverDelegate, I: Interner, @@ -188,8 +186,8 @@ where #[instrument(level = "trace", skip(ecx), ret)] pub(in crate::solve) fn instantiate_constituent_tys_for_copy_clone_trait( ecx: &EvalCtxt<'_, D>, - ty: Ty, -) -> Result>>, NoSolution> + ty: ty::Ty, +) -> Result>>, NoSolution> where D: SolverDelegate, I: Interner, @@ -248,7 +246,7 @@ where if ecx.cx().features().coroutine_clone() { Ok(ty::Binder::dummy(vec![ args.as_coroutine().tupled_upvars_ty(), - I::Ty::new_coroutine_witness_for_coroutine(ecx.cx(), def_id, args), + Ty::new_coroutine_witness_for_coroutine(ecx.cx(), def_id, args), ])) } else { Err(NoSolution) @@ -270,18 +268,17 @@ where // Returns a binder of the tupled inputs types and output type from a builtin callable type. pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable( cx: I, - self_ty: Ty, + self_ty: ty::Ty, goal_kind: ty::ClosureKind, -) -> Result, Ty)>>, NoSolution> { +) -> Result, ty::Ty)>>, NoSolution> { match self_ty.kind() { // keep this in sync with assemble_fn_pointer_candidates until the old solver is removed. ty::FnDef(def_id, args) => { let sig = cx.fn_sig(def_id); if sig.skip_binder().is_fn_trait_compatible() && !cx.has_target_features(def_id) { Ok(Some( - sig.instantiate(cx, args).map_bound(|sig| { - (I::Ty::new_tup(cx, sig.inputs().as_slice()), sig.output()) - }), + sig.instantiate(cx, args) + .map_bound(|sig| (Ty::new_tup(cx, sig.inputs().as_slice()), sig.output())), )) } else { Err(NoSolution) @@ -292,9 +289,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_callable { - pub tupled_inputs_ty: Ty, + pub tupled_inputs_ty: ty::Ty, /// Type returned by calling the closure /// i.e. `f()`. - pub output_coroutine_ty: Ty, + pub output_coroutine_ty: ty::Ty, /// Type returned by `await`ing the output /// i.e. `f().await`. - pub coroutine_return_ty: Ty, + pub coroutine_return_ty: ty::Ty, } // Returns a binder of the tupled inputs types, output type, and coroutine type @@ -429,7 +424,7 @@ pub(in crate::solve) struct AsyncCallableRelevantTypes { // know the kind already, we can short-circuit this check. pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable( cx: I, - self_ty: Ty, + self_ty: ty::Ty, goal_kind: ty::ClosureKind, env_region: I::Region, ) -> Result<(ty::Binder>, Vec), NoSolution> { @@ -460,7 +455,7 @@ pub(in crate::solve) fn extract_tupled_inputs_and_output_from_async_callable( 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_ty = I::Ty::new_projection(cx, future_output_def_id, [sig.output()]); + let future_output_ty = Ty::new_projection(cx, future_output_def_id, [sig.output()]); Ok(( bound_sig.rebind(AsyncCallableRelevantTypes { - tupled_inputs_ty: I::Ty::new_tup(cx, sig.inputs().as_slice()), + tupled_inputs_ty: Ty::new_tup(cx, sig.inputs().as_slice()), output_coroutine_ty: sig.output(), coroutine_return_ty: future_output_ty, }), @@ -613,7 +608,7 @@ fn coroutine_closure_to_certain_coroutine( def_id: I::CoroutineClosureId, args: ty::CoroutineClosureArgs, sig: ty::CoroutineClosureSignature, -) -> Ty { +) -> ty::Ty { sig.to_coroutine_given_kind_and_upvars( cx, args.parent_args(), @@ -637,14 +632,14 @@ fn coroutine_closure_to_ambiguous_coroutine( def_id: I::CoroutineClosureId, args: ty::CoroutineClosureArgs, sig: ty::CoroutineClosureSignature, -) -> Ty { +) -> ty::Ty { let upvars_projection_def_id = cx.require_lang_item(SolverLangItem::AsyncFnKindUpvars); - let tupled_upvars_ty = I::Ty::new_projection( + let tupled_upvars_ty = Ty::new_projection( cx, upvars_projection_def_id, [ I::GenericArg::from(args.kind_ty()), - I::Ty::from_closure_kind(cx, goal_kind).into(), + Ty::from_closure_kind(cx, goal_kind).into(), goal_region.into(), sig.tupled_inputs_ty.into(), args.tupled_upvars_ty().into(), @@ -654,7 +649,7 @@ fn coroutine_closure_to_ambiguous_coroutine( sig.to_coroutine( cx, args.parent_args(), - I::Ty::from_closure_kind(cx, goal_kind), + Ty::from_closure_kind(cx, goal_kind), cx.coroutine_for_closure(def_id), tupled_upvars_ty, ) @@ -669,8 +664,8 @@ fn coroutine_closure_to_ambiguous_coroutine( #[instrument(level = "trace", skip(cx), ret)] pub(in crate::solve) fn extract_fn_def_from_const_callable( cx: I, - self_ty: Ty, -) -> Result<(ty::Binder, Ty)>, I::DefId, I::GenericArgs), NoSolution> { + self_ty: ty::Ty, +) -> Result<(ty::Binder, ty::Ty)>, I::DefId, I::GenericArgs), NoSolution> { match self_ty.kind() { ty::FnDef(def_id, args) => { let sig = cx.fn_sig(def_id); @@ -679,9 +674,8 @@ pub(in crate::solve) fn extract_fn_def_from_const_callable( && cx.fn_is_const(def_id) { Ok(( - sig.instantiate(cx, args).map_bound(|sig| { - (I::Ty::new_tup(cx, sig.inputs().as_slice()), sig.output()) - }), + sig.instantiate(cx, args) + .map_bound(|sig| (Ty::new_tup(cx, sig.inputs().as_slice()), sig.output())), def_id.into(), args, )) @@ -748,7 +742,7 @@ pub(in crate::solve) fn extract_fn_def_from_const_callable( // the old solver, for as long as that exists. pub(in crate::solve) fn const_conditions_for_destruct( cx: I, - self_ty: Ty, + self_ty: ty::Ty, ) -> Result>, NoSolution> { let destruct_def_id = cx.require_trait_lang_item(SolverTraitLangItem::Destruct); @@ -929,7 +923,7 @@ where struct ReplaceProjectionWith<'a, 'b, I: Interner, D: SolverDelegate> { ecx: &'a mut EvalCtxt<'b, D>, param_env: I::ParamEnv, - self_ty: Ty, + self_ty: ty::Ty, mapping: &'a HashMap>>>, nested: Vec>, } @@ -1015,7 +1009,7 @@ where self.ecx.cx() } - fn try_fold_ty(&mut self, ty: Ty) -> Result, Ambiguous> { + fn try_fold_ty(&mut self, ty: ty::Ty) -> Result, Ambiguous> { if let ty::Alias(ty::Projection, alias_ty) = ty.kind() && let Some(term) = self.try_eagerly_replace_alias(alias_ty.into())? { diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs index 376a817370496..13ed945857db2 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs @@ -4,14 +4,10 @@ mod inherent; mod opaque_types; use rustc_type_ir::fast_reject::DeepRejectCtxt; -#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] -use rustc_type_ir::inherent::Ty as _; use rustc_type_ir::inherent::*; use rustc_type_ir::lang_items::{SolverAdtLangItem, SolverLangItem, SolverTraitLangItem}; use rustc_type_ir::solve::SizedTraitKind; -use rustc_type_ir::{ - self as ty, FieldInfo, Interner, NormalizesTo, PredicateKind, Ty, Upcast as _, -}; +use rustc_type_ir::{self as ty, FieldInfo, Interner, NormalizesTo, PredicateKind, Upcast as _}; use tracing::instrument; use crate::delegate::SolverDelegate; @@ -129,7 +125,7 @@ where D: SolverDelegate, I: Interner, { - fn self_ty(self) -> Ty { + fn self_ty(self) -> ty::Ty { self.self_ty() } @@ -137,7 +133,7 @@ where self.alias.trait_ref(cx) } - fn with_replaced_self_ty(self, cx: I, self_ty: Ty) -> Self { + fn with_replaced_self_ty(self, cx: I, self_ty: ty::Ty) -> Self { self.with_replaced_self_ty(cx, self_ty) } @@ -267,7 +263,7 @@ where let error_response = |ecx: &mut EvalCtxt<'_, D>, guar| { let error_term = match goal.predicate.alias.kind(cx) { - ty::AliasTermKind::ProjectionTy => I::Ty::new_error(cx, guar).into(), + ty::AliasTermKind::ProjectionTy => Ty::new_error(cx, guar).into(), ty::AliasTermKind::ProjectionConst => Const::new_error(cx, guar).into(), kind => panic!("expected projection, found {kind:?}"), }; @@ -645,11 +641,11 @@ where | ty::Coroutine(..) | ty::CoroutineWitness(..) | ty::Never - | ty::Foreign(..) => I::Ty::new_unit(cx), + | ty::Foreign(..) => Ty::new_unit(cx), - ty::Error(e) => I::Ty::new_error(cx, e), + ty::Error(e) => Ty::new_error(cx, e), - ty::Str | ty::Slice(_) => I::Ty::new_usize(cx), + ty::Str | ty::Slice(_) => Ty::new_usize(cx), ty::Dynamic(_, _) => { let dyn_metadata = cx.require_lang_item(SolverLangItem::DynMetadata); @@ -670,7 +666,7 @@ where [I::GenericArg::from(goal.predicate.self_ty())], ); ecx.add_goal(GoalSource::Misc, goal.with(cx, sized_predicate)); - ecx.instantiate_normalizes_to_term(goal, I::Ty::new_unit(cx).into()); + ecx.instantiate_normalizes_to_term(goal, Ty::new_unit(cx).into()); ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes) }); // In case the dummy alias-bound candidate does not apply, we instead treat this projection @@ -687,16 +683,16 @@ where } ty::Adt(def, args) if def.is_struct() => match def.struct_tail_ty(cx) { - None => I::Ty::new_unit(cx), + None => Ty::new_unit(cx), Some(tail_ty) => { - I::Ty::new_projection(cx, metadata_def_id, [tail_ty.instantiate(cx, args)]) + Ty::new_projection(cx, metadata_def_id, [tail_ty.instantiate(cx, args)]) } }, - ty::Adt(_, _) => I::Ty::new_unit(cx), + ty::Adt(_, _) => Ty::new_unit(cx), ty::Tuple(elements) => match elements.last() { - None => I::Ty::new_unit(cx), - Some(tail_ty) => I::Ty::new_projection(cx, metadata_def_id, [tail_ty]), + None => Ty::new_unit(cx), + Some(tail_ty) => Ty::new_projection(cx, metadata_def_id, [tail_ty]), }, ty::UnsafeBinder(_) => { @@ -807,10 +803,10 @@ where let expected_ty = ecx.next_ty_infer(); // Take `AsyncIterator` and turn it into the corresponding // coroutine yield ty `Poll>`. - let wrapped_expected_ty = I::Ty::new_adt( + let wrapped_expected_ty = Ty::new_adt( cx, cx.adt_def(cx.require_adt_lang_item(SolverAdtLangItem::Poll)), - cx.mk_args(&[I::Ty::new_adt( + cx.mk_args(&[Ty::new_adt( cx, cx.adt_def(cx.require_adt_lang_item(SolverAdtLangItem::Option)), cx.mk_args(&[expected_ty.into()]), diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index 478241648e25a..82051b2fea4ef 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -2,15 +2,13 @@ use rustc_type_ir::data_structures::IndexSet; use rustc_type_ir::fast_reject::DeepRejectCtxt; -#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] -use rustc_type_ir::inherent::Ty as _; use rustc_type_ir::inherent::*; use rustc_type_ir::lang_items::SolverTraitLangItem; use rustc_type_ir::solve::{ AliasBoundKind, CandidatePreferenceMode, CanonicalResponse, SizedTraitKind, }; use rustc_type_ir::{ - self as ty, FieldInfo, Interner, Movability, PredicatePolarity, TraitPredicate, TraitRef, Ty, + self as ty, FieldInfo, Interner, Movability, PredicatePolarity, TraitPredicate, TraitRef, TypeVisitableExt as _, TypingMode, Upcast as _, elaborate, }; use tracing::{debug, instrument, trace}; @@ -31,7 +29,7 @@ where D: SolverDelegate, I: Interner, { - fn self_ty(self) -> Ty { + fn self_ty(self) -> ty::Ty { self.self_ty() } @@ -39,7 +37,7 @@ where self.trait_ref } - fn with_replaced_self_ty(self, cx: I, self_ty: Ty) -> Self { + fn with_replaced_self_ty(self, cx: I, self_ty: ty::Ty) -> Self { self.with_replaced_self_ty(cx, self_ty) } @@ -931,7 +929,7 @@ where /// ``` fn consider_builtin_dyn_upcast_candidates( &mut self, - goal: Goal, Ty)>, + goal: Goal, ty::Ty)>, a_data: I::BoundExistentialPredicates, a_region: I::Region, b_data: I::BoundExistentialPredicates, @@ -979,7 +977,7 @@ where fn consider_builtin_unsize_to_dyn_candidate( &mut self, - goal: Goal, Ty)>, + goal: Goal, ty::Ty)>, b_data: I::BoundExistentialPredicates, b_region: I::Region, ) -> Result, NoSolution> { @@ -1020,7 +1018,7 @@ where fn consider_builtin_upcast_to_principal( &mut self, - goal: Goal, Ty)>, + goal: Goal, ty::Ty)>, source: CandidateSource, a_data: I::BoundExistentialPredicates, a_region: I::Region, @@ -1134,9 +1132,9 @@ where /// `#[rustc_deny_explicit_impl]` in this case. fn consider_builtin_array_unsize( &mut self, - goal: Goal, Ty)>, - a_elem_ty: Ty, - b_elem_ty: Ty, + goal: Goal, ty::Ty)>, + a_elem_ty: ty::Ty, + b_elem_ty: ty::Ty, ) -> Result, NoSolution> { self.eq(goal.param_env, a_elem_ty, b_elem_ty)?; self.probe_builtin_trait_candidate(BuiltinImplSource::Misc) @@ -1158,7 +1156,7 @@ where /// ``` fn consider_builtin_struct_unsize( &mut self, - goal: Goal, Ty)>, + goal: Goal, ty::Ty)>, def: I::AdtDef, a_args: I::GenericArgs, b_args: I::GenericArgs, @@ -1184,7 +1182,7 @@ where let new_a_args = cx.mk_args_from_iter(a_args.iter().enumerate().map(|(i, a)| { if unsizing_params.contains(i as u32) { b_args.get(i).unwrap() } else { a } })); - let unsized_a_ty = I::Ty::new_adt(cx, def, new_a_args); + let unsized_a_ty = Ty::new_adt(cx, def, new_a_args); // Finally, we require that `TailA: Unsize` for the tail field // types. @@ -1321,8 +1319,8 @@ where goal: Goal>, constituent_tys: impl Fn( &EvalCtxt<'_, D>, - Ty, - ) -> Result>>, NoSolution>, + ty::Ty, + ) -> Result>>, NoSolution>, ) -> Result, NoSolution> { self.probe_trait_candidate(source).enter(|ecx| { let goals = @@ -1544,7 +1542,10 @@ where self.merge_trait_candidates(candidate_preference_mode, candidates, failed_candidate_info) } - fn try_stall_coroutine(&mut self, self_ty: Ty) -> Option, NoSolution>> { + fn try_stall_coroutine( + &mut self, + self_ty: ty::Ty, + ) -> Option, NoSolution>> { if let ty::Coroutine(def_id, _) = self_ty.kind() { match self.typing_mode() { TypingMode::Analysis { diff --git a/compiler/rustc_type_ir/src/fast_reject.rs b/compiler/rustc_type_ir/src/fast_reject.rs index 884d6bce4b71c..72b58776565b5 100644 --- a/compiler/rustc_type_ir/src/fast_reject.rs +++ b/compiler/rustc_type_ir/src/fast_reject.rs @@ -11,11 +11,9 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHas #[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext}; -#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] -use crate::inherent::Ty as _; use crate::inherent::*; use crate::visit::TypeVisitableExt as _; -use crate::{self as ty, Interner, Ty}; +use crate::{self as ty, Interner}; /// See `simplify_type`. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] @@ -115,7 +113,7 @@ pub enum TreatParams { /// ¹ meaning that if the outermost layers are different, then the whole types are also different. pub fn simplify_type( cx: I, - ty: Ty, + ty: ty::Ty, treat_params: TreatParams, ) -> Option> { match ty.kind() { @@ -238,11 +236,16 @@ impl, rhs: Ty) -> bool { + pub fn types_may_unify(self, lhs: ty::Ty, rhs: ty::Ty) -> bool { self.types_may_unify_inner(lhs, rhs, Self::STARTING_DEPTH) } - pub fn types_may_unify_with_depth(self, lhs: Ty, rhs: Ty, depth_limit: usize) -> bool { + pub fn types_may_unify_with_depth( + self, + lhs: ty::Ty, + rhs: ty::Ty, + depth_limit: usize, + ) -> bool { self.types_may_unify_inner(lhs, rhs, depth_limit) } @@ -270,7 +273,7 @@ impl, rhs: Ty, depth: usize) -> bool { + fn types_may_unify_inner(self, lhs: ty::Ty, rhs: ty::Ty, depth: usize) -> bool { if lhs == rhs { return true; } @@ -529,7 +532,7 @@ impl) -> bool { + fn var_and_ty_may_unify(self, var: ty::InferTy, ty: ty::Ty) -> bool { if !ty.is_known_rigid() { return true; } diff --git a/compiler/rustc_type_ir/src/fold.rs b/compiler/rustc_type_ir/src/fold.rs index 4e8e0a4ed4015..ef162b21b660e 100644 --- a/compiler/rustc_type_ir/src/fold.rs +++ b/compiler/rustc_type_ir/src/fold.rs @@ -53,11 +53,9 @@ use rustc_index::{Idx, IndexVec}; use thin_vec::ThinVec; use tracing::{debug, instrument}; -#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] -use crate::inherent::Ty as _; use crate::inherent::*; use crate::visit::{TypeVisitable, TypeVisitableExt as _}; -use crate::{self as ty, BoundVarIndexKind, Interner, Ty, TypeFlags}; +use crate::{self as ty, BoundVarIndexKind, Interner, TypeFlags}; /// This trait is implemented for every type that can be folded, /// providing the skeleton of the traversal. @@ -137,7 +135,7 @@ pub trait TypeFolder: Sized { t.super_fold_with(self) } - fn fold_ty(&mut self, t: Ty) -> Ty { + fn fold_ty(&mut self, t: ty::Ty) -> ty::Ty { t.super_fold_with(self) } @@ -179,7 +177,7 @@ pub trait FallibleTypeFolder: Sized { t.try_super_fold_with(self) } - fn try_fold_ty(&mut self, t: Ty) -> Result, Self::Error> { + fn try_fold_ty(&mut self, t: ty::Ty) -> Result, Self::Error> { t.try_super_fold_with(self) } @@ -410,13 +408,13 @@ impl TypeFolder for Shifter { } } - fn fold_ty(&mut self, ty: Ty) -> Ty { + fn fold_ty(&mut self, ty: ty::Ty) -> ty::Ty { match ty.kind() { ty::Bound(BoundVarIndexKind::Bound(debruijn), bound_ty) if debruijn >= self.current_index => { let debruijn = debruijn.shifted_in(self.amount); - I::Ty::new_bound(self.cx, debruijn, bound_ty) + Ty::new_bound(self.cx, debruijn, bound_ty) } _ if ty.has_vars_bound_at_or_above(self.current_index) => ty.super_fold_with(self), @@ -540,7 +538,7 @@ where } } - fn fold_ty(&mut self, t: Ty) -> Ty { + fn fold_ty(&mut self, t: ty::Ty) -> ty::Ty { if t.has_type_flags( TypeFlags::HAS_FREE_REGIONS | TypeFlags::HAS_RE_BOUND | TypeFlags::HAS_RE_ERASED, ) { diff --git a/compiler/rustc_type_ir/src/predicate.rs b/compiler/rustc_type_ir/src/predicate.rs index b8ea99777aaba..f4975f3ad4486 100644 --- a/compiler/rustc_type_ir/src/predicate.rs +++ b/compiler/rustc_type_ir/src/predicate.rs @@ -10,13 +10,11 @@ use rustc_type_ir_macros::{ GenericTypeVisitable, Lift_Generic, TypeFoldable_Generic, TypeVisitable_Generic, }; -#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] -use crate::inherent::Ty as _; use crate::inherent::*; use crate::lift::Lift; use crate::upcast::{Upcast, UpcastFrom}; use crate::visit::TypeVisitableExt as _; -use crate::{self as ty, Interner, Ty}; +use crate::{self as ty, Interner}; /// `A: 'region` #[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, A)] @@ -103,7 +101,7 @@ impl TraitRef { ) } - pub fn with_replaced_self_ty(self, interner: I, self_ty: Ty) -> Self { + pub fn with_replaced_self_ty(self, interner: I, self_ty: ty::Ty) -> Self { TraitRef::new( interner, self.def_id, @@ -112,13 +110,13 @@ impl TraitRef { } #[inline] - pub fn self_ty(&self) -> Ty { + pub fn self_ty(&self) -> ty::Ty { self.args.type_at(0) } } impl ty::Binder> { - pub fn self_ty(&self) -> ty::Binder> { + pub fn self_ty(&self) -> ty::Binder> { self.map_bound_ref(|tr| tr.self_ty()) } @@ -154,7 +152,7 @@ pub struct TraitPredicate { impl Eq for TraitPredicate {} impl TraitPredicate { - pub fn with_replaced_self_ty(self, interner: I, self_ty: Ty) -> Self { + pub fn with_replaced_self_ty(self, interner: I, self_ty: ty::Ty) -> Self { Self { trait_ref: self.trait_ref.with_replaced_self_ty(interner, self_ty), polarity: self.polarity, @@ -165,7 +163,7 @@ impl TraitPredicate { self.trait_ref.def_id } - pub fn self_ty(self) -> Ty { + pub fn self_ty(self) -> ty::Ty { self.trait_ref.self_ty() } } @@ -176,7 +174,7 @@ impl ty::Binder> { self.skip_binder().def_id() } - pub fn self_ty(self) -> ty::Binder> { + pub fn self_ty(self) -> ty::Binder> { self.map_bound(|trait_ref| trait_ref.self_ty()) } @@ -309,7 +307,7 @@ impl ty::Binder> { /// Given an existential predicate like `?Self: PartialEq` (e.g., derived from `dyn PartialEq`), /// and a concrete type `self_ty`, returns a full predicate where the existentially quantified variable `?Self` /// has been replaced with `self_ty` (e.g., `self_ty: PartialEq`, in our example). - pub fn with_self_ty(&self, cx: I, self_ty: Ty) -> I::Clause { + pub fn with_self_ty(&self, cx: I, self_ty: ty::Ty) -> I::Clause { match self.skip_binder() { ExistentialPredicate::Trait(tr) => self.rebind(tr).with_self_ty(cx, self_ty).upcast(cx), ExistentialPredicate::Projection(p) => { @@ -386,7 +384,7 @@ impl ExistentialTraitRef { /// we convert the principal trait-ref into a normal trait-ref, /// you must give *some* self type. A common choice is `mk_err()` /// or some placeholder type. - pub fn with_self_ty(self, interner: I, self_ty: Ty) -> TraitRef { + pub fn with_self_ty(self, interner: I, self_ty: ty::Ty) -> TraitRef { // otherwise the escaping vars would be captured by the binder // debug_assert!(!self_ty.has_escaping_bound_vars()); @@ -403,7 +401,7 @@ impl ty::Binder> { /// we convert the principal trait-ref into a normal trait-ref, /// you must give *some* self type. A common choice is `mk_err()` /// or some placeholder type. - pub fn with_self_ty(&self, cx: I, self_ty: Ty) -> ty::Binder> { + pub fn with_self_ty(&self, cx: I, self_ty: ty::Ty) -> ty::Binder> { self.map_bound(|trait_ref| trait_ref.with_self_ty(cx, self_ty)) } } @@ -461,7 +459,7 @@ impl ExistentialProjection { ExistentialTraitRef::new_from_args(interner, def_id.try_into().unwrap(), args) } - pub fn with_self_ty(&self, interner: I, self_ty: Ty) -> ProjectionPredicate { + pub fn with_self_ty(&self, interner: I, self_ty: ty::Ty) -> ProjectionPredicate { // otherwise the escaping regions would be captured by the binders debug_assert!(!self_ty.has_escaping_bound_vars()); @@ -489,7 +487,7 @@ impl ExistentialProjection { } impl ty::Binder> { - pub fn with_self_ty(&self, cx: I, self_ty: Ty) -> ty::Binder> { + pub fn with_self_ty(&self, cx: I, self_ty: ty::Ty) -> ty::Binder> { self.map_bound(|p| p.with_self_ty(cx, self_ty)) } @@ -647,25 +645,25 @@ impl AliasTerm { pub fn to_term(self, interner: I) -> I::Term { match self.kind(interner) { - AliasTermKind::ProjectionTy => I::Ty::new_alias( + AliasTermKind::ProjectionTy => Ty::new_alias( interner, ty::AliasTyKind::Projection, ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () }, ) .into(), - AliasTermKind::InherentTy => I::Ty::new_alias( + AliasTermKind::InherentTy => Ty::new_alias( interner, ty::AliasTyKind::Inherent, ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () }, ) .into(), - AliasTermKind::OpaqueTy => I::Ty::new_alias( + AliasTermKind::OpaqueTy => Ty::new_alias( interner, ty::AliasTyKind::Opaque, ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () }, ) .into(), - AliasTermKind::FreeTy => I::Ty::new_alias( + AliasTermKind::FreeTy => Ty::new_alias( interner, ty::AliasTyKind::Free, ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () }, @@ -685,11 +683,11 @@ impl AliasTerm { /// The following methods work only with (trait) associated term projections. impl AliasTerm { - pub fn self_ty(self) -> Ty { + pub fn self_ty(self) -> ty::Ty { self.args.type_at(0) } - pub fn with_replaced_self_ty(self, interner: I, self_ty: Ty) -> Self { + pub fn with_replaced_self_ty(self, interner: I, self_ty: ty::Ty) -> Self { AliasTerm::new( interner, self.def_id, @@ -798,11 +796,11 @@ pub struct ProjectionPredicate { impl Eq for ProjectionPredicate {} impl ProjectionPredicate { - pub fn self_ty(self) -> Ty { + pub fn self_ty(self) -> ty::Ty { self.projection_term.self_ty() } - pub fn with_replaced_self_ty(self, interner: I, self_ty: Ty) -> ProjectionPredicate { + pub fn with_replaced_self_ty(self, interner: I, self_ty: ty::Ty) -> ProjectionPredicate { Self { projection_term: self.projection_term.with_replaced_self_ty(interner, self_ty), ..self @@ -861,11 +859,11 @@ pub struct NormalizesTo { impl Eq for NormalizesTo {} impl NormalizesTo { - pub fn self_ty(self) -> Ty { + pub fn self_ty(self) -> ty::Ty { self.alias.self_ty() } - pub fn with_replaced_self_ty(self, interner: I, self_ty: Ty) -> NormalizesTo { + pub fn with_replaced_self_ty(self, interner: I, self_ty: ty::Ty) -> NormalizesTo { Self { alias: self.alias.with_replaced_self_ty(interner, self_ty), ..self } } @@ -898,11 +896,11 @@ pub struct HostEffectPredicate { impl Eq for HostEffectPredicate {} impl HostEffectPredicate { - pub fn self_ty(self) -> Ty { + pub fn self_ty(self) -> ty::Ty { self.trait_ref.self_ty() } - pub fn with_replaced_self_ty(self, interner: I, self_ty: Ty) -> Self { + pub fn with_replaced_self_ty(self, interner: I, self_ty: ty::Ty) -> Self { Self { trait_ref: self.trait_ref.with_replaced_self_ty(interner, self_ty), ..self } } @@ -917,7 +915,7 @@ impl ty::Binder> { self.skip_binder().def_id() } - pub fn self_ty(self) -> ty::Binder> { + pub fn self_ty(self) -> ty::Binder> { self.map_bound(|trait_ref| trait_ref.self_ty()) } @@ -938,8 +936,8 @@ impl ty::Binder> { )] pub struct SubtypePredicate { pub a_is_expected: bool, - pub a: Ty, - pub b: Ty, + pub a: ty::Ty, + pub b: ty::Ty, } impl Eq for SubtypePredicate {} @@ -952,8 +950,8 @@ impl Eq for SubtypePredicate {} derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) )] pub struct CoercePredicate { - pub a: Ty, - pub b: Ty, + pub a: ty::Ty, + pub b: ty::Ty, } impl Eq for CoercePredicate {} diff --git a/compiler/rustc_type_ir/src/relate.rs b/compiler/rustc_type_ir/src/relate.rs index cc7f5f715f0ba..31248bea4cf85 100644 --- a/compiler/rustc_type_ir/src/relate.rs +++ b/compiler/rustc_type_ir/src/relate.rs @@ -6,10 +6,8 @@ use tracing::{instrument, trace}; use crate::error::{ExpectedFound, TypeError}; use crate::fold::TypeFoldable; -#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] -use crate::inherent::Ty as _; use crate::inherent::*; -use crate::{self as ty, Interner, Ty}; +use crate::{self as ty, Interner}; pub mod combine; pub mod solver_relating; @@ -46,7 +44,7 @@ pub enum VarianceDiagInfo { Invariant { /// The generic type containing the generic parameter /// that changes the variance (e.g. `*mut T`, `MyStruct`) - ty: Ty, + ty: ty::Ty, /// The index of the generic parameter being used /// (e.g. `0` for `*mut T`, `1` for `MyStruct<'CovariantParam, 'InvariantParam>`) param_index: u32, @@ -77,13 +75,13 @@ pub trait TypeRelation: Sized { fn relate_ty_args( &mut self, - a_ty: Ty, - b_ty: Ty, + a_ty: ty::Ty, + b_ty: ty::Ty, ty_def_id: I::DefId, a_arg: I::GenericArgs, b_arg: I::GenericArgs, - mk: impl FnOnce(I::GenericArgs) -> Ty, - ) -> RelateResult>; + mk: impl FnOnce(I::GenericArgs) -> ty::Ty, + ) -> RelateResult>; /// Switch variance for the purpose of relating `a` and `b`. fn relate_with_variance>( @@ -100,7 +98,7 @@ pub trait TypeRelation: Sized { // additional hooks for other types in the future if needed // without making older code, which called `relate`, obsolete. - fn tys(&mut self, a: Ty, b: Ty) -> RelateResult>; + fn tys(&mut self, a: ty::Ty, b: ty::Ty) -> RelateResult>; fn regions(&mut self, a: I::Region, b: I::Region) -> RelateResult; @@ -334,9 +332,9 @@ impl Relate for ty::ExistentialTraitRef { #[instrument(level = "trace", skip(relation), ret)] pub fn structurally_relate_tys>( relation: &mut R, - a: Ty, - b: Ty, -) -> RelateResult> { + a: ty::Ty, + b: ty::Ty, +) -> RelateResult> { let cx = relation.cx(); match (a.kind(), b.kind()) { (ty::Infer(_), _) | (_, ty::Infer(_)) => { @@ -348,7 +346,7 @@ pub fn structurally_relate_tys>( panic!("bound types encountered in structurally_relate_tys") } - (ty::Error(guar), _) | (_, ty::Error(guar)) => Ok(I::Ty::new_error(cx, guar)), + (ty::Error(guar), _) | (_, ty::Error(guar)) => Ok(Ty::new_error(cx, guar)), (ty::Never, _) | (ty::Char, _) @@ -375,14 +373,14 @@ pub fn structurally_relate_tys>( Ok(a) } else { relation.relate_ty_args(a, b, a_def.def_id().into(), a_args, b_args, |args| { - I::Ty::new_adt(cx, a_def, args) + Ty::new_adt(cx, a_def, args) }) } } - (ty::Foreign(a_id), ty::Foreign(b_id)) if a_id == b_id => Ok(I::Ty::new_foreign(cx, a_id)), + (ty::Foreign(a_id), ty::Foreign(b_id)) if a_id == b_id => Ok(Ty::new_foreign(cx, a_id)), - (ty::Dynamic(a_obj, a_region), ty::Dynamic(b_obj, b_region)) => Ok(I::Ty::new_dynamic( + (ty::Dynamic(a_obj, a_region), ty::Dynamic(b_obj, b_region)) => Ok(Ty::new_dynamic( cx, relation.relate(a_obj, b_obj)?, relation.relate(a_region, b_region)?, @@ -393,7 +391,7 @@ pub fn structurally_relate_tys>( // the (anonymous) type of the same coroutine expression. So // all of their regions should be equated. let args = relate_args_invariantly(relation, a_args, b_args)?; - Ok(I::Ty::new_coroutine(cx, a_id, args)) + Ok(Ty::new_coroutine(cx, a_id, args)) } (ty::CoroutineWitness(a_id, a_args), ty::CoroutineWitness(b_id, b_args)) @@ -403,7 +401,7 @@ pub fn structurally_relate_tys>( // the (anonymous) type of the same coroutine expression. So // all of their regions should be equated. let args = relate_args_invariantly(relation, a_args, b_args)?; - Ok(I::Ty::new_coroutine_witness(cx, a_id, args)) + Ok(Ty::new_coroutine_witness(cx, a_id, args)) } (ty::Closure(a_id, a_args), ty::Closure(b_id, b_args)) if a_id == b_id => { @@ -411,14 +409,14 @@ pub fn structurally_relate_tys>( // the (anonymous) type of the same closure expression. So // all of their regions should be equated. let args = relate_args_invariantly(relation, a_args, b_args)?; - Ok(I::Ty::new_closure(cx, a_id, args)) + Ok(Ty::new_closure(cx, a_id, args)) } (ty::CoroutineClosure(a_id, a_args), ty::CoroutineClosure(b_id, b_args)) if a_id == b_id => { let args = relate_args_invariantly(relation, a_args, b_args)?; - Ok(I::Ty::new_coroutine_closure(cx, a_id, args)) + Ok(Ty::new_coroutine_closure(cx, a_id, args)) } (ty::RawPtr(a_ty, a_mutbl), ty::RawPtr(b_ty, b_mutbl)) => { @@ -435,7 +433,7 @@ pub fn structurally_relate_tys>( let ty = relation.relate_with_variance(variance, info, a_ty, b_ty)?; - Ok(I::Ty::new_ptr(cx, ty, a_mutbl)) + Ok(Ty::new_ptr(cx, ty, a_mutbl)) } (ty::Ref(a_r, a_ty, a_mutbl), ty::Ref(b_r, b_ty, b_mutbl)) => { @@ -453,13 +451,13 @@ pub fn structurally_relate_tys>( let r = relation.relate(a_r, b_r)?; let ty = relation.relate_with_variance(variance, info, a_ty, b_ty)?; - Ok(I::Ty::new_ref(cx, r, ty, a_mutbl)) + Ok(Ty::new_ref(cx, r, ty, a_mutbl)) } (ty::Array(a_t, sz_a), ty::Array(b_t, sz_b)) => { let t = relation.relate(a_t, b_t)?; match relation.relate(sz_a, sz_b) { - Ok(sz) => Ok(I::Ty::new_array_with_const_len(cx, t, sz)), + Ok(sz) => Ok(Ty::new_array_with_const_len(cx, t, sz)), Err(TypeError::ConstMismatch(_)) => { Err(TypeError::ArraySize(ExpectedFound::new(sz_a, sz_b))) } @@ -469,12 +467,12 @@ pub fn structurally_relate_tys>( (ty::Slice(a_t), ty::Slice(b_t)) => { let t = relation.relate(a_t, b_t)?; - Ok(I::Ty::new_slice(cx, t)) + Ok(Ty::new_slice(cx, t)) } (ty::Tuple(as_), ty::Tuple(bs)) => { if as_.len() == bs.len() { - Ok(I::Ty::new_tup_from_iter( + Ok(Ty::new_tup_from_iter( cx, iter::zip(as_.iter(), bs.iter()).map(|(a, b)| relation.relate(a, b)), )?) @@ -490,31 +488,31 @@ pub fn structurally_relate_tys>( Ok(a) } else { relation.relate_ty_args(a, b, a_def_id.into(), a_args, b_args, |args| { - I::Ty::new_fn_def(cx, a_def_id, args) + Ty::new_fn_def(cx, a_def_id, args) }) } } (ty::FnPtr(a_sig_tys, a_hdr), ty::FnPtr(b_sig_tys, b_hdr)) => { let fty = relation.relate(a_sig_tys.with(a_hdr), b_sig_tys.with(b_hdr))?; - Ok(I::Ty::new_fn_ptr(cx, fty)) + Ok(Ty::new_fn_ptr(cx, fty)) } // Alias tend to mostly already be handled downstream due to normalization. (ty::Alias(a_kind, a_data), ty::Alias(b_kind, b_data)) => { let alias_ty = relation.relate(a_data, b_data)?; assert_eq!(a_kind, b_kind); - Ok(I::Ty::new_alias(cx, a_kind, alias_ty)) + Ok(Ty::new_alias(cx, a_kind, alias_ty)) } (ty::Pat(a_ty, a_pat), ty::Pat(b_ty, b_pat)) => { let ty = relation.relate(a_ty, b_ty)?; let pat = relation.relate(a_pat, b_pat)?; - Ok(I::Ty::new_pat(cx, ty, pat)) + Ok(Ty::new_pat(cx, ty, pat)) } (ty::UnsafeBinder(a_binder), ty::UnsafeBinder(b_binder)) => { - Ok(I::Ty::new_unsafe_binder(cx, relation.binders(*a_binder, *b_binder)?)) + Ok(Ty::new_unsafe_binder(cx, relation.binders(*a_binder, *b_binder)?)) } _ => Err(TypeError::Sorts(ExpectedFound::new(a, b))), diff --git a/compiler/rustc_type_ir/src/relate/combine.rs b/compiler/rustc_type_ir/src/relate/combine.rs index de5d63c032128..11fbbf89b9c7b 100644 --- a/compiler/rustc_type_ir/src/relate/combine.rs +++ b/compiler/rustc_type_ir/src/relate/combine.rs @@ -7,13 +7,11 @@ use super::{ structurally_relate_consts, structurally_relate_tys, }; use crate::error::TypeError; -#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] -use crate::inherent::Ty as _; use crate::inherent::*; use crate::relate::VarianceDiagInfo; use crate::solve::Goal; use crate::visit::TypeVisitableExt as _; -use crate::{self as ty, InferCtxtLike, Interner, Ty, TypingMode, Upcast}; +use crate::{self as ty, InferCtxtLike, Interner, TypingMode, Upcast}; pub trait PredicateEmittingRelation::Interner>: TypeRelation @@ -41,15 +39,15 @@ where ); /// Register `AliasRelate` obligation(s) that both types must be related to each other. - fn register_alias_relate_predicate(&mut self, a: Ty, b: Ty); + fn register_alias_relate_predicate(&mut self, a: ty::Ty, b: ty::Ty); } pub fn super_combine_tys( infcx: &Infcx, relation: &mut R, - a: Ty, - b: Ty, -) -> RelateResult> + a: ty::Ty, + b: ty::Ty, +) -> RelateResult> where Infcx: InferCtxtLike, I: Interner, @@ -62,7 +60,7 @@ where match (a.kind(), b.kind()) { (ty::Error(e), _) | (_, ty::Error(e)) => { infcx.set_tainted_by_errors(e); - return Ok(I::Ty::new_error(infcx.cx(), e)); + return Ok(Ty::new_error(infcx.cx(), e)); } // Relate integral variables to other types @@ -228,13 +226,13 @@ where pub fn combine_ty_args( infcx: &Infcx, relation: &mut R, - a_ty: Ty, - b_ty: Ty, + a_ty: ty::Ty, + b_ty: ty::Ty, variances: I::VariancesOf, a_args: I::GenericArgs, b_args: I::GenericArgs, - mk: impl FnOnce(I::GenericArgs) -> Ty, -) -> RelateResult> + mk: impl FnOnce(I::GenericArgs) -> ty::Ty, +) -> RelateResult> where Infcx: InferCtxtLike, I: Interner, diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index de8ae4a36f033..24d28acc05e98 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -14,12 +14,10 @@ use rustc_type_ir_macros::{ use self::TyKind::*; pub use self::closure::*; -#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] -use crate::inherent::Ty as _; use crate::inherent::*; #[cfg(feature = "nightly")] use crate::visit::TypeVisitable; -use crate::{self as ty, BoundVarIndexKind, FloatTy, IntTy, Interner, Ty, UintTy}; +use crate::{self as ty, BoundVarIndexKind, FloatTy, IntTy, Interner, UintTy}; mod closure; @@ -102,7 +100,7 @@ pub enum TyKind { Str, /// An array with the given length. Written as `[T; N]`. - Array(Ty, I::Const), + Array(ty::Ty, I::Const), /// A pattern newtype. /// @@ -111,17 +109,17 @@ pub enum TyKind { /// Only `Copy` and `Clone` will automatically get implemented for pattern types. /// Auto-traits treat this as if it were an aggregate with a single nested type. /// Only supports integer range patterns for now. - Pat(Ty, I::Pat), + Pat(ty::Ty, I::Pat), /// The pointee of an array slice. Written as `[T]`. - Slice(Ty), + Slice(ty::Ty), /// A raw pointer. Written as `*mut T` or `*const T` - RawPtr(Ty, Mutability), + RawPtr(ty::Ty, Mutability), /// A reference; a pointer with an associated lifetime. Written as /// `&'a mut T` or `&'a T`. - Ref(I::Region, Ty, Mutability), + Ref(I::Region, ty::Ty, Mutability), /// The anonymous type of a function declaration/definition. /// @@ -471,18 +469,18 @@ impl AliasTy { matches!(self.kind(interner), AliasTyKind::Opaque) } - pub fn to_ty(self, interner: I) -> Ty { - I::Ty::new_alias(interner, self.kind(interner), self) + pub fn to_ty(self, interner: I) -> ty::Ty { + Ty::new_alias(interner, self.kind(interner), self) } } /// The following methods work only with (trait) associated type projections. impl AliasTy { - pub fn self_ty(self) -> Ty { + pub fn self_ty(self) -> ty::Ty { self.args.type_at(0) } - pub fn with_replaced_self_ty(self, interner: I, self_ty: Ty) -> Self { + pub fn with_replaced_self_ty(self, interner: I, self_ty: ty::Ty) -> Self { AliasTy::new( interner, self.def_id, @@ -737,7 +735,7 @@ impl fmt::Debug for InferTy { )] #[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] pub struct TypeAndMut { - pub ty: Ty, + pub ty: ty::Ty, pub mutbl: Mutability, } @@ -767,7 +765,7 @@ impl FnSig { self.inputs_and_output.inputs() } - pub fn output(self) -> Ty { + pub fn output(self) -> ty::Ty { self.inputs_and_output.output() } @@ -785,7 +783,7 @@ impl ty::Binder> { #[inline] #[track_caller] - pub fn input(self, index: usize) -> ty::Binder> { + pub fn input(self, index: usize) -> ty::Binder> { self.map_bound(|fn_sig| fn_sig.inputs().get(index).unwrap()) } @@ -794,7 +792,7 @@ impl ty::Binder> { } #[inline] - pub fn output(self) -> ty::Binder> { + pub fn output(self) -> ty::Binder> { self.map_bound(|fn_sig| fn_sig.output()) } @@ -858,21 +856,21 @@ impl fmt::Debug for FnSig { } // FIXME: this is a distinct type because we need to define `Encode`/`Decode` -// impls in this crate for `Binder>`. +// impls in this crate for `Binder>`. #[derive_where(Clone, Copy, PartialEq, Hash; I: Interner)] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] #[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic, Lift_Generic)] -pub struct UnsafeBinderInner(ty::Binder>); +pub struct UnsafeBinderInner(ty::Binder>); impl Eq for UnsafeBinderInner {} -impl From>> for UnsafeBinderInner { - fn from(value: ty::Binder>) -> Self { +impl From>> for UnsafeBinderInner { + fn from(value: ty::Binder>) -> Self { UnsafeBinderInner(value) } } -impl From> for ty::Binder> { +impl From> for ty::Binder> { fn from(value: UnsafeBinderInner) -> Self { value.0 } @@ -885,7 +883,7 @@ impl fmt::Debug for UnsafeBinderInner { } impl Deref for UnsafeBinderInner { - type Target = ty::Binder>; + type Target = ty::Binder>; fn deref(&self) -> &Self::Target { &self.0 @@ -896,7 +894,7 @@ impl Deref for UnsafeBinderInner { impl rustc_serialize::Encodable for UnsafeBinderInner where - Ty: rustc_serialize::Encodable, + ty::Ty: rustc_serialize::Encodable, I::BoundVarKinds: rustc_serialize::Encodable, { fn encode(&self, e: &mut E) { @@ -909,7 +907,7 @@ where impl rustc_serialize::Decodable for UnsafeBinderInner where - Ty: TypeVisitable + rustc_serialize::Decodable, + ty::Ty: TypeVisitable + rustc_serialize::Decodable, I::BoundVarKinds: rustc_serialize::Decodable, { fn decode(decoder: &mut D) -> Self { @@ -939,7 +937,7 @@ impl FnSigTys { self.inputs_and_output.inputs() } - pub fn output(self) -> Ty { + pub fn output(self) -> ty::Ty { self.inputs_and_output.output() } } @@ -962,7 +960,7 @@ impl ty::Binder> { #[inline] #[track_caller] - pub fn input(self, index: usize) -> ty::Binder> { + pub fn input(self, index: usize) -> ty::Binder> { self.map_bound(|sig_tys| sig_tys.inputs().get(index).unwrap()) } @@ -971,7 +969,7 @@ impl ty::Binder> { } #[inline] - pub fn output(self) -> ty::Binder> { + pub fn output(self) -> ty::Binder> { self.map_bound(|sig_tys| sig_tys.output()) } } diff --git a/compiler/rustc_type_ir/src/ty_kind/closure.rs b/compiler/rustc_type_ir/src/ty_kind/closure.rs index d713b832a5213..08c303b8de9c8 100644 --- a/compiler/rustc_type_ir/src/ty_kind/closure.rs +++ b/compiler/rustc_type_ir/src/ty_kind/closure.rs @@ -7,11 +7,9 @@ use rustc_type_ir_macros::{ use crate::data_structures::DelayedMap; use crate::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable, shift_region}; -#[cfg_attr(feature = "nightly", allow(rustc::non_glob_import_of_type_ir_inherent))] -use crate::inherent::Ty as _; use crate::inherent::*; use crate::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor}; -use crate::{self as ty, Interner, Ty}; +use crate::{self as ty, Interner}; /// A closure can be modeled as a struct that looks like: /// ```ignore (illustrative) @@ -123,13 +121,13 @@ pub struct ClosureArgsParts { /// This is the args of the typeck root. pub parent_args: I::GenericArgsSlice, /// Represents the maximum calling capability of the closure. - pub closure_kind_ty: Ty, + pub closure_kind_ty: ty::Ty, /// Captures the closure's signature. This closure signature is "tupled", and /// thus has a peculiar signature of `extern "rust-call" fn((Args, ...)) -> Ty`. - pub closure_sig_as_fn_ptr_ty: Ty, + pub closure_sig_as_fn_ptr_ty: ty::Ty, /// The upvars captured by the closure. Remains an inference variable /// until the upvar analysis, which happens late in HIR typeck. - pub tupled_upvars_ty: Ty, + pub tupled_upvars_ty: ty::Ty, } impl ClosureArgs { @@ -171,14 +169,14 @@ impl ClosureArgs { /// Returns the tuple type representing the upvars for this closure. #[inline] - pub fn tupled_upvars_ty(self) -> Ty { + pub fn tupled_upvars_ty(self) -> ty::Ty { self.split().tupled_upvars_ty } /// Returns the closure kind for this closure; may return a type /// variable during inference. To get the closure kind during /// inference, use `infcx.closure_kind(args)`. - pub fn kind_ty(self) -> Ty { + pub fn kind_ty(self) -> ty::Ty { self.split().closure_kind_ty } @@ -187,7 +185,7 @@ impl ClosureArgs { // FIXME(eddyb) this should be unnecessary, as the shallowly resolved // type is known at the time of the creation of `ClosureArgs`, // see `rustc_hir_analysis::check::closure`. - pub fn sig_as_fn_ptr_ty(self) -> Ty { + pub fn sig_as_fn_ptr_ty(self) -> ty::Ty { self.split().closure_sig_as_fn_ptr_ty } @@ -225,7 +223,7 @@ pub struct CoroutineClosureArgsParts { /// This is the args of the typeck root. pub parent_args: I::GenericArgsSlice, /// Represents the maximum calling capability of the closure. - pub closure_kind_ty: Ty, + pub closure_kind_ty: ty::Ty, /// Represents all of the relevant parts of the coroutine returned by this /// coroutine-closure. This signature parts type will have the general /// shape of `fn(tupled_inputs, resume_ty) -> (return_ty, yield_ty)`, where @@ -234,10 +232,10 @@ pub struct CoroutineClosureArgsParts { /// /// Use `coroutine_closure_sig` to break up this type rather than using it /// yourself. - pub signature_parts_ty: Ty, + pub signature_parts_ty: ty::Ty, /// The upvars captured by the closure. Remains an inference variable /// until the upvar analysis, which happens late in HIR typeck. - pub tupled_upvars_ty: Ty, + pub tupled_upvars_ty: ty::Ty, /// a function pointer that has the shape `for<'env> fn() -> (&'env T, ...)`. /// This allows us to represent the binder of the self-captures of the closure. /// @@ -245,7 +243,7 @@ pub struct CoroutineClosureArgsParts { /// from the closure's upvars, this will be `for<'env> fn() -> (&'env String,)`, /// while the `tupled_upvars_ty`, representing the by-move version of the same /// captures, will be `(String,)`. - pub coroutine_captures_by_ref_ty: Ty, + pub coroutine_captures_by_ref_ty: ty::Ty, } impl CoroutineClosureArgs { @@ -279,11 +277,11 @@ impl CoroutineClosureArgs { } #[inline] - pub fn tupled_upvars_ty(self) -> Ty { + pub fn tupled_upvars_ty(self) -> ty::Ty { self.split().tupled_upvars_ty } - pub fn kind_ty(self) -> Ty { + pub fn kind_ty(self) -> ty::Ty { self.split().closure_kind_ty } @@ -291,7 +289,7 @@ impl CoroutineClosureArgs { self.kind_ty().to_opt_closure_kind().unwrap() } - pub fn signature_parts_ty(self) -> Ty { + pub fn signature_parts_ty(self) -> ty::Ty { self.split().signature_parts_ty } @@ -316,7 +314,7 @@ impl CoroutineClosureArgs { }) } - pub fn coroutine_captures_by_ref_ty(self) -> Ty { + pub fn coroutine_captures_by_ref_ty(self) -> ty::Ty { self.split().coroutine_captures_by_ref_ty } @@ -360,10 +358,10 @@ impl TypeVisitor for HasRegionsBoundAt { #[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] pub struct CoroutineClosureSignature { - pub tupled_inputs_ty: Ty, - pub resume_ty: Ty, - pub yield_ty: Ty, - pub return_ty: Ty, + pub tupled_inputs_ty: ty::Ty, + pub resume_ty: ty::Ty, + pub yield_ty: ty::Ty, + pub return_ty: ty::Ty, // Like the `fn_sig_as_fn_ptr_ty` of a regular closure, these types // never actually differ. But we save them rather than recreating them @@ -395,10 +393,10 @@ impl CoroutineClosureSignature { self, cx: I, parent_args: I::GenericArgsSlice, - coroutine_kind_ty: Ty, + coroutine_kind_ty: ty::Ty, coroutine_def_id: I::CoroutineId, - tupled_upvars_ty: Ty, - ) -> Ty { + tupled_upvars_ty: ty::Ty, + ) -> ty::Ty { let coroutine_args = ty::CoroutineArgs::new( cx, ty::CoroutineArgsParts { @@ -411,7 +409,7 @@ impl CoroutineClosureSignature { }, ); - I::Ty::new_coroutine(cx, coroutine_def_id, coroutine_args.args) + Ty::new_coroutine(cx, coroutine_def_id, coroutine_args.args) } /// Given known upvars and a [`ClosureKind`](ty::ClosureKind), compute the coroutine @@ -426,9 +424,9 @@ impl CoroutineClosureSignature { coroutine_def_id: I::CoroutineId, goal_kind: ty::ClosureKind, env_region: I::Region, - closure_tupled_upvars_ty: Ty, - coroutine_captures_by_ref_ty: Ty, - ) -> Ty { + closure_tupled_upvars_ty: ty::Ty, + coroutine_captures_by_ref_ty: ty::Ty, + ) -> ty::Ty { let tupled_upvars_ty = Self::tupled_upvars_by_closure_kind( cx, goal_kind, @@ -441,7 +439,7 @@ impl CoroutineClosureSignature { self.to_coroutine( cx, parent_args, - I::Ty::from_coroutine_closure_kind(cx, goal_kind), + Ty::from_coroutine_closure_kind(cx, goal_kind), coroutine_def_id, tupled_upvars_ty, ) @@ -459,11 +457,11 @@ impl CoroutineClosureSignature { pub fn tupled_upvars_by_closure_kind( cx: I, kind: ty::ClosureKind, - tupled_inputs_ty: Ty, - closure_tupled_upvars_ty: Ty, - coroutine_captures_by_ref_ty: Ty, + tupled_inputs_ty: ty::Ty, + closure_tupled_upvars_ty: ty::Ty, + coroutine_captures_by_ref_ty: ty::Ty, env_region: I::Region, - ) -> Ty { + ) -> ty::Ty { match kind { ty::ClosureKind::Fn | ty::ClosureKind::FnMut => { let ty::FnPtr(sig_tys, _) = coroutine_captures_by_ref_ty.kind() else { @@ -476,7 +474,7 @@ impl CoroutineClosureSignature { debruijn: ty::INNERMOST, cache: Default::default(), }); - I::Ty::new_tup_from_iter( + Ty::new_tup_from_iter( cx, tupled_inputs_ty .tuple_fields() @@ -484,7 +482,7 @@ impl CoroutineClosureSignature { .chain(coroutine_captures_by_ref_ty.tuple_fields().iter()), ) } - ty::ClosureKind::FnOnce => I::Ty::new_tup_from_iter( + ty::ClosureKind::FnOnce => Ty::new_tup_from_iter( cx, tupled_inputs_ty .tuple_fields() @@ -505,7 +503,7 @@ struct FoldEscapingRegions { // Depends on `debruijn` because we may have types with regions of different // debruijn depths depending on the binders we've entered. - cache: DelayedMap<(ty::DebruijnIndex, Ty), Ty>, + cache: DelayedMap<(ty::DebruijnIndex, ty::Ty), ty::Ty>, } impl TypeFolder for FoldEscapingRegions { @@ -513,7 +511,7 @@ impl TypeFolder for FoldEscapingRegions { self.interner } - fn fold_ty(&mut self, t: Ty) -> Ty { + fn fold_ty(&mut self, t: ty::Ty) -> ty::Ty { if !t.has_vars_bound_at_or_above(self.debruijn) { t } else if let Some(&t) = self.cache.get(&(self.debruijn, t)) { @@ -555,9 +553,9 @@ impl TypeFolder for FoldEscapingRegions { #[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, GenericTypeVisitable, TypeFoldable_Generic)] pub struct GenSig { - pub resume_ty: Ty, - pub yield_ty: Ty, - pub return_ty: Ty, + pub resume_ty: ty::Ty, + pub yield_ty: ty::Ty, + pub return_ty: ty::Ty, } impl Eq for GenSig {} @@ -583,15 +581,15 @@ pub struct CoroutineArgsParts { /// kind: `i8`/`i16`/`i32`. /// /// For regular coroutines, this field will always just be `()`. - pub kind_ty: Ty, + pub kind_ty: ty::Ty, - pub resume_ty: Ty, - pub yield_ty: Ty, - pub return_ty: Ty, + pub resume_ty: ty::Ty, + pub yield_ty: ty::Ty, + pub return_ty: ty::Ty, /// The upvars captured by the closure. Remains an inference variable /// until the upvar analysis, which happens late in HIR typeck. - pub tupled_upvars_ty: Ty, + pub tupled_upvars_ty: ty::Ty, } impl CoroutineArgs { @@ -621,7 +619,7 @@ impl CoroutineArgs { } // Returns the kind of the coroutine. See docs on the `kind_ty` field. - pub fn kind_ty(self) -> Ty { + pub fn kind_ty(self) -> ty::Ty { self.split().kind_ty } @@ -640,22 +638,22 @@ impl CoroutineArgs { /// Returns the tuple type representing the upvars for this coroutine. #[inline] - pub fn tupled_upvars_ty(self) -> Ty { + pub fn tupled_upvars_ty(self) -> ty::Ty { self.split().tupled_upvars_ty } /// Returns the type representing the resume type of the coroutine. - pub fn resume_ty(self) -> Ty { + pub fn resume_ty(self) -> ty::Ty { self.split().resume_ty } /// Returns the type representing the yield type of the coroutine. - pub fn yield_ty(self) -> Ty { + pub fn yield_ty(self) -> ty::Ty { self.split().yield_ty } /// Returns the type representing the return type of the coroutine. - pub fn return_ty(self) -> Ty { + pub fn return_ty(self) -> ty::Ty { self.split().return_ty }