From 918ede64740b3610dfd8b43ff0d995261a236ac5 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 26 Nov 2022 20:43:31 +0000 Subject: [PATCH 01/11] make Opaque have one field: OpaqueTy --- compiler/rustc_middle/src/ty/mod.rs | 2 +- compiler/rustc_middle/src/ty/sty.rs | 10 +++++++++ compiler/rustc_type_ir/src/lib.rs | 1 + compiler/rustc_type_ir/src/sty.rs | 32 ++++++++++++++--------------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index e480414a35896..efc45b5646e2a 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -97,7 +97,7 @@ pub use self::sty::{ BoundVariableKind, CanonicalPolyFnSig, ClosureSubsts, ClosureSubstsParts, ConstVid, EarlyBoundRegion, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FnSig, FreeRegion, GenSig, GeneratorSubsts, GeneratorSubstsParts, InlineConstSubsts, - InlineConstSubstsParts, ParamConst, ParamTy, PolyExistentialPredicate, + InlineConstSubstsParts, OpaqueTy, ParamConst, ParamTy, PolyExistentialPredicate, PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef, ProjectionTy, Region, RegionKind, RegionVid, TraitRef, TyKind, TypeAndMut, UpvarSubsts, VarianceDiagInfo, diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 9b9c26d6a8b1b..4c75614a5bc6a 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1199,6 +1199,16 @@ impl<'tcx> ProjectionTy<'tcx> { } } +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] +#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] +pub struct OpaqueTy<'tcx> { + /// The parameters of the opaque. + pub substs: SubstsRef<'tcx>, + + /// The `DefId` of the `impl Trait`. + pub def_id: DefId, +} + #[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable, Lift)] pub struct GenSig<'tcx> { pub resume_ty: Ty<'tcx>, diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index e3f7a1bd033ce..983fc9d992ade 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -44,6 +44,7 @@ pub trait Interner { type ListTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type ProjectionTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type ParamTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; + type OpaqueTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type BoundTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type PlaceholderType: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type InferTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/sty.rs index 9aa2be124e294..5119733d84cd8 100644 --- a/compiler/rustc_type_ir/src/sty.rs +++ b/compiler/rustc_type_ir/src/sty.rs @@ -184,7 +184,7 @@ pub enum TyKind { /// while for TAIT it is used for the generic parameters of the alias. /// /// During codegen, `tcx.type_of(def_id)` can be used to get the underlying type. - Opaque(I::DefId, I::SubstsRef), + Opaque(I::OpaqueTy), /// A type parameter; for example, `T` in `fn f(x: T) {}`. Param(I::ParamTy), @@ -253,7 +253,7 @@ const fn tykind_discriminant(value: &TyKind) -> usize { Never => 18, Tuple(_) => 19, Projection(_) => 20, - Opaque(_, _) => 21, + Opaque(_) => 21, Param(_) => 22, Bound(_, _) => 23, Placeholder(_) => 24, @@ -287,7 +287,7 @@ impl Clone for TyKind { Never => Never, Tuple(t) => Tuple(t.clone()), Projection(p) => Projection(p.clone()), - Opaque(d, s) => Opaque(d.clone(), s.clone()), + Opaque(o) => Opaque(o.clone()), Param(p) => Param(p.clone()), Bound(d, b) => Bound(d.clone(), b.clone()), Placeholder(p) => Placeholder(p.clone()), @@ -324,7 +324,7 @@ impl PartialEq for TyKind { (GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g == b_g, (Tuple(a_t), Tuple(b_t)) => a_t == b_t, (Projection(a_p), Projection(b_p)) => a_p == b_p, - (Opaque(a_d, a_s), Opaque(b_d, b_s)) => a_d == b_d && a_s == b_s, + (Opaque(a_o), Opaque(b_o)) => a_o == b_o, (Param(a_p), Param(b_p)) => a_p == b_p, (Bound(a_d, a_b), Bound(b_d, b_b)) => a_d == b_d && a_b == b_b, (Placeholder(a_p), Placeholder(b_p)) => a_p == b_p, @@ -382,7 +382,7 @@ impl Ord for TyKind { (GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g.cmp(b_g), (Tuple(a_t), Tuple(b_t)) => a_t.cmp(b_t), (Projection(a_p), Projection(b_p)) => a_p.cmp(b_p), - (Opaque(a_d, a_s), Opaque(b_d, b_s)) => a_d.cmp(b_d).then_with(|| a_s.cmp(b_s)), + (Opaque(a_o), Opaque(b_o)) => a_o.cmp(b_o), (Param(a_p), Param(b_p)) => a_p.cmp(b_p), (Bound(a_d, a_b), Bound(b_d, b_b)) => a_d.cmp(b_d).then_with(|| a_b.cmp(b_b)), (Placeholder(a_p), Placeholder(b_p)) => a_p.cmp(b_p), @@ -444,9 +444,8 @@ impl hash::Hash for TyKind { GeneratorWitness(g) => g.hash(state), Tuple(t) => t.hash(state), Projection(p) => p.hash(state), - Opaque(d, s) => { - d.hash(state); - s.hash(state) + Opaque(o) => { + o.hash(state); } Param(p) => p.hash(state), Bound(d, b) => { @@ -486,7 +485,7 @@ impl fmt::Debug for TyKind { Never => f.write_str("Never"), Tuple(t) => f.debug_tuple_field1_finish("Tuple", t), Projection(p) => f.debug_tuple_field1_finish("Projection", p), - Opaque(d, s) => f.debug_tuple_field2_finish("Opaque", d, s), + Opaque(o) => f.debug_tuple_field1_finish("Opaque", o), Param(p) => f.debug_tuple_field1_finish("Param", p), Bound(d, b) => f.debug_tuple_field2_finish("Bound", d, b), Placeholder(p) => f.debug_tuple_field1_finish("Placeholder", p), @@ -515,6 +514,7 @@ where I::ListTy: Encodable, I::ProjectionTy: Encodable, I::ParamTy: Encodable, + I::OpaqueTy: Encodable, I::BoundTy: Encodable, I::PlaceholderType: Encodable, I::InferTy: Encodable, @@ -589,9 +589,8 @@ where Projection(p) => e.emit_enum_variant(disc, |e| { p.encode(e); }), - Opaque(def_id, substs) => e.emit_enum_variant(disc, |e| { - def_id.encode(e); - substs.encode(e); + Opaque(o) => e.emit_enum_variant(disc, |e| { + o.encode(e); }), Param(p) => e.emit_enum_variant(disc, |e| { p.encode(e); @@ -632,6 +631,7 @@ where I::ListTy: Decodable, I::ProjectionTy: Decodable, I::ParamTy: Decodable, + I::OpaqueTy: Decodable, I::BoundTy: Decodable, I::PlaceholderType: Decodable, I::InferTy: Decodable, @@ -661,7 +661,7 @@ where 18 => Never, 19 => Tuple(Decodable::decode(d)), 20 => Projection(Decodable::decode(d)), - 21 => Opaque(Decodable::decode(d), Decodable::decode(d)), + 21 => Opaque(Decodable::decode(d)), 22 => Param(Decodable::decode(d)), 23 => Bound(Decodable::decode(d), Decodable::decode(d)), 24 => Placeholder(Decodable::decode(d)), @@ -698,6 +698,7 @@ where I::ProjectionTy: HashStable, I::BoundTy: HashStable, I::ParamTy: HashStable, + I::OpaqueTy: HashStable, I::PlaceholderType: HashStable, I::InferTy: HashStable, I::ErrorGuaranteed: HashStable, @@ -775,9 +776,8 @@ where Projection(p) => { p.hash_stable(__hcx, __hasher); } - Opaque(def_id, substs) => { - def_id.hash_stable(__hcx, __hasher); - substs.hash_stable(__hcx, __hasher); + Opaque(o) => { + o.hash_stable(__hcx, __hasher); } Param(p) => { p.hash_stable(__hcx, __hasher); From 7f3af726065d9eaabf93d87f22d97f60cca7a5f1 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 26 Nov 2022 21:09:39 +0000 Subject: [PATCH 02/11] Use ty::OpaqueTy everywhere --- .../src/diagnostics/conflict_errors.rs | 4 ++-- .../src/diagnostics/region_errors.rs | 2 +- .../src/interpret/intrinsics.rs | 2 +- .../src/transform/validate.rs | 2 +- .../rustc_const_eval/src/util/type_name.rs | 2 +- .../rustc_hir_analysis/src/check/check.rs | 2 +- .../rustc_hir_analysis/src/collect/type_of.rs | 4 ++-- .../src/variance/constraints.rs | 2 +- compiler/rustc_hir_typeck/src/_match.rs | 2 +- compiler/rustc_hir_typeck/src/cast.rs | 4 +++- compiler/rustc_hir_typeck/src/closure.rs | 4 ++-- compiler/rustc_hir_typeck/src/coercion.rs | 2 +- compiler/rustc_hir_typeck/src/expr.rs | 2 +- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 2 +- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 2 +- .../src/fn_ctxt/suggestions.rs | 2 +- .../src/generator_interior/mod.rs | 2 +- compiler/rustc_hir_typeck/src/writeback.rs | 2 +- compiler/rustc_infer/src/infer/combine.rs | 2 +- compiler/rustc_infer/src/infer/equate.rs | 10 +++++--- .../src/infer/error_reporting/mod.rs | 13 ++++++---- .../src/infer/error_reporting/suggest.rs | 16 +++++++------ compiler/rustc_infer/src/infer/lattice.rs | 12 ++++++---- .../rustc_infer/src/infer/nll_relate/mod.rs | 24 +++++++++++-------- .../rustc_infer/src/infer/opaque_types.rs | 19 ++++++++------- .../src/infer/outlives/components.rs | 2 +- .../src/infer/outlives/obligations.rs | 2 +- compiler/rustc_infer/src/infer/sub.rs | 10 +++++--- .../src/opaque_hidden_inferred_bound.rs | 2 +- compiler/rustc_lint/src/unused.rs | 4 ++-- compiler/rustc_middle/src/ty/context.rs | 5 ++-- compiler/rustc_middle/src/ty/diagnostics.rs | 10 ++++---- compiler/rustc_middle/src/ty/error.rs | 2 +- compiler/rustc_middle/src/ty/flags.rs | 2 +- compiler/rustc_middle/src/ty/print/pretty.rs | 6 +++-- compiler/rustc_middle/src/ty/relate.rs | 7 +++--- .../rustc_middle/src/ty/structural_impls.rs | 6 +++-- compiler/rustc_middle/src/ty/util.rs | 2 +- compiler/rustc_middle/src/ty/walk.rs | 2 +- compiler/rustc_mir_transform/src/inline.rs | 2 +- compiler/rustc_privacy/src/lib.rs | 2 +- compiler/rustc_symbol_mangling/src/legacy.rs | 2 +- compiler/rustc_symbol_mangling/src/v0.rs | 2 +- .../src/traits/error_reporting/suggestions.rs | 4 ++-- .../src/traits/project.rs | 6 +++-- .../src/traits/query/normalize.rs | 2 +- .../src/traits/select/candidate_assembly.rs | 2 +- .../src/traits/select/confirmation.rs | 2 +- .../src/traits/select/mod.rs | 4 ++-- .../rustc_trait_selection/src/traits/wf.rs | 6 ++--- compiler/rustc_traits/src/chalk/db.rs | 6 +++-- compiler/rustc_traits/src/chalk/lowering.rs | 16 +++++++------ src/librustdoc/clean/mod.rs | 2 +- .../clippy_lints/src/future_not_send.rs | 8 +++---- src/tools/clippy/clippy_utils/src/ty.rs | 6 ++--- 55 files changed, 156 insertions(+), 118 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 5fb4dcf09f5df..c777f9a7401af 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -697,8 +697,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { .map_bound(|p| p.predicates), None, ), - ty::Opaque(did, substs) => { - find_fn_kind_from_did(tcx.bound_explicit_item_bounds(*did), Some(*substs)) + ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + find_fn_kind_from_did(tcx.bound_explicit_item_bounds(*def_id), Some(*substs)) } ty::Closure(_, substs) => match substs.as_closure().kind() { ty::ClosureKind::Fn => Some(hir::Mutability::Not), diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 9bc2e79e29bc1..b885590f7396f 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -504,7 +504,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let ErrorConstraintInfo { outlived_fr, span, .. } = errci; let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty; - if let ty::Opaque(def_id, _) = *output_ty.kind() { + if let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = *output_ty.kind() { output_ty = self.infcx.tcx.type_of(def_id) }; diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index b9be7fa48000b..87dd0a665d340 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -83,7 +83,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>( ConstValue::from_machine_usize(adt.variants().len() as u64, &tcx) } ty::Projection(_) - | ty::Opaque(_, _) + | ty::Opaque(ty::OpaqueTy { def_id: _, substs: _ }) | ty::Param(_) | ty::Placeholder(_) | ty::Infer(_) => throw_inval!(TooGeneric), diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 64318f5f54d5d..62ed8f0c0f7bb 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -241,7 +241,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { }; let kind = match parent_ty.ty.kind() { - &ty::Opaque(def_id, substs) => { + &ty::Opaque(ty::OpaqueTy { def_id, substs }) => { self.tcx.bound_type_of(def_id).subst(self.tcx, substs).kind() } kind => kind, diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index 14c8c88028bda..ecb46d12a0141 100644 --- a/compiler/rustc_const_eval/src/util/type_name.rs +++ b/compiler/rustc_const_eval/src/util/type_name.rs @@ -58,7 +58,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { // Types with identity (print the module path). ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs) | ty::FnDef(def_id, substs) - | ty::Opaque(def_id, substs) + | ty::Opaque(ty::OpaqueTy { def_id, substs }) | ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) | ty::Closure(def_id, substs) | ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs), diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index fc0ca62090d19..c696f93897c13 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -1440,7 +1440,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) -> E impl<'tcx> ty::visit::TypeVisitor<'tcx> for OpaqueTypeCollector { fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { match *t.kind() { - ty::Opaque(def, _) => { + ty::Opaque(ty::OpaqueTy { def_id: def, substs: _ }) => { self.0.push(def); ControlFlow::CONTINUE } diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 9bd1715ce39ff..f838ec7025fd8 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -666,7 +666,7 @@ fn find_opaque_ty_constraints_for_tait(tcx: TyCtxt<'_>, def_id: LocalDefId) -> T let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); let scope = tcx.hir().get_defining_scope(hir_id); - let mut locator = ConstraintLocator { def_id: def_id, tcx, found: None, typeck_types: vec![] }; + let mut locator = ConstraintLocator { def_id, tcx, found: None, typeck_types: vec![] }; debug!(?scope); @@ -803,7 +803,7 @@ fn find_opaque_ty_constraints_for_rpit( if let Some(concrete) = concrete { let scope = tcx.hir().local_def_id_to_hir_id(owner_def_id); debug!(?scope); - let mut locator = ConstraintChecker { def_id: def_id, tcx, found: concrete }; + let mut locator = ConstraintChecker { def_id, tcx, found: concrete }; match tcx.hir().get(scope) { Node::Item(it) => intravisit::walk_item(&mut locator, it), diff --git a/compiler/rustc_hir_analysis/src/variance/constraints.rs b/compiler/rustc_hir_analysis/src/variance/constraints.rs index 6ce0c18bf45f1..31806ff6766ea 100644 --- a/compiler/rustc_hir_analysis/src/variance/constraints.rs +++ b/compiler/rustc_hir_analysis/src/variance/constraints.rs @@ -253,7 +253,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { self.add_constraints_from_invariant_substs(current, data.substs, variance); } - ty::Opaque(_, substs) => { + ty::Opaque(ty::OpaqueTy { def_id: _, substs }) => { self.add_constraints_from_invariant_substs(current, substs, variance); } diff --git a/compiler/rustc_hir_typeck/src/_match.rs b/compiler/rustc_hir_typeck/src/_match.rs index e25a9e9036a15..e3afc117bb2ad 100644 --- a/compiler/rustc_hir_typeck/src/_match.rs +++ b/compiler/rustc_hir_typeck/src/_match.rs @@ -518,7 +518,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let substs = sig.output().walk().find_map(|arg| { if let ty::GenericArgKind::Type(ty) = arg.unpack() - && let ty::Opaque(def_id, substs) = *ty.kind() + && let ty::Opaque(ty::OpaqueTy { def_id, substs }) = *ty.kind() && def_id == rpit_def_id { Some(substs) diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 890a068a7befc..6035e6e4db41e 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -119,7 +119,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Foreign(..) => Some(PointerKind::Thin), // We should really try to normalize here. ty::Projection(pi) => Some(PointerKind::OfProjection(pi)), - ty::Opaque(def_id, substs) => Some(PointerKind::OfOpaque(def_id, substs)), + ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + Some(PointerKind::OfOpaque(def_id, substs)) + } ty::Param(p) => Some(PointerKind::OfParam(p)), // Insufficient type information. ty::Placeholder(..) | ty::Bound(..) | ty::Infer(_) => None, diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 429cb60ba2b61..3e3126cd446f9 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -167,7 +167,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected_ty: Ty<'tcx>, ) -> (Option>, Option) { match *expected_ty.kind() { - ty::Opaque(def_id, substs) => self.deduce_signature_from_predicates( + ty::Opaque(ty::OpaqueTy { def_id, substs }) => self.deduce_signature_from_predicates( self.tcx.bound_explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs), ), ty::Dynamic(ref object_type, ..) => { @@ -677,7 +677,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { get_future_output(obligation.predicate, obligation.cause.span) })? } - ty::Opaque(def_id, substs) => self + ty::Opaque(ty::OpaqueTy { def_id, substs }) => self .tcx .bound_explicit_item_bounds(def_id) .subst_iter_copied(self.tcx, substs) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index f0b349f0c98dd..9dd3b3741f9df 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1805,7 +1805,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { { let ty = >::ast_ty_to_ty(fcx, ty); // Get the `impl Trait`'s `DefId`. - if let ty::Opaque(def_id, _) = ty.kind() + if let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = ty.kind() // Get the `impl Trait`'s `Item` so that we can get its trait bounds and // get the `Trait`'s `DefId`. && let hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, .. }) = diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index ed87b94a040d0..bd226e1f8b18e 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -2391,7 +2391,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Param(param_ty) => { self.point_at_param_definition(&mut err, param_ty); } - ty::Opaque(_, _) => { + ty::Opaque(ty::OpaqueTy { def_id: _, substs: _ }) => { self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs()); } _ => {} diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 952d272625918..a556af81b4f09 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -716,7 +716,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if formal_ret.has_infer_types() { for ty in ret_ty.walk() { if let ty::subst::GenericArgKind::Type(ty) = ty.unpack() - && let ty::Opaque(def_id, _) = *ty.kind() + && let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = *ty.kind() && let Some(def_id) = def_id.as_local() && self.opaque_type_origin(def_id, DUMMY_SP).is_some() { return None; diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 93618c6141730..77821556eaf09 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -2124,7 +2124,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } } - ty::Opaque(new_def_id, _) + ty::Opaque(ty::OpaqueTy { def_id: new_def_id, substs: _ }) | ty::Closure(new_def_id, _) | ty::FnDef(new_def_id, _) => { def_id = new_def_id; diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 4f92477b5d87e..c0534ea89d8a0 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -174,7 +174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let fn_sig = substs.as_closure().sig(); Some((DefIdOrName::DefId(def_id), fn_sig.output(), fn_sig.inputs().map_bound(|inputs| &inputs[1..]))) } - ty::Opaque(def_id, substs) => { + ty::Opaque(ty::OpaqueTy { def_id, substs }) => { self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| { if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder() && Some(proj.projection_ty.item_def_id) == self.tcx.lang_items().fn_once_output() diff --git a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs index 3b1518ff79b4e..58d1d39d215a5 100644 --- a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs +++ b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs @@ -563,7 +563,7 @@ fn check_must_not_suspend_ty<'tcx>( } ty::Adt(def, _) => check_must_not_suspend_def(fcx.tcx, def.did(), hir_id, data), // FIXME: support adding the attribute to TAITs - ty::Opaque(def, _) => { + ty::Opaque(ty::OpaqueTy { def_id: def, substs: _ }) => { let mut has_emitted = false; for &(predicate, _) in fcx.tcx.explicit_item_bounds(def) { // We only look at the `DefId`, so it is safe to skip the binder here. diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index 58ced6a1d3b4f..f14cac868ea4b 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -546,7 +546,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { impl<'tcx> ty::TypeVisitor<'tcx> for RecursionChecker { type BreakTy = (); fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { - if let ty::Opaque(def_id, _) = *t.kind() { + if let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = *t.kind() { if def_id == self.def_id.to_def_id() { return ControlFlow::Break(()); } diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index cf895ed0d3e59..4f6a0630d3d1f 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -675,7 +675,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> { // relatable. Ok(t) } - ty::Opaque(def_id, substs) => { + ty::Opaque(ty::OpaqueTy { def_id, substs }) => { let s = self.relate(substs, substs)?; Ok(if s == substs { t } else { self.infcx.tcx.mk_opaque(def_id, s) }) } diff --git a/compiler/rustc_infer/src/infer/equate.rs b/compiler/rustc_infer/src/infer/equate.rs index 17f932e78a105..c0056c27a582d 100644 --- a/compiler/rustc_infer/src/infer/equate.rs +++ b/compiler/rustc_infer/src/infer/equate.rs @@ -100,11 +100,15 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> { self.fields.instantiate(a, RelationDir::EqTo, b_id, self.a_is_expected)?; } - (&ty::Opaque(a_def_id, _), &ty::Opaque(b_def_id, _)) if a_def_id == b_def_id => { + ( + &ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }), + &ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }), + ) if a_def_id == b_def_id => { self.fields.infcx.super_combine_tys(self, a, b)?; } - (&ty::Opaque(did, ..), _) | (_, &ty::Opaque(did, ..)) - if self.fields.define_opaque_types && did.is_local() => + (&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), _) + | (_, &ty::Opaque(ty::OpaqueTy { def_id, substs: _ })) + if self.fields.define_opaque_types && def_id.is_local() => { self.fields.obligations.extend( infcx diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 987559d7e4724..fea6213375953 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -338,8 +338,9 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>( impl<'tcx> InferCtxt<'tcx> { pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option> { + // FIXME(alias): Merge these let (def_id, substs) = match *ty.kind() { - ty::Opaque(def_id, substs) => (def_id, substs), + ty::Opaque(ty::OpaqueTy { def_id, substs }) => (def_id, substs), ty::Projection(data) if self.tcx.def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder => { @@ -1729,8 +1730,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { TypeError::Sorts(values) => { let extra = expected == found; let sort_string = |ty: Ty<'tcx>, path: Option| { + // FIXME(alias): Merge these let mut s = match (extra, ty.kind()) { - (true, ty::Opaque(def_id, _)) => { + (true, ty::Opaque(ty::OpaqueTy { def_id, .. })) => { let sm = self.tcx.sess.source_map(); let pos = sm.lookup_char_pos(self.tcx.def_span(*def_id).lo()); format!( @@ -2383,7 +2385,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { // fn get_later(g: G, dest: &mut T) -> impl FnOnce() + '_ // suggest: // fn get_later<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a - ty::Closure(_, _substs) | ty::Opaque(_, _substs) if return_impl_trait => { + ty::Closure(_, _substs) + | ty::Opaque(ty::OpaqueTy { def_id: _, substs: _substs }) + if return_impl_trait => + { new_binding_suggestion(&mut err, type_param_span); } _ => { @@ -2765,7 +2770,7 @@ impl TyCategory { pub fn from_ty(tcx: TyCtxt<'_>, ty: Ty<'_>) -> Option<(Self, DefId)> { match *ty.kind() { ty::Closure(def_id, _) => Some((Self::Closure, def_id)), - ty::Opaque(def_id, _) => Some((Self::Opaque, def_id)), + ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) => Some((Self::Opaque, def_id)), ty::Generator(def_id, ..) => { Some((Self::Generator(tcx.generator_kind(def_id).unwrap()), def_id)) } diff --git a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs index 73b5a2cc4ad23..fe134830d6858 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs @@ -486,12 +486,14 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { _ if self.same_type_modulo_infer(last_expr_ty, expected_ty) => { StatementAsExpression::CorrectType } - (ty::Opaque(last_def_id, _), ty::Opaque(exp_def_id, _)) - if last_def_id == exp_def_id => - { - StatementAsExpression::CorrectType - } - (ty::Opaque(last_def_id, last_bounds), ty::Opaque(exp_def_id, exp_bounds)) => { + ( + ty::Opaque(ty::OpaqueTy { def_id: last_def_id, substs: _ }), + ty::Opaque(ty::OpaqueTy { def_id: exp_def_id, substs: _ }), + ) if last_def_id == exp_def_id => StatementAsExpression::CorrectType, + ( + ty::Opaque(ty::OpaqueTy { def_id: last_def_id, substs: last_bounds }), + ty::Opaque(ty::OpaqueTy { def_id: exp_def_id, substs: exp_bounds }), + ) => { debug!( "both opaque, likely future {:?} {:?} {:?} {:?}", last_def_id, last_bounds, exp_def_id, exp_bounds @@ -507,7 +509,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { ( hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds: last_bounds, .. }), hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds: exp_bounds, .. }), - ) if std::iter::zip(*last_bounds, *exp_bounds).all(|(left, right)| { + ) if iter::zip(*last_bounds, *exp_bounds).all(|(left, right)| { match (left, right) { ( hir::GenericBound::Trait(tl, ml), diff --git a/compiler/rustc_infer/src/infer/lattice.rs b/compiler/rustc_infer/src/infer/lattice.rs index eba65361ae6b2..6513abd38795d 100644 --- a/compiler/rustc_infer/src/infer/lattice.rs +++ b/compiler/rustc_infer/src/infer/lattice.rs @@ -105,11 +105,13 @@ where Ok(v) } - (&ty::Opaque(a_def_id, _), &ty::Opaque(b_def_id, _)) if a_def_id == b_def_id => { - infcx.super_combine_tys(this, a, b) - } - (&ty::Opaque(did, ..), _) | (_, &ty::Opaque(did, ..)) - if this.define_opaque_types() && did.is_local() => + ( + &ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }), + &ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }), + ) if a_def_id == b_def_id => infcx.super_combine_tys(this, a, b), + (&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), _) + | (_, &ty::Opaque(ty::OpaqueTy { def_id, substs: _ })) + if this.define_opaque_types() && def_id.is_local() => { this.add_obligations( infcx diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index f6bc4db0d59df..e0f9220ca5f08 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -608,16 +608,20 @@ where (&ty::Infer(ty::TyVar(vid)), _) => self.relate_ty_var((vid, b)), - (&ty::Opaque(a_def_id, _), &ty::Opaque(b_def_id, _)) if a_def_id == b_def_id => { - infcx.super_combine_tys(self, a, b).or_else(|err| { - self.tcx().sess.delay_span_bug( - self.delegate.span(), - "failure to relate an opaque to itself should result in an error later on", - ); - if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) } - }) - } - (&ty::Opaque(did, ..), _) | (_, &ty::Opaque(did, ..)) if did.is_local() => { + ( + &ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }), + &ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }), + ) if a_def_id == b_def_id => infcx.super_combine_tys(self, a, b).or_else(|err| { + self.tcx().sess.delay_span_bug( + self.delegate.span(), + "failure to relate an opaque to itself should result in an error later on", + ); + if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) } + }), + (&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), _) + | (_, &ty::Opaque(ty::OpaqueTy { def_id, substs: _ })) + if def_id.is_local() => + { self.relate_opaques(a, b) } diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index 524f7a39ebbfb..495369031d1d5 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -66,7 +66,9 @@ impl<'tcx> InferCtxt<'tcx> { lt_op: |lt| lt, ct_op: |ct| ct, ty_op: |ty| match *ty.kind() { - ty::Opaque(def_id, _substs) if replace_opaque_type(def_id) => { + ty::Opaque(ty::OpaqueTy { def_id, substs: _substs }) + if replace_opaque_type(def_id) => + { let def_span = self.tcx.def_span(def_id); let span = if span.contains(def_span) { def_span } else { span }; let code = traits::ObligationCauseCode::OpaqueReturnType(None); @@ -104,7 +106,7 @@ impl<'tcx> InferCtxt<'tcx> { } let (a, b) = if a_is_expected { (a, b) } else { (b, a) }; let process = |a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected| match *a.kind() { - ty::Opaque(def_id, substs) if def_id.is_local() => { + ty::Opaque(ty::OpaqueTy { def_id, substs }) if def_id.is_local() => { let def_id = def_id.expect_local(); let origin = match self.defining_use_anchor { DefiningAnchor::Bind(_) => { @@ -147,18 +149,19 @@ impl<'tcx> InferCtxt<'tcx> { DefiningAnchor::Bubble => self.opaque_ty_origin_unchecked(def_id, cause.span), DefiningAnchor::Error => return None, }; - if let ty::Opaque(did2, _) = *b.kind() { + if let ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }) = *b.kind() { // We could accept this, but there are various ways to handle this situation, and we don't // want to make a decision on it right now. Likely this case is so super rare anyway, that // no one encounters it in practice. // It does occur however in `fn fut() -> impl Future { async { 42 } }`, // where it is of no concern, so we only check for TAITs. - if let Some(OpaqueTyOrigin::TyAlias) = - did2.as_local().and_then(|did2| self.opaque_type_origin(did2, cause.span)) + if let Some(OpaqueTyOrigin::TyAlias) = b_def_id + .as_local() + .and_then(|b_def_id| self.opaque_type_origin(b_def_id, cause.span)) { self.tcx.sess.emit_err(OpaqueHiddenTypeDiag { span: cause.span, - hidden_type: self.tcx.def_span(did2), + hidden_type: self.tcx.def_span(b_def_id), opaque_type: self.tcx.def_span(def_id), }); } @@ -475,7 +478,7 @@ where substs.as_generator().resume_ty().visit_with(self); } - ty::Opaque(def_id, ref substs) => { + ty::Opaque(ty::OpaqueTy { def_id, ref substs }) => { // Skip lifetime paramters that are not captures. let variances = self.tcx.variances_of(*def_id); @@ -578,7 +581,7 @@ impl<'tcx> InferCtxt<'tcx> { } // Replace all other mentions of the same opaque type with the hidden type, // as the bounds must hold on the hidden type after all. - ty::Opaque(def_id2, substs2) + ty::Opaque(ty::OpaqueTy { def_id: def_id2, substs: substs2 }) if def_id.to_def_id() == def_id2 && substs == substs2 => { hidden_ty diff --git a/compiler/rustc_infer/src/infer/outlives/components.rs b/compiler/rustc_infer/src/infer/outlives/components.rs index 14ee9f0519010..ea3b0efb85bb1 100644 --- a/compiler/rustc_infer/src/infer/outlives/components.rs +++ b/compiler/rustc_infer/src/infer/outlives/components.rs @@ -130,7 +130,7 @@ fn compute_components<'tcx>( // outlives any other lifetime, which is unsound. // See https://github.com/rust-lang/rust/issues/84305 for // more details. - ty::Opaque(def_id, substs) => { + ty::Opaque(ty::OpaqueTy { def_id, substs }) => { out.push(Component::Opaque(def_id, substs)); }, diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index 6ca884799aa6f..3fc3e6b09df09 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -338,7 +338,7 @@ where substs, true, |ty| match *ty.kind() { - ty::Opaque(def_id, substs) => (def_id, substs), + ty::Opaque(ty::OpaqueTy { def_id, substs }) => (def_id, substs), _ => bug!("expected only projection types from env, not {:?}", ty), }, ); diff --git a/compiler/rustc_infer/src/infer/sub.rs b/compiler/rustc_infer/src/infer/sub.rs index 79a1afa469e89..f05d661451571 100644 --- a/compiler/rustc_infer/src/infer/sub.rs +++ b/compiler/rustc_infer/src/infer/sub.rs @@ -130,12 +130,16 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> { Ok(self.tcx().ty_error_with_guaranteed(e)) } - (&ty::Opaque(a_def_id, _), &ty::Opaque(b_def_id, _)) if a_def_id == b_def_id => { + ( + &ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }), + &ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }), + ) if a_def_id == b_def_id => { self.fields.infcx.super_combine_tys(self, a, b)?; Ok(a) } - (&ty::Opaque(did, ..), _) | (_, &ty::Opaque(did, ..)) - if self.fields.define_opaque_types && did.is_local() => + (&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), _) + | (_, &ty::Opaque(ty::OpaqueTy { def_id, substs: _ })) + if self.fields.define_opaque_types && def_id.is_local() => { self.fields.obligations.extend( infcx diff --git a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs index 03d6f4fd92687..863c19bd3d60b 100644 --- a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs +++ b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs @@ -117,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { // then we can emit a suggestion to add the bound. let add_bound = match (proj_term.kind(), assoc_pred.kind().skip_binder()) { ( - ty::Opaque(def_id, _), + ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)), ) => Some(AddBound { suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(), diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index dc352778f1d1b..14882be3e012c 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { if let hir::ExprKind::Match(await_expr, _arms, hir::MatchSource::AwaitDesugar) = expr.kind && let ty = cx.typeck_results().expr_ty(&await_expr) - && let ty::Opaque(future_def_id, _) = ty.kind() + && let ty::Opaque(ty::OpaqueTy { def_id: future_def_id, substs: _ }) = ty.kind() && cx.tcx.ty_is_opaque_future(ty) // FIXME: This also includes non-async fns that return `impl Future`. && let async_fn_def_id = cx.tcx.parent(*future_def_id) @@ -251,7 +251,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { .map(|inner| MustUsePath::Boxed(Box::new(inner))) } ty::Adt(def, _) => is_def_must_use(cx, def.did(), span), - ty::Opaque(def, _) => { + ty::Opaque(ty::OpaqueTy { def_id: def, substs: _ }) => { elaborate_predicates_with_span( cx.tcx, cx.tcx.explicit_item_bounds(def).iter().cloned(), diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 7d4971d1e9e62..c56f6073b05f8 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -117,6 +117,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { type BinderListTy = Binder<'tcx, &'tcx List>>; type ListTy = &'tcx List>; type ProjectionTy = ty::ProjectionTy<'tcx>; + type OpaqueTy = ty::OpaqueTy<'tcx>; type ParamTy = ParamTy; type BoundTy = ty::BoundTy; type PlaceholderType = ty::PlaceholderType; @@ -2323,7 +2324,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Given a `ty`, return whether it's an `impl Future<...>`. pub fn ty_is_opaque_future(self, ty: Ty<'_>) -> bool { - let ty::Opaque(def_id, _) = ty.kind() else { return false }; + let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = ty.kind() else { return false }; let future_trait = self.require_lang_item(LangItem::Future, None); self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| { @@ -2668,7 +2669,7 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> { - self.mk_ty(Opaque(def_id, substs)) + self.mk_ty(Opaque(ty::OpaqueTy { def_id, substs })) } pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> { diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 511d51cd670fb..8657010eb1b92 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -4,7 +4,7 @@ use std::ops::ControlFlow; use crate::ty::{ visit::TypeVisitable, Const, ConstKind, DefIdTree, ExistentialPredicate, InferConst, InferTy, - PolyTraitPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor, + OpaqueTy, PolyTraitPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor, }; use rustc_data_structures::fx::FxHashMap; @@ -457,11 +457,11 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> { return ControlFlow::Break(()); } - Opaque(did, _) => { - let parent = self.tcx.parent(*did); + Opaque(OpaqueTy { def_id, substs: _ }) => { + let parent = self.tcx.parent(*def_id); if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent) - && let Opaque(parent_did, _) = self.tcx.type_of(parent).kind() - && parent_did == did + && let Opaque(OpaqueTy { def_id: parent_opaque_def_id, substs: _ }) = self.tcx.type_of(parent).kind() + && parent_opaque_def_id == def_id { // Okay } else { diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index f065c91a6b58b..f7689820d3bb6 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -779,7 +779,7 @@ fn foo(&self) -> Self::T { String::new() } ty: Ty<'tcx>, ) -> bool { let assoc = self.associated_item(proj_ty.item_def_id); - if let ty::Opaque(def_id, _) = *proj_ty.self_ty().kind() { + if let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = *proj_ty.self_ty().kind() { let opaque_local_def_id = def_id.as_local(); let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id { match &self.hir().expect_item(opaque_local_def_id).kind { diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index 046a2660a1f6d..cd93eb71f71f2 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -160,7 +160,7 @@ impl FlagComputation { self.add_projection_ty(data); } - &ty::Opaque(_, substs) => { + &ty::Opaque(ty::OpaqueTy { def_id: _, substs }) => { self.add_flags(TypeFlags::HAS_TY_OPAQUE); self.add_substs(substs); } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 6bf42f81f131e..42ebc96c022cd 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -728,7 +728,7 @@ pub trait PrettyPrinter<'tcx>: } } ty::Placeholder(placeholder) => p!(write("Placeholder({:?})", placeholder)), - ty::Opaque(def_id, substs) => { + ty::Opaque(ty::OpaqueTy { def_id, substs }) => { // FIXME(eddyb) print this with `print_def_path`. // We use verbose printing in 'NO_QUERIES' mode, to // avoid needing to call `predicates_of`. This should @@ -743,7 +743,9 @@ pub trait PrettyPrinter<'tcx>: let parent = self.tcx().parent(def_id); match self.tcx().def_kind(parent) { DefKind::TyAlias | DefKind::AssocTy => { - if let ty::Opaque(d, _) = *self.tcx().type_of(parent).kind() { + if let ty::Opaque(ty::OpaqueTy { def_id: d, substs: _ }) = + *self.tcx().type_of(parent).kind() + { if d == def_id { // If the type alias directly starts with the `impl` of the // opaque type we're printing, then skip the `::{opaque#1}`. diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 1873bf0711fc4..6d285f7f4924d 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -564,9 +564,10 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( Ok(tcx.mk_projection(projection_ty.item_def_id, projection_ty.substs)) } - (&ty::Opaque(a_def_id, a_substs), &ty::Opaque(b_def_id, b_substs)) - if a_def_id == b_def_id => - { + ( + &ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: a_substs }), + &ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: b_substs }), + ) if a_def_id == b_def_id => { if relation.intercrate() { // During coherence, opaque types should be treated as equal to each other, even if their generic params // differ, as they could resolve to the same hidden type, even for different generic params. diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 9f70b4f1ffd25..69627385235cc 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -652,7 +652,9 @@ impl<'tcx> TypeSuperFoldable<'tcx> for Ty<'tcx> { ty::GeneratorWitness(types) => ty::GeneratorWitness(types.try_fold_with(folder)?), ty::Closure(did, substs) => ty::Closure(did, substs.try_fold_with(folder)?), ty::Projection(data) => ty::Projection(data.try_fold_with(folder)?), - ty::Opaque(did, substs) => ty::Opaque(did, substs.try_fold_with(folder)?), + ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + ty::Opaque(ty::OpaqueTy { def_id, substs: substs.try_fold_with(folder)? }) + } ty::Bool | ty::Char @@ -698,7 +700,7 @@ impl<'tcx> TypeSuperVisitable<'tcx> for Ty<'tcx> { ty::GeneratorWitness(ref types) => types.visit_with(visitor), ty::Closure(_did, ref substs) => substs.visit_with(visitor), ty::Projection(ref data) => data.visit_with(visitor), - ty::Opaque(_, ref substs) => substs.visit_with(visitor), + ty::Opaque(ty::OpaqueTy { def_id: _, ref substs }) => substs.visit_with(visitor), ty::Bool | ty::Char diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 9ea8dc6e69fdd..c1ef703e62da4 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -826,7 +826,7 @@ impl<'tcx> TypeFolder<'tcx> for OpaqueTypeExpander<'tcx> { } fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Opaque(def_id, substs) = *t.kind() { + if let ty::Opaque(ty::OpaqueTy { def_id, substs }) = *t.kind() { self.expand_opaque_ty(def_id, substs).unwrap_or(t) } else if t.has_opaque_types() { t.super_fold_with(self) diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index 4fab5abe909d4..958549e11ca9a 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -188,7 +188,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) })); } ty::Adt(_, substs) - | ty::Opaque(_, substs) + | ty::Opaque(ty::OpaqueTy { def_id: _, substs }) | ty::Closure(_, substs) | ty::Generator(_, substs, _) | ty::FnDef(_, substs) => { diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 220cf7df9c6c7..ecf05cc32190e 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -849,7 +849,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> { }; let kind = match parent_ty.ty.kind() { - &ty::Opaque(def_id, substs) => { + &ty::Opaque(ty::OpaqueTy { def_id, substs }) => { self.tcx.bound_type_of(def_id).subst(self.tcx, substs).kind() } kind => kind, diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index a254c892478cf..6a4bbea79d13c 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -241,7 +241,7 @@ where self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref)?; } } - ty::Opaque(def_id, ..) => { + ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) => { // Skip repeated `Opaque`s to avoid infinite recursion. if self.visited_opaque_tys.insert(def_id) { // The intent is to treat `impl Trait1 + Trait2` identically to diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index c60a2f4671d6c..36c1463736eb6 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -216,7 +216,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> { match *ty.kind() { // Print all nominal types as paths (unlike `pretty_print_type`). ty::FnDef(def_id, substs) - | ty::Opaque(def_id, substs) + | ty::Opaque(ty::OpaqueTy { def_id, substs }) | ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) | ty::Closure(def_id, substs) | ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs), diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 2cca480f271c7..b3d19e329973d 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -439,7 +439,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { // Mangle all nominal types as paths. ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs) | ty::FnDef(def_id, substs) - | ty::Opaque(def_id, substs) + | ty::Opaque(ty::OpaqueTy { def_id, substs }) | ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) | ty::Closure(def_id, substs) | ty::Generator(def_id, substs, _) => { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 40c8102547112..7a391037f31b5 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -855,7 +855,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { fn_sig.inputs().map_bound(|inputs| &inputs[1..]), )) } - ty::Opaque(def_id, substs) => { + ty::Opaque(ty::OpaqueTy { def_id, substs }) => { self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| { if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder() && Some(proj.projection_ty.item_def_id) == self.tcx.lang_items().fn_once_output() @@ -2644,7 +2644,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { Some(ident) => err.span_note(ident.span, &msg), None => err.note(&msg), }, - ty::Opaque(def_id, _) => { + ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) => { // Avoid printing the future from `core::future::identity_future`, it's not helpful if tcx.parent(*def_id) == identity_future { break 'print; diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 5789754e4fcef..69f0e9865dcef 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -496,7 +496,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { // This is really important. While we *can* handle this, this has // severe performance implications for large opaque types with // late-bound regions. See `issue-88862` benchmark. - ty::Opaque(def_id, substs) if !substs.has_escaping_bound_vars() => { + ty::Opaque(ty::OpaqueTy { def_id, substs }) if !substs.has_escaping_bound_vars() => { // Only normalize `impl Trait` outside of type inference, usually in codegen. match self.param_env.reveal() { Reveal::UserFacing => ty.super_fold_with(self), @@ -1378,7 +1378,9 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>( // If so, extract what we know from the trait and try to come up with a good answer. let bounds = match *obligation.predicate.self_ty().kind() { ty::Projection(ref data) => tcx.bound_item_bounds(data.item_def_id).subst(tcx, data.substs), - ty::Opaque(def_id, substs) => tcx.bound_item_bounds(def_id).subst(tcx, substs), + ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + tcx.bound_item_bounds(def_id).subst(tcx, substs) + } ty::Infer(ty::TyVar(_)) => { // If the self-type is an inference variable, then it MAY wind up // being a projected type, so induce an ambiguity. diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 7ad532d8a3464..41a162a9f6738 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -205,7 +205,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { // This is really important. While we *can* handle this, this has // severe performance implications for large opaque types with // late-bound regions. See `issue-88862` benchmark. - ty::Opaque(def_id, substs) if !substs.has_escaping_bound_vars() => { + ty::Opaque(ty::OpaqueTy { def_id, substs }) if !substs.has_escaping_bound_vars() => { // Only normalize `impl Trait` outside of type inference, usually in codegen. match self.param_env.reveal() { Reveal::UserFacing => ty.try_super_fold_with(self), diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index e4b70f0d2ffa7..4cd2d445bd0be 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -830,7 +830,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::GeneratorWitness(_) | ty::Never | ty::Projection(_) - | ty::Opaque(_, _) + | ty::Opaque(ty::OpaqueTy { def_id: _, substs: _ }) | ty::Param(_) | ty::Bound(_, _) | ty::Error(_) diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index fda415155c469..cd3025024fe36 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -156,7 +156,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate); let (def_id, substs) = match *placeholder_self_ty.kind() { ty::Projection(proj) => (proj.item_def_id, proj.substs), - ty::Opaque(def_id, substs) => (def_id, substs), + ty::Opaque(ty::OpaqueTy { def_id, substs }) => (def_id, substs), _ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty), }; diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 035deb6163981..054bbf8fb0ef3 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1596,7 +1596,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let tcx = self.infcx.tcx; let (def_id, substs) = match *placeholder_trait_predicate.trait_ref.self_ty().kind() { ty::Projection(ref data) => (data.item_def_id, data.substs), - ty::Opaque(def_id, substs) => (def_id, substs), + ty::Opaque(ty::OpaqueTy { def_id, substs }) => (def_id, substs), _ => { span_bug!( obligation.cause.span, @@ -2260,7 +2260,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { t.rebind(def.all_fields().map(|f| f.ty(self.tcx(), substs)).collect()) } - ty::Opaque(def_id, substs) => { + ty::Opaque(ty::OpaqueTy { def_id, substs }) => { // We can resolve the `impl Trait` to its concrete type, // which enforces a DAG between the functions requiring // the auto trait bounds in question. diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index e47ba64245f50..ab678e4d98f81 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -648,12 +648,12 @@ impl<'tcx> WfPredicates<'tcx> { // types appearing in the fn signature } - ty::Opaque(did, substs) => { + ty::Opaque(ty::OpaqueTy { def_id, substs }) => { // All of the requirements on type parameters // have already been checked for `impl Trait` in // return position. We do need to check type-alias-impl-trait though. - if ty::is_impl_trait_defn(self.tcx, did).is_none() { - let obligations = self.nominal_obligations(did, substs); + if ty::is_impl_trait_defn(self.tcx, def_id).is_none() { + let obligations = self.nominal_obligations(def_id, substs); self.out.extend(obligations); } } diff --git a/compiler/rustc_traits/src/chalk/db.rs b/compiler/rustc_traits/src/chalk/db.rs index 344c8b93c1704..6c841b94fc04b 100644 --- a/compiler/rustc_traits/src/chalk/db.rs +++ b/compiler/rustc_traits/src/chalk/db.rs @@ -432,7 +432,9 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t (ast::Mutability::Not, chalk_ir::Mutability::Not) => true, } } - (&ty::Opaque(def_id, ..), OpaqueType(opaque_ty_id, ..)) => def_id == opaque_ty_id.0, + (&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), OpaqueType(opaque_ty_id, ..)) => { + def_id == opaque_ty_id.0 + } (&ty::FnDef(def_id, ..), FnDef(fn_def_id, ..)) => def_id == fn_def_id.0, (&ty::Str, Str) => true, (&ty::Never, Never) => true, @@ -786,7 +788,7 @@ impl<'tcx> ty::TypeFolder<'tcx> for ReplaceOpaqueTyFolder<'tcx> { } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Opaque(def_id, substs) = *ty.kind() { + if let ty::Opaque(ty::OpaqueTy { def_id, substs }) = *ty.kind() { if def_id == self.opaque_ty_id.0 && substs == self.identity_substs { return self.tcx.mk_ty(ty::Bound( self.binder_index, diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index c4ab86e9e9bab..8a2de801a19c8 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -354,7 +354,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty>> for Ty<'tcx> { chalk_ir::TyKind::Tuple(types.len(), types.as_substs().lower_into(interner)) } ty::Projection(proj) => chalk_ir::TyKind::Alias(proj.lower_into(interner)), - ty::Opaque(def_id, substs) => { + ty::Opaque(ty::OpaqueTy { def_id, substs }) => { chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { opaque_ty_id: chalk_ir::OpaqueTyId(def_id), substitution: substs.lower_into(interner), @@ -442,9 +442,10 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty> { mutbl.lower_into(interner), ), TyKind::Str => ty::Str, - TyKind::OpaqueType(opaque_ty, substitution) => { - ty::Opaque(opaque_ty.0, substitution.lower_into(interner)) - } + TyKind::OpaqueType(opaque_ty, substitution) => ty::Opaque(ty::OpaqueTy { + def_id: opaque_ty.0, + substs: substitution.lower_into(interner), + }), TyKind::AssociatedType(assoc_ty, substitution) => ty::Projection(ty::ProjectionTy { substs: substitution.lower_into(interner), item_def_id: assoc_ty.0, @@ -460,9 +461,10 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty> { item_def_id: projection.associated_ty_id.0, substs: projection.substitution.lower_into(interner), }), - chalk_ir::AliasTy::Opaque(opaque) => { - ty::Opaque(opaque.opaque_ty_id.0, opaque.substitution.lower_into(interner)) - } + chalk_ir::AliasTy::Opaque(opaque) => ty::Opaque(ty::OpaqueTy { + def_id: opaque.opaque_ty_id.0, + substs: opaque.substitution.lower_into(interner), + }), }, TyKind::Function(_quantified_ty) => unimplemented!(), TyKind::BoundVar(_bound) => ty::Bound( diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c6ab8e1a83bef..8ebdea883903c 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1833,7 +1833,7 @@ pub(crate) fn clean_middle_ty<'tcx>( } } - ty::Opaque(def_id, substs) => { + ty::Opaque(ty::OpaqueTy { def_id, substs }) => { // Grab the "TraitA + TraitB" from `impl TraitA + TraitB`, // by looking up the bounds associated with the def_id. let bounds = cx diff --git a/src/tools/clippy/clippy_lints/src/future_not_send.rs b/src/tools/clippy/clippy_lints/src/future_not_send.rs index 61934a9142633..8a7a65c860016 100644 --- a/src/tools/clippy/clippy_lints/src/future_not_send.rs +++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs @@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{Clause, EarlyBinder, Opaque, PredicateKind}; +use rustc_middle::ty::{Clause, EarlyBinder, Opaque, OpaqueTy, PredicateKind}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt; @@ -62,11 +62,11 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { return; } let ret_ty = return_ty(cx, hir_id); - if let Opaque(id, subst) = *ret_ty.kind() { - let preds = cx.tcx.explicit_item_bounds(id); + if let Opaque(OpaqueTy { def_id, substs }) = *ret_ty.kind() { + let preds = cx.tcx.explicit_item_bounds(def_id); let mut is_future = false; for &(p, _span) in preds { - let p = EarlyBinder(p).subst(cx.tcx, subst); + let p = EarlyBinder(p).subst(cx.tcx, substs); if let Some(trait_pred) = p.to_opt_poly_trait_pred() { if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() { is_future = true; diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index bfb2d472a393c..f5f70b195c981 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -79,7 +79,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' return true; } - if let ty::Opaque(def_id, _) = *inner_ty.kind() { + if let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = *inner_ty.kind() { for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) { match predicate.kind().skip_binder() { // For `impl Trait`, it will register a predicate of `T: Trait`, so we go through @@ -250,7 +250,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { is_must_use_ty(cx, *ty) }, ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), - ty::Opaque(def_id, _) => { + ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() { if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) { @@ -631,7 +631,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))), - ty::Opaque(id, _) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(id), cx.tcx.opt_parent(id)), + ty::Opaque(ty::OpaqueTy{ def_id, substs: _ }) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id)), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), ty::Dynamic(bounds, _, _) => { let lang_items = cx.tcx.lang_items(); From 5c6afb850c29f5604f685bf4d4fea85a2deb7197 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 26 Nov 2022 21:21:20 +0000 Subject: [PATCH 03/11] ProjectionTy.item_def_id -> ProjectionTy.def_id --- .../src/debuginfo/type_names.rs | 2 +- .../rustc_const_eval/src/util/type_name.rs | 2 +- .../rustc_hir_analysis/src/astconv/mod.rs | 7 +-- .../src/check/compare_method.rs | 14 ++--- compiler/rustc_hir_analysis/src/check/mod.rs | 6 +- .../rustc_hir_analysis/src/check/wfcheck.rs | 10 +-- .../src/collect/predicates_of.rs | 2 +- .../rustc_hir_analysis/src/collect/type_of.rs | 2 +- .../src/outlives/implicit_infer.rs | 2 +- .../rustc_hir_analysis/src/outlives/utils.rs | 2 +- .../rustc_hir_analysis/src/variance/mod.rs | 11 ++-- compiler/rustc_hir_typeck/src/closure.rs | 8 +-- .../src/fn_ctxt/suggestions.rs | 6 +- .../rustc_hir_typeck/src/method/suggest.rs | 4 +- compiler/rustc_infer/src/infer/at.rs | 4 +- .../src/infer/error_reporting/mod.rs | 10 +-- .../src/infer/error_reporting/suggest.rs | 2 +- .../rustc_infer/src/infer/opaque_types.rs | 8 +-- .../src/infer/outlives/obligations.rs | 4 +- .../rustc_infer/src/infer/outlives/verify.rs | 2 +- compiler/rustc_infer/src/infer/projection.rs | 2 +- .../src/infer/region_constraints/mod.rs | 2 +- compiler/rustc_infer/src/traits/util.rs | 3 +- .../src/opaque_hidden_inferred_bound.rs | 4 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 2 +- compiler/rustc_middle/src/ty/error.rs | 18 +++--- compiler/rustc_middle/src/ty/mod.rs | 2 +- compiler/rustc_middle/src/ty/print/pretty.rs | 10 +-- compiler/rustc_middle/src/ty/relate.rs | 22 +++---- compiler/rustc_middle/src/ty/sty.rs | 22 +++---- compiler/rustc_privacy/src/lib.rs | 4 +- compiler/rustc_symbol_mangling/src/legacy.rs | 2 +- .../src/typeid/typeid_itanium_cxx_abi.rs | 2 +- compiler/rustc_symbol_mangling/src/v0.rs | 4 +- .../src/traits/error_reporting/mod.rs | 9 ++- .../src/traits/error_reporting/suggestions.rs | 10 +-- .../src/traits/object_safety.rs | 8 +-- .../src/traits/project.rs | 61 +++++++++---------- .../src/traits/select/candidate_assembly.rs | 2 +- .../src/traits/select/confirmation.rs | 2 +- .../src/traits/select/mod.rs | 4 +- .../rustc_trait_selection/src/traits/wf.rs | 8 +-- compiler/rustc_traits/src/chalk/lowering.rs | 10 +-- compiler/rustc_type_ir/src/sty.rs | 3 +- src/librustdoc/clean/mod.rs | 8 +-- .../clippy/clippy_lints/src/dereference.rs | 2 +- src/tools/clippy/clippy_lints/src/len_zero.rs | 2 +- .../src/methods/needless_collect.rs | 2 +- src/tools/clippy/clippy_utils/src/ty.rs | 10 +-- 50 files changed, 164 insertions(+), 186 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index b004fbf85a97f..7a8d1d8d9fad6 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -235,7 +235,7 @@ fn push_debuginfo_type_name<'tcx>( let projection_bounds: SmallVec<[_; 4]> = trait_data .projection_bounds() .map(|bound| { - let ExistentialProjection { item_def_id, term, .. } = + let ExistentialProjection { def_id: item_def_id, term, .. } = tcx.erase_late_bound_regions(bound); // FIXME(associated_const_equality): allow for consts here (item_def_id, term.ty().unwrap()) diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index ecb46d12a0141..5c78f63020d26 100644 --- a/compiler/rustc_const_eval/src/util/type_name.rs +++ b/compiler/rustc_const_eval/src/util/type_name.rs @@ -59,7 +59,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs) | ty::FnDef(def_id, substs) | ty::Opaque(ty::OpaqueTy { def_id, substs }) - | ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) + | ty::Projection(ty::ProjectionTy { def_id, substs }) | ty::Closure(def_id, substs) | ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs), ty::Foreign(def_id) => self.print_def_path(def_id, &[]), diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 66906b331da2e..7c6b8a2455036 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -1146,10 +1146,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { debug!(?substs_trait_ref_and_assoc_item); - ty::ProjectionTy { - item_def_id: assoc_item.def_id, - substs: substs_trait_ref_and_assoc_item, - } + ty::ProjectionTy { def_id: assoc_item.def_id, substs: substs_trait_ref_and_assoc_item } }); if !speculative { @@ -1195,7 +1192,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // the "projection predicate" for: // // `::Item = u32` - let assoc_item_def_id = projection_ty.skip_binder().item_def_id; + let assoc_item_def_id = projection_ty.skip_binder().def_id; let def_kind = tcx.def_kind(assoc_item_def_id); match (def_kind, term.unpack()) { (hir::def::DefKind::AssocTy, ty::TermKind::Ty(_)) diff --git a/compiler/rustc_hir_analysis/src/check/compare_method.rs b/compiler/rustc_hir_analysis/src/check/compare_method.rs index 1d6f9b2917651..1d720aa5d376d 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_method.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_method.rs @@ -572,9 +572,9 @@ impl<'tcx> TypeFolder<'tcx> for ImplTraitInTraitCollector<'_, 'tcx> { fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { if let ty::Projection(proj) = ty.kind() - && self.tcx().def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder + && self.tcx().def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder { - if let Some((ty, _)) = self.types.get(&proj.item_def_id) { + if let Some((ty, _)) = self.types.get(&proj.def_id) { return *ty; } //FIXME(RPITIT): Deny nested RPITIT in substs too @@ -586,9 +586,9 @@ impl<'tcx> TypeFolder<'tcx> for ImplTraitInTraitCollector<'_, 'tcx> { span: self.span, kind: TypeVariableOriginKind::MiscVariable, }); - self.types.insert(proj.item_def_id, (infer_ty, proj.substs)); + self.types.insert(proj.def_id, (infer_ty, proj.substs)); // Recurse into bounds - for (pred, pred_span) in self.tcx().bound_explicit_item_bounds(proj.item_def_id).subst_iter_copied(self.tcx(), proj.substs) { + for (pred, pred_span) in self.tcx().bound_explicit_item_bounds(proj.def_id).subst_iter_copied(self.tcx(), proj.substs) { let pred = pred.fold_with(self); let pred = self.ocx.normalize( &ObligationCause::misc(self.span, self.body_id), @@ -601,7 +601,7 @@ impl<'tcx> TypeFolder<'tcx> for ImplTraitInTraitCollector<'_, 'tcx> { ObligationCause::new( self.span, self.body_id, - ObligationCauseCode::BindingObligation(proj.item_def_id, pred_span), + ObligationCauseCode::BindingObligation(proj.def_id, pred_span), ), self.param_env, pred, @@ -1735,7 +1735,7 @@ pub fn check_type_bounds<'tcx>( let mut predicates = param_env.caller_bounds().iter().collect::>(); match impl_ty_value.kind() { ty::Projection(proj) - if proj.item_def_id == trait_ty.def_id && proj.substs == rebased_substs => + if proj.def_id == trait_ty.def_id && proj.substs == rebased_substs => { // Don't include this predicate if the projected type is // exactly the same as the projection. This can occur in @@ -1747,7 +1747,7 @@ pub fn check_type_bounds<'tcx>( ty::Binder::bind_with_vars( ty::ProjectionPredicate { projection_ty: ty::ProjectionTy { - item_def_id: trait_ty.def_id, + def_id: trait_ty.def_id, substs: rebased_substs, }, term: impl_ty_value.into(), diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index 29255472a2516..1c7b83f99a873 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -352,11 +352,7 @@ fn bounds_from_generic_predicates<'tcx>( // insert the associated types where they correspond, but for now let's be "lazy" and // propose this instead of the following valid resugaring: // `T: Trait, Trait::Assoc = K` → `T: Trait` - where_clauses.push(format!( - "{} = {}", - tcx.def_path_str(p.projection_ty.item_def_id), - p.term, - )); + where_clauses.push(format!("{} = {}", tcx.def_path_str(p.projection_ty.def_id), p.term,)); } let where_clauses = if where_clauses.is_empty() { String::new() diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 69eb96fe8e925..c0dbae8137103 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -759,7 +759,7 @@ impl<'tcx> TypeVisitor<'tcx> for GATSubstCollector<'tcx> { fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { match t.kind() { - ty::Projection(p) if p.item_def_id == self.gat => { + ty::Projection(p) if p.def_id == self.gat => { for (idx, subst) in p.substs.iter().enumerate() { match subst.unpack() { GenericArgKind::Lifetime(lt) if !lt.is_late_bound() => { @@ -1593,11 +1593,11 @@ fn check_return_position_impl_trait_in_trait_bounds<'tcx>( for arg in fn_output.walk() { if let ty::GenericArgKind::Type(ty) = arg.unpack() && let ty::Projection(proj) = ty.kind() - && tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder - && tcx.impl_trait_in_trait_parent(proj.item_def_id) == fn_def_id.to_def_id() + && tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder + && tcx.impl_trait_in_trait_parent(proj.def_id) == fn_def_id.to_def_id() { - let span = tcx.def_span(proj.item_def_id); - let bounds = wfcx.tcx().explicit_item_bounds(proj.item_def_id); + let span = tcx.def_span(proj.def_id); + let bounds = wfcx.tcx().explicit_item_bounds(proj.def_id); let wf_obligations = bounds.iter().flat_map(|&(bound, bound_span)| { let bound = ty::EarlyBinder(bound).subst(tcx, proj.substs); let normalized_bound = wfcx.normalize(span, None, bound); diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index 45e241f4e093d..617de63b1bdfb 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -413,7 +413,7 @@ pub(super) fn explicit_predicates_of<'tcx>( // supertrait). if let ty::Projection(projection) = ty.kind() { projection.substs == trait_identity_substs - && tcx.associated_item(projection.item_def_id).container_id(tcx) == def_id + && tcx.associated_item(projection.def_id).container_id(tcx) == def_id } else { false } diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index f838ec7025fd8..43bc71ea1e4fa 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -69,7 +69,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option< // as a precaution for if it's ever allowed to elide lifetimes in GAT's. It currently isn't // but it can't hurt to be safe ^^ if let ty::Projection(projection) = ty.kind() { - let generics = tcx.generics_of(projection.item_def_id); + let generics = tcx.generics_of(projection.def_id); let arg_index = segment .args diff --git a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs index 90c6edb65e46f..3d29470ee66c5 100644 --- a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs +++ b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs @@ -202,7 +202,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( debug!("Projection"); check_explicit_predicates( tcx, - tcx.parent(obj.item_def_id), + tcx.parent(obj.def_id), obj.substs, required_predicates, explicit_map, diff --git a/compiler/rustc_hir_analysis/src/outlives/utils.rs b/compiler/rustc_hir_analysis/src/outlives/utils.rs index 0409c7081dc4f..b51b740d08e2e 100644 --- a/compiler/rustc_hir_analysis/src/outlives/utils.rs +++ b/compiler/rustc_hir_analysis/src/outlives/utils.rs @@ -90,7 +90,7 @@ pub(crate) fn insert_outlives_predicate<'tcx>( // ``` // // Here we want to add an explicit `where ::Item: 'a`. - let ty: Ty<'tcx> = tcx.mk_projection(proj_ty.item_def_id, proj_ty.substs); + let ty: Ty<'tcx> = tcx.mk_projection(proj_ty.def_id, proj_ty.substs); required_predicates .entry(ty::OutlivesPredicate(ty.into(), outlived_region)) .or_insert(span); diff --git a/compiler/rustc_hir_analysis/src/variance/mod.rs b/compiler/rustc_hir_analysis/src/variance/mod.rs index 8b2719c2f8aaa..9f8baa55bed67 100644 --- a/compiler/rustc_hir_analysis/src/variance/mod.rs +++ b/compiler/rustc_hir_analysis/src/variance/mod.rs @@ -110,12 +110,13 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc #[instrument(level = "trace", skip(self), ret)] fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { - match t.kind() { - ty::Opaque(def_id, substs) => self.visit_opaque(*def_id, substs), + // FIXME(alias): merge these + match t.kind() { + ty::Opaque(ty::OpaqueTy { def_id, substs }) => self.visit_opaque(*def_id, substs), ty::Projection(proj) - if self.tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder => + if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder => { - self.visit_opaque(proj.item_def_id, proj.substs) + self.visit_opaque(proj.def_id, proj.substs) } _ => t.super_visit_with(self), } @@ -167,7 +168,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc } } ty::PredicateKind::Clause(ty::Clause::Projection(ty::ProjectionPredicate { - projection_ty: ty::ProjectionTy { substs, item_def_id: _ }, + projection_ty: ty::ProjectionTy { substs, def_id: _ }, term, })) => { for subst in &substs[1..] { diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 3e3126cd446f9..5d89e47e6e017 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -684,10 +684,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .find_map(|(p, s)| get_future_output(p, s))?, ty::Error(_) => return None, ty::Projection(proj) - if self.tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder => + if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder => { self.tcx - .bound_explicit_item_bounds(proj.item_def_id) + .bound_explicit_item_bounds(proj.def_id) .subst_iter_copied(self.tcx, proj.substs) .find_map(|(p, s)| get_future_output(p, s))? } @@ -743,11 +743,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // The `Future` trait has only one associated item, `Output`, // so check that this is what we see. let output_assoc_item = self.tcx.associated_item_def_ids(future_trait)[0]; - if output_assoc_item != predicate.projection_ty.item_def_id { + if output_assoc_item != predicate.projection_ty.def_id { span_bug!( cause_span, "projecting associated item `{:?}` from future, which is not Output `{:?}`", - predicate.projection_ty.item_def_id, + predicate.projection_ty.def_id, output_assoc_item, ); } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index c0534ea89d8a0..bed3fc1c53aac 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -177,7 +177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Opaque(ty::OpaqueTy { def_id, substs }) => { self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| { if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder() - && Some(proj.projection_ty.item_def_id) == self.tcx.lang_items().fn_once_output() + && Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() // args tuple will always be substs[1] && let ty::Tuple(args) = proj.projection_ty.substs.type_at(1).kind() { @@ -194,7 +194,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Dynamic(data, _, ty::Dyn) => { data.iter().find_map(|pred| { if let ty::ExistentialPredicate::Projection(proj) = pred.skip_binder() - && Some(proj.item_def_id) == self.tcx.lang_items().fn_once_output() + && Some(proj.def_id) == self.tcx.lang_items().fn_once_output() // for existential projection, substs are shifted over by 1 && let ty::Tuple(args) = proj.substs.type_at(0).kind() { @@ -212,7 +212,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let def_id = self.tcx.generics_of(self.body_id.owner).type_param(¶m, self.tcx).def_id; self.tcx.predicates_of(self.body_id.owner).predicates.iter().find_map(|(pred, _)| { if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder() - && Some(proj.projection_ty.item_def_id) == self.tcx.lang_items().fn_once_output() + && Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() && proj.projection_ty.self_ty() == found // args tuple will always be substs[1] && let ty::Tuple(args) = proj.projection_ty.substs.type_at(1).kind() diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index db93cfab2c0db..5451f41d94325 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -559,7 +559,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let quiet_projection_ty = ty::ProjectionTy { substs: substs_with_infer_self, - item_def_id: projection_ty.item_def_id, + def_id: projection_ty.def_id, }; let term = pred.skip_binder().term; @@ -2269,7 +2269,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { t.def_id() == info.def_id } ty::PredicateKind::Clause(ty::Clause::Projection(p)) => { - p.projection_ty.item_def_id == info.def_id + p.projection_ty.def_id == info.def_id } _ => false, } diff --git a/compiler/rustc_infer/src/infer/at.rs b/compiler/rustc_infer/src/infer/at.rs index 4429e4f43629a..1f2768f9884af 100644 --- a/compiler/rustc_infer/src/infer/at.rs +++ b/compiler/rustc_infer/src/infer/at.rs @@ -419,8 +419,8 @@ impl<'tcx> ToTrace<'tcx> for ty::ProjectionTy<'tcx> { a: Self, b: Self, ) -> TypeTrace<'tcx> { - let a_ty = tcx.mk_projection(a.item_def_id, a.substs); - let b_ty = tcx.mk_projection(b.item_def_id, b.substs); + let a_ty = tcx.mk_projection(a.def_id, a.substs); + let b_ty = tcx.mk_projection(b.def_id, b.substs); TypeTrace { cause: cause.clone(), values: Terms(ExpectedFound::new(a_is_expected, a_ty.into(), b_ty.into())), diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index fea6213375953..615452d019de4 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -342,9 +342,9 @@ impl<'tcx> InferCtxt<'tcx> { let (def_id, substs) = match *ty.kind() { ty::Opaque(ty::OpaqueTy { def_id, substs }) => (def_id, substs), ty::Projection(data) - if self.tcx.def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder => + if self.tcx.def_kind(data.def_id) == DefKind::ImplTraitPlaceholder => { - (data.item_def_id, data.substs) + (data.def_id, data.substs) } _ => return None, }; @@ -358,7 +358,7 @@ impl<'tcx> InferCtxt<'tcx> { .kind() .map_bound(|kind| match kind { ty::PredicateKind::Clause(ty::Clause::Projection(projection_predicate)) - if projection_predicate.projection_ty.item_def_id == item_def_id => + if projection_predicate.projection_ty.def_id == item_def_id => { projection_predicate.term.ty() } @@ -1743,11 +1743,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { ) } (true, ty::Projection(proj)) - if self.tcx.def_kind(proj.item_def_id) + if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder => { let sm = self.tcx.sess.source_map(); - let pos = sm.lookup_char_pos(self.tcx.def_span(proj.item_def_id).lo()); + let pos = sm.lookup_char_pos(self.tcx.def_span(proj.def_id).lo()); format!( " (trait associated opaque type at <{}:{}:{}>)", sm.filename_for_diagnostics(&pos.file.name), diff --git a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs index fe134830d6858..7cac038927c74 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs @@ -509,7 +509,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { ( hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds: last_bounds, .. }), hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds: exp_bounds, .. }), - ) if iter::zip(*last_bounds, *exp_bounds).all(|(left, right)| { + ) if std::iter::zip(*last_bounds, *exp_bounds).all(|(left, right)| { match (left, right) { ( hir::GenericBound::Trait(tl, ml), diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index 495369031d1d5..25edfd0928a21 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -490,10 +490,10 @@ where } ty::Projection(proj) - if self.tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder => + if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder => { // Skip lifetime paramters that are not captures. - let variances = self.tcx.variances_of(proj.item_def_id); + let variances = self.tcx.variances_of(proj.def_id); for (v, s) in std::iter::zip(variances, proj.substs.iter()) { if *v != ty::Variance::Bivariant { @@ -568,7 +568,7 @@ impl<'tcx> InferCtxt<'tcx> { // FIXME(RPITIT): Don't replace RPITITs with inference vars. ty::Projection(projection_ty) if !projection_ty.has_escaping_bound_vars() - && tcx.def_kind(projection_ty.item_def_id) + && tcx.def_kind(projection_ty.def_id) != DefKind::ImplTraitPlaceholder => { self.infer_projection( @@ -588,7 +588,7 @@ impl<'tcx> InferCtxt<'tcx> { } // FIXME(RPITIT): This can go away when we move to associated types ty::Projection(proj) - if def_id.to_def_id() == proj.item_def_id && substs == proj.substs => + if def_id.to_def_id() == proj.def_id && substs == proj.substs => { hidden_ty } diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index 3fc3e6b09df09..c496b040edbbe 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -355,11 +355,11 @@ where origin, region, GenericKind::Projection(projection_ty), - projection_ty.item_def_id, + projection_ty.def_id, projection_ty.substs, false, |ty| match ty.kind() { - ty::Projection(projection_ty) => (projection_ty.item_def_id, projection_ty.substs), + ty::Projection(projection_ty) => (projection_ty.def_id, projection_ty.substs), _ => bug!("expected only projection types from env, not {:?}", ty), }, ); diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index f470b2eb8c193..136da4a3cb12a 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -178,7 +178,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { ), Component::Projection(projection_ty) => self.projection_opaque_bounds( GenericKind::Projection(projection_ty), - projection_ty.item_def_id, + projection_ty.def_id, projection_ty.substs, visited, ), diff --git a/compiler/rustc_infer/src/infer/projection.rs b/compiler/rustc_infer/src/infer/projection.rs index eb6deee291cf7..d81e09fcb5d05 100644 --- a/compiler/rustc_infer/src/infer/projection.rs +++ b/compiler/rustc_infer/src/infer/projection.rs @@ -21,7 +21,7 @@ impl<'tcx> InferCtxt<'tcx> { recursion_depth: usize, obligations: &mut Vec>, ) -> Ty<'tcx> { - let def_id = projection_ty.item_def_id; + let def_id = projection_ty.def_id; let ty_var = self.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::NormalizeProjectionType, span: self.tcx.def_span(def_id), diff --git a/compiler/rustc_infer/src/infer/region_constraints/mod.rs b/compiler/rustc_infer/src/infer/region_constraints/mod.rs index 985c5d360db8e..7b0d0a9cb5291 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/mod.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/mod.rs @@ -773,7 +773,7 @@ impl<'tcx> GenericKind<'tcx> { pub fn to_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { match *self { GenericKind::Param(ref p) => p.to_ty(tcx), - GenericKind::Projection(ref p) => tcx.mk_projection(p.item_def_id, p.substs), + GenericKind::Projection(ref p) => tcx.mk_projection(p.def_id, p.substs), GenericKind::Opaque(def_id, substs) => tcx.mk_opaque(def_id, substs), } } diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index 512e6079f43a0..8f0bd3a9abe5e 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -259,8 +259,7 @@ impl<'tcx> Elaborator<'tcx> { Component::Projection(projection) => { // We might end up here if we have `Foo<::Assoc>: 'a`. // With this, we can deduce that `::Assoc: 'a`. - let ty = - tcx.mk_projection(projection.item_def_id, projection.substs); + let ty = tcx.mk_projection(projection.def_id, projection.substs); Some(ty::PredicateKind::Clause(ty::Clause::TypeOutlives( ty::OutlivesPredicate(ty, r_min), ))) diff --git a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs index 863c19bd3d60b..f745e8201a859 100644 --- a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs +++ b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs @@ -82,7 +82,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { let Some(proj_term) = proj.term.ty() else { continue }; let proj_ty = - cx.tcx.mk_projection(proj.projection_ty.item_def_id, proj.projection_ty.substs); + cx.tcx.mk_projection(proj.projection_ty.def_id, proj.projection_ty.substs); // For every instance of the projection type in the bounds, // replace them with the term we're assigning to the associated // type in our opaque type. @@ -97,7 +97,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { // with `impl Send: OtherTrait`. for (assoc_pred, assoc_pred_span) in cx .tcx - .bound_explicit_item_bounds(proj.projection_ty.item_def_id) + .bound_explicit_item_bounds(proj.projection_ty.def_id) .subst_iter_copied(cx.tcx, &proj.projection_ty.substs) { let assoc_pred = assoc_pred.fold_with(proj_replacer); diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 29f9e82da75cc..4c22cd65002b3 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1112,7 +1112,7 @@ fn should_encode_trait_impl_trait_tys<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> tcx.fn_sig(trait_item_def_id).skip_binder().output().walk().any(|arg| { if let ty::GenericArgKind::Type(ty) = arg.unpack() && let ty::Projection(data) = ty.kind() - && tcx.def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder + && tcx.def_kind(data.def_id) == DefKind::ImplTraitPlaceholder { true } else { diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index c56f6073b05f8..938eb664da951 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2599,7 +2599,7 @@ impl<'tcx> TyCtxt<'tcx> { substs.len(), "wrong number of generic parameters for {item_def_id:?}: {substs:?}", ); - self.mk_ty(Projection(ProjectionTy { item_def_id, substs })) + self.mk_ty(Projection(ProjectionTy { def_id: item_def_id, substs })) } #[inline] diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index f7689820d3bb6..32bc53203c1c3 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -443,7 +443,7 @@ impl<'tcx> TyCtxt<'tcx> { diag.note("an associated type was expected, but a different one was found"); } (ty::Param(p), ty::Projection(proj)) | (ty::Projection(proj), ty::Param(p)) - if self.def_kind(proj.item_def_id) != DefKind::ImplTraitPlaceholder => + if self.def_kind(proj.def_id) != DefKind::ImplTraitPlaceholder => { let generics = self.generics_of(body_owner_def_id); let p_span = self.def_span(generics.type_param(p, self).def_id); @@ -466,7 +466,7 @@ impl<'tcx> TyCtxt<'tcx> { let (trait_ref, assoc_substs) = proj.trait_ref_and_own_substs(self); let path = self.def_path_str_with_substs(trait_ref.def_id, trait_ref.substs); - let item_name = self.item_name(proj.item_def_id); + let item_name = self.item_name(proj.def_id); let item_args = self.format_generic_args(assoc_substs); let path = if path.ends_with('>') { @@ -553,7 +553,7 @@ impl Trait for X { diag.span_label(p_span, "this type parameter"); } } - (ty::Projection(proj_ty), _) if self.def_kind(proj_ty.item_def_id) != DefKind::ImplTraitPlaceholder => { + (ty::Projection(proj_ty), _) if self.def_kind(proj_ty.def_id) != DefKind::ImplTraitPlaceholder => { self.expected_projection( diag, proj_ty, @@ -562,7 +562,7 @@ impl Trait for X { cause.code(), ); } - (_, ty::Projection(proj_ty)) if self.def_kind(proj_ty.item_def_id) != DefKind::ImplTraitPlaceholder => { + (_, ty::Projection(proj_ty)) if self.def_kind(proj_ty.def_id) != DefKind::ImplTraitPlaceholder => { let msg = format!( "consider constraining the associated type `{}` to `{}`", values.found, values.expected, @@ -627,7 +627,7 @@ impl Trait for X { proj_ty: &ty::ProjectionTy<'tcx>, ty: Ty<'tcx>, ) -> bool { - let assoc = self.associated_item(proj_ty.item_def_id); + let assoc = self.associated_item(proj_ty.def_id); let (trait_ref, assoc_substs) = proj_ty.trait_ref_and_own_substs(self); if let Some(item) = self.hir().get_if_local(body_owner_def_id) { if let Some(hir_generics) = item.generics() { @@ -703,7 +703,7 @@ impl Trait for X { ); let impl_comparison = matches!(cause_code, ObligationCauseCode::CompareImplItemObligation { .. }); - let assoc = self.associated_item(proj_ty.item_def_id); + let assoc = self.associated_item(proj_ty.def_id); if !callable_scope || impl_comparison { // We do not want to suggest calling functions when the reason of the // type error is a comparison of an `impl` with its `trait` or when the @@ -716,7 +716,7 @@ impl Trait for X { diag, assoc.container_id(self), current_method_ident, - proj_ty.item_def_id, + proj_ty.def_id, values.expected, ); // Possibly suggest constraining the associated type to conform to the @@ -778,7 +778,7 @@ fn foo(&self) -> Self::T { String::new() } proj_ty: &ty::ProjectionTy<'tcx>, ty: Ty<'tcx>, ) -> bool { - let assoc = self.associated_item(proj_ty.item_def_id); + let assoc = self.associated_item(proj_ty.def_id); if let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = *proj_ty.self_ty().kind() { let opaque_local_def_id = def_id.as_local(); let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id { @@ -828,7 +828,7 @@ fn foo(&self) -> Self::T { String::new() } .filter_map(|(_, item)| { let method = self.fn_sig(item.def_id); match *method.output().skip_binder().kind() { - ty::Projection(ty::ProjectionTy { item_def_id, .. }) + ty::Projection(ty::ProjectionTy { def_id: item_def_id, .. }) if item_def_id == proj_ty_item_def_id => { Some(( diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index efc45b5646e2a..5e173df2eb6f8 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1046,7 +1046,7 @@ impl<'tcx> PolyProjectionPredicate<'tcx> { /// associated type, which is in `tcx.associated_item(projection_def_id()).container`. pub fn projection_def_id(&self) -> DefId { // Ok to skip binder since trait `DefId` does not care about regions. - self.skip_binder().projection_ty.item_def_id + self.skip_binder().projection_ty.def_id } } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 42ebc96c022cd..37735fbb1651a 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -720,9 +720,9 @@ pub trait PrettyPrinter<'tcx>: } ty::Projection(ref data) => { if !(self.should_print_verbose() || NO_QUERIES.with(|q| q.get())) - && self.tcx().def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder + && self.tcx().def_kind(data.def_id) == DefKind::ImplTraitPlaceholder { - return self.pretty_print_opaque_impl_type(data.item_def_id, data.substs); + return self.pretty_print_opaque_impl_type(data.def_id, data.substs); } else { p!(print(data)) } @@ -1022,7 +1022,7 @@ pub trait PrettyPrinter<'tcx>: // unless we can find out what generator return type it comes from. let term = if let Some(ty) = term.skip_binder().ty() && let ty::Projection(proj) = ty.kind() - && let Some(assoc) = tcx.opt_associated_item(proj.item_def_id) + && let Some(assoc) = tcx.opt_associated_item(proj.def_id) && assoc.trait_container(tcx) == tcx.lang_items().gen_trait() && assoc.name == rustc_span::sym::Return { @@ -2655,7 +2655,7 @@ define_print_and_forward_display! { } ty::ExistentialProjection<'tcx> { - let name = cx.tcx().associated_item(self.item_def_id).name; + let name = cx.tcx().associated_item(self.def_id).name; p!(write("{} = ", name), print(self.term)) } @@ -2743,7 +2743,7 @@ define_print_and_forward_display! { } ty::ProjectionTy<'tcx> { - p!(print_def_path(self.item_def_id, self.substs)); + p!(print_def_path(self.def_id, self.substs)); } ty::ClosureKind { diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 6d285f7f4924d..0c5e6e1564947 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -276,15 +276,11 @@ impl<'tcx> Relate<'tcx> for ty::ProjectionTy<'tcx> { a: ty::ProjectionTy<'tcx>, b: ty::ProjectionTy<'tcx>, ) -> RelateResult<'tcx, ty::ProjectionTy<'tcx>> { - if a.item_def_id != b.item_def_id { - Err(TypeError::ProjectionMismatched(expected_found( - relation, - a.item_def_id, - b.item_def_id, - ))) + if a.def_id != b.def_id { + Err(TypeError::ProjectionMismatched(expected_found(relation, a.def_id, b.def_id))) } else { let substs = relation.relate(a.substs, b.substs)?; - Ok(ty::ProjectionTy { item_def_id: a.item_def_id, substs: &substs }) + Ok(ty::ProjectionTy { def_id: a.def_id, substs: &substs }) } } } @@ -295,12 +291,8 @@ impl<'tcx> Relate<'tcx> for ty::ExistentialProjection<'tcx> { a: ty::ExistentialProjection<'tcx>, b: ty::ExistentialProjection<'tcx>, ) -> RelateResult<'tcx, ty::ExistentialProjection<'tcx>> { - if a.item_def_id != b.item_def_id { - Err(TypeError::ProjectionMismatched(expected_found( - relation, - a.item_def_id, - b.item_def_id, - ))) + if a.def_id != b.def_id { + Err(TypeError::ProjectionMismatched(expected_found(relation, a.def_id, b.def_id))) } else { let term = relation.relate_with_variance( ty::Invariant, @@ -314,7 +306,7 @@ impl<'tcx> Relate<'tcx> for ty::ExistentialProjection<'tcx> { a.substs, b.substs, )?; - Ok(ty::ExistentialProjection { item_def_id: a.item_def_id, substs, term }) + Ok(ty::ExistentialProjection { def_id: a.def_id, substs, term }) } } } @@ -561,7 +553,7 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( // these two are already handled downstream in case of lazy normalization (&ty::Projection(a_data), &ty::Projection(b_data)) => { let projection_ty = relation.relate(a_data, b_data)?; - Ok(tcx.mk_projection(projection_ty.item_def_id, projection_ty.substs)) + Ok(tcx.mk_projection(projection_ty.def_id, projection_ty.substs)) } ( diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 4c75614a5bc6a..6d63c5ee9389e 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -693,7 +693,7 @@ impl<'tcx> ExistentialPredicate<'tcx> { match (*self, *other) { (Trait(_), Trait(_)) => Ordering::Equal, (Projection(ref a), Projection(ref b)) => { - tcx.def_path_hash(a.item_def_id).cmp(&tcx.def_path_hash(b.item_def_id)) + tcx.def_path_hash(a.def_id).cmp(&tcx.def_path_hash(b.def_id)) } (AutoTrait(ref a), AutoTrait(ref b)) => { tcx.def_path_hash(*a).cmp(&tcx.def_path_hash(*b)) @@ -1152,15 +1152,15 @@ pub struct ProjectionTy<'tcx> { /// Note that this is not the `DefId` of the `TraitRef` containing this /// associated type, which is in `tcx.associated_item(item_def_id).container`, /// aka. `tcx.parent(item_def_id).unwrap()`. - pub item_def_id: DefId, + pub def_id: DefId, } impl<'tcx> ProjectionTy<'tcx> { pub fn trait_def_id(&self, tcx: TyCtxt<'tcx>) -> DefId { - match tcx.def_kind(self.item_def_id) { - DefKind::AssocTy | DefKind::AssocConst => tcx.parent(self.item_def_id), + match tcx.def_kind(self.def_id) { + DefKind::AssocTy | DefKind::AssocConst => tcx.parent(self.def_id), DefKind::ImplTraitPlaceholder => { - tcx.parent(tcx.impl_trait_in_trait_parent(self.item_def_id)) + tcx.parent(tcx.impl_trait_in_trait_parent(self.def_id)) } kind => bug!("unexpected DefKind in ProjectionTy: {kind:?}"), } @@ -1173,7 +1173,7 @@ impl<'tcx> ProjectionTy<'tcx> { &self, tcx: TyCtxt<'tcx>, ) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) { - let def_id = tcx.parent(self.item_def_id); + let def_id = tcx.parent(self.def_id); assert_eq!(tcx.def_kind(def_id), DefKind::Trait); let trait_generics = tcx.generics_of(def_id); ( @@ -1415,7 +1415,7 @@ impl From for BoundTy { #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct ExistentialProjection<'tcx> { - pub item_def_id: DefId, + pub def_id: DefId, pub substs: SubstsRef<'tcx>, pub term: Term<'tcx>, } @@ -1428,7 +1428,7 @@ impl<'tcx> ExistentialProjection<'tcx> { /// then this function would return an `exists T. T: Iterator` existential trait /// reference. pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::ExistentialTraitRef<'tcx> { - let def_id = tcx.parent(self.item_def_id); + let def_id = tcx.parent(self.def_id); let subst_count = tcx.generics_of(def_id).count() - 1; let substs = tcx.intern_substs(&self.substs[..subst_count]); ty::ExistentialTraitRef { def_id, substs } @@ -1444,7 +1444,7 @@ impl<'tcx> ExistentialProjection<'tcx> { ty::ProjectionPredicate { projection_ty: ty::ProjectionTy { - item_def_id: self.item_def_id, + def_id: self.def_id, substs: tcx.mk_substs_trait(self_ty, self.substs), }, term: self.term, @@ -1459,7 +1459,7 @@ impl<'tcx> ExistentialProjection<'tcx> { projection_predicate.projection_ty.substs.type_at(0); Self { - item_def_id: projection_predicate.projection_ty.item_def_id, + def_id: projection_predicate.projection_ty.def_id, substs: tcx.intern_substs(&projection_predicate.projection_ty.substs[1..]), term: projection_predicate.term, } @@ -1476,7 +1476,7 @@ impl<'tcx> PolyExistentialProjection<'tcx> { } pub fn item_def_id(&self) -> DefId { - self.skip_binder().item_def_id + self.skip_binder().def_id } } diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 6a4bbea79d13c..d077b2852ba9d 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -123,13 +123,13 @@ where projection: ty::ProjectionTy<'tcx>, ) -> ControlFlow { let tcx = self.def_id_visitor.tcx(); - let (trait_ref, assoc_substs) = if tcx.def_kind(projection.item_def_id) + let (trait_ref, assoc_substs) = if tcx.def_kind(projection.def_id) != DefKind::ImplTraitPlaceholder { projection.trait_ref_and_own_substs(tcx) } else { // HACK(RPITIT): Remove this when RPITITs are lowered to regular assoc tys - let def_id = tcx.impl_trait_in_trait_parent(projection.item_def_id); + let def_id = tcx.impl_trait_in_trait_parent(projection.def_id); let trait_generics = tcx.generics_of(def_id); ( ty::TraitRef { def_id, substs: projection.substs.truncate_to(tcx, trait_generics) }, diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index 36c1463736eb6..e957829054a4c 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -217,7 +217,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> { // Print all nominal types as paths (unlike `pretty_print_type`). ty::FnDef(def_id, substs) | ty::Opaque(ty::OpaqueTy { def_id, substs }) - | ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) + | ty::Projection(ty::ProjectionTy { def_id, substs }) | ty::Closure(def_id, substs) | ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs), diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs index 87128e0f893a2..dddc7b7513a5b 100644 --- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs +++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs @@ -240,7 +240,7 @@ fn encode_predicate<'tcx>( s.push_str(&encode_substs(tcx, trait_ref.substs, dict, options)); } ty::ExistentialPredicate::Projection(projection) => { - let name = encode_ty_name(tcx, projection.item_def_id); + let name = encode_ty_name(tcx, projection.def_id); let _ = write!(s, "u{}{}", name.len(), &name); s.push_str(&encode_substs(tcx, projection.substs, dict, options)); match projection.term.unpack() { diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index b3d19e329973d..c24b83060db40 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -440,7 +440,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs) | ty::FnDef(def_id, substs) | ty::Opaque(ty::OpaqueTy { def_id, substs }) - | ty::Projection(ty::ProjectionTy { item_def_id: def_id, substs }) + | ty::Projection(ty::ProjectionTy { def_id, substs }) | ty::Closure(def_id, substs) | ty::Generator(def_id, substs, _) => { self = self.print_def_path(def_id, substs)?; @@ -544,7 +544,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { cx = cx.print_def_path(trait_ref.def_id, trait_ref.substs)?; } ty::ExistentialPredicate::Projection(projection) => { - let name = cx.tcx.associated_item(projection.item_def_id).name; + let name = cx.tcx.associated_item(projection.def_id).name; cx.push("p"); cx.push_ident(name.as_str()); cx = match projection.term.unpack() { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 30ff07ee6c372..82477ec6c440c 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1634,8 +1634,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let normalized_ty = ocx.normalize( &obligation.cause, obligation.param_env, - self.tcx - .mk_projection(data.projection_ty.item_def_id, data.projection_ty.substs), + self.tcx.mk_projection(data.projection_ty.def_id, data.projection_ty.substs), ); debug!(?obligation.cause, ?obligation.param_env); @@ -1686,10 +1685,10 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let secondary_span = match predicate.kind().skip_binder() { ty::PredicateKind::Clause(ty::Clause::Projection(proj)) => self .tcx - .opt_associated_item(proj.projection_ty.item_def_id) + .opt_associated_item(proj.projection_ty.def_id) .and_then(|trait_assoc_item| { self.tcx - .trait_of_item(proj.projection_ty.item_def_id) + .trait_of_item(proj.projection_ty.def_id) .map(|id| (trait_assoc_item, id)) }) .and_then(|(trait_assoc_item, id)| { @@ -1745,7 +1744,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let trait_def_id = pred.projection_ty.trait_def_id(self.tcx); let self_ty = pred.projection_ty.self_ty(); - if Some(pred.projection_ty.item_def_id) == self.tcx.lang_items().fn_once_output() { + if Some(pred.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() { Some(format!( "expected `{self_ty}` to be a {fn_kind} that returns `{expected_ty}`, but it returns `{normalized_ty}`", fn_kind = self_ty.prefix_string(self.tcx) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 7a391037f31b5..c685a652b3ab9 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -858,7 +858,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ty::Opaque(ty::OpaqueTy { def_id, substs }) => { self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| { if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder() - && Some(proj.projection_ty.item_def_id) == self.tcx.lang_items().fn_once_output() + && Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() // args tuple will always be substs[1] && let ty::Tuple(args) = proj.projection_ty.substs.type_at(1).kind() { @@ -875,7 +875,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ty::Dynamic(data, _, ty::Dyn) => { data.iter().find_map(|pred| { if let ty::ExistentialPredicate::Projection(proj) = pred.skip_binder() - && Some(proj.item_def_id) == self.tcx.lang_items().fn_once_output() + && Some(proj.def_id) == self.tcx.lang_items().fn_once_output() // for existential projection, substs are shifted over by 1 && let ty::Tuple(args) = proj.substs.type_at(0).kind() { @@ -892,7 +892,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ty::Param(_) => { obligation.param_env.caller_bounds().iter().find_map(|pred| { if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder() - && Some(proj.projection_ty.item_def_id) == self.tcx.lang_items().fn_once_output() + && Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() && proj.projection_ty.self_ty() == found // args tuple will always be substs[1] && let ty::Tuple(args) = proj.projection_ty.substs.type_at(1).kind() @@ -3248,7 +3248,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // This corresponds to `::Item = _`. let trait_ref = ty::Binder::dummy(ty::PredicateKind::Clause( ty::Clause::Projection(ty::ProjectionPredicate { - projection_ty: ty::ProjectionTy { substs, item_def_id: proj.item_def_id }, + projection_ty: ty::ProjectionTy { substs, def_id: proj.def_id }, term: ty_var.into(), }), )); @@ -3263,7 +3263,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { if ocx.select_where_possible().is_empty() { // `ty_var` now holds the type that `Item` is for `ExprTy`. let ty_var = self.resolve_vars_if_possible(ty_var); - assocs_in_this_method.push(Some((span, (proj.item_def_id, ty_var)))); + assocs_in_this_method.push(Some((span, (proj.def_id, ty_var)))); } else { // `` didn't select, so likely we've // reached the end of the iterator chain, like the originating diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index a45749fe48cd4..4cfcd74f33776 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -589,7 +589,7 @@ fn object_ty_for_trait<'tcx>( let pred = obligation.predicate.to_opt_poly_projection_pred()?; Some(pred.map_bound(|p| { ty::ExistentialPredicate::Projection(ty::ExistentialProjection { - item_def_id: p.projection_ty.item_def_id, + def_id: p.projection_ty.def_id, substs: p.projection_ty.substs, term: p.term, }) @@ -795,7 +795,7 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeVisitable<'tcx>>( } } ty::Projection(ref data) - if self.tcx.def_kind(data.item_def_id) == DefKind::ImplTraitPlaceholder => + if self.tcx.def_kind(data.def_id) == DefKind::ImplTraitPlaceholder => { // We'll deny these later in their own pass ControlFlow::CONTINUE @@ -862,9 +862,9 @@ pub fn contains_illegal_impl_trait_in_trait<'tcx>( ty.skip_binder().walk().find_map(|arg| { if let ty::GenericArgKind::Type(ty) = arg.unpack() && let ty::Projection(proj) = ty.kind() - && tcx.def_kind(proj.item_def_id) == DefKind::ImplTraitPlaceholder + && tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder { - Some(MethodViolationCode::ReferencesImplTraitInTrait(tcx.def_span(proj.item_def_id))) + Some(MethodViolationCode::ReferencesImplTraitInTrait(tcx.def_span(proj.def_id))) } else { None } diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 69f0e9865dcef..a2f813dc88e43 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -1189,10 +1189,9 @@ fn normalize_to_error<'a, 'tcx>( predicate: trait_ref.without_const().to_predicate(selcx.tcx()), }; let tcx = selcx.infcx.tcx; - let def_id = projection_ty.item_def_id; let new_value = selcx.infcx.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::NormalizeProjectionType, - span: tcx.def_span(def_id), + span: tcx.def_span(projection_ty.def_id), }); Normalized { value: new_value, obligations: vec![trait_obligation] } } @@ -1270,7 +1269,7 @@ fn project<'cx, 'tcx>( // need to investigate whether or not this is fine. selcx .tcx() - .mk_projection(obligation.predicate.item_def_id, obligation.predicate.substs) + .mk_projection(obligation.predicate.def_id, obligation.predicate.substs) .into(), )), // Error occurred while trying to processing impls. @@ -1290,13 +1289,12 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>( candidate_set: &mut ProjectionCandidateSet<'tcx>, ) { let tcx = selcx.tcx(); - if tcx.def_kind(obligation.predicate.item_def_id) == DefKind::ImplTraitPlaceholder { - let trait_fn_def_id = tcx.impl_trait_in_trait_parent(obligation.predicate.item_def_id); + if tcx.def_kind(obligation.predicate.def_id) == DefKind::ImplTraitPlaceholder { + let trait_fn_def_id = tcx.impl_trait_in_trait_parent(obligation.predicate.def_id); // If we are trying to project an RPITIT with trait's default `Self` parameter, // then we must be within a default trait body. if obligation.predicate.self_ty() - == ty::InternalSubsts::identity_for_item(tcx, obligation.predicate.item_def_id) - .type_at(0) + == ty::InternalSubsts::identity_for_item(tcx, obligation.predicate.def_id).type_at(0) && tcx.associated_item(trait_fn_def_id).defaultness(tcx).has_value() { candidate_set.push_candidate(ProjectionCandidate::ImplTraitInTrait( @@ -1377,7 +1375,7 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>( // Check whether the self-type is itself a projection. // If so, extract what we know from the trait and try to come up with a good answer. let bounds = match *obligation.predicate.self_ty().kind() { - ty::Projection(ref data) => tcx.bound_item_bounds(data.item_def_id).subst(tcx, data.substs), + ty::Projection(ref data) => tcx.bound_item_bounds(data.def_id).subst(tcx, data.substs), ty::Opaque(ty::OpaqueTy { def_id, substs }) => { tcx.bound_item_bounds(def_id).subst(tcx, substs) } @@ -1432,7 +1430,7 @@ fn assemble_candidates_from_object_ty<'cx, 'tcx>( }; let env_predicates = data .projection_bounds() - .filter(|bound| bound.item_def_id() == obligation.predicate.item_def_id) + .filter(|bound| bound.item_def_id() == obligation.predicate.def_id) .map(|p| p.with_self_ty(tcx, object_ty).to_predicate(tcx)); assemble_candidates_from_predicates( @@ -1464,7 +1462,7 @@ fn assemble_candidates_from_predicates<'cx, 'tcx>( predicate.kind().skip_binder() { let data = bound_predicate.rebind(data); - if data.projection_def_id() != obligation.predicate.item_def_id { + if data.projection_def_id() != obligation.predicate.def_id { continue; } @@ -1505,7 +1503,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( candidate_set: &mut ProjectionCandidateSet<'tcx>, ) { // Can't assemble candidate from impl for RPITIT - if selcx.tcx().def_kind(obligation.predicate.item_def_id) == DefKind::ImplTraitPlaceholder { + if selcx.tcx().def_kind(obligation.predicate.def_id) == DefKind::ImplTraitPlaceholder { return; } @@ -1557,7 +1555,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( // NOTE: This should be kept in sync with the similar code in // `rustc_ty_utils::instance::resolve_associated_item()`. let node_item = - assoc_def(selcx, impl_data.impl_def_id, obligation.predicate.item_def_id) + assoc_def(selcx, impl_data.impl_def_id, obligation.predicate.def_id) .map_err(|ErrorGuaranteed { .. }| ())?; if node_item.is_final() { @@ -1790,7 +1788,7 @@ fn confirm_candidate<'cx, 'tcx>( ProjectionCandidate::ImplTraitInTrait(ImplTraitInTraitCandidate::Trait) => Progress { term: selcx .tcx() - .mk_opaque(obligation.predicate.item_def_id, obligation.predicate.substs) + .mk_opaque(obligation.predicate.def_id, obligation.predicate.substs) .into(), obligations: vec![], }, @@ -1862,7 +1860,7 @@ fn confirm_generator_candidate<'cx, 'tcx>( gen_sig, ) .map_bound(|(trait_ref, yield_ty, return_ty)| { - let name = tcx.associated_item(obligation.predicate.item_def_id).name; + let name = tcx.associated_item(obligation.predicate.def_id).name; let ty = if name == sym::Return { return_ty } else if name == sym::Yield { @@ -1874,7 +1872,7 @@ fn confirm_generator_candidate<'cx, 'tcx>( ty::ProjectionPredicate { projection_ty: ty::ProjectionTy { substs: trait_ref.substs, - item_def_id: obligation.predicate.item_def_id, + def_id: obligation.predicate.def_id, }, term: ty.into(), } @@ -1911,12 +1909,12 @@ fn confirm_future_candidate<'cx, 'tcx>( gen_sig, ) .map_bound(|(trait_ref, return_ty)| { - debug_assert_eq!(tcx.associated_item(obligation.predicate.item_def_id).name, sym::Output); + debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output); ty::ProjectionPredicate { projection_ty: ty::ProjectionTy { substs: trait_ref.substs, - item_def_id: obligation.predicate.item_def_id, + def_id: obligation.predicate.def_id, }, term: return_ty.into(), } @@ -1936,7 +1934,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>( let self_ty = obligation.predicate.self_ty(); let substs = tcx.mk_substs([self_ty.into()].iter()); let lang_items = tcx.lang_items(); - let item_def_id = obligation.predicate.item_def_id; + let item_def_id = obligation.predicate.def_id; let trait_def_id = tcx.trait_of_item(item_def_id).unwrap(); let (term, obligations) = if lang_items.discriminant_kind_trait() == Some(trait_def_id) { let discriminant_def_id = tcx.require_lang_item(LangItem::Discriminant, None); @@ -1970,8 +1968,10 @@ fn confirm_builtin_candidate<'cx, 'tcx>( bug!("unexpected builtin trait with associated type: {:?}", obligation.predicate); }; - let predicate = - ty::ProjectionPredicate { projection_ty: ty::ProjectionTy { substs, item_def_id }, term }; + let predicate = ty::ProjectionPredicate { + projection_ty: ty::ProjectionTy { substs, def_id: item_def_id }, + term, + }; confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false) .with_addl_obligations(obligations) @@ -2040,10 +2040,7 @@ fn confirm_callable_candidate<'cx, 'tcx>( flag, ) .map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate { - projection_ty: ty::ProjectionTy { - substs: trait_ref.substs, - item_def_id: fn_once_output_def_id, - }, + projection_ty: ty::ProjectionTy { substs: trait_ref.substs, def_id: fn_once_output_def_id }, term: ret_type.into(), }); @@ -2124,7 +2121,7 @@ fn confirm_impl_candidate<'cx, 'tcx>( let tcx = selcx.tcx(); let ImplSourceUserDefinedData { impl_def_id, substs, mut nested } = impl_impl_source; - let assoc_item_id = obligation.predicate.item_def_id; + let assoc_item_id = obligation.predicate.def_id; let trait_def_id = tcx.trait_id_of_impl(impl_def_id).unwrap(); let param_env = obligation.param_env; @@ -2224,7 +2221,7 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>( let tcx = selcx.tcx(); let mut obligations = data.nested; - let trait_fn_def_id = tcx.impl_trait_in_trait_parent(obligation.predicate.item_def_id); + let trait_fn_def_id = tcx.impl_trait_in_trait_parent(obligation.predicate.def_id); let Ok(leaf_def) = assoc_def(selcx, data.impl_def_id, trait_fn_def_id) else { return Progress { term: tcx.ty_error().into(), obligations }; }; @@ -2235,9 +2232,7 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>( // Use the default `impl Trait` for the trait, e.g., for a default trait body if leaf_def.item.container == ty::AssocItemContainer::TraitContainer { return Progress { - term: tcx - .mk_opaque(obligation.predicate.item_def_id, obligation.predicate.substs) - .into(), + term: tcx.mk_opaque(obligation.predicate.def_id, obligation.predicate.substs).into(), obligations, }; } @@ -2304,7 +2299,7 @@ fn confirm_impl_trait_in_trait_candidate<'tcx>( obligation.recursion_depth + 1, tcx.bound_trait_impl_trait_tys(impl_fn_def_id) .map_bound(|tys| { - tys.map_or_else(|_| tcx.ty_error(), |tys| tys[&obligation.predicate.item_def_id]) + tys.map_or_else(|_| tcx.ty_error(), |tys| tys[&obligation.predicate.def_id]) }) .subst(tcx, impl_fn_substs), &mut obligations, @@ -2322,7 +2317,7 @@ fn assoc_ty_own_obligations<'cx, 'tcx>( ) { let tcx = selcx.tcx(); let own = tcx - .predicates_of(obligation.predicate.item_def_id) + .predicates_of(obligation.predicate.def_id) .instantiate_own(tcx, obligation.predicate.substs); for (predicate, span) in std::iter::zip(own.predicates, own.spans) { let normalized = normalize_with_depth_to( @@ -2345,13 +2340,13 @@ fn assoc_ty_own_obligations<'cx, 'tcx>( ObligationCause::new( obligation.cause.span, obligation.cause.body_id, - super::ItemObligation(obligation.predicate.item_def_id), + super::ItemObligation(obligation.predicate.def_id), ) } else { ObligationCause::new( obligation.cause.span, obligation.cause.body_id, - super::BindingObligation(obligation.predicate.item_def_id, span), + super::BindingObligation(obligation.predicate.def_id, span), ) }; nested.push(Obligation::with_depth( diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 4cd2d445bd0be..509a4c0172764 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -537,7 +537,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { self, param_env, ty::ProjectionTy { - item_def_id: tcx.lang_items().deref_target()?, + def_id: tcx.lang_items().deref_target()?, substs: trait_ref.substs, }, cause.clone(), diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index cd3025024fe36..cfc77a1a1d520 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -155,7 +155,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let placeholder_self_ty = placeholder_trait_predicate.self_ty(); let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate); let (def_id, substs) = match *placeholder_self_ty.kind() { - ty::Projection(proj) => (proj.item_def_id, proj.substs), + ty::Projection(proj) => (proj.def_id, proj.substs), ty::Opaque(ty::OpaqueTy { def_id, substs }) => (def_id, substs), _ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty), }; diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 054bbf8fb0ef3..e279d6bfdbc28 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1595,7 +1595,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let tcx = self.infcx.tcx; let (def_id, substs) = match *placeholder_trait_predicate.trait_ref.self_ty().kind() { - ty::Projection(ref data) => (data.item_def_id, data.substs), + ty::Projection(ref data) => (data.def_id, data.substs), ty::Opaque(ty::OpaqueTy { def_id, substs }) => (def_id, substs), _ => { span_bug!( @@ -1745,7 +1745,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { }); if is_match { - let generics = self.tcx().generics_of(obligation.predicate.item_def_id); + let generics = self.tcx().generics_of(obligation.predicate.def_id); // FIXME(generic-associated-types): Addresses aggressive inference in #92917. // If this type is a GAT, and of the GAT substs resolve to something new, // that means that we must have newly inferred something about the GAT. diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index ab678e4d98f81..e1a1f84841514 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -236,7 +236,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( // `traits-assoc-type-in-supertrait-bad.rs`. if let Some(ty::Projection(projection_ty)) = proj.term.ty().map(|ty| ty.kind()) && let Some(&impl_item_id) = - tcx.impl_item_implementor_ids(impl_def_id).get(&projection_ty.item_def_id) + tcx.impl_item_implementor_ids(impl_def_id).get(&projection_ty.def_id) && let Some(impl_item_span) = items .iter() .find(|item| item.id.owner_id.to_def_id() == impl_item_id) @@ -249,9 +249,9 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( // An associated item obligation born out of the `trait` failed to be met. An example // can be seen in `ui/associated-types/point-at-type-on-obligation-failure-2.rs`. debug!("extended_cause_with_original_assoc_item_obligation trait proj {:?}", pred); - if let ty::Projection(ty::ProjectionTy { item_def_id, .. }) = *pred.self_ty().kind() + if let ty::Projection(ty::ProjectionTy { def_id, .. }) = *pred.self_ty().kind() && let Some(&impl_item_id) = - tcx.impl_item_implementor_ids(impl_def_id).get(&item_def_id) + tcx.impl_item_implementor_ids(impl_def_id).get(&def_id) && let Some(impl_item_span) = items .iter() .find(|item| item.id.owner_id.to_def_id() == impl_item_id) @@ -392,7 +392,7 @@ impl<'tcx> WfPredicates<'tcx> { // `i32: Copy` // ] // Projection types do not require const predicates. - let obligations = self.nominal_obligations_without_const(data.item_def_id, data.substs); + let obligations = self.nominal_obligations_without_const(data.def_id, data.substs); self.out.extend(obligations); let tcx = self.tcx(); diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 8a2de801a19c8..96e895ff2a6e7 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -69,7 +69,7 @@ impl<'tcx> LowerInto<'tcx, SubstsRef<'tcx>> for &chalk_ir::Substitution LowerInto<'tcx, chalk_ir::AliasTy>> for ty::ProjectionTy<'tcx> { fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::AliasTy> { chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { - associated_ty_id: chalk_ir::AssocTypeId(self.item_def_id), + associated_ty_id: chalk_ir::AssocTypeId(self.def_id), substitution: self.substs.lower_into(interner), }) } @@ -448,7 +448,7 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty> { }), TyKind::AssociatedType(assoc_ty, substitution) => ty::Projection(ty::ProjectionTy { substs: substitution.lower_into(interner), - item_def_id: assoc_ty.0, + def_id: assoc_ty.0, }), TyKind::Foreign(def_id) => ty::Foreign(def_id.0), TyKind::Error => return interner.tcx.ty_error(), @@ -458,7 +458,7 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty> { }), TyKind::Alias(alias_ty) => match alias_ty { chalk_ir::AliasTy::Projection(projection) => ty::Projection(ty::ProjectionTy { - item_def_id: projection.associated_ty_id.0, + def_id: projection.associated_ty_id.0, substs: projection.substitution.lower_into(interner), }), chalk_ir::AliasTy::Opaque(opaque) => ty::Opaque(ty::OpaqueTy { @@ -690,7 +690,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders LowerInto<'tcx, chalk_solve::rust_ir::AliasEqBound let (trait_ref, own_substs) = self.projection_ty.trait_ref_and_own_substs(interner.tcx); chalk_solve::rust_ir::AliasEqBound { trait_bound: trait_ref.lower_into(interner), - associated_ty_id: chalk_ir::AssocTypeId(self.projection_ty.item_def_id), + associated_ty_id: chalk_ir::AssocTypeId(self.projection_ty.def_id), parameters: own_substs.iter().map(|arg| arg.lower_into(interner)).collect(), value: self.term.ty().unwrap().lower_into(interner), } diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/sty.rs index 5119733d84cd8..8303d8de08716 100644 --- a/compiler/rustc_type_ir/src/sty.rs +++ b/compiler/rustc_type_ir/src/sty.rs @@ -170,8 +170,7 @@ pub enum TyKind { /// A tuple type. For example, `(i32, bool)`. Tuple(I::ListTy), - /// The projection of an associated type. For example, - /// `>::N`. + /// A projection or opaque type. Both of these types Projection(I::ProjectionTy), /// Opaque (`impl Trait`) type found in a return type. diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 8ebdea883903c..d128b5f79acbc 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -418,10 +418,10 @@ fn clean_projection<'tcx>( cx: &mut DocContext<'tcx>, def_id: Option, ) -> Type { - if cx.tcx.def_kind(ty.skip_binder().item_def_id) == DefKind::ImplTraitPlaceholder { + if cx.tcx.def_kind(ty.skip_binder().def_id) == DefKind::ImplTraitPlaceholder { let bounds = cx .tcx - .explicit_item_bounds(ty.skip_binder().item_def_id) + .explicit_item_bounds(ty.skip_binder().def_id) .iter() .map(|(bound, _)| EarlyBinder(*bound).subst(cx.tcx, ty.skip_binder().substs)) .collect::>(); @@ -456,8 +456,8 @@ fn projection_to_path_segment<'tcx>( ty: ty::Binder<'tcx, ty::ProjectionTy<'tcx>>, cx: &mut DocContext<'tcx>, ) -> PathSegment { - let item = cx.tcx.associated_item(ty.skip_binder().item_def_id); - let generics = cx.tcx.generics_of(ty.skip_binder().item_def_id); + let item = cx.tcx.associated_item(ty.skip_binder().def_id); + let generics = cx.tcx.generics_of(ty.skip_binder().def_id); PathSegment { name: item.name, args: GenericArgs::AngleBracketed { diff --git a/src/tools/clippy/clippy_lints/src/dereference.rs b/src/tools/clippy/clippy_lints/src/dereference.rs index 38329659e02b7..ad5a1b2beb70c 100644 --- a/src/tools/clippy/clippy_lints/src/dereference.rs +++ b/src/tools/clippy/clippy_lints/src/dereference.rs @@ -1330,7 +1330,7 @@ fn replace_types<'tcx>( && let Some(term_ty) = projection_predicate.term.ty() && let ty::Param(term_param_ty) = term_ty.kind() { - let item_def_id = projection_predicate.projection_ty.item_def_id; + let item_def_id = projection_predicate.projection_ty.def_id; let assoc_item = cx.tcx.associated_item(item_def_id); let projection = cx.tcx .mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(new_ty, [])); diff --git a/src/tools/clippy/clippy_lints/src/len_zero.rs b/src/tools/clippy/clippy_lints/src/len_zero.rs index 4c133c06a157a..982f99c271639 100644 --- a/src/tools/clippy/clippy_lints/src/len_zero.rs +++ b/src/tools/clippy/clippy_lints/src/len_zero.rs @@ -493,7 +493,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { .filter_by_name_unhygienic(is_empty) .any(|item| is_is_empty(cx, item)) }), - ty::Projection(ref proj) => has_is_empty_impl(cx, proj.item_def_id), + ty::Projection(ref proj) => has_is_empty_impl(cx, proj.def_id), ty::Adt(id, _) => has_is_empty_impl(cx, id.did()), ty::Array(..) | ty::Slice(..) | ty::Str => true, _ => false, diff --git a/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs b/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs index b088e642e0e9a..f4d3ef3b74250 100644 --- a/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs +++ b/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs @@ -151,7 +151,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty: && let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, item, [collect_ty]) && let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions( cx.param_env, - cx.tcx.mk_projection(into_iter_item_proj.item_def_id, into_iter_item_proj.substs) + cx.tcx.mk_projection(into_iter_item_proj.def_id, into_iter_item_proj.substs) ) { iter_item_ty == into_iter_item_ty diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index f5f70b195c981..11e41d1958ce6 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -685,7 +685,7 @@ fn sig_from_bounds<'tcx>( inputs = Some(i); }, PredicateKind::Clause(ty::Clause::Projection(p)) - if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() + if Some(p.projection_ty.def_id) == lang_items.fn_once_output() && p.projection_ty.self_ty() == ty => { if output.is_some() { @@ -708,7 +708,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O for (pred, _) in cx .tcx - .bound_explicit_item_bounds(ty.item_def_id) + .bound_explicit_item_bounds(ty.def_id) .subst_iter_copied(cx.tcx, ty.substs) { match pred.kind().skip_binder() { @@ -726,7 +726,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> O inputs = Some(i); }, PredicateKind::Clause(ty::Clause::Projection(p)) - if Some(p.projection_ty.item_def_id) == lang_items.fn_once_output() => + if Some(p.projection_ty.def_id) == lang_items.fn_once_output() => { if output.is_some() { // Multiple different fn trait impls. Is this even allowed? @@ -1041,7 +1041,7 @@ pub fn make_projection<'tcx>( Some(ProjectionTy { substs, - item_def_id: assoc_item.def_id, + def_id: assoc_item.def_id, }) } helper( @@ -1081,7 +1081,7 @@ pub fn make_normalized_projection<'tcx>( ); return None; } - match tcx.try_normalize_erasing_regions(param_env, tcx.mk_projection(ty.item_def_id, ty.substs)) { + match tcx.try_normalize_erasing_regions(param_env, tcx.mk_projection(ty.def_id, ty.substs)) { Ok(ty) => Some(ty), Err(e) => { debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}"); From c13bd83528da223fa073e9c7e5fdc435254baab6 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 26 Nov 2022 21:32:01 +0000 Subject: [PATCH 04/11] squash OpaqueTy and ProjectionTy into AliasTy --- .../src/diagnostics/conflict_errors.rs | 2 +- .../src/diagnostics/region_errors.rs | 2 +- .../src/interpret/intrinsics.rs | 2 +- .../src/transform/validate.rs | 2 +- .../rustc_const_eval/src/util/type_name.rs | 4 +- .../rustc_hir_analysis/src/astconv/mod.rs | 2 +- .../rustc_hir_analysis/src/check/check.rs | 2 +- .../src/check/compare_method.rs | 2 +- .../src/variance/constraints.rs | 2 +- .../rustc_hir_analysis/src/variance/mod.rs | 8 ++-- compiler/rustc_hir_typeck/src/_match.rs | 2 +- compiler/rustc_hir_typeck/src/cast.rs | 4 +- compiler/rustc_hir_typeck/src/closure.rs | 4 +- compiler/rustc_hir_typeck/src/coercion.rs | 2 +- compiler/rustc_hir_typeck/src/expr.rs | 2 +- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 2 +- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 2 +- .../src/fn_ctxt/suggestions.rs | 2 +- .../src/generator_interior/mod.rs | 2 +- .../rustc_hir_typeck/src/method/suggest.rs | 2 +- compiler/rustc_hir_typeck/src/writeback.rs | 2 +- compiler/rustc_infer/src/infer/at.rs | 2 +- compiler/rustc_infer/src/infer/combine.rs | 2 +- compiler/rustc_infer/src/infer/equate.rs | 8 ++-- .../src/infer/error_reporting/mod.rs | 8 ++-- .../src/infer/error_reporting/suggest.rs | 8 ++-- compiler/rustc_infer/src/infer/lattice.rs | 8 ++-- .../rustc_infer/src/infer/nll_relate/mod.rs | 10 ++--- .../rustc_infer/src/infer/opaque_types.rs | 10 ++--- .../src/infer/outlives/components.rs | 4 +- .../src/infer/outlives/obligations.rs | 4 +- compiler/rustc_infer/src/infer/projection.rs | 2 +- .../src/infer/region_constraints/mod.rs | 2 +- compiler/rustc_infer/src/infer/sub.rs | 8 ++-- compiler/rustc_infer/src/traits/project.rs | 4 +- .../src/opaque_hidden_inferred_bound.rs | 2 +- compiler/rustc_lint/src/unused.rs | 4 +- compiler/rustc_middle/src/traits/mod.rs | 2 +- compiler/rustc_middle/src/traits/query.rs | 5 +-- compiler/rustc_middle/src/ty/context.rs | 17 ++++---- compiler/rustc_middle/src/ty/diagnostics.rs | 8 ++-- compiler/rustc_middle/src/ty/error.rs | 10 ++--- compiler/rustc_middle/src/ty/flags.rs | 4 +- compiler/rustc_middle/src/ty/mod.rs | 9 ++--- compiler/rustc_middle/src/ty/print/pretty.rs | 6 +-- compiler/rustc_middle/src/ty/relate.rs | 14 +++---- .../rustc_middle/src/ty/structural_impls.rs | 6 +-- compiler/rustc_middle/src/ty/sty.rs | 39 +++++++++---------- compiler/rustc_middle/src/ty/util.rs | 2 +- compiler/rustc_middle/src/ty/walk.rs | 2 +- compiler/rustc_mir_transform/src/inline.rs | 2 +- compiler/rustc_privacy/src/lib.rs | 12 ++---- compiler/rustc_symbol_mangling/src/legacy.rs | 4 +- compiler/rustc_symbol_mangling/src/v0.rs | 4 +- .../src/traits/error_reporting/suggestions.rs | 8 ++-- .../src/traits/project.rs | 20 +++++----- .../src/traits/query/normalize.rs | 2 +- .../src/traits/select/candidate_assembly.rs | 7 +--- .../src/traits/select/confirmation.rs | 2 +- .../src/traits/select/mod.rs | 4 +- .../rustc_trait_selection/src/traits/wf.rs | 6 +-- compiler/rustc_traits/src/chalk/db.rs | 4 +- compiler/rustc_traits/src/chalk/lowering.rs | 12 +++--- src/librustdoc/clean/mod.rs | 6 +-- .../clippy_lints/src/future_not_send.rs | 4 +- src/tools/clippy/clippy_utils/src/ty.rs | 18 ++++----- 66 files changed, 182 insertions(+), 197 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index c777f9a7401af..241f47ad14bf5 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -697,7 +697,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { .map_bound(|p| p.predicates), None, ), - ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + ty::Opaque(ty::AliasTy { def_id, substs }) => { find_fn_kind_from_did(tcx.bound_explicit_item_bounds(*def_id), Some(*substs)) } ty::Closure(_, substs) => match substs.as_closure().kind() { diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index b885590f7396f..27372b3b8fcde 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -504,7 +504,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let ErrorConstraintInfo { outlived_fr, span, .. } = errci; let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty; - if let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = *output_ty.kind() { + if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *output_ty.kind() { output_ty = self.infcx.tcx.type_of(def_id) }; diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 87dd0a665d340..a7276bf33b303 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -83,7 +83,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>( ConstValue::from_machine_usize(adt.variants().len() as u64, &tcx) } ty::Projection(_) - | ty::Opaque(ty::OpaqueTy { def_id: _, substs: _ }) + | ty::Opaque(ty::AliasTy { def_id: _, substs: _ }) | ty::Param(_) | ty::Placeholder(_) | ty::Infer(_) => throw_inval!(TooGeneric), diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 62ed8f0c0f7bb..0286c8f04f116 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -241,7 +241,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { }; let kind = match parent_ty.ty.kind() { - &ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + &ty::Opaque(ty::AliasTy { def_id, substs }) => { self.tcx.bound_type_of(def_id).subst(self.tcx, substs).kind() } kind => kind, diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index 5c78f63020d26..e0569987ee43d 100644 --- a/compiler/rustc_const_eval/src/util/type_name.rs +++ b/compiler/rustc_const_eval/src/util/type_name.rs @@ -58,8 +58,8 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { // Types with identity (print the module path). ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs) | ty::FnDef(def_id, substs) - | ty::Opaque(ty::OpaqueTy { def_id, substs }) - | ty::Projection(ty::ProjectionTy { def_id, substs }) + | ty::Opaque(ty::AliasTy { def_id, substs }) + | ty::Projection(ty::AliasTy { def_id, substs }) | ty::Closure(def_id, substs) | ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs), ty::Foreign(def_id) => self.print_def_path(def_id, &[]), diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 7c6b8a2455036..f91c17d5c03cf 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -1146,7 +1146,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { debug!(?substs_trait_ref_and_assoc_item); - ty::ProjectionTy { def_id: assoc_item.def_id, substs: substs_trait_ref_and_assoc_item } + ty::AliasTy { def_id: assoc_item.def_id, substs: substs_trait_ref_and_assoc_item } }); if !speculative { diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index c696f93897c13..9b42c16b88273 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -1440,7 +1440,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) -> E impl<'tcx> ty::visit::TypeVisitor<'tcx> for OpaqueTypeCollector { fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { match *t.kind() { - ty::Opaque(ty::OpaqueTy { def_id: def, substs: _ }) => { + ty::Opaque(ty::AliasTy { def_id: def, substs: _ }) => { self.0.push(def); ControlFlow::CONTINUE } diff --git a/compiler/rustc_hir_analysis/src/check/compare_method.rs b/compiler/rustc_hir_analysis/src/check/compare_method.rs index 1d720aa5d376d..d09c17e9f9b87 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_method.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_method.rs @@ -1746,7 +1746,7 @@ pub fn check_type_bounds<'tcx>( _ => predicates.push( ty::Binder::bind_with_vars( ty::ProjectionPredicate { - projection_ty: ty::ProjectionTy { + projection_ty: ty::AliasTy { def_id: trait_ty.def_id, substs: rebased_substs, }, diff --git a/compiler/rustc_hir_analysis/src/variance/constraints.rs b/compiler/rustc_hir_analysis/src/variance/constraints.rs index 31806ff6766ea..2d1b4fc4dc6fc 100644 --- a/compiler/rustc_hir_analysis/src/variance/constraints.rs +++ b/compiler/rustc_hir_analysis/src/variance/constraints.rs @@ -253,7 +253,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { self.add_constraints_from_invariant_substs(current, data.substs, variance); } - ty::Opaque(ty::OpaqueTy { def_id: _, substs }) => { + ty::Opaque(ty::AliasTy { def_id: _, substs }) => { self.add_constraints_from_invariant_substs(current, substs, variance); } diff --git a/compiler/rustc_hir_analysis/src/variance/mod.rs b/compiler/rustc_hir_analysis/src/variance/mod.rs index 9f8baa55bed67..3eb33319f7f5d 100644 --- a/compiler/rustc_hir_analysis/src/variance/mod.rs +++ b/compiler/rustc_hir_analysis/src/variance/mod.rs @@ -110,9 +110,9 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc #[instrument(level = "trace", skip(self), ret)] fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { - // FIXME(alias): merge these - match t.kind() { - ty::Opaque(ty::OpaqueTy { def_id, substs }) => self.visit_opaque(*def_id, substs), + // FIXME(alias): merge these + match t.kind() { + ty::Opaque(ty::AliasTy { def_id, substs }) => self.visit_opaque(*def_id, substs), ty::Projection(proj) if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder => { @@ -168,7 +168,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc } } ty::PredicateKind::Clause(ty::Clause::Projection(ty::ProjectionPredicate { - projection_ty: ty::ProjectionTy { substs, def_id: _ }, + projection_ty: ty::AliasTy { substs, def_id: _ }, term, })) => { for subst in &substs[1..] { diff --git a/compiler/rustc_hir_typeck/src/_match.rs b/compiler/rustc_hir_typeck/src/_match.rs index e3afc117bb2ad..32635f5a12b97 100644 --- a/compiler/rustc_hir_typeck/src/_match.rs +++ b/compiler/rustc_hir_typeck/src/_match.rs @@ -518,7 +518,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let substs = sig.output().walk().find_map(|arg| { if let ty::GenericArgKind::Type(ty) = arg.unpack() - && let ty::Opaque(ty::OpaqueTy { def_id, substs }) = *ty.kind() + && let ty::Opaque(ty::AliasTy { def_id, substs }) = *ty.kind() && def_id == rpit_def_id { Some(substs) diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 6035e6e4db41e..171086cf7244f 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -76,7 +76,7 @@ enum PointerKind<'tcx> { /// Slice Length, /// The unsize info of this projection - OfProjection(ty::ProjectionTy<'tcx>), + OfProjection(ty::AliasTy<'tcx>), /// The unsize info of this opaque ty OfOpaque(DefId, SubstsRef<'tcx>), /// The unsize info of this parameter @@ -119,7 +119,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Foreign(..) => Some(PointerKind::Thin), // We should really try to normalize here. ty::Projection(pi) => Some(PointerKind::OfProjection(pi)), - ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + ty::Opaque(ty::AliasTy { def_id, substs }) => { Some(PointerKind::OfOpaque(def_id, substs)) } ty::Param(p) => Some(PointerKind::OfParam(p)), diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 5d89e47e6e017..dd87a7f32d276 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -167,7 +167,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected_ty: Ty<'tcx>, ) -> (Option>, Option) { match *expected_ty.kind() { - ty::Opaque(ty::OpaqueTy { def_id, substs }) => self.deduce_signature_from_predicates( + ty::Opaque(ty::AliasTy { def_id, substs }) => self.deduce_signature_from_predicates( self.tcx.bound_explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs), ), ty::Dynamic(ref object_type, ..) => { @@ -677,7 +677,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { get_future_output(obligation.predicate, obligation.cause.span) })? } - ty::Opaque(ty::OpaqueTy { def_id, substs }) => self + ty::Opaque(ty::AliasTy { def_id, substs }) => self .tcx .bound_explicit_item_bounds(def_id) .subst_iter_copied(self.tcx, substs) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index 9dd3b3741f9df..a7593ecc57213 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1805,7 +1805,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { { let ty = >::ast_ty_to_ty(fcx, ty); // Get the `impl Trait`'s `DefId`. - if let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = ty.kind() + if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = ty.kind() // Get the `impl Trait`'s `Item` so that we can get its trait bounds and // get the `Trait`'s `DefId`. && let hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, .. }) = diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index bd226e1f8b18e..25a043fd40a52 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -2391,7 +2391,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Param(param_ty) => { self.point_at_param_definition(&mut err, param_ty); } - ty::Opaque(ty::OpaqueTy { def_id: _, substs: _ }) => { + ty::Opaque(ty::AliasTy { def_id: _, substs: _ }) => { self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs()); } _ => {} diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index a556af81b4f09..482fa046b4d31 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -716,7 +716,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if formal_ret.has_infer_types() { for ty in ret_ty.walk() { if let ty::subst::GenericArgKind::Type(ty) = ty.unpack() - && let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = *ty.kind() + && let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *ty.kind() && let Some(def_id) = def_id.as_local() && self.opaque_type_origin(def_id, DUMMY_SP).is_some() { return None; diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 77821556eaf09..6e26c413b1ccf 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -2124,7 +2124,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } } - ty::Opaque(ty::OpaqueTy { def_id: new_def_id, substs: _ }) + ty::Opaque(ty::AliasTy { def_id: new_def_id, substs: _ }) | ty::Closure(new_def_id, _) | ty::FnDef(new_def_id, _) => { def_id = new_def_id; diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index bed3fc1c53aac..21990775ad905 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -174,7 +174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let fn_sig = substs.as_closure().sig(); Some((DefIdOrName::DefId(def_id), fn_sig.output(), fn_sig.inputs().map_bound(|inputs| &inputs[1..]))) } - ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + ty::Opaque(ty::AliasTy { def_id, substs }) => { self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| { if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder() && Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() diff --git a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs index 58d1d39d215a5..3280f502cc74a 100644 --- a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs +++ b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs @@ -563,7 +563,7 @@ fn check_must_not_suspend_ty<'tcx>( } ty::Adt(def, _) => check_must_not_suspend_def(fcx.tcx, def.did(), hir_id, data), // FIXME: support adding the attribute to TAITs - ty::Opaque(ty::OpaqueTy { def_id: def, substs: _ }) => { + ty::Opaque(ty::AliasTy { def_id: def, substs: _ }) => { let mut has_emitted = false; for &(predicate, _) in fcx.tcx.explicit_item_bounds(def) { // We only look at the `DefId`, so it is safe to skip the binder here. diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 5451f41d94325..f27a19b2da1f9 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -557,7 +557,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .chain(projection_ty.substs.iter().skip(1)), ); - let quiet_projection_ty = ty::ProjectionTy { + let quiet_projection_ty = ty::AliasTy { substs: substs_with_infer_self, def_id: projection_ty.def_id, }; diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index f14cac868ea4b..e62332b38e716 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -546,7 +546,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { impl<'tcx> ty::TypeVisitor<'tcx> for RecursionChecker { type BreakTy = (); fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { - if let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = *t.kind() { + if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *t.kind() { if def_id == self.def_id.to_def_id() { return ControlFlow::Break(()); } diff --git a/compiler/rustc_infer/src/infer/at.rs b/compiler/rustc_infer/src/infer/at.rs index 1f2768f9884af..e9186540a7b7c 100644 --- a/compiler/rustc_infer/src/infer/at.rs +++ b/compiler/rustc_infer/src/infer/at.rs @@ -411,7 +411,7 @@ impl<'tcx> ToTrace<'tcx> for ty::PolyTraitRef<'tcx> { } } -impl<'tcx> ToTrace<'tcx> for ty::ProjectionTy<'tcx> { +impl<'tcx> ToTrace<'tcx> for ty::AliasTy<'tcx> { fn to_trace( tcx: TyCtxt<'tcx>, cause: &ObligationCause<'tcx>, diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index 4f6a0630d3d1f..dbf21a4e3fcfa 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -675,7 +675,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> { // relatable. Ok(t) } - ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + ty::Opaque(ty::AliasTy { def_id, substs }) => { let s = self.relate(substs, substs)?; Ok(if s == substs { t } else { self.infcx.tcx.mk_opaque(def_id, s) }) } diff --git a/compiler/rustc_infer/src/infer/equate.rs b/compiler/rustc_infer/src/infer/equate.rs index c0056c27a582d..f3d2d4f154778 100644 --- a/compiler/rustc_infer/src/infer/equate.rs +++ b/compiler/rustc_infer/src/infer/equate.rs @@ -101,13 +101,13 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> { } ( - &ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }), - &ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }), + &ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }), + &ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }), ) if a_def_id == b_def_id => { self.fields.infcx.super_combine_tys(self, a, b)?; } - (&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), _) - | (_, &ty::Opaque(ty::OpaqueTy { def_id, substs: _ })) + (&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _) + | (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ })) if self.fields.define_opaque_types && def_id.is_local() => { self.fields.obligations.extend( diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 615452d019de4..5b9f4d077736d 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -340,7 +340,7 @@ impl<'tcx> InferCtxt<'tcx> { pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option> { // FIXME(alias): Merge these let (def_id, substs) = match *ty.kind() { - ty::Opaque(ty::OpaqueTy { def_id, substs }) => (def_id, substs), + ty::Opaque(ty::AliasTy { def_id, substs }) => (def_id, substs), ty::Projection(data) if self.tcx.def_kind(data.def_id) == DefKind::ImplTraitPlaceholder => { @@ -1732,7 +1732,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let sort_string = |ty: Ty<'tcx>, path: Option| { // FIXME(alias): Merge these let mut s = match (extra, ty.kind()) { - (true, ty::Opaque(ty::OpaqueTy { def_id, .. })) => { + (true, ty::Opaque(ty::AliasTy { def_id, .. })) => { let sm = self.tcx.sess.source_map(); let pos = sm.lookup_char_pos(self.tcx.def_span(*def_id).lo()); format!( @@ -2386,7 +2386,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { // suggest: // fn get_later<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a ty::Closure(_, _substs) - | ty::Opaque(ty::OpaqueTy { def_id: _, substs: _substs }) + | ty::Opaque(ty::AliasTy { def_id: _, substs: _substs }) if return_impl_trait => { new_binding_suggestion(&mut err, type_param_span); @@ -2770,7 +2770,7 @@ impl TyCategory { pub fn from_ty(tcx: TyCtxt<'_>, ty: Ty<'_>) -> Option<(Self, DefId)> { match *ty.kind() { ty::Closure(def_id, _) => Some((Self::Closure, def_id)), - ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) => Some((Self::Opaque, def_id)), + ty::Opaque(ty::AliasTy { def_id, substs: _ }) => Some((Self::Opaque, def_id)), ty::Generator(def_id, ..) => { Some((Self::Generator(tcx.generator_kind(def_id).unwrap()), def_id)) } diff --git a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs index 7cac038927c74..e32f0edf3443e 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs @@ -487,12 +487,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { StatementAsExpression::CorrectType } ( - ty::Opaque(ty::OpaqueTy { def_id: last_def_id, substs: _ }), - ty::Opaque(ty::OpaqueTy { def_id: exp_def_id, substs: _ }), + ty::Opaque(ty::AliasTy { def_id: last_def_id, substs: _ }), + ty::Opaque(ty::AliasTy { def_id: exp_def_id, substs: _ }), ) if last_def_id == exp_def_id => StatementAsExpression::CorrectType, ( - ty::Opaque(ty::OpaqueTy { def_id: last_def_id, substs: last_bounds }), - ty::Opaque(ty::OpaqueTy { def_id: exp_def_id, substs: exp_bounds }), + ty::Opaque(ty::AliasTy { def_id: last_def_id, substs: last_bounds }), + ty::Opaque(ty::AliasTy { def_id: exp_def_id, substs: exp_bounds }), ) => { debug!( "both opaque, likely future {:?} {:?} {:?} {:?}", diff --git a/compiler/rustc_infer/src/infer/lattice.rs b/compiler/rustc_infer/src/infer/lattice.rs index 6513abd38795d..2202adede13c1 100644 --- a/compiler/rustc_infer/src/infer/lattice.rs +++ b/compiler/rustc_infer/src/infer/lattice.rs @@ -106,11 +106,11 @@ where } ( - &ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }), - &ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }), + &ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }), + &ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }), ) if a_def_id == b_def_id => infcx.super_combine_tys(this, a, b), - (&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), _) - | (_, &ty::Opaque(ty::OpaqueTy { def_id, substs: _ })) + (&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _) + | (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ })) if this.define_opaque_types() && def_id.is_local() => { this.add_obligations( diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index e0f9220ca5f08..f6c2dd8a99b8f 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -275,7 +275,7 @@ where /// `ProjectionEq(projection = ?U)`, `ProjectionEq(other_projection = ?U)`. fn relate_projection_ty( &mut self, - projection_ty: ty::ProjectionTy<'tcx>, + projection_ty: ty::AliasTy<'tcx>, value_ty: Ty<'tcx>, ) -> Ty<'tcx> { use rustc_span::DUMMY_SP; @@ -609,8 +609,8 @@ where (&ty::Infer(ty::TyVar(vid)), _) => self.relate_ty_var((vid, b)), ( - &ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }), - &ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }), + &ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }), + &ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }), ) if a_def_id == b_def_id => infcx.super_combine_tys(self, a, b).or_else(|err| { self.tcx().sess.delay_span_bug( self.delegate.span(), @@ -618,8 +618,8 @@ where ); if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) } }), - (&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), _) - | (_, &ty::Opaque(ty::OpaqueTy { def_id, substs: _ })) + (&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _) + | (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ })) if def_id.is_local() => { self.relate_opaques(a, b) diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index 25edfd0928a21..065a7987a0df6 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -66,7 +66,7 @@ impl<'tcx> InferCtxt<'tcx> { lt_op: |lt| lt, ct_op: |ct| ct, ty_op: |ty| match *ty.kind() { - ty::Opaque(ty::OpaqueTy { def_id, substs: _substs }) + ty::Opaque(ty::AliasTy { def_id, substs: _substs }) if replace_opaque_type(def_id) => { let def_span = self.tcx.def_span(def_id); @@ -106,7 +106,7 @@ impl<'tcx> InferCtxt<'tcx> { } let (a, b) = if a_is_expected { (a, b) } else { (b, a) }; let process = |a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected| match *a.kind() { - ty::Opaque(ty::OpaqueTy { def_id, substs }) if def_id.is_local() => { + ty::Opaque(ty::AliasTy { def_id, substs }) if def_id.is_local() => { let def_id = def_id.expect_local(); let origin = match self.defining_use_anchor { DefiningAnchor::Bind(_) => { @@ -149,7 +149,7 @@ impl<'tcx> InferCtxt<'tcx> { DefiningAnchor::Bubble => self.opaque_ty_origin_unchecked(def_id, cause.span), DefiningAnchor::Error => return None, }; - if let ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }) = *b.kind() { + if let ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }) = *b.kind() { // We could accept this, but there are various ways to handle this situation, and we don't // want to make a decision on it right now. Likely this case is so super rare anyway, that // no one encounters it in practice. @@ -478,7 +478,7 @@ where substs.as_generator().resume_ty().visit_with(self); } - ty::Opaque(ty::OpaqueTy { def_id, ref substs }) => { + ty::Opaque(ty::AliasTy { def_id, ref substs }) => { // Skip lifetime paramters that are not captures. let variances = self.tcx.variances_of(*def_id); @@ -581,7 +581,7 @@ impl<'tcx> InferCtxt<'tcx> { } // Replace all other mentions of the same opaque type with the hidden type, // as the bounds must hold on the hidden type after all. - ty::Opaque(ty::OpaqueTy { def_id: def_id2, substs: substs2 }) + ty::Opaque(ty::AliasTy { def_id: def_id2, substs: substs2 }) if def_id.to_def_id() == def_id2 && substs == substs2 => { hidden_ty diff --git a/compiler/rustc_infer/src/infer/outlives/components.rs b/compiler/rustc_infer/src/infer/outlives/components.rs index ea3b0efb85bb1..75d70abb56fb0 100644 --- a/compiler/rustc_infer/src/infer/outlives/components.rs +++ b/compiler/rustc_infer/src/infer/outlives/components.rs @@ -23,7 +23,7 @@ pub enum Component<'tcx> { // is not in a position to judge which is the best technique, so // we just product the projection as a component and leave it to // the consumer to decide (but see `EscapingProjection` below). - Projection(ty::ProjectionTy<'tcx>), + Projection(ty::AliasTy<'tcx>), // In the case where a projection has escaping regions -- meaning // regions bound within the type itself -- we always use @@ -130,7 +130,7 @@ fn compute_components<'tcx>( // outlives any other lifetime, which is unsound. // See https://github.com/rust-lang/rust/issues/84305 for // more details. - ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + ty::Opaque(ty::AliasTy { def_id, substs }) => { out.push(Component::Opaque(def_id, substs)); }, diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index c496b040edbbe..bf583547491e1 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -338,7 +338,7 @@ where substs, true, |ty| match *ty.kind() { - ty::Opaque(ty::OpaqueTy { def_id, substs }) => (def_id, substs), + ty::Opaque(ty::AliasTy { def_id, substs }) => (def_id, substs), _ => bug!("expected only projection types from env, not {:?}", ty), }, ); @@ -349,7 +349,7 @@ where &mut self, origin: infer::SubregionOrigin<'tcx>, region: ty::Region<'tcx>, - projection_ty: ty::ProjectionTy<'tcx>, + projection_ty: ty::AliasTy<'tcx>, ) { self.generic_must_outlive( origin, diff --git a/compiler/rustc_infer/src/infer/projection.rs b/compiler/rustc_infer/src/infer/projection.rs index d81e09fcb5d05..4667d99ff0008 100644 --- a/compiler/rustc_infer/src/infer/projection.rs +++ b/compiler/rustc_infer/src/infer/projection.rs @@ -16,7 +16,7 @@ impl<'tcx> InferCtxt<'tcx> { pub fn infer_projection( &self, param_env: ty::ParamEnv<'tcx>, - projection_ty: ty::ProjectionTy<'tcx>, + projection_ty: ty::AliasTy<'tcx>, cause: ObligationCause<'tcx>, recursion_depth: usize, obligations: &mut Vec>, diff --git a/compiler/rustc_infer/src/infer/region_constraints/mod.rs b/compiler/rustc_infer/src/infer/region_constraints/mod.rs index 7b0d0a9cb5291..9a427ceacd0a7 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/mod.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/mod.rs @@ -169,7 +169,7 @@ pub struct Verify<'tcx> { #[derive(Copy, Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)] pub enum GenericKind<'tcx> { Param(ty::ParamTy), - Projection(ty::ProjectionTy<'tcx>), + Projection(ty::AliasTy<'tcx>), Opaque(DefId, SubstsRef<'tcx>), } diff --git a/compiler/rustc_infer/src/infer/sub.rs b/compiler/rustc_infer/src/infer/sub.rs index f05d661451571..6b5000c37c56c 100644 --- a/compiler/rustc_infer/src/infer/sub.rs +++ b/compiler/rustc_infer/src/infer/sub.rs @@ -131,14 +131,14 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> { } ( - &ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: _ }), - &ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: _ }), + &ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }), + &ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }), ) if a_def_id == b_def_id => { self.fields.infcx.super_combine_tys(self, a, b)?; Ok(a) } - (&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), _) - | (_, &ty::Opaque(ty::OpaqueTy { def_id, substs: _ })) + (&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _) + | (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ })) if self.fields.define_opaque_types && def_id.is_local() => { self.fields.obligations.extend( diff --git a/compiler/rustc_infer/src/traits/project.rs b/compiler/rustc_infer/src/traits/project.rs index 5d22f9f972e10..aade57be9fe6e 100644 --- a/compiler/rustc_infer/src/traits/project.rs +++ b/compiler/rustc_infer/src/traits/project.rs @@ -77,11 +77,11 @@ pub struct ProjectionCacheStorage<'tcx> { #[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)] pub struct ProjectionCacheKey<'tcx> { - ty: ty::ProjectionTy<'tcx>, + ty: ty::AliasTy<'tcx>, } impl<'tcx> ProjectionCacheKey<'tcx> { - pub fn new(ty: ty::ProjectionTy<'tcx>) -> Self { + pub fn new(ty: ty::AliasTy<'tcx>) -> Self { Self { ty } } } diff --git a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs index f745e8201a859..6cd806354bbdb 100644 --- a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs +++ b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs @@ -117,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { // then we can emit a suggestion to add the bound. let add_bound = match (proj_term.kind(), assoc_pred.kind().skip_binder()) { ( - ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), + ty::Opaque(ty::AliasTy { def_id, substs: _ }), ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)), ) => Some(AddBound { suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(), diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 14882be3e012c..6851f6f9d6b0d 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { if let hir::ExprKind::Match(await_expr, _arms, hir::MatchSource::AwaitDesugar) = expr.kind && let ty = cx.typeck_results().expr_ty(&await_expr) - && let ty::Opaque(ty::OpaqueTy { def_id: future_def_id, substs: _ }) = ty.kind() + && let ty::Opaque(ty::AliasTy { def_id: future_def_id, substs: _ }) = ty.kind() && cx.tcx.ty_is_opaque_future(ty) // FIXME: This also includes non-async fns that return `impl Future`. && let async_fn_def_id = cx.tcx.parent(*future_def_id) @@ -251,7 +251,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { .map(|inner| MustUsePath::Boxed(Box::new(inner))) } ty::Adt(def, _) => is_def_must_use(cx, def.did(), span), - ty::Opaque(ty::OpaqueTy { def_id: def, substs: _ }) => { + ty::Opaque(ty::AliasTy { def_id: def, substs: _ }) => { elaborate_predicates_with_span( cx.tcx, cx.tcx.explicit_item_bounds(def).iter().cloned(), diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 143435cb2a1f4..d00b26a5a3d0b 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -250,7 +250,7 @@ pub enum ObligationCauseCode<'tcx> { TupleElem, /// This is the trait reference from the given projection. - ProjectionWf(ty::ProjectionTy<'tcx>), + ProjectionWf(ty::AliasTy<'tcx>), /// Must satisfy all of the where-clause predicates of the /// given item. diff --git a/compiler/rustc_middle/src/traits/query.rs b/compiler/rustc_middle/src/traits/query.rs index d40d7de5f315f..7380c62a6693a 100644 --- a/compiler/rustc_middle/src/traits/query.rs +++ b/compiler/rustc_middle/src/traits/query.rs @@ -76,8 +76,7 @@ pub mod type_op { } } -pub type CanonicalProjectionGoal<'tcx> = - Canonical<'tcx, ty::ParamEnvAnd<'tcx, ty::ProjectionTy<'tcx>>>; +pub type CanonicalProjectionGoal<'tcx> = Canonical<'tcx, ty::ParamEnvAnd<'tcx, ty::AliasTy<'tcx>>>; pub type CanonicalTyGoal<'tcx> = Canonical<'tcx, ty::ParamEnvAnd<'tcx, Ty<'tcx>>>; @@ -218,6 +217,6 @@ pub struct NormalizationResult<'tcx> { pub enum OutlivesBound<'tcx> { RegionSubRegion(ty::Region<'tcx>, ty::Region<'tcx>), RegionSubParam(ty::Region<'tcx>, ty::ParamTy), - RegionSubProjection(ty::Region<'tcx>, ty::ProjectionTy<'tcx>), + RegionSubProjection(ty::Region<'tcx>, ty::AliasTy<'tcx>), RegionSubOpaque(ty::Region<'tcx>, DefId, SubstsRef<'tcx>), } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 938eb664da951..fe65f6b2ae5ec 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -18,12 +18,11 @@ use crate::thir::Thir; use crate::traits; use crate::ty::query::{self, TyCtxtAt}; use crate::ty::{ - self, AdtDef, AdtDefData, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig, + self, AdtDef, AdtDefData, AdtKind, AliasTy, Binder, BindingMode, BoundVar, CanonicalPolyFnSig, ClosureSizeProfileData, Const, ConstS, DefIdTree, FloatTy, FloatVar, FloatVid, GenericParamDefKind, InferTy, IntTy, IntVar, IntVid, List, ParamConst, ParamTy, - PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, ProjectionTy, Region, - RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyVar, TyVid, TypeAndMut, UintTy, - Visibility, + PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, Region, RegionKind, ReprOptions, + TraitObjectVisitor, Ty, TyKind, TyVar, TyVid, TypeAndMut, UintTy, Visibility, }; use crate::ty::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef, UserSubsts}; use rustc_ast as ast; @@ -116,8 +115,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> { type ListBinderExistentialPredicate = &'tcx List>; type BinderListTy = Binder<'tcx, &'tcx List>>; type ListTy = &'tcx List>; - type ProjectionTy = ty::ProjectionTy<'tcx>; - type OpaqueTy = ty::OpaqueTy<'tcx>; + type ProjectionTy = ty::AliasTy<'tcx>; + type OpaqueTy = ty::AliasTy<'tcx>; type ParamTy = ParamTy; type BoundTy = ty::BoundTy; type PlaceholderType = ty::PlaceholderType; @@ -2324,7 +2323,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Given a `ty`, return whether it's an `impl Future<...>`. pub fn ty_is_opaque_future(self, ty: Ty<'_>) -> bool { - let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = ty.kind() else { return false }; + let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = ty.kind() else { return false }; let future_trait = self.require_lang_item(LangItem::Future, None); self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| { @@ -2599,7 +2598,7 @@ impl<'tcx> TyCtxt<'tcx> { substs.len(), "wrong number of generic parameters for {item_def_id:?}: {substs:?}", ); - self.mk_ty(Projection(ProjectionTy { def_id: item_def_id, substs })) + self.mk_ty(Projection(AliasTy { def_id: item_def_id, substs })) } #[inline] @@ -2669,7 +2668,7 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> { - self.mk_ty(Opaque(ty::OpaqueTy { def_id, substs })) + self.mk_ty(Opaque(ty::AliasTy { def_id, substs })) } pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> { diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 8657010eb1b92..cdde8d380e41f 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -3,8 +3,8 @@ use std::ops::ControlFlow; use crate::ty::{ - visit::TypeVisitable, Const, ConstKind, DefIdTree, ExistentialPredicate, InferConst, InferTy, - OpaqueTy, PolyTraitPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor, + visit::TypeVisitable, AliasTy, Const, ConstKind, DefIdTree, ExistentialPredicate, InferConst, + InferTy, PolyTraitPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor, }; use rustc_data_structures::fx::FxHashMap; @@ -457,10 +457,10 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> { return ControlFlow::Break(()); } - Opaque(OpaqueTy { def_id, substs: _ }) => { + Opaque(AliasTy { def_id, substs: _ }) => { let parent = self.tcx.parent(*def_id); if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent) - && let Opaque(OpaqueTy { def_id: parent_opaque_def_id, substs: _ }) = self.tcx.type_of(parent).kind() + && let Opaque(AliasTy { def_id: parent_opaque_def_id, substs: _ }) = self.tcx.type_of(parent).kind() && parent_opaque_def_id == def_id { // Okay diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 32bc53203c1c3..15eae4b0aed29 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -624,7 +624,7 @@ impl Trait for X { diag: &mut Diagnostic, msg: &str, body_owner_def_id: DefId, - proj_ty: &ty::ProjectionTy<'tcx>, + proj_ty: &ty::AliasTy<'tcx>, ty: Ty<'tcx>, ) -> bool { let assoc = self.associated_item(proj_ty.def_id); @@ -680,7 +680,7 @@ impl Trait for X { fn expected_projection( self, diag: &mut Diagnostic, - proj_ty: &ty::ProjectionTy<'tcx>, + proj_ty: &ty::AliasTy<'tcx>, values: ExpectedFound>, body_owner_def_id: DefId, cause_code: &ObligationCauseCode<'_>, @@ -775,11 +775,11 @@ fn foo(&self) -> Self::T { String::new() } self, diag: &mut Diagnostic, msg: &str, - proj_ty: &ty::ProjectionTy<'tcx>, + proj_ty: &ty::AliasTy<'tcx>, ty: Ty<'tcx>, ) -> bool { let assoc = self.associated_item(proj_ty.def_id); - if let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = *proj_ty.self_ty().kind() { + if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *proj_ty.self_ty().kind() { let opaque_local_def_id = def_id.as_local(); let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id { match &self.hir().expect_item(opaque_local_def_id).kind { @@ -828,7 +828,7 @@ fn foo(&self) -> Self::T { String::new() } .filter_map(|(_, item)| { let method = self.fn_sig(item.def_id); match *method.output().skip_binder().kind() { - ty::Projection(ty::ProjectionTy { def_id: item_def_id, .. }) + ty::Projection(ty::AliasTy { def_id: item_def_id, .. }) if item_def_id == proj_ty_item_def_id => { Some(( diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index cd93eb71f71f2..d30882c6a81d9 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -160,7 +160,7 @@ impl FlagComputation { self.add_projection_ty(data); } - &ty::Opaque(ty::OpaqueTy { def_id: _, substs }) => { + &ty::Opaque(ty::AliasTy { def_id: _, substs }) => { self.add_flags(TypeFlags::HAS_TY_OPAQUE); self.add_substs(substs); } @@ -345,7 +345,7 @@ impl FlagComputation { } } - fn add_projection_ty(&mut self, projection_ty: ty::ProjectionTy<'_>) { + fn add_projection_ty(&mut self, projection_ty: ty::AliasTy<'_>) { self.add_substs(projection_ty.substs); } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 5e173df2eb6f8..ea508a0b97200 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -93,14 +93,13 @@ pub use self::parameterized::ParameterizedOverTcx; pub use self::rvalue_scopes::RvalueScopes; pub use self::sty::BoundRegionKind::*; pub use self::sty::{ - Article, Binder, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind, BoundVar, + AliasTy, Article, Binder, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind, BoundVar, BoundVariableKind, CanonicalPolyFnSig, ClosureSubsts, ClosureSubstsParts, ConstVid, EarlyBoundRegion, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FnSig, FreeRegion, GenSig, GeneratorSubsts, GeneratorSubstsParts, InlineConstSubsts, - InlineConstSubstsParts, OpaqueTy, ParamConst, ParamTy, PolyExistentialPredicate, + InlineConstSubstsParts, ParamConst, ParamTy, PolyExistentialPredicate, PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef, - ProjectionTy, Region, RegionKind, RegionVid, TraitRef, TyKind, TypeAndMut, UpvarSubsts, - VarianceDiagInfo, + Region, RegionKind, RegionVid, TraitRef, TyKind, TypeAndMut, UpvarSubsts, VarianceDiagInfo, }; pub use self::trait_def::TraitDef; @@ -1010,7 +1009,7 @@ impl<'tcx> TermKind<'tcx> { #[derive(Copy, Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct ProjectionPredicate<'tcx> { - pub projection_ty: ProjectionTy<'tcx>, + pub projection_ty: AliasTy<'tcx>, pub term: Term<'tcx>, } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 37735fbb1651a..437049947966a 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -728,7 +728,7 @@ pub trait PrettyPrinter<'tcx>: } } ty::Placeholder(placeholder) => p!(write("Placeholder({:?})", placeholder)), - ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + ty::Opaque(ty::AliasTy { def_id, substs }) => { // FIXME(eddyb) print this with `print_def_path`. // We use verbose printing in 'NO_QUERIES' mode, to // avoid needing to call `predicates_of`. This should @@ -743,7 +743,7 @@ pub trait PrettyPrinter<'tcx>: let parent = self.tcx().parent(def_id); match self.tcx().def_kind(parent) { DefKind::TyAlias | DefKind::AssocTy => { - if let ty::Opaque(ty::OpaqueTy { def_id: d, substs: _ }) = + if let ty::Opaque(ty::AliasTy { def_id: d, substs: _ }) = *self.tcx().type_of(parent).kind() { if d == def_id { @@ -2742,7 +2742,7 @@ define_print_and_forward_display! { } } - ty::ProjectionTy<'tcx> { + ty::AliasTy<'tcx> { p!(print_def_path(self.def_id, self.substs)); } diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 0c5e6e1564947..108166c605d12 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -270,17 +270,17 @@ impl<'tcx> Relate<'tcx> for abi::Abi { } } -impl<'tcx> Relate<'tcx> for ty::ProjectionTy<'tcx> { +impl<'tcx> Relate<'tcx> for ty::AliasTy<'tcx> { fn relate>( relation: &mut R, - a: ty::ProjectionTy<'tcx>, - b: ty::ProjectionTy<'tcx>, - ) -> RelateResult<'tcx, ty::ProjectionTy<'tcx>> { + a: ty::AliasTy<'tcx>, + b: ty::AliasTy<'tcx>, + ) -> RelateResult<'tcx, ty::AliasTy<'tcx>> { if a.def_id != b.def_id { Err(TypeError::ProjectionMismatched(expected_found(relation, a.def_id, b.def_id))) } else { let substs = relation.relate(a.substs, b.substs)?; - Ok(ty::ProjectionTy { def_id: a.def_id, substs: &substs }) + Ok(ty::AliasTy { def_id: a.def_id, substs: &substs }) } } } @@ -557,8 +557,8 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( } ( - &ty::Opaque(ty::OpaqueTy { def_id: a_def_id, substs: a_substs }), - &ty::Opaque(ty::OpaqueTy { def_id: b_def_id, substs: b_substs }), + &ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: a_substs }), + &ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: b_substs }), ) if a_def_id == b_def_id => { if relation.intercrate() { // During coherence, opaque types should be treated as equal to each other, even if their generic params diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 69627385235cc..9d6a55b15f2c3 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -652,8 +652,8 @@ impl<'tcx> TypeSuperFoldable<'tcx> for Ty<'tcx> { ty::GeneratorWitness(types) => ty::GeneratorWitness(types.try_fold_with(folder)?), ty::Closure(did, substs) => ty::Closure(did, substs.try_fold_with(folder)?), ty::Projection(data) => ty::Projection(data.try_fold_with(folder)?), - ty::Opaque(ty::OpaqueTy { def_id, substs }) => { - ty::Opaque(ty::OpaqueTy { def_id, substs: substs.try_fold_with(folder)? }) + ty::Opaque(ty::AliasTy { def_id, substs }) => { + ty::Opaque(ty::AliasTy { def_id, substs: substs.try_fold_with(folder)? }) } ty::Bool @@ -700,7 +700,7 @@ impl<'tcx> TypeSuperVisitable<'tcx> for Ty<'tcx> { ty::GeneratorWitness(ref types) => types.visit_with(visitor), ty::Closure(_did, ref substs) => substs.visit_with(visitor), ty::Projection(ref data) => data.visit_with(visitor), - ty::Opaque(ty::OpaqueTy { def_id: _, ref substs }) => substs.visit_with(visitor), + ty::Opaque(ty::AliasTy { def_id: _, ref substs }) => substs.visit_with(visitor), ty::Bool | ty::Char diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 6d63c5ee9389e..cf872365d2004 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1139,15 +1139,19 @@ impl<'tcx, T: IntoIterator> Binder<'tcx, T> { } } -/// Represents the projection of an associated type. In explicit UFCS -/// form this would be written `>::N`. +/// Represents the projection of an associated type. +/// +/// For a projection, this would be `>::N`. +/// +/// For an opaque type, there is no explicit syntax. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] -pub struct ProjectionTy<'tcx> { - /// The parameters of the associated item. +pub struct AliasTy<'tcx> { + /// The parameters of the associated or opaque item. pub substs: SubstsRef<'tcx>, - /// The `DefId` of the `TraitItem` for the associated type `N`. + /// The `DefId` of the `TraitItem` for the associated type `N` if this is a projection, + /// or the `OpaqueType` item if this is an opaque. /// /// Note that this is not the `DefId` of the `TraitRef` containing this /// associated type, which is in `tcx.associated_item(item_def_id).container`, @@ -1155,7 +1159,7 @@ pub struct ProjectionTy<'tcx> { pub def_id: DefId, } -impl<'tcx> ProjectionTy<'tcx> { +impl<'tcx> AliasTy<'tcx> { pub fn trait_def_id(&self, tcx: TyCtxt<'tcx>) -> DefId { match tcx.def_kind(self.def_id) { DefKind::AssocTy | DefKind::AssocConst => tcx.parent(self.def_id), @@ -1173,11 +1177,14 @@ impl<'tcx> ProjectionTy<'tcx> { &self, tcx: TyCtxt<'tcx>, ) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) { - let def_id = tcx.parent(self.def_id); - assert_eq!(tcx.def_kind(def_id), DefKind::Trait); - let trait_generics = tcx.generics_of(def_id); + debug_assert!(matches!(tcx.def_kind(self.def_id), DefKind::AssocTy | DefKind::AssocConst)); + let trait_def_id = self.trait_def_id(tcx); + let trait_generics = tcx.generics_of(trait_def_id); ( - ty::TraitRef { def_id, substs: self.substs.truncate_to(tcx, trait_generics) }, + ty::TraitRef { + def_id: trait_def_id, + substs: self.substs.truncate_to(tcx, trait_generics), + }, &self.substs[trait_generics.count()..], ) } @@ -1199,16 +1206,6 @@ impl<'tcx> ProjectionTy<'tcx> { } } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, TyEncodable, TyDecodable)] -#[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] -pub struct OpaqueTy<'tcx> { - /// The parameters of the opaque. - pub substs: SubstsRef<'tcx>, - - /// The `DefId` of the `impl Trait`. - pub def_id: DefId, -} - #[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable, Lift)] pub struct GenSig<'tcx> { pub resume_ty: Ty<'tcx>, @@ -1443,7 +1440,7 @@ impl<'tcx> ExistentialProjection<'tcx> { debug_assert!(!self_ty.has_escaping_bound_vars()); ty::ProjectionPredicate { - projection_ty: ty::ProjectionTy { + projection_ty: ty::AliasTy { def_id: self.def_id, substs: tcx.mk_substs_trait(self_ty, self.substs), }, diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index c1ef703e62da4..b2ed9ca420049 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -826,7 +826,7 @@ impl<'tcx> TypeFolder<'tcx> for OpaqueTypeExpander<'tcx> { } fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Opaque(ty::OpaqueTy { def_id, substs }) = *t.kind() { + if let ty::Opaque(ty::AliasTy { def_id, substs }) = *t.kind() { self.expand_opaque_ty(def_id, substs).unwrap_or(t) } else if t.has_opaque_types() { t.super_fold_with(self) diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index 958549e11ca9a..e79b5bcae5da9 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -188,7 +188,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) })); } ty::Adt(_, substs) - | ty::Opaque(ty::OpaqueTy { def_id: _, substs }) + | ty::Opaque(ty::AliasTy { def_id: _, substs }) | ty::Closure(_, substs) | ty::Generator(_, substs, _) | ty::FnDef(_, substs) => { diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index ecf05cc32190e..f887dc5f2eab7 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -849,7 +849,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> { }; let kind = match parent_ty.ty.kind() { - &ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + &ty::Opaque(ty::AliasTy { def_id, substs }) => { self.tcx.bound_type_of(def_id).subst(self.tcx, substs).kind() } kind => kind, diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index d077b2852ba9d..3246a1e2f88c9 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -88,10 +88,7 @@ trait DefIdVisitor<'tcx> { fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> ControlFlow { self.skeleton().visit_trait(trait_ref) } - fn visit_projection_ty( - &mut self, - projection: ty::ProjectionTy<'tcx>, - ) -> ControlFlow { + fn visit_projection_ty(&mut self, projection: ty::AliasTy<'tcx>) -> ControlFlow { self.skeleton().visit_projection_ty(projection) } fn visit_predicates( @@ -118,10 +115,7 @@ where if self.def_id_visitor.shallow() { ControlFlow::CONTINUE } else { substs.visit_with(self) } } - fn visit_projection_ty( - &mut self, - projection: ty::ProjectionTy<'tcx>, - ) -> ControlFlow { + fn visit_projection_ty(&mut self, projection: ty::AliasTy<'tcx>) -> ControlFlow { let tcx = self.def_id_visitor.tcx(); let (trait_ref, assoc_substs) = if tcx.def_kind(projection.def_id) != DefKind::ImplTraitPlaceholder @@ -241,7 +235,7 @@ where self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref)?; } } - ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) => { + ty::Opaque(ty::AliasTy { def_id, substs: _ }) => { // Skip repeated `Opaque`s to avoid infinite recursion. if self.visited_opaque_tys.insert(def_id) { // The intent is to treat `impl Trait1 + Trait2` identically to diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index e957829054a4c..d21288d851cec 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -216,8 +216,8 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> { match *ty.kind() { // Print all nominal types as paths (unlike `pretty_print_type`). ty::FnDef(def_id, substs) - | ty::Opaque(ty::OpaqueTy { def_id, substs }) - | ty::Projection(ty::ProjectionTy { def_id, substs }) + | ty::Opaque(ty::AliasTy { def_id, substs }) + | ty::Projection(ty::AliasTy { def_id, substs }) | ty::Closure(def_id, substs) | ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs), diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index c24b83060db40..52d0469fd445f 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -439,8 +439,8 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { // Mangle all nominal types as paths. ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs) | ty::FnDef(def_id, substs) - | ty::Opaque(ty::OpaqueTy { def_id, substs }) - | ty::Projection(ty::ProjectionTy { def_id, substs }) + | ty::Opaque(ty::AliasTy { def_id, substs }) + | ty::Projection(ty::AliasTy { def_id, substs }) | ty::Closure(def_id, substs) | ty::Generator(def_id, substs, _) => { self = self.print_def_path(def_id, substs)?; diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index c685a652b3ab9..6c9c516b305f8 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -369,7 +369,7 @@ fn suggest_restriction<'tcx>( msg: &str, err: &mut Diagnostic, fn_sig: Option<&hir::FnSig<'_>>, - projection: Option<&ty::ProjectionTy<'_>>, + projection: Option<&ty::AliasTy<'_>>, trait_pred: ty::PolyTraitPredicate<'tcx>, // When we are dealing with a trait, `super_traits` will be `Some`: // Given `trait T: A + B + C {}` @@ -855,7 +855,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { fn_sig.inputs().map_bound(|inputs| &inputs[1..]), )) } - ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + ty::Opaque(ty::AliasTy { def_id, substs }) => { self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| { if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder() && Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() @@ -2644,7 +2644,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { Some(ident) => err.span_note(ident.span, &msg), None => err.note(&msg), }, - ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) => { + ty::Opaque(ty::AliasTy { def_id, substs: _ }) => { // Avoid printing the future from `core::future::identity_future`, it's not helpful if tcx.parent(*def_id) == identity_future { break 'print; @@ -3248,7 +3248,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // This corresponds to `::Item = _`. let trait_ref = ty::Binder::dummy(ty::PredicateKind::Clause( ty::Clause::Projection(ty::ProjectionPredicate { - projection_ty: ty::ProjectionTy { substs, def_id: proj.def_id }, + projection_ty: ty::AliasTy { substs, def_id: proj.def_id }, term: ty_var.into(), }), )); diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index a2f813dc88e43..ea9c066566e3d 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -45,7 +45,7 @@ pub type PolyProjectionObligation<'tcx> = Obligation<'tcx, ty::PolyProjectionPre pub type ProjectionObligation<'tcx> = Obligation<'tcx, ty::ProjectionPredicate<'tcx>>; -pub type ProjectionTyObligation<'tcx> = Obligation<'tcx, ty::ProjectionTy<'tcx>>; +pub type ProjectionTyObligation<'tcx> = Obligation<'tcx, ty::AliasTy<'tcx>>; pub(super) struct InProgress; @@ -496,7 +496,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { // This is really important. While we *can* handle this, this has // severe performance implications for large opaque types with // late-bound regions. See `issue-88862` benchmark. - ty::Opaque(ty::OpaqueTy { def_id, substs }) if !substs.has_escaping_bound_vars() => { + ty::Opaque(ty::AliasTy { def_id, substs }) if !substs.has_escaping_bound_vars() => { // Only normalize `impl Trait` outside of type inference, usually in codegen. match self.param_env.reveal() { Reveal::UserFacing => ty.super_fold_with(self), @@ -957,7 +957,7 @@ impl<'tcx> TypeFolder<'tcx> for PlaceholderReplacer<'_, 'tcx> { pub fn normalize_projection_type<'a, 'b, 'tcx>( selcx: &'a mut SelectionContext<'b, 'tcx>, param_env: ty::ParamEnv<'tcx>, - projection_ty: ty::ProjectionTy<'tcx>, + projection_ty: ty::AliasTy<'tcx>, cause: ObligationCause<'tcx>, depth: usize, obligations: &mut Vec>, @@ -995,7 +995,7 @@ pub fn normalize_projection_type<'a, 'b, 'tcx>( fn opt_normalize_projection_type<'a, 'b, 'tcx>( selcx: &'a mut SelectionContext<'b, 'tcx>, param_env: ty::ParamEnv<'tcx>, - projection_ty: ty::ProjectionTy<'tcx>, + projection_ty: ty::AliasTy<'tcx>, cause: ObligationCause<'tcx>, depth: usize, obligations: &mut Vec>, @@ -1177,7 +1177,7 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>( fn normalize_to_error<'a, 'tcx>( selcx: &mut SelectionContext<'a, 'tcx>, param_env: ty::ParamEnv<'tcx>, - projection_ty: ty::ProjectionTy<'tcx>, + projection_ty: ty::AliasTy<'tcx>, cause: ObligationCause<'tcx>, depth: usize, ) -> NormalizedTy<'tcx> { @@ -1376,7 +1376,7 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>( // If so, extract what we know from the trait and try to come up with a good answer. let bounds = match *obligation.predicate.self_ty().kind() { ty::Projection(ref data) => tcx.bound_item_bounds(data.def_id).subst(tcx, data.substs), - ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + ty::Opaque(ty::AliasTy { def_id, substs }) => { tcx.bound_item_bounds(def_id).subst(tcx, substs) } ty::Infer(ty::TyVar(_)) => { @@ -1870,7 +1870,7 @@ fn confirm_generator_candidate<'cx, 'tcx>( }; ty::ProjectionPredicate { - projection_ty: ty::ProjectionTy { + projection_ty: ty::AliasTy { substs: trait_ref.substs, def_id: obligation.predicate.def_id, }, @@ -1912,7 +1912,7 @@ fn confirm_future_candidate<'cx, 'tcx>( debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output); ty::ProjectionPredicate { - projection_ty: ty::ProjectionTy { + projection_ty: ty::AliasTy { substs: trait_ref.substs, def_id: obligation.predicate.def_id, }, @@ -1969,7 +1969,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>( }; let predicate = ty::ProjectionPredicate { - projection_ty: ty::ProjectionTy { substs, def_id: item_def_id }, + projection_ty: ty::AliasTy { substs, def_id: item_def_id }, term, }; @@ -2040,7 +2040,7 @@ fn confirm_callable_candidate<'cx, 'tcx>( flag, ) .map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate { - projection_ty: ty::ProjectionTy { substs: trait_ref.substs, def_id: fn_once_output_def_id }, + projection_ty: ty::AliasTy { substs: trait_ref.substs, def_id: fn_once_output_def_id }, term: ret_type.into(), }); diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 41a162a9f6738..7291965760eff 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -205,7 +205,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { // This is really important. While we *can* handle this, this has // severe performance implications for large opaque types with // late-bound regions. See `issue-88862` benchmark. - ty::Opaque(ty::OpaqueTy { def_id, substs }) if !substs.has_escaping_bound_vars() => { + ty::Opaque(ty::AliasTy { def_id, substs }) if !substs.has_escaping_bound_vars() => { // Only normalize `impl Trait` outside of type inference, usually in codegen. match self.param_env.reveal() { Reveal::UserFacing => ty.try_super_fold_with(self), diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 509a4c0172764..f65e573401d30 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -536,10 +536,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let ty = traits::normalize_projection_type( self, param_env, - ty::ProjectionTy { - def_id: tcx.lang_items().deref_target()?, - substs: trait_ref.substs, - }, + ty::AliasTy { def_id: tcx.lang_items().deref_target()?, substs: trait_ref.substs }, cause.clone(), 0, // We're *intentionally* throwing these away, @@ -830,7 +827,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::GeneratorWitness(_) | ty::Never | ty::Projection(_) - | ty::Opaque(ty::OpaqueTy { def_id: _, substs: _ }) + | ty::Opaque(ty::AliasTy { def_id: _, substs: _ }) | ty::Param(_) | ty::Bound(_, _) | ty::Error(_) diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index cfc77a1a1d520..e945d320b73bc 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -156,7 +156,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate); let (def_id, substs) = match *placeholder_self_ty.kind() { ty::Projection(proj) => (proj.def_id, proj.substs), - ty::Opaque(ty::OpaqueTy { def_id, substs }) => (def_id, substs), + ty::Opaque(ty::AliasTy { def_id, substs }) => (def_id, substs), _ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty), }; diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index e279d6bfdbc28..f26705d63a93e 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1596,7 +1596,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let tcx = self.infcx.tcx; let (def_id, substs) = match *placeholder_trait_predicate.trait_ref.self_ty().kind() { ty::Projection(ref data) => (data.def_id, data.substs), - ty::Opaque(ty::OpaqueTy { def_id, substs }) => (def_id, substs), + ty::Opaque(ty::AliasTy { def_id, substs }) => (def_id, substs), _ => { span_bug!( obligation.cause.span, @@ -2260,7 +2260,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { t.rebind(def.all_fields().map(|f| f.ty(self.tcx(), substs)).collect()) } - ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + ty::Opaque(ty::AliasTy { def_id, substs }) => { // We can resolve the `impl Trait` to its concrete type, // which enforces a DAG between the functions requiring // the auto trait bounds in question. diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index e1a1f84841514..60283a46c8ade 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -249,7 +249,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( // An associated item obligation born out of the `trait` failed to be met. An example // can be seen in `ui/associated-types/point-at-type-on-obligation-failure-2.rs`. debug!("extended_cause_with_original_assoc_item_obligation trait proj {:?}", pred); - if let ty::Projection(ty::ProjectionTy { def_id, .. }) = *pred.self_ty().kind() + if let ty::Projection(ty::AliasTy { def_id, .. }) = *pred.self_ty().kind() && let Some(&impl_item_id) = tcx.impl_item_implementor_ids(impl_def_id).get(&def_id) && let Some(impl_item_span) = items @@ -369,7 +369,7 @@ impl<'tcx> WfPredicates<'tcx> { /// Pushes the obligations required for `trait_ref::Item` to be WF /// into `self.out`. - fn compute_projection(&mut self, data: ty::ProjectionTy<'tcx>) { + fn compute_projection(&mut self, data: ty::AliasTy<'tcx>) { // A projection is well-formed if // // (a) its predicates hold (*) @@ -648,7 +648,7 @@ impl<'tcx> WfPredicates<'tcx> { // types appearing in the fn signature } - ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + ty::Opaque(ty::AliasTy { def_id, substs }) => { // All of the requirements on type parameters // have already been checked for `impl Trait` in // return position. We do need to check type-alias-impl-trait though. diff --git a/compiler/rustc_traits/src/chalk/db.rs b/compiler/rustc_traits/src/chalk/db.rs index 6c841b94fc04b..30482cea26290 100644 --- a/compiler/rustc_traits/src/chalk/db.rs +++ b/compiler/rustc_traits/src/chalk/db.rs @@ -432,7 +432,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t (ast::Mutability::Not, chalk_ir::Mutability::Not) => true, } } - (&ty::Opaque(ty::OpaqueTy { def_id, substs: _ }), OpaqueType(opaque_ty_id, ..)) => { + (&ty::Opaque(ty::AliasTy { def_id, substs: _ }), OpaqueType(opaque_ty_id, ..)) => { def_id == opaque_ty_id.0 } (&ty::FnDef(def_id, ..), FnDef(fn_def_id, ..)) => def_id == fn_def_id.0, @@ -788,7 +788,7 @@ impl<'tcx> ty::TypeFolder<'tcx> for ReplaceOpaqueTyFolder<'tcx> { } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Opaque(ty::OpaqueTy { def_id, substs }) = *ty.kind() { + if let ty::Opaque(ty::AliasTy { def_id, substs }) = *ty.kind() { if def_id == self.opaque_ty_id.0 && substs == self.identity_substs { return self.tcx.mk_ty(ty::Bound( self.binder_index, diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 96e895ff2a6e7..fb89b0cd4c27e 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -66,7 +66,7 @@ impl<'tcx> LowerInto<'tcx, SubstsRef<'tcx>> for &chalk_ir::Substitution LowerInto<'tcx, chalk_ir::AliasTy>> for ty::ProjectionTy<'tcx> { +impl<'tcx> LowerInto<'tcx, chalk_ir::AliasTy>> for ty::AliasTy<'tcx> { fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::AliasTy> { chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { associated_ty_id: chalk_ir::AssocTypeId(self.def_id), @@ -354,7 +354,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty>> for Ty<'tcx> { chalk_ir::TyKind::Tuple(types.len(), types.as_substs().lower_into(interner)) } ty::Projection(proj) => chalk_ir::TyKind::Alias(proj.lower_into(interner)), - ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + ty::Opaque(ty::AliasTy { def_id, substs }) => { chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { opaque_ty_id: chalk_ir::OpaqueTyId(def_id), substitution: substs.lower_into(interner), @@ -442,11 +442,11 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty> { mutbl.lower_into(interner), ), TyKind::Str => ty::Str, - TyKind::OpaqueType(opaque_ty, substitution) => ty::Opaque(ty::OpaqueTy { + TyKind::OpaqueType(opaque_ty, substitution) => ty::Opaque(ty::AliasTy { def_id: opaque_ty.0, substs: substitution.lower_into(interner), }), - TyKind::AssociatedType(assoc_ty, substitution) => ty::Projection(ty::ProjectionTy { + TyKind::AssociatedType(assoc_ty, substitution) => ty::Projection(ty::AliasTy { substs: substitution.lower_into(interner), def_id: assoc_ty.0, }), @@ -457,11 +457,11 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty> { name: ty::BoundVar::from_usize(placeholder.idx), }), TyKind::Alias(alias_ty) => match alias_ty { - chalk_ir::AliasTy::Projection(projection) => ty::Projection(ty::ProjectionTy { + chalk_ir::AliasTy::Projection(projection) => ty::Projection(ty::AliasTy { def_id: projection.associated_ty_id.0, substs: projection.substitution.lower_into(interner), }), - chalk_ir::AliasTy::Opaque(opaque) => ty::Opaque(ty::OpaqueTy { + chalk_ir::AliasTy::Opaque(opaque) => ty::Opaque(ty::AliasTy { def_id: opaque.opaque_ty_id.0, substs: opaque.substitution.lower_into(interner), }), diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index d128b5f79acbc..98aaff4fb0849 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -414,7 +414,7 @@ fn clean_projection_predicate<'tcx>( } fn clean_projection<'tcx>( - ty: ty::Binder<'tcx, ty::ProjectionTy<'tcx>>, + ty: ty::Binder<'tcx, ty::AliasTy<'tcx>>, cx: &mut DocContext<'tcx>, def_id: Option, ) -> Type { @@ -453,7 +453,7 @@ fn compute_should_show_cast(self_def_id: Option, trait_: &Path, self_type } fn projection_to_path_segment<'tcx>( - ty: ty::Binder<'tcx, ty::ProjectionTy<'tcx>>, + ty: ty::Binder<'tcx, ty::AliasTy<'tcx>>, cx: &mut DocContext<'tcx>, ) -> PathSegment { let item = cx.tcx.associated_item(ty.skip_binder().def_id); @@ -1833,7 +1833,7 @@ pub(crate) fn clean_middle_ty<'tcx>( } } - ty::Opaque(ty::OpaqueTy { def_id, substs }) => { + ty::Opaque(ty::AliasTy { def_id, substs }) => { // Grab the "TraitA + TraitB" from `impl TraitA + TraitB`, // by looking up the bounds associated with the def_id. let bounds = cx diff --git a/src/tools/clippy/clippy_lints/src/future_not_send.rs b/src/tools/clippy/clippy_lints/src/future_not_send.rs index 8a7a65c860016..3ff774867b1ef 100644 --- a/src/tools/clippy/clippy_lints/src/future_not_send.rs +++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs @@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{Clause, EarlyBinder, Opaque, OpaqueTy, PredicateKind}; +use rustc_middle::ty::{AliasTy, Clause, EarlyBinder, Opaque, PredicateKind}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt; @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { return; } let ret_ty = return_ty(cx, hir_id); - if let Opaque(OpaqueTy { def_id, substs }) = *ret_ty.kind() { + if let Opaque(AliasTy { def_id, substs }) = *ret_ty.kind() { let preds = cx.tcx.explicit_item_bounds(def_id); let mut is_future = false; for &(p, _span) in preds { diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index 11e41d1958ce6..bddab7eca53ba 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -17,7 +17,7 @@ use rustc_lint::LateContext; use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::ty::{ self, AdtDef, AssocKind, Binder, BoundRegion, DefIdTree, FnSig, IntTy, List, ParamEnv, Predicate, PredicateKind, - ProjectionTy, Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy, + AliasTy, Region, RegionKind, SubstsRef, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, UintTy, VariantDef, VariantDiscr, }; use rustc_middle::ty::{GenericArg, GenericArgKind}; @@ -79,7 +79,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' return true; } - if let ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) = *inner_ty.kind() { + if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *inner_ty.kind() { for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) { match predicate.kind().skip_binder() { // For `impl Trait`, it will register a predicate of `T: Trait`, so we go through @@ -250,7 +250,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { is_must_use_ty(cx, *ty) }, ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), - ty::Opaque(ty::OpaqueTy { def_id, substs: _ }) => { + ty::Opaque(ty::AliasTy { def_id, substs: _ }) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() { if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) { @@ -631,7 +631,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))), - ty::Opaque(ty::OpaqueTy{ def_id, substs: _ }) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id)), + ty::Opaque(ty::AliasTy { def_id, substs: _ }) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id)), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), ty::Dynamic(bounds, _, _) => { let lang_items = cx.tcx.lang_items(); @@ -701,7 +701,7 @@ fn sig_from_bounds<'tcx>( inputs.map(|ty| ExprFnSig::Trait(ty, output, predicates_id)) } -fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: ProjectionTy<'tcx>) -> Option> { +fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option> { let mut inputs = None; let mut output = None; let lang_items = cx.tcx.lang_items(); @@ -980,13 +980,13 @@ pub fn make_projection<'tcx>( container_id: DefId, assoc_ty: Symbol, substs: impl IntoIterator>>, -) -> Option> { +) -> Option> { fn helper<'tcx>( tcx: TyCtxt<'tcx>, container_id: DefId, assoc_ty: Symbol, substs: SubstsRef<'tcx>, - ) -> Option> { + ) -> Option> { let Some(assoc_item) = tcx .associated_items(container_id) .find_by_name_and_kind(tcx, Ident::with_dummy_span(assoc_ty), AssocKind::Type, container_id) @@ -1039,7 +1039,7 @@ pub fn make_projection<'tcx>( } } - Some(ProjectionTy { + Some(AliasTy { substs, def_id: assoc_item.def_id, }) @@ -1065,7 +1065,7 @@ pub fn make_normalized_projection<'tcx>( assoc_ty: Symbol, substs: impl IntoIterator>>, ) -> Option> { - fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: ProjectionTy<'tcx>) -> Option> { + fn helper<'tcx>(tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>, ty: AliasTy<'tcx>) -> Option> { #[cfg(debug_assertions)] if let Some((i, subst)) = ty .substs From 61adaf81873101587ffff4e1b8671acbc33d3df1 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 26 Nov 2022 21:51:55 +0000 Subject: [PATCH 05/11] Combine projection and opaque into alias --- .../src/diagnostics/conflict_errors.rs | 2 +- .../src/diagnostics/region_errors.rs | 2 +- .../src/debuginfo/type_names.rs | 4 +- .../src/const_eval/valtrees.rs | 8 +- .../src/interpret/intrinsics.rs | 4 +- .../src/interpret/validity.rs | 4 +- .../src/transform/validate.rs | 4 +- .../rustc_const_eval/src/util/type_name.rs | 4 +- .../rustc_hir_analysis/src/astconv/mod.rs | 2 +- .../rustc_hir_analysis/src/check/check.rs | 2 +- .../src/check/compare_method.rs | 4 +- .../rustc_hir_analysis/src/check/wfcheck.rs | 4 +- .../src/coherence/inherent_impls.rs | 2 +- .../src/collect/lifetimes.rs | 2 +- .../src/collect/predicates_of.rs | 2 +- .../rustc_hir_analysis/src/collect/type_of.rs | 4 +- .../src/constrained_generic_params.rs | 2 +- .../src/outlives/implicit_infer.rs | 2 +- .../src/variance/constraints.rs | 4 +- .../rustc_hir_analysis/src/variance/mod.rs | 4 +- compiler/rustc_hir_typeck/src/_match.rs | 4 +- compiler/rustc_hir_typeck/src/cast.rs | 4 +- compiler/rustc_hir_typeck/src/closure.rs | 11 ++- compiler/rustc_hir_typeck/src/coercion.rs | 2 +- compiler/rustc_hir_typeck/src/expr.rs | 2 +- .../rustc_hir_typeck/src/fn_ctxt/_impl.rs | 2 +- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 4 +- .../src/fn_ctxt/suggestions.rs | 2 +- .../src/generator_interior/mod.rs | 2 +- .../rustc_hir_typeck/src/method/suggest.rs | 2 +- compiler/rustc_hir_typeck/src/writeback.rs | 2 +- .../src/infer/canonical/canonicalizer.rs | 4 +- compiler/rustc_infer/src/infer/combine.rs | 2 +- compiler/rustc_infer/src/infer/equate.rs | 8 +- .../src/infer/error_reporting/mod.rs | 17 ++-- .../infer/error_reporting/need_type_info.rs | 5 +- .../src/infer/error_reporting/suggest.rs | 8 +- compiler/rustc_infer/src/infer/freshen.rs | 5 +- compiler/rustc_infer/src/infer/lattice.rs | 8 +- .../rustc_infer/src/infer/nll_relate/mod.rs | 22 +++-- .../rustc_infer/src/infer/opaque_types.rs | 18 ++-- .../src/infer/outlives/components.rs | 4 +- .../src/infer/outlives/obligations.rs | 6 +- compiler/rustc_infer/src/infer/sub.rs | 8 +- compiler/rustc_lint/src/builtin.rs | 4 +- .../src/opaque_hidden_inferred_bound.rs | 2 +- compiler/rustc_lint/src/types.rs | 10 +- compiler/rustc_lint/src/unused.rs | 4 +- compiler/rustc_metadata/src/rmeta/encoder.rs | 2 +- compiler/rustc_middle/src/ty/context.rs | 12 +-- compiler/rustc_middle/src/ty/diagnostics.rs | 6 +- compiler/rustc_middle/src/ty/error.rs | 27 +++--- compiler/rustc_middle/src/ty/fast_reject.rs | 11 ++- compiler/rustc_middle/src/ty/flags.rs | 4 +- .../rustc_middle/src/ty/inhabitedness/mod.rs | 2 +- compiler/rustc_middle/src/ty/layout.rs | 8 +- compiler/rustc_middle/src/ty/mod.rs | 1 + compiler/rustc_middle/src/ty/print/mod.rs | 4 +- compiler/rustc_middle/src/ty/print/pretty.rs | 8 +- compiler/rustc_middle/src/ty/relate.rs | 6 +- .../rustc_middle/src/ty/structural_impls.rs | 14 ++- compiler/rustc_middle/src/ty/sty.rs | 15 +-- compiler/rustc_middle/src/ty/util.rs | 28 +++--- compiler/rustc_middle/src/ty/visit.rs | 2 +- compiler/rustc_middle/src/ty/walk.rs | 4 +- compiler/rustc_mir_build/src/build/block.rs | 4 +- .../src/thir/pattern/const_to_pat.rs | 2 +- .../src/thir/pattern/usefulness.rs | 2 +- compiler/rustc_mir_transform/src/inline.rs | 2 +- .../rustc_mir_transform/src/remove_zsts.rs | 6 +- compiler/rustc_privacy/src/lib.rs | 4 +- compiler/rustc_symbol_mangling/src/legacy.rs | 10 +- .../src/typeid/typeid_itanium_cxx_abi.rs | 8 +- compiler/rustc_symbol_mangling/src/v0.rs | 4 +- .../src/traits/auto_trait.rs | 4 +- .../src/traits/coherence.rs | 4 +- .../src/traits/error_reporting/mod.rs | 4 +- .../src/traits/error_reporting/suggestions.rs | 8 +- .../src/traits/object_safety.rs | 6 +- .../src/traits/project.rs | 24 +++-- .../src/traits/query/dropck_outlives.rs | 4 +- .../src/traits/query/normalize.rs | 8 +- .../src/traits/select/candidate_assembly.rs | 12 +-- .../src/traits/select/confirmation.rs | 8 +- .../src/traits/select/mod.rs | 15 +-- .../src/traits/structural_match.rs | 4 +- .../rustc_trait_selection/src/traits/wf.rs | 8 +- compiler/rustc_traits/src/chalk/db.rs | 9 +- compiler/rustc_traits/src/chalk/lowering.rs | 42 +++++---- compiler/rustc_traits/src/dropck_outlives.rs | 4 +- compiler/rustc_ty_utils/src/layout.rs | 2 +- compiler/rustc_ty_utils/src/needs_drop.rs | 5 +- compiler/rustc_ty_utils/src/ty.rs | 2 +- compiler/rustc_type_ir/src/lib.rs | 3 +- compiler/rustc_type_ir/src/sty.rs | 92 +++++++------------ src/librustdoc/clean/mod.rs | 8 +- .../passes/collect_intra_doc_links.rs | 3 +- .../internal-lints/ty_tykind_usage.rs | 3 +- .../internal-lints/ty_tykind_usage.stderr | 28 +++--- .../clippy/clippy_lints/src/dereference.rs | 8 +- .../clippy_lints/src/future_not_send.rs | 4 +- src/tools/clippy/clippy_lints/src/len_zero.rs | 2 +- .../clippy_utils/src/qualify_min_const_fn.rs | 2 +- src/tools/clippy/clippy_utils/src/ty.rs | 8 +- 104 files changed, 387 insertions(+), 381 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 241f47ad14bf5..a92cb6bb38d47 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -697,7 +697,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { .map_bound(|p| p.predicates), None, ), - ty::Opaque(ty::AliasTy { def_id, substs }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { find_fn_kind_from_did(tcx.bound_explicit_item_bounds(*def_id), Some(*substs)) } ty::Closure(_, substs) => match substs.as_closure().kind() { diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index 27372b3b8fcde..e6520301818d8 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -504,7 +504,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let ErrorConstraintInfo { outlived_fr, span, .. } = errci; let mut output_ty = self.regioncx.universal_regions().unnormalized_output_ty; - if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *output_ty.kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *output_ty.kind() { output_ty = self.infcx.tcx.type_of(def_id) }; diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index 7a8d1d8d9fad6..c260de699ced8 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -411,9 +411,9 @@ fn push_debuginfo_type_name<'tcx>( ty::Error(_) | ty::Infer(_) | ty::Placeholder(..) - | ty::Projection(..) + | ty::Alias(ty::Projection, ..) | ty::Bound(..) - | ty::Opaque(..) + | ty::Alias(ty::Opaque, ..) | ty::GeneratorWitness(..) => { bug!( "debuginfo: Trying to create type name for \ diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs index f4da11883957a..5cc9ff8f85539 100644 --- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs +++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs @@ -142,12 +142,12 @@ pub(crate) fn const_to_valtree_inner<'tcx>( | ty::Foreign(..) | ty::Infer(ty::FreshIntTy(_)) | ty::Infer(ty::FreshFloatTy(_)) - | ty::Projection(..) + | ty::Alias(ty::Projection, ..) | ty::Param(_) | ty::Bound(..) | ty::Placeholder(..) // FIXME(oli-obk): we could look behind opaque types - | ty::Opaque(..) + | ty::Alias(ty::Opaque, ..) | ty::Infer(_) // FIXME(oli-obk): we can probably encode closures just like structs | ty::Closure(..) @@ -307,11 +307,11 @@ pub fn valtree_to_const_value<'tcx>( | ty::Foreign(..) | ty::Infer(ty::FreshIntTy(_)) | ty::Infer(ty::FreshFloatTy(_)) - | ty::Projection(..) + | ty::Alias(ty::Projection, ..) | ty::Param(_) | ty::Bound(..) | ty::Placeholder(..) - | ty::Opaque(..) + | ty::Alias(ty::Opaque, ..) | ty::Infer(_) | ty::Closure(..) | ty::Generator(..) diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index a7276bf33b303..4fc664b70f8d7 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -82,8 +82,8 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>( ty::Adt(ref adt, _) => { ConstValue::from_machine_usize(adt.variants().len() as u64, &tcx) } - ty::Projection(_) - | ty::Opaque(ty::AliasTy { def_id: _, substs: _ }) + ty::Alias(ty::Projection, _) + | ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs: _ }) | ty::Param(_) | ty::Placeholder(_) | ty::Infer(_) => throw_inval!(TooGeneric), diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index fc65306e440a9..b7dd2517d69ee 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -601,8 +601,8 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' | ty::Placeholder(..) | ty::Bound(..) | ty::Param(..) - | ty::Opaque(..) - | ty::Projection(..) + | ty::Alias(ty::Opaque, ..) + | ty::Alias(ty::Projection, ..) | ty::GeneratorWitness(..) => bug!("Encountered invalid type {:?}", ty), } } diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 0286c8f04f116..b070ca9b0b778 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -241,7 +241,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { }; let kind = match parent_ty.ty.kind() { - &ty::Opaque(ty::AliasTy { def_id, substs }) => { + &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { self.tcx.bound_type_of(def_id).subst(self.tcx, substs).kind() } kind => kind, @@ -652,7 +652,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { self.fail(location, "`SetDiscriminant`is not allowed until deaggregation"); } let pty = place.ty(&self.body.local_decls, self.tcx).ty.kind(); - if !matches!(pty, ty::Adt(..) | ty::Generator(..) | ty::Opaque(..)) { + if !matches!(pty, ty::Adt(..) | ty::Generator(..) | ty::Alias(ty::Opaque, ..)) { self.fail( location, format!( diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index e0569987ee43d..c31cd94699063 100644 --- a/compiler/rustc_const_eval/src/util/type_name.rs +++ b/compiler/rustc_const_eval/src/util/type_name.rs @@ -58,8 +58,8 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { // Types with identity (print the module path). ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs) | ty::FnDef(def_id, substs) - | ty::Opaque(ty::AliasTy { def_id, substs }) - | ty::Projection(ty::AliasTy { def_id, substs }) + | ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) + | ty::Alias(ty::Projection, ty::AliasTy { def_id, substs }) | ty::Closure(def_id, substs) | ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs), ty::Foreign(def_id) => self.print_def_path(def_id, &[]), diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index f91c17d5c03cf..c8c10385f0cd6 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -1241,7 +1241,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // // Calling `skip_binder` is okay, because `add_bounds` expects the `param_ty` // parameter to have a skipped binder. - let param_ty = tcx.mk_ty(ty::Projection(projection_ty.skip_binder())); + let param_ty = tcx.mk_ty(ty::Alias(ty::Projection, projection_ty.skip_binder())); self.add_bounds(param_ty, ast_bounds.iter(), bounds, candidate.bound_vars()); } } diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 9b42c16b88273..dd841707b2906 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -1440,7 +1440,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) -> E impl<'tcx> ty::visit::TypeVisitor<'tcx> for OpaqueTypeCollector { fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { match *t.kind() { - ty::Opaque(ty::AliasTy { def_id: def, substs: _ }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, substs: _ }) => { self.0.push(def); ControlFlow::CONTINUE } diff --git a/compiler/rustc_hir_analysis/src/check/compare_method.rs b/compiler/rustc_hir_analysis/src/check/compare_method.rs index d09c17e9f9b87..ba7d31cea2e2f 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_method.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_method.rs @@ -571,7 +571,7 @@ impl<'tcx> TypeFolder<'tcx> for ImplTraitInTraitCollector<'_, 'tcx> { } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Projection(proj) = ty.kind() + if let ty::Alias(ty::Projection, proj) = ty.kind() && self.tcx().def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder { if let Some((ty, _)) = self.types.get(&proj.def_id) { @@ -1734,7 +1734,7 @@ pub fn check_type_bounds<'tcx>( let normalize_param_env = { let mut predicates = param_env.caller_bounds().iter().collect::>(); match impl_ty_value.kind() { - ty::Projection(proj) + ty::Alias(ty::Projection, proj) if proj.def_id == trait_ty.def_id && proj.substs == rebased_substs => { // Don't include this predicate if the projected type is diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index c0dbae8137103..94d333c336ef3 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -759,7 +759,7 @@ impl<'tcx> TypeVisitor<'tcx> for GATSubstCollector<'tcx> { fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { match t.kind() { - ty::Projection(p) if p.def_id == self.gat => { + ty::Alias(ty::Projection, p) if p.def_id == self.gat => { for (idx, subst) in p.substs.iter().enumerate() { match subst.unpack() { GenericArgKind::Lifetime(lt) if !lt.is_late_bound() => { @@ -1592,7 +1592,7 @@ fn check_return_position_impl_trait_in_trait_bounds<'tcx>( { for arg in fn_output.walk() { if let ty::GenericArgKind::Type(ty) = arg.unpack() - && let ty::Projection(proj) = ty.kind() + && let ty::Alias(ty::Projection, proj) = ty.kind() && tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder && tcx.impl_trait_in_trait_parent(proj.def_id) == fn_def_id.to_def_id() { diff --git a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs index 2890c149b3afe..32c3e95688b87 100644 --- a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs +++ b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs @@ -223,7 +223,7 @@ impl<'tcx> InherentCollect<'tcx> { | ty::Tuple(..) => { self.check_primitive_impl(item.owner_id.def_id, self_ty, items, ty.span) } - ty::Projection(..) | ty::Opaque(..) | ty::Param(_) => { + ty::Alias(ty::Projection, ..) | ty::Alias(ty::Opaque, ..) | ty::Param(_) => { let mut err = struct_span_err!( self.tcx.sess, ty.span, diff --git a/compiler/rustc_hir_analysis/src/collect/lifetimes.rs b/compiler/rustc_hir_analysis/src/collect/lifetimes.rs index 9a7b261fffd4d..b4ad3467e7d87 100644 --- a/compiler/rustc_hir_analysis/src/collect/lifetimes.rs +++ b/compiler/rustc_hir_analysis/src/collect/lifetimes.rs @@ -1749,7 +1749,7 @@ fn is_late_bound_map(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<&FxIndexSet< ty::Param(param_ty) => { self.arg_is_constrained[param_ty.index as usize] = true; } - ty::Projection(_) => return ControlFlow::Continue(()), + ty::Alias(ty::Projection, _) => return ControlFlow::Continue(()), _ => (), } t.super_visit_with(self) diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index 617de63b1bdfb..776bfe9c53ae2 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -411,7 +411,7 @@ pub(super) fn explicit_predicates_of<'tcx>( // substs are the same as the trait's. // * It must be an associated type for this trait (*not* a // supertrait). - if let ty::Projection(projection) = ty.kind() { + if let ty::Alias(ty::Projection, projection) = ty.kind() { projection.substs == trait_identity_substs && tcx.associated_item(projection.def_id).container_id(tcx) == def_id } else { diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 43bc71ea1e4fa..b678990f94e91 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -52,7 +52,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option< // Using the ItemCtxt convert the HIR for the unresolved assoc type into a // ty which is a fully resolved projection. // For the code example above, this would mean converting Self::Assoc<3> - // into a ty::Projection(::Assoc<3>) + // into a ty::Alias(ty::Projection, ::Assoc<3>) let item_hir_id = tcx .hir() .parent_iter(hir_id) @@ -68,7 +68,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option< // the def_id that this query was called with. We filter to only type and const args here // as a precaution for if it's ever allowed to elide lifetimes in GAT's. It currently isn't // but it can't hurt to be safe ^^ - if let ty::Projection(projection) = ty.kind() { + if let ty::Alias(ty::Projection, projection) = ty.kind() { let generics = tcx.generics_of(projection.def_id); let arg_index = segment diff --git a/compiler/rustc_hir_analysis/src/constrained_generic_params.rs b/compiler/rustc_hir_analysis/src/constrained_generic_params.rs index b4057df7896f3..95c971c0d7845 100644 --- a/compiler/rustc_hir_analysis/src/constrained_generic_params.rs +++ b/compiler/rustc_hir_analysis/src/constrained_generic_params.rs @@ -59,7 +59,7 @@ struct ParameterCollector { impl<'tcx> TypeVisitor<'tcx> for ParameterCollector { fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { match *t.kind() { - ty::Projection(..) if !self.include_nonconstraining => { + ty::Alias(ty::Projection, ..) if !self.include_nonconstraining => { // projections are not injective return ControlFlow::CONTINUE; } diff --git a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs index 3d29470ee66c5..af8d7e8515865 100644 --- a/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs +++ b/compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs @@ -196,7 +196,7 @@ fn insert_required_predicates_to_be_wf<'tcx>( } } - ty::Projection(obj) => { + ty::Alias(ty::Projection, obj) => { // This corresponds to `>::Bar`. In this case, we should use the // explicit predicates as well. debug!("Projection"); diff --git a/compiler/rustc_hir_analysis/src/variance/constraints.rs b/compiler/rustc_hir_analysis/src/variance/constraints.rs index 2d1b4fc4dc6fc..75bb7abf0ed2e 100644 --- a/compiler/rustc_hir_analysis/src/variance/constraints.rs +++ b/compiler/rustc_hir_analysis/src/variance/constraints.rs @@ -249,11 +249,11 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { self.add_constraints_from_substs(current, def.did(), substs, variance); } - ty::Projection(ref data) => { + ty::Alias(ty::Projection, ref data) => { self.add_constraints_from_invariant_substs(current, data.substs, variance); } - ty::Opaque(ty::AliasTy { def_id: _, substs }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs }) => { self.add_constraints_from_invariant_substs(current, substs, variance); } diff --git a/compiler/rustc_hir_analysis/src/variance/mod.rs b/compiler/rustc_hir_analysis/src/variance/mod.rs index 3eb33319f7f5d..feb49ed1e30fe 100644 --- a/compiler/rustc_hir_analysis/src/variance/mod.rs +++ b/compiler/rustc_hir_analysis/src/variance/mod.rs @@ -112,8 +112,8 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { // FIXME(alias): merge these match t.kind() { - ty::Opaque(ty::AliasTy { def_id, substs }) => self.visit_opaque(*def_id, substs), - ty::Projection(proj) + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => self.visit_opaque(*def_id, substs), + ty::Alias(ty::Projection, proj) if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder => { self.visit_opaque(proj.def_id, proj.substs) diff --git a/compiler/rustc_hir_typeck/src/_match.rs b/compiler/rustc_hir_typeck/src/_match.rs index 32635f5a12b97..a86bd80a668b0 100644 --- a/compiler/rustc_hir_typeck/src/_match.rs +++ b/compiler/rustc_hir_typeck/src/_match.rs @@ -212,7 +212,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.can_coerce(arm_ty, ret_ty) && prior_arm.map_or(true, |(_, ty, _)| self.can_coerce(ty, ret_ty)) // The match arms need to unify for the case of `impl Trait`. - && !matches!(ret_ty.kind(), ty::Opaque(..)) + && !matches!(ret_ty.kind(), ty::Alias(ty::Opaque, ..)) } _ => false, }; @@ -518,7 +518,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let substs = sig.output().walk().find_map(|arg| { if let ty::GenericArgKind::Type(ty) = arg.unpack() - && let ty::Opaque(ty::AliasTy { def_id, substs }) = *ty.kind() + && let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) = *ty.kind() && def_id == rpit_def_id { Some(substs) diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 171086cf7244f..235e9c661a909 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -118,8 +118,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Pointers to foreign types are thin, despite being unsized ty::Foreign(..) => Some(PointerKind::Thin), // We should really try to normalize here. - ty::Projection(pi) => Some(PointerKind::OfProjection(pi)), - ty::Opaque(ty::AliasTy { def_id, substs }) => { + ty::Alias(ty::Projection, pi) => Some(PointerKind::OfProjection(pi)), + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { Some(PointerKind::OfOpaque(def_id, substs)) } ty::Param(p) => Some(PointerKind::OfParam(p)), diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index dd87a7f32d276..a96d27868a6d5 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -167,9 +167,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { expected_ty: Ty<'tcx>, ) -> (Option>, Option) { match *expected_ty.kind() { - ty::Opaque(ty::AliasTy { def_id, substs }) => self.deduce_signature_from_predicates( - self.tcx.bound_explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs), - ), + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => self + .deduce_signature_from_predicates( + self.tcx.bound_explicit_item_bounds(def_id).subst_iter_copied(self.tcx, substs), + ), ty::Dynamic(ref object_type, ..) => { let sig = object_type.projection_bounds().find_map(|pb| { let pb = pb.with_self_ty(self.tcx, self.tcx.types.trait_object_dummy_self); @@ -677,13 +678,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { get_future_output(obligation.predicate, obligation.cause.span) })? } - ty::Opaque(ty::AliasTy { def_id, substs }) => self + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => self .tcx .bound_explicit_item_bounds(def_id) .subst_iter_copied(self.tcx, substs) .find_map(|(p, s)| get_future_output(p, s))?, ty::Error(_) => return None, - ty::Projection(proj) + ty::Alias(ty::Projection, proj) if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder => { self.tcx diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index a7593ecc57213..a4ca7571142b6 100644 --- a/compiler/rustc_hir_typeck/src/coercion.rs +++ b/compiler/rustc_hir_typeck/src/coercion.rs @@ -1805,7 +1805,7 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> { { let ty = >::ast_ty_to_ty(fcx, ty); // Get the `impl Trait`'s `DefId`. - if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = ty.kind() + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = ty.kind() // Get the `impl Trait`'s `Item` so that we can get its trait bounds and // get the `Trait`'s `DefId`. && let hir::ItemKind::OpaqueTy(hir::OpaqueTy { bounds, .. }) = diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 25a043fd40a52..4e2a785622407 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -2391,7 +2391,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Param(param_ty) => { self.point_at_param_definition(&mut err, param_ty); } - ty::Opaque(ty::AliasTy { def_id: _, substs: _ }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs: _ }) => { self.suggest_await_on_field_access(&mut err, ident, base, base_ty.peel_refs()); } _ => {} diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 482fa046b4d31..c8ea8ba5ab065 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -716,7 +716,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if formal_ret.has_infer_types() { for ty in ret_ty.walk() { if let ty::subst::GenericArgKind::Type(ty) = ty.unpack() - && let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *ty.kind() + && let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *ty.kind() && let Some(def_id) = def_id.as_local() && self.opaque_type_origin(def_id, DUMMY_SP).is_some() { return None; diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 6e26c413b1ccf..615f374b2ec0b 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -2124,7 +2124,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } } - ty::Opaque(ty::AliasTy { def_id: new_def_id, substs: _ }) + ty::Alias(ty::Opaque, ty::AliasTy { def_id: new_def_id, substs: _ }) | ty::Closure(new_def_id, _) | ty::FnDef(new_def_id, _) => { def_id = new_def_id; @@ -2217,7 +2217,7 @@ fn find_param_in_ty<'tcx>(ty: Ty<'tcx>, param_to_point_at: ty::GenericArg<'tcx>) if arg == param_to_point_at { return true; } else if let ty::GenericArgKind::Type(ty) = arg.unpack() - && let ty::Projection(..) = ty.kind() + && let ty::Alias(ty::Projection, ..) = ty.kind() { // This logic may seem a bit strange, but typically when // we have a projection type in a function signature, the diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 21990775ad905..e6e1098e33d74 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -174,7 +174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let fn_sig = substs.as_closure().sig(); Some((DefIdOrName::DefId(def_id), fn_sig.output(), fn_sig.inputs().map_bound(|inputs| &inputs[1..]))) } - ty::Opaque(ty::AliasTy { def_id, substs }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| { if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder() && Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() diff --git a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs index 3280f502cc74a..d83b9eb995d2b 100644 --- a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs +++ b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs @@ -563,7 +563,7 @@ fn check_must_not_suspend_ty<'tcx>( } ty::Adt(def, _) => check_must_not_suspend_def(fcx.tcx, def.did(), hir_id, data), // FIXME: support adding the attribute to TAITs - ty::Opaque(ty::AliasTy { def_id: def, substs: _ }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, substs: _ }) => { let mut has_emitted = false; for &(predicate, _) in fcx.tcx.explicit_item_bounds(def) { // We only look at the `DefId`, so it is safe to skip the binder here. diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index f27a19b2da1f9..c8be8c2721ffa 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -1969,7 +1969,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | ty::Float(_) | ty::Adt(_, _) | ty::Str - | ty::Projection(_) + | ty::Alias(ty::Projection, _) | ty::Param(_) => format!("{deref_ty}"), // we need to test something like <&[_]>::len or <(&[u32])>::len // and Vec::function(); diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index e62332b38e716..d25d9672c36d0 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -546,7 +546,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { impl<'tcx> ty::TypeVisitor<'tcx> for RecursionChecker { type BreakTy = (); fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { - if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *t.kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *t.kind() { if def_id == self.def_id.to_def_id() { return ControlFlow::Break(()); } diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index 3dc0d60b1eb0f..79a55c5883acc 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -453,10 +453,10 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> { | ty::Dynamic(..) | ty::Never | ty::Tuple(..) - | ty::Projection(..) + | ty::Alias(ty::Projection, ..) | ty::Foreign(..) | ty::Param(..) - | ty::Opaque(..) => { + | ty::Alias(ty::Opaque, ..) => { if t.flags().intersects(self.needs_canonical_flags) { t.super_fold_with(self) } else { diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index dbf21a4e3fcfa..316077f69d99b 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -675,7 +675,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> { // relatable. Ok(t) } - ty::Opaque(ty::AliasTy { def_id, substs }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { let s = self.relate(substs, substs)?; Ok(if s == substs { t } else { self.infcx.tcx.mk_opaque(def_id, s) }) } diff --git a/compiler/rustc_infer/src/infer/equate.rs b/compiler/rustc_infer/src/infer/equate.rs index f3d2d4f154778..9fd4bdee096ac 100644 --- a/compiler/rustc_infer/src/infer/equate.rs +++ b/compiler/rustc_infer/src/infer/equate.rs @@ -101,13 +101,13 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> { } ( - &ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }), - &ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }), ) if a_def_id == b_def_id => { self.fields.infcx.super_combine_tys(self, a, b)?; } - (&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _) - | (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ })) + (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _) + | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ })) if self.fields.define_opaque_types && def_id.is_local() => { self.fields.obligations.extend( diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 5b9f4d077736d..7079322a4a460 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -340,8 +340,8 @@ impl<'tcx> InferCtxt<'tcx> { pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option> { // FIXME(alias): Merge these let (def_id, substs) = match *ty.kind() { - ty::Opaque(ty::AliasTy { def_id, substs }) => (def_id, substs), - ty::Projection(data) + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => (def_id, substs), + ty::Alias(ty::Projection, data) if self.tcx.def_kind(data.def_id) == DefKind::ImplTraitPlaceholder => { (data.def_id, data.substs) @@ -1732,7 +1732,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { let sort_string = |ty: Ty<'tcx>, path: Option| { // FIXME(alias): Merge these let mut s = match (extra, ty.kind()) { - (true, ty::Opaque(ty::AliasTy { def_id, .. })) => { + (true, ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) => { let sm = self.tcx.sess.source_map(); let pos = sm.lookup_char_pos(self.tcx.def_span(*def_id).lo()); format!( @@ -1742,7 +1742,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { pos.col.to_usize() + 1, ) } - (true, ty::Projection(proj)) + (true, ty::Alias(ty::Projection, proj)) if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder => { @@ -2385,10 +2385,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { // fn get_later(g: G, dest: &mut T) -> impl FnOnce() + '_ // suggest: // fn get_later<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a - ty::Closure(_, _substs) - | ty::Opaque(ty::AliasTy { def_id: _, substs: _substs }) - if return_impl_trait => - { + ty::Closure(..) | ty::Alias(ty::Opaque, ..) if return_impl_trait => { new_binding_suggestion(&mut err, type_param_span); } _ => { @@ -2770,7 +2767,9 @@ impl TyCategory { pub fn from_ty(tcx: TyCtxt<'_>, ty: Ty<'_>) -> Option<(Self, DefId)> { match *ty.kind() { ty::Closure(def_id, _) => Some((Self::Closure, def_id)), - ty::Opaque(ty::AliasTy { def_id, substs: _ }) => Some((Self::Opaque, def_id)), + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => { + Some((Self::Opaque, def_id)) + } ty::Generator(def_id, ..) => { Some((Self::Generator(tcx.generator_kind(def_id).unwrap()), def_id)) } diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 8ff1639a3a24b..4f9e069c1763d 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -852,7 +852,10 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { match inner.unpack() { GenericArgKind::Lifetime(_) => {} GenericArgKind::Type(ty) => { - if matches!(ty.kind(), ty::Opaque(..) | ty::Closure(..) | ty::Generator(..)) { + if matches!( + ty.kind(), + ty::Alias(ty::Opaque, ..) | ty::Closure(..) | ty::Generator(..) + ) { // Opaque types can't be named by the user right now. // // Both the generic arguments of closures and generators can diff --git a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs index e32f0edf3443e..62655d11ca309 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs @@ -487,12 +487,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { StatementAsExpression::CorrectType } ( - ty::Opaque(ty::AliasTy { def_id: last_def_id, substs: _ }), - ty::Opaque(ty::AliasTy { def_id: exp_def_id, substs: _ }), + ty::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, substs: _ }), + ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, substs: _ }), ) if last_def_id == exp_def_id => StatementAsExpression::CorrectType, ( - ty::Opaque(ty::AliasTy { def_id: last_def_id, substs: last_bounds }), - ty::Opaque(ty::AliasTy { def_id: exp_def_id, substs: exp_bounds }), + ty::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, substs: last_bounds }), + ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, substs: exp_bounds }), ) => { debug!( "both opaque, likely future {:?} {:?} {:?} {:?}", diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index f6946929bd23f..8f53b1ccdf458 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -205,12 +205,11 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> { | ty::Dynamic(..) | ty::Never | ty::Tuple(..) - | ty::Projection(..) + | ty::Alias(..) | ty::Foreign(..) | ty::Param(..) | ty::Closure(..) - | ty::GeneratorWitness(..) - | ty::Opaque(..) => t.super_fold_with(self), + | ty::GeneratorWitness(..) => t.super_fold_with(self), ty::Placeholder(..) | ty::Bound(..) => bug!("unexpected type {:?}", t), } diff --git a/compiler/rustc_infer/src/infer/lattice.rs b/compiler/rustc_infer/src/infer/lattice.rs index 2202adede13c1..47d76dc5bdf02 100644 --- a/compiler/rustc_infer/src/infer/lattice.rs +++ b/compiler/rustc_infer/src/infer/lattice.rs @@ -106,11 +106,11 @@ where } ( - &ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }), - &ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }), ) if a_def_id == b_def_id => infcx.super_combine_tys(this, a, b), - (&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _) - | (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ })) + (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _) + | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ })) if this.define_opaque_types() && def_id.is_local() => { this.add_obligations( diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index f6c2dd8a99b8f..3b9683e5b5933 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -281,7 +281,7 @@ where use rustc_span::DUMMY_SP; match *value_ty.kind() { - ty::Projection(other_projection_ty) => { + ty::Alias(ty::Projection, other_projection_ty) => { let var = self.infcx.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::MiscVariable, span: DUMMY_SP, @@ -335,7 +335,9 @@ where return Ok(value_ty); } - ty::Projection(projection_ty) if D::normalization() == NormalizationStrategy::Lazy => { + ty::Alias(ty::Projection, projection_ty) + if D::normalization() == NormalizationStrategy::Lazy => + { return Ok(self.relate_projection_ty(projection_ty, self.infcx.tcx.mk_ty_var(vid))); } @@ -406,8 +408,8 @@ where } }; let (a, b) = match (a.kind(), b.kind()) { - (&ty::Opaque(..), _) => (a, generalize(b, false)?), - (_, &ty::Opaque(..)) => (generalize(a, true)?, b), + (&ty::Alias(ty::Opaque, ..), _) => (a, generalize(b, false)?), + (_, &ty::Alias(ty::Opaque, ..)) => (generalize(a, true)?, b), _ => unreachable!(), }; let cause = ObligationCause::dummy_with_span(self.delegate.span()); @@ -609,8 +611,8 @@ where (&ty::Infer(ty::TyVar(vid)), _) => self.relate_ty_var((vid, b)), ( - &ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }), - &ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }), ) if a_def_id == b_def_id => infcx.super_combine_tys(self, a, b).or_else(|err| { self.tcx().sess.delay_span_bug( self.delegate.span(), @@ -618,20 +620,20 @@ where ); if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) } }), - (&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _) - | (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ })) + (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _) + | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ })) if def_id.is_local() => { self.relate_opaques(a, b) } - (&ty::Projection(projection_ty), _) + (&ty::Alias(ty::Projection, projection_ty), _) if D::normalization() == NormalizationStrategy::Lazy => { Ok(self.relate_projection_ty(projection_ty, b)) } - (_, &ty::Projection(projection_ty)) + (_, &ty::Alias(ty::Projection, projection_ty)) if D::normalization() == NormalizationStrategy::Lazy => { Ok(self.relate_projection_ty(projection_ty, a)) diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index 065a7987a0df6..98f08e831735c 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -66,7 +66,7 @@ impl<'tcx> InferCtxt<'tcx> { lt_op: |lt| lt, ct_op: |ct| ct, ty_op: |ty| match *ty.kind() { - ty::Opaque(ty::AliasTy { def_id, substs: _substs }) + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) if replace_opaque_type(def_id) => { let def_span = self.tcx.def_span(def_id); @@ -106,7 +106,7 @@ impl<'tcx> InferCtxt<'tcx> { } let (a, b) = if a_is_expected { (a, b) } else { (b, a) }; let process = |a: Ty<'tcx>, b: Ty<'tcx>, a_is_expected| match *a.kind() { - ty::Opaque(ty::AliasTy { def_id, substs }) if def_id.is_local() => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) if def_id.is_local() => { let def_id = def_id.expect_local(); let origin = match self.defining_use_anchor { DefiningAnchor::Bind(_) => { @@ -149,7 +149,9 @@ impl<'tcx> InferCtxt<'tcx> { DefiningAnchor::Bubble => self.opaque_ty_origin_unchecked(def_id, cause.span), DefiningAnchor::Error => return None, }; - if let ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }) = *b.kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }) = + *b.kind() + { // We could accept this, but there are various ways to handle this situation, and we don't // want to make a decision on it right now. Likely this case is so super rare anyway, that // no one encounters it in practice. @@ -478,7 +480,7 @@ where substs.as_generator().resume_ty().visit_with(self); } - ty::Opaque(ty::AliasTy { def_id, ref substs }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, ref substs }) => { // Skip lifetime paramters that are not captures. let variances = self.tcx.variances_of(*def_id); @@ -489,7 +491,7 @@ where } } - ty::Projection(proj) + ty::Alias(ty::Projection, proj) if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder => { // Skip lifetime paramters that are not captures. @@ -566,7 +568,7 @@ impl<'tcx> InferCtxt<'tcx> { // We can't normalize associated types from `rustc_infer`, // but we can eagerly register inference variables for them. // FIXME(RPITIT): Don't replace RPITITs with inference vars. - ty::Projection(projection_ty) + ty::Alias(ty::Projection, projection_ty) if !projection_ty.has_escaping_bound_vars() && tcx.def_kind(projection_ty.def_id) != DefKind::ImplTraitPlaceholder => @@ -581,13 +583,13 @@ impl<'tcx> InferCtxt<'tcx> { } // Replace all other mentions of the same opaque type with the hidden type, // as the bounds must hold on the hidden type after all. - ty::Opaque(ty::AliasTy { def_id: def_id2, substs: substs2 }) + ty::Alias(ty::Opaque, ty::AliasTy { def_id: def_id2, substs: substs2 }) if def_id.to_def_id() == def_id2 && substs == substs2 => { hidden_ty } // FIXME(RPITIT): This can go away when we move to associated types - ty::Projection(proj) + ty::Alias(ty::Projection, proj) if def_id.to_def_id() == proj.def_id && substs == proj.substs => { hidden_ty diff --git a/compiler/rustc_infer/src/infer/outlives/components.rs b/compiler/rustc_infer/src/infer/outlives/components.rs index 75d70abb56fb0..984bbe169e6cf 100644 --- a/compiler/rustc_infer/src/infer/outlives/components.rs +++ b/compiler/rustc_infer/src/infer/outlives/components.rs @@ -130,7 +130,7 @@ fn compute_components<'tcx>( // outlives any other lifetime, which is unsound. // See https://github.com/rust-lang/rust/issues/84305 for // more details. - ty::Opaque(ty::AliasTy { def_id, substs }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { out.push(Component::Opaque(def_id, substs)); }, @@ -142,7 +142,7 @@ fn compute_components<'tcx>( // trait-ref. Therefore, if we see any higher-ranked regions, // we simply fallback to the most restrictive rule, which // requires that `Pi: 'a` for all `i`. - ty::Projection(ref data) => { + ty::Alias(ty::Projection, ref data) => { if !data.has_escaping_bound_vars() { // best case: no escaping regions, so push the // projection and skip the subtree (thus generating no diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index bf583547491e1..da85de6019932 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -338,7 +338,7 @@ where substs, true, |ty| match *ty.kind() { - ty::Opaque(ty::AliasTy { def_id, substs }) => (def_id, substs), + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => (def_id, substs), _ => bug!("expected only projection types from env, not {:?}", ty), }, ); @@ -359,7 +359,9 @@ where projection_ty.substs, false, |ty| match ty.kind() { - ty::Projection(projection_ty) => (projection_ty.def_id, projection_ty.substs), + ty::Alias(ty::Projection, projection_ty) => { + (projection_ty.def_id, projection_ty.substs) + } _ => bug!("expected only projection types from env, not {:?}", ty), }, ); diff --git a/compiler/rustc_infer/src/infer/sub.rs b/compiler/rustc_infer/src/infer/sub.rs index 6b5000c37c56c..58e27f8b21d63 100644 --- a/compiler/rustc_infer/src/infer/sub.rs +++ b/compiler/rustc_infer/src/infer/sub.rs @@ -131,14 +131,14 @@ impl<'tcx> TypeRelation<'tcx> for Sub<'_, '_, 'tcx> { } ( - &ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: _ }), - &ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: _ }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }), ) if a_def_id == b_def_id => { self.fields.infcx.super_combine_tys(self, a, b)?; Ok(a) } - (&ty::Opaque(ty::AliasTy { def_id, substs: _ }), _) - | (_, &ty::Opaque(ty::AliasTy { def_id, substs: _ })) + (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _) + | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ })) if self.fields.define_opaque_types && def_id.is_local() => { self.fields.obligations.extend( diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 0932eee92373d..43862570e8095 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -3016,8 +3016,8 @@ impl ClashingExternDeclarations { | (Closure(..), Closure(..)) | (Generator(..), Generator(..)) | (GeneratorWitness(..), GeneratorWitness(..)) - | (Projection(..), Projection(..)) - | (Opaque(..), Opaque(..)) => false, + | (Alias(ty::Projection, ..), Alias(ty::Projection, ..)) + | (Alias(ty::Opaque, ..), Alias(ty::Opaque, ..)) => false, // These definitely should have been caught above. (Bool, Bool) | (Char, Char) | (Never, Never) | (Str, Str) => unreachable!(), diff --git a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs index 6cd806354bbdb..3808d308186c0 100644 --- a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs +++ b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs @@ -117,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound { // then we can emit a suggestion to add the bound. let add_bound = match (proj_term.kind(), assoc_pred.kind().skip_binder()) { ( - ty::Opaque(ty::AliasTy { def_id, substs: _ }), + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)), ) => Some(AddBound { suggest_span: cx.tcx.def_span(*def_id).shrink_to_hi(), diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 8446da6098ee9..8e27bc03c489a 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -1139,18 +1139,20 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { // While opaque types are checked for earlier, if a projection in a struct field // normalizes to an opaque type, then it will reach this branch. - ty::Opaque(..) => { + ty::Alias(ty::Opaque, ..) => { FfiUnsafe { ty, reason: fluent::lint_improper_ctypes_opaque, help: None } } // `extern "C" fn` functions can have type parameters, which may or may not be FFI-safe, // so they are currently ignored for the purposes of this lint. - ty::Param(..) | ty::Projection(..) if matches!(self.mode, CItemKind::Definition) => { + ty::Param(..) | ty::Alias(ty::Projection, ..) + if matches!(self.mode, CItemKind::Definition) => + { FfiSafe } ty::Param(..) - | ty::Projection(..) + | ty::Alias(ty::Projection, ..) | ty::Infer(..) | ty::Bound(..) | ty::Error(_) @@ -1205,7 +1207,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { return ControlFlow::CONTINUE; } - if let ty::Opaque(..) = ty.kind() { + if let ty::Alias(ty::Opaque, ..) = ty.kind() { ControlFlow::Break(ty) } else { ty.super_visit_with(self) diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 6851f6f9d6b0d..fb2c8b1ef647c 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -96,7 +96,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { if let hir::ExprKind::Match(await_expr, _arms, hir::MatchSource::AwaitDesugar) = expr.kind && let ty = cx.typeck_results().expr_ty(&await_expr) - && let ty::Opaque(ty::AliasTy { def_id: future_def_id, substs: _ }) = ty.kind() + && let ty::Alias(ty::Opaque, ty::AliasTy { def_id: future_def_id, substs: _ }) = ty.kind() && cx.tcx.ty_is_opaque_future(ty) // FIXME: This also includes non-async fns that return `impl Future`. && let async_fn_def_id = cx.tcx.parent(*future_def_id) @@ -251,7 +251,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { .map(|inner| MustUsePath::Boxed(Box::new(inner))) } ty::Adt(def, _) => is_def_must_use(cx, def.did(), span), - ty::Opaque(ty::AliasTy { def_id: def, substs: _ }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, substs: _ }) => { elaborate_predicates_with_span( cx.tcx, cx.tcx.explicit_item_bounds(def).iter().cloned(), diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 4c22cd65002b3..856f5bc4645fd 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1111,7 +1111,7 @@ fn should_encode_trait_impl_trait_tys<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> // associated types. tcx.fn_sig(trait_item_def_id).skip_binder().output().walk().any(|arg| { if let ty::GenericArgKind::Type(ty) = arg.unpack() - && let ty::Projection(data) = ty.kind() + && let ty::Alias(ty::Projection, data) = ty.kind() && tcx.def_kind(data.def_id) == DefKind::ImplTraitPlaceholder { true diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index fe65f6b2ae5ec..dc333b4702f39 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -115,8 +115,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { type ListBinderExistentialPredicate = &'tcx List>; type BinderListTy = Binder<'tcx, &'tcx List>>; type ListTy = &'tcx List>; - type ProjectionTy = ty::AliasTy<'tcx>; - type OpaqueTy = ty::AliasTy<'tcx>; + type AliasTy = ty::AliasTy<'tcx>; type ParamTy = ParamTy; type BoundTy = ty::BoundTy; type PlaceholderType = ty::PlaceholderType; @@ -2145,8 +2144,7 @@ impl<'tcx> TyCtxt<'tcx> { Bound, Param, Infer, - Projection, - Opaque, + Alias, Foreign )?; @@ -2323,7 +2321,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Given a `ty`, return whether it's an `impl Future<...>`. pub fn ty_is_opaque_future(self, ty: Ty<'_>) -> bool { - let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = ty.kind() else { return false }; + let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = ty.kind() else { return false }; let future_trait = self.require_lang_item(LangItem::Future, None); self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| { @@ -2598,7 +2596,7 @@ impl<'tcx> TyCtxt<'tcx> { substs.len(), "wrong number of generic parameters for {item_def_id:?}: {substs:?}", ); - self.mk_ty(Projection(AliasTy { def_id: item_def_id, substs })) + self.mk_ty(Alias(ty::Projection, AliasTy { def_id: item_def_id, substs })) } #[inline] @@ -2668,7 +2666,7 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> { - self.mk_ty(Opaque(ty::AliasTy { def_id, substs })) + self.mk_ty(Alias(ty::Opaque, ty::AliasTy { def_id, substs })) } pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> { diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index cdde8d380e41f..d7880a32ea9cd 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -4,7 +4,7 @@ use std::ops::ControlFlow; use crate::ty::{ visit::TypeVisitable, AliasTy, Const, ConstKind, DefIdTree, ExistentialPredicate, InferConst, - InferTy, PolyTraitPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor, + InferTy, Opaque, PolyTraitPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor, }; use rustc_data_structures::fx::FxHashMap; @@ -457,10 +457,10 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> { return ControlFlow::Break(()); } - Opaque(AliasTy { def_id, substs: _ }) => { + Alias(Opaque, AliasTy { def_id, substs: _ }) => { let parent = self.tcx.parent(*def_id); if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent) - && let Opaque(AliasTy { def_id: parent_opaque_def_id, substs: _ }) = self.tcx.type_of(parent).kind() + && let Alias(Opaque, AliasTy { def_id: parent_opaque_def_id, substs: _ }) = self.tcx.type_of(parent).kind() && parent_opaque_def_id == def_id { // Okay diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 15eae4b0aed29..22dc921aba1ca 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -337,9 +337,9 @@ impl<'tcx> Ty<'tcx> { ty::Infer(ty::FreshTy(_)) => "fresh type".into(), ty::Infer(ty::FreshIntTy(_)) => "fresh integral type".into(), ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(), - ty::Projection(_) => "associated type".into(), + ty::Alias(ty::Projection, _) => "associated type".into(), ty::Param(p) => format!("type parameter `{}`", p).into(), - ty::Opaque(..) => "opaque type".into(), + ty::Alias(ty::Opaque, ..) => "opaque type".into(), ty::Error(_) => "type error".into(), } } @@ -375,9 +375,9 @@ impl<'tcx> Ty<'tcx> { ty::Tuple(..) => "tuple".into(), ty::Placeholder(..) => "higher-ranked type".into(), ty::Bound(..) => "bound type variable".into(), - ty::Projection(_) => "associated type".into(), + ty::Alias(ty::Projection, _) => "associated type".into(), ty::Param(_) => "type parameter".into(), - ty::Opaque(..) => "opaque type".into(), + ty::Alias(ty::Opaque, ..) => "opaque type".into(), } } } @@ -400,7 +400,7 @@ impl<'tcx> TyCtxt<'tcx> { diag.note("no two closures, even if identical, have the same type"); diag.help("consider boxing your closure and/or using it as a trait object"); } - (ty::Opaque(..), ty::Opaque(..)) => { + (ty::Alias(ty::Opaque, ..), ty::Alias(ty::Opaque, ..)) => { // Issue #63167 diag.note("distinct uses of `impl Trait` result in different opaque types"); } @@ -439,10 +439,10 @@ impl<'tcx> TyCtxt<'tcx> { #traits-as-parameters", ); } - (ty::Projection(_), ty::Projection(_)) => { + (ty::Alias(ty::Projection, _), ty::Alias(ty::Projection, _)) => { diag.note("an associated type was expected, but a different one was found"); } - (ty::Param(p), ty::Projection(proj)) | (ty::Projection(proj), ty::Param(p)) + (ty::Param(p), ty::Alias(ty::Projection, proj)) | (ty::Alias(ty::Projection, proj), ty::Param(p)) if self.def_kind(proj.def_id) != DefKind::ImplTraitPlaceholder => { let generics = self.generics_of(body_owner_def_id); @@ -493,8 +493,8 @@ impl<'tcx> TyCtxt<'tcx> { diag.note("you might be missing a type parameter or trait bound"); } } - (ty::Param(p), ty::Dynamic(..) | ty::Opaque(..)) - | (ty::Dynamic(..) | ty::Opaque(..), ty::Param(p)) => { + (ty::Param(p), ty::Dynamic(..) | ty::Alias(ty::Opaque, ..)) + | (ty::Dynamic(..) | ty::Alias(ty::Opaque, ..), ty::Param(p)) => { let generics = self.generics_of(body_owner_def_id); let p_span = self.def_span(generics.type_param(p, self).def_id); if !sp.contains(p_span) { @@ -553,7 +553,7 @@ impl Trait for X { diag.span_label(p_span, "this type parameter"); } } - (ty::Projection(proj_ty), _) if self.def_kind(proj_ty.def_id) != DefKind::ImplTraitPlaceholder => { + (ty::Alias(ty::Projection, proj_ty), _) if self.def_kind(proj_ty.def_id) != DefKind::ImplTraitPlaceholder => { self.expected_projection( diag, proj_ty, @@ -562,7 +562,7 @@ impl Trait for X { cause.code(), ); } - (_, ty::Projection(proj_ty)) if self.def_kind(proj_ty.def_id) != DefKind::ImplTraitPlaceholder => { + (_, ty::Alias(ty::Projection, proj_ty)) if self.def_kind(proj_ty.def_id) != DefKind::ImplTraitPlaceholder => { let msg = format!( "consider constraining the associated type `{}` to `{}`", values.found, values.expected, @@ -779,7 +779,8 @@ fn foo(&self) -> Self::T { String::new() } ty: Ty<'tcx>, ) -> bool { let assoc = self.associated_item(proj_ty.def_id); - if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *proj_ty.self_ty().kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *proj_ty.self_ty().kind() + { let opaque_local_def_id = def_id.as_local(); let opaque_hir_ty = if let Some(opaque_local_def_id) = opaque_local_def_id { match &self.hir().expect_item(opaque_local_def_id).kind { @@ -828,7 +829,7 @@ fn foo(&self) -> Self::T { String::new() } .filter_map(|(_, item)| { let method = self.fn_sig(item.def_id); match *method.output().skip_binder().kind() { - ty::Projection(ty::AliasTy { def_id: item_def_id, .. }) + ty::Alias(ty::Projection, ty::AliasTy { def_id: item_def_id, .. }) if item_def_id == proj_ty_item_def_id => { Some(( diff --git a/compiler/rustc_middle/src/ty/fast_reject.rs b/compiler/rustc_middle/src/ty/fast_reject.rs index c9c09c93a3e1c..2771eb51a9b18 100644 --- a/compiler/rustc_middle/src/ty/fast_reject.rs +++ b/compiler/rustc_middle/src/ty/fast_reject.rs @@ -126,7 +126,7 @@ pub fn simplify_type<'tcx>( TreatParams::AsPlaceholder => Some(PlaceholderSimplifiedType), TreatParams::AsInfer => None, }, - ty::Opaque(..) | ty::Projection(_) => match treat_params { + ty::Alias(ty::Opaque, ..) | ty::Alias(ty::Projection, _) => match treat_params { // When treating `ty::Param` as a placeholder, projections also // don't unify with anything else as long as they are fully normalized. // @@ -225,7 +225,10 @@ impl DeepRejectCtxt { match impl_ty.kind() { // Start by checking whether the type in the impl may unify with // pretty much everything. Just return `true` in that case. - ty::Param(_) | ty::Projection(_) | ty::Error(_) | ty::Opaque(..) => return true, + ty::Param(_) + | ty::Alias(ty::Projection, _) + | ty::Error(_) + | ty::Alias(ty::Opaque, ..) => return true, // These types only unify with inference variables or their own // variant. ty::Bool @@ -323,7 +326,7 @@ impl DeepRejectCtxt { _ => false, }, - ty::Opaque(..) => true, + ty::Alias(ty::Opaque, ..) => true, // Impls cannot contain these types as these cannot be named directly. ty::FnDef(..) | ty::Closure(..) | ty::Generator(..) => false, @@ -344,7 +347,7 @@ impl DeepRejectCtxt { // projections can unify with other stuff. // // Looking forward to lazy normalization this is the safer strategy anyways. - ty::Projection(_) => true, + ty::Alias(ty::Projection, _) => true, ty::Error(_) => true, diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index d30882c6a81d9..174ac74fc9e61 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -155,12 +155,12 @@ impl FlagComputation { self.add_substs(substs); } - &ty::Projection(data) => { + &ty::Alias(ty::Projection, data) => { self.add_flags(TypeFlags::HAS_TY_PROJECTION); self.add_projection_ty(data); } - &ty::Opaque(ty::AliasTy { def_id: _, substs }) => { + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs }) => { self.add_flags(TypeFlags::HAS_TY_OPAQUE); self.add_substs(substs); } diff --git a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs index ace81bc4f8352..5d5089cec82a6 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs @@ -112,7 +112,7 @@ impl<'tcx> Ty<'tcx> { InhabitedPredicate::True } Never => InhabitedPredicate::False, - Param(_) | Projection(_) => InhabitedPredicate::GenericType(self), + Param(_) | Alias(ty::Projection, _) => InhabitedPredicate::GenericType(self), Tuple(tys) if tys.is_empty() => InhabitedPredicate::True, // use a query for more complex cases Adt(..) | Array(..) | Tuple(_) => tcx.inhabited_predicate_type(self), diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 488fd567846a3..40297492bb642 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -271,7 +271,7 @@ impl<'tcx> SizeSkeleton<'tcx> { let non_zero = !ty.is_unsafe_ptr(); let tail = tcx.struct_tail_erasing_lifetimes(pointee, param_env); match tail.kind() { - ty::Param(_) | ty::Projection(_) => { + ty::Param(_) | ty::Alias(ty::Projection, _) => { debug_assert!(tail.has_non_region_param()); Ok(SizeSkeleton::Pointer { non_zero, tail: tcx.erase_regions(tail) }) } @@ -349,7 +349,7 @@ impl<'tcx> SizeSkeleton<'tcx> { } } - ty::Projection(_) | ty::Opaque(..) => { + ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..) => { let normalized = tcx.normalize_erasing_regions(param_env, ty); if ty == normalized { Err(err) @@ -757,10 +757,10 @@ where } } - ty::Projection(_) + ty::Alias(ty::Projection, _) | ty::Bound(..) | ty::Placeholder(..) - | ty::Opaque(..) + | ty::Alias(ty::Opaque, ..) | ty::Param(_) | ty::Infer(_) | ty::Error(_) => bug!("TyAndLayout::field: unexpected type `{}`", this.ty), diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index ea508a0b97200..6cb28a0fd8077 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -64,6 +64,7 @@ use std::ops::ControlFlow; use std::{fmt, str}; pub use crate::ty::diagnostics::*; +pub use rustc_type_ir::AliasKind::*; pub use rustc_type_ir::DynKind::*; pub use rustc_type_ir::InferTy::*; pub use rustc_type_ir::RegionKind::*; diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index 667298b9b5b13..8de8fd5246c48 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -275,10 +275,10 @@ fn characteristic_def_id_of_type_cached<'a>( | ty::Uint(_) | ty::Str | ty::FnPtr(_) - | ty::Projection(_) + | ty::Alias(ty::Projection, _) | ty::Placeholder(..) | ty::Param(_) - | ty::Opaque(..) + | ty::Alias(ty::Opaque, ..) | ty::Infer(_) | ty::Bound(..) | ty::Error(_) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 437049947966a..6acc2dc65d369 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -718,7 +718,7 @@ pub trait PrettyPrinter<'tcx>: ty::Foreign(def_id) => { p!(print_def_path(def_id, &[])); } - ty::Projection(ref data) => { + ty::Alias(ty::Projection, ref data) => { if !(self.should_print_verbose() || NO_QUERIES.with(|q| q.get())) && self.tcx().def_kind(data.def_id) == DefKind::ImplTraitPlaceholder { @@ -728,7 +728,7 @@ pub trait PrettyPrinter<'tcx>: } } ty::Placeholder(placeholder) => p!(write("Placeholder({:?})", placeholder)), - ty::Opaque(ty::AliasTy { def_id, substs }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { // FIXME(eddyb) print this with `print_def_path`. // We use verbose printing in 'NO_QUERIES' mode, to // avoid needing to call `predicates_of`. This should @@ -743,7 +743,7 @@ pub trait PrettyPrinter<'tcx>: let parent = self.tcx().parent(def_id); match self.tcx().def_kind(parent) { DefKind::TyAlias | DefKind::AssocTy => { - if let ty::Opaque(ty::AliasTy { def_id: d, substs: _ }) = + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: d, substs: _ }) = *self.tcx().type_of(parent).kind() { if d == def_id { @@ -1021,7 +1021,7 @@ pub trait PrettyPrinter<'tcx>: // Skip printing `<[generator@] as Generator<_>>::Return` from async blocks, // unless we can find out what generator return type it comes from. let term = if let Some(ty) = term.skip_binder().ty() - && let ty::Projection(proj) = ty.kind() + && let ty::Alias(ty::Projection, proj) = ty.kind() && let Some(assoc) = tcx.opt_associated_item(proj.def_id) && assoc.trait_container(tcx) == tcx.lang_items().gen_trait() && assoc.name == rustc_span::sym::Return diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 108166c605d12..1eac8859ca934 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -551,14 +551,14 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( } // these two are already handled downstream in case of lazy normalization - (&ty::Projection(a_data), &ty::Projection(b_data)) => { + (&ty::Alias(ty::Projection, a_data), &ty::Alias(ty::Projection, b_data)) => { let projection_ty = relation.relate(a_data, b_data)?; Ok(tcx.mk_projection(projection_ty.def_id, projection_ty.substs)) } ( - &ty::Opaque(ty::AliasTy { def_id: a_def_id, substs: a_substs }), - &ty::Opaque(ty::AliasTy { def_id: b_def_id, substs: b_substs }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: a_substs }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: b_substs }), ) if a_def_id == b_def_id => { if relation.intercrate() { // During coherence, opaque types should be treated as equal to each other, even if their generic params diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 9d6a55b15f2c3..3d85ae3584ba8 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -651,9 +651,11 @@ impl<'tcx> TypeSuperFoldable<'tcx> for Ty<'tcx> { } ty::GeneratorWitness(types) => ty::GeneratorWitness(types.try_fold_with(folder)?), ty::Closure(did, substs) => ty::Closure(did, substs.try_fold_with(folder)?), - ty::Projection(data) => ty::Projection(data.try_fold_with(folder)?), - ty::Opaque(ty::AliasTy { def_id, substs }) => { - ty::Opaque(ty::AliasTy { def_id, substs: substs.try_fold_with(folder)? }) + ty::Alias(ty::Projection, data) => { + ty::Alias(ty::Projection, data.try_fold_with(folder)?) + } + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: substs.try_fold_with(folder)? }) } ty::Bool @@ -699,8 +701,10 @@ impl<'tcx> TypeSuperVisitable<'tcx> for Ty<'tcx> { ty::Generator(_did, ref substs, _) => substs.visit_with(visitor), ty::GeneratorWitness(ref types) => types.visit_with(visitor), ty::Closure(_did, ref substs) => substs.visit_with(visitor), - ty::Projection(ref data) => data.visit_with(visitor), - ty::Opaque(ty::AliasTy { def_id: _, ref substs }) => substs.visit_with(visitor), + ty::Alias(ty::Projection, ref data) => data.visit_with(visitor), + ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, ref substs }) => { + substs.visit_with(visitor) + } ty::Bool | ty::Char diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index cf872365d2004..a1c15f4044cf9 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1980,7 +1980,7 @@ impl<'tcx> Ty<'tcx> { #[inline] pub fn is_impl_trait(self) -> bool { - matches!(self.kind(), Opaque(..)) + matches!(self.kind(), Alias(ty::Opaque, ..)) } #[inline] @@ -2047,7 +2047,10 @@ impl<'tcx> Ty<'tcx> { ty::Adt(adt, _) if adt.is_enum() => adt.repr().discr_type().to_ty(tcx), ty::Generator(_, substs, _) => substs.as_generator().discr_ty(tcx), - ty::Param(_) | ty::Projection(_) | ty::Opaque(..) | ty::Infer(ty::TyVar(_)) => { + ty::Param(_) + | ty::Alias(ty::Projection, _) + | ty::Alias(ty::Opaque, ..) + | ty::Infer(ty::TyVar(_)) => { let assoc_items = tcx.associated_item_def_ids( tcx.require_lang_item(hir::LangItem::DiscriminantKind, None), ); @@ -2127,7 +2130,7 @@ impl<'tcx> Ty<'tcx> { // type parameters only have unit metadata if they're sized, so return true // to make sure we double check this during confirmation - ty::Param(_) | ty::Projection(_) | ty::Opaque(..) => (tcx.types.unit, true), + ty::Param(_) | ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..) => (tcx.types.unit, true), ty::Infer(ty::TyVar(_)) | ty::Bound(..) @@ -2203,7 +2206,7 @@ impl<'tcx> Ty<'tcx> { ty::Adt(def, _substs) => def.sized_constraint(tcx).0.is_empty(), - ty::Projection(_) | ty::Param(_) | ty::Opaque(..) => false, + ty::Alias(ty::Projection, _) | ty::Param(_) | ty::Alias(ty::Opaque, ..) => false, ty::Infer(ty::TyVar(_)) => false, @@ -2259,9 +2262,9 @@ impl<'tcx> Ty<'tcx> { ty::Generator(..) | ty::GeneratorWitness(..) => false, // Might be, but not "trivial" so just giving the safe answer. - ty::Adt(..) | ty::Closure(..) | ty::Opaque(..) => false, + ty::Adt(..) | ty::Closure(..) | ty::Alias(ty::Opaque, ..) => false, - ty::Projection(..) | ty::Param(..) | ty::Infer(..) | ty::Error(..) => false, + ty::Alias(ty::Projection, ..) | ty::Param(..) | ty::Infer(..) | ty::Error(..) => false, ty::Bound(..) | ty::Placeholder(..) => { bug!("`is_trivially_pure_clone_copy` applied to unexpected type: {:?}", self); diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index b2ed9ca420049..cf35240f165bd 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -259,7 +259,7 @@ impl<'tcx> TyCtxt<'tcx> { ty::Tuple(_) => break, - ty::Projection(_) | ty::Opaque(..) => { + ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..) => { let normalized = normalize(ty); if ty == normalized { return ty; @@ -332,8 +332,8 @@ impl<'tcx> TyCtxt<'tcx> { break; } } - (ty::Projection(_) | ty::Opaque(..), _) - | (_, ty::Projection(_) | ty::Opaque(..)) => { + (ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..), _) + | (_, ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..)) => { // If either side is a projection, attempt to // progress via normalization. (Should be safe to // apply to both sides as normalization is @@ -826,7 +826,7 @@ impl<'tcx> TypeFolder<'tcx> for OpaqueTypeExpander<'tcx> { } fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Opaque(ty::AliasTy { def_id, substs }) = *t.kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) = *t.kind() { self.expand_opaque_ty(def_id, substs).unwrap_or(t) } else if t.has_opaque_types() { t.super_fold_with(self) @@ -938,10 +938,10 @@ impl<'tcx> Ty<'tcx> { | ty::Generator(..) | ty::GeneratorWitness(_) | ty::Infer(_) - | ty::Opaque(..) + | ty::Alias(ty::Opaque, ..) | ty::Param(_) | ty::Placeholder(_) - | ty::Projection(_) => false, + | ty::Alias(ty::Projection, _) => false, } } @@ -978,10 +978,10 @@ impl<'tcx> Ty<'tcx> { | ty::Generator(..) | ty::GeneratorWitness(_) | ty::Infer(_) - | ty::Opaque(..) + | ty::Alias(ty::Opaque, ..) | ty::Param(_) | ty::Placeholder(_) - | ty::Projection(_) => false, + | ty::Alias(ty::Projection, _) => false, } } @@ -1101,8 +1101,8 @@ impl<'tcx> Ty<'tcx> { // // FIXME(ecstaticmorse): Maybe we should `bug` here? This should probably only be // called for known, fully-monomorphized types. - ty::Projection(_) - | ty::Opaque(..) + ty::Alias(ty::Projection, _) + | ty::Alias(ty::Opaque, ..) | ty::Param(_) | ty::Bound(..) | ty::Placeholder(_) @@ -1237,11 +1237,11 @@ pub fn needs_drop_components<'tcx>( // These require checking for `Copy` bounds or `Adt` destructors. ty::Adt(..) - | ty::Projection(..) + | ty::Alias(ty::Projection, ..) | ty::Param(_) | ty::Bound(..) | ty::Placeholder(..) - | ty::Opaque(..) + | ty::Alias(ty::Opaque, ..) | ty::Infer(_) | ty::Closure(..) | ty::Generator(..) => Ok(smallvec![ty]), @@ -1265,13 +1265,13 @@ pub fn is_trivially_const_drop<'tcx>(ty: Ty<'tcx>) -> bool { | ty::Never | ty::Foreign(_) => true, - ty::Opaque(..) + ty::Alias(ty::Opaque, ..) | ty::Dynamic(..) | ty::Error(_) | ty::Bound(..) | ty::Param(_) | ty::Placeholder(_) - | ty::Projection(_) + | ty::Alias(ty::Projection, _) | ty::Infer(_) => false, // Not trivial because they have components, and instead of looking inside, diff --git a/compiler/rustc_middle/src/ty/visit.rs b/compiler/rustc_middle/src/ty/visit.rs index 4cdfd9e594042..085232a47cc57 100644 --- a/compiler/rustc_middle/src/ty/visit.rs +++ b/compiler/rustc_middle/src/ty/visit.rs @@ -654,7 +654,7 @@ impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector { // ignore the inputs to a projection, as they may not appear // in the normalized form if self.just_constrained { - if let ty::Projection(..) | ty::Opaque(..) = t.kind() { + if let ty::Alias(ty::Projection, ..) | ty::Alias(ty::Opaque, ..) = t.kind() { return ControlFlow::CONTINUE; } } diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index e79b5bcae5da9..f4876d019cee0 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -165,7 +165,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) stack.push(ty.into()); stack.push(lt.into()); } - ty::Projection(data) => { + ty::Alias(ty::Projection, data) => { stack.extend(data.substs.iter().rev()); } ty::Dynamic(obj, lt, _) => { @@ -188,7 +188,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) })); } ty::Adt(_, substs) - | ty::Opaque(ty::AliasTy { def_id: _, substs }) + | ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs }) | ty::Closure(_, substs) | ty::Generator(_, substs, _) | ty::FnDef(_, substs) => { diff --git a/compiler/rustc_mir_build/src/build/block.rs b/compiler/rustc_mir_build/src/build/block.rs index 49d7136a2f1ff..6e39f1d3a97bf 100644 --- a/compiler/rustc_mir_build/src/build/block.rs +++ b/compiler/rustc_mir_build/src/build/block.rs @@ -373,7 +373,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // the case of `!`, no return value is required, as the block will never return. // Opaque types of empty bodies also need this unit assignment, in order to infer that their // type is actually unit. Otherwise there will be no defining use found in the MIR. - if destination_ty.is_unit() || matches!(destination_ty.kind(), ty::Opaque(..)) { + if destination_ty.is_unit() + || matches!(destination_ty.kind(), ty::Alias(ty::Opaque, ..)) + { // We only want to assign an implicit `()` as the return value of the block if the // block does not diverge. (Otherwise, we may try to assign a unit to a `!`-type.) this.cfg.push_assign_unit(block, source_info, destination, this.tcx); diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs index a21f6cd39f014..7e1f708b0d6a1 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs @@ -121,7 +121,7 @@ impl<'tcx> ConstToPat<'tcx> { ty::Dynamic(..) => { "trait objects cannot be used in patterns".to_string() } - ty::Opaque(..) => { + ty::Alias(ty::Opaque, ..) => { "opaque types cannot be used in patterns".to_string() } ty::Closure(..) => { diff --git a/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs b/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs index 3e370a0537665..8f80cb95e58e7 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/usefulness.rs @@ -845,7 +845,7 @@ fn is_useful<'p, 'tcx>( // Opaque types can't get destructured/split, but the patterns can // actually hint at hidden types, so we use the patterns' types instead. - if let ty::Opaque(..) = ty.kind() { + if let ty::Alias(ty::Opaque, ..) = ty.kind() { if let Some(row) = rows.first() { ty = row.head().ty(); } diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index f887dc5f2eab7..ef7589d3ef231 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -849,7 +849,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> { }; let kind = match parent_ty.ty.kind() { - &ty::Opaque(ty::AliasTy { def_id, substs }) => { + &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { self.tcx.bound_type_of(def_id).subst(self.tcx, substs).kind() } kind => kind, diff --git a/compiler/rustc_mir_transform/src/remove_zsts.rs b/compiler/rustc_mir_transform/src/remove_zsts.rs index 569e783fee847..6cabef92d8c21 100644 --- a/compiler/rustc_mir_transform/src/remove_zsts.rs +++ b/compiler/rustc_mir_transform/src/remove_zsts.rs @@ -52,7 +52,11 @@ impl<'tcx> MirPass<'tcx> for RemoveZsts { fn maybe_zst(ty: Ty<'_>) -> bool { match ty.kind() { // maybe ZST (could be more precise) - ty::Adt(..) | ty::Array(..) | ty::Closure(..) | ty::Tuple(..) | ty::Opaque(..) => true, + ty::Adt(..) + | ty::Array(..) + | ty::Closure(..) + | ty::Tuple(..) + | ty::Alias(ty::Opaque, ..) => true, // definitely ZST ty::FnDef(..) | ty::Never => true, // unreachable or can't be ZST diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 3246a1e2f88c9..deaeec9a80e46 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -208,7 +208,7 @@ where } } } - ty::Projection(proj) => { + ty::Alias(ty::Projection, proj) => { if self.def_id_visitor.skip_assoc_tys() { // Visitors searching for minimal visibility/reachability want to // conservatively approximate associated types like `::Alias` @@ -235,7 +235,7 @@ where self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref)?; } } - ty::Opaque(ty::AliasTy { def_id, substs: _ }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => { // Skip repeated `Opaque`s to avoid infinite recursion. if self.visited_opaque_tys.insert(def_id) { // The intent is to treat `impl Trait1 + Trait2` identically to diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index d21288d851cec..a82fee8cf4bdf 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -216,8 +216,8 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> { match *ty.kind() { // Print all nominal types as paths (unlike `pretty_print_type`). ty::FnDef(def_id, substs) - | ty::Opaque(ty::AliasTy { def_id, substs }) - | ty::Projection(ty::AliasTy { def_id, substs }) + | ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) + | ty::Alias(ty::Projection, ty::AliasTy { def_id, substs }) | ty::Closure(def_id, substs) | ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs), @@ -287,11 +287,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> { // Similar to `pretty_path_qualified`, but for the other // types that are printed as paths (see `print_type` above). match self_ty.kind() { - ty::FnDef(..) - | ty::Opaque(..) - | ty::Projection(_) - | ty::Closure(..) - | ty::Generator(..) + ty::FnDef(..) | ty::Alias(..) | ty::Closure(..) | ty::Generator(..) if trait_ref.is_none() => { self.print_type(self_ty) diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs index dddc7b7513a5b..cff6a276eecef 100644 --- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs +++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs @@ -646,10 +646,10 @@ fn encode_ty<'tcx>( | ty::Error(..) | ty::GeneratorWitness(..) | ty::Infer(..) - | ty::Opaque(..) + | ty::Alias(ty::Opaque, ..) | ty::Param(..) | ty::Placeholder(..) - | ty::Projection(..) => { + | ty::Alias(ty::Projection, ..) => { bug!("encode_ty: unexpected `{:?}`", ty.kind()); } }; @@ -799,10 +799,10 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio | ty::Error(..) | ty::GeneratorWitness(..) | ty::Infer(..) - | ty::Opaque(..) + | ty::Alias(ty::Opaque, ..) | ty::Param(..) | ty::Placeholder(..) - | ty::Projection(..) => { + | ty::Alias(ty::Projection, ..) => { bug!("transform_ty: unexpected `{:?}`", ty.kind()); } } diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 52d0469fd445f..175367ad41436 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -439,8 +439,8 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { // Mangle all nominal types as paths. ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs) | ty::FnDef(def_id, substs) - | ty::Opaque(ty::AliasTy { def_id, substs }) - | ty::Projection(ty::AliasTy { def_id, substs }) + | ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) + | ty::Alias(ty::Projection, ty::AliasTy { def_id, substs }) | ty::Closure(def_id, substs) | ty::Generator(def_id, substs, _) => { self = self.print_def_path(def_id, substs)?; diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 8e04da4f9be24..aef2f8ff9911c 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -579,14 +579,14 @@ impl<'tcx> AutoTraitFinder<'tcx> { pub fn is_of_param(&self, ty: Ty<'_>) -> bool { match ty.kind() { ty::Param(_) => true, - ty::Projection(p) => self.is_of_param(p.self_ty()), + ty::Alias(ty::Projection, p) => self.is_of_param(p.self_ty()), _ => false, } } fn is_self_referential_projection(&self, p: ty::PolyProjectionPredicate<'_>) -> bool { if let Some(ty) = p.term().skip_binder().ty() { - matches!(ty.kind(), ty::Projection(proj) if proj == &p.skip_binder().projection_ty) + matches!(ty.kind(), ty::Alias(ty::Projection, proj) if proj == &p.skip_binder().projection_ty) } else { false } diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 899e30275a052..7c569621cfeb8 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -659,7 +659,7 @@ impl<'tcx> TypeVisitor<'tcx> for OrphanChecker<'tcx> { | ty::RawPtr(..) | ty::Never | ty::Tuple(..) - | ty::Projection(..) => self.found_non_local_ty(ty), + | ty::Alias(ty::Projection, ..) => self.found_non_local_ty(ty), ty::Param(..) => self.found_param_ty(ty), @@ -704,7 +704,7 @@ impl<'tcx> TypeVisitor<'tcx> for OrphanChecker<'tcx> { ); ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)) } - ty::Opaque(..) => { + ty::Alias(ty::Opaque, ..) => { // This merits some explanation. // Normally, opaque types are not involved when performing // coherence checking, since it is illegal to directly diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 82477ec6c440c..e8d964dd17209 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1787,8 +1787,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ty::Closure(..) => Some(9), ty::Tuple(..) => Some(10), ty::Param(..) => Some(11), - ty::Projection(..) => Some(12), - ty::Opaque(..) => Some(13), + ty::Alias(ty::Projection, ..) => Some(12), + ty::Alias(ty::Opaque, ..) => Some(13), ty::Never => Some(14), ty::Adt(..) => Some(15), ty::Generator(..) => Some(16), diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 6c9c516b305f8..313ac28d2203e 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -495,7 +495,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let self_ty = trait_pred.skip_binder().self_ty(); let (param_ty, projection) = match self_ty.kind() { ty::Param(_) => (true, None), - ty::Projection(projection) => (false, Some(projection)), + ty::Alias(ty::Projection, projection) => (false, Some(projection)), _ => (false, None), }; @@ -855,7 +855,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { fn_sig.inputs().map_bound(|inputs| &inputs[1..]), )) } - ty::Opaque(ty::AliasTy { def_id, substs }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { self.tcx.bound_item_bounds(def_id).subst(self.tcx, substs).iter().find_map(|pred| { if let ty::PredicateKind::Clause(ty::Clause::Projection(proj)) = pred.kind().skip_binder() && Some(proj.projection_ty.def_id) == self.tcx.lang_items().fn_once_output() @@ -2644,7 +2644,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { Some(ident) => err.span_note(ident.span, &msg), None => err.note(&msg), }, - ty::Opaque(ty::AliasTy { def_id, substs: _ }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => { // Avoid printing the future from `core::future::identity_future`, it's not helpful if tcx.parent(*def_id) == identity_future { break 'print; @@ -3221,7 +3221,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let ocx = ObligationCtxt::new_in_snapshot(self.infcx); for diff in &type_diffs { let Sorts(expected_found) = diff else { continue; }; - let ty::Projection(proj) = expected_found.expected.kind() else { continue; }; + let ty::Alias(ty::Projection, proj) = expected_found.expected.kind() else { continue; }; let origin = TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span }; diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 4cfcd74f33776..3e85ea69635e6 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -794,13 +794,13 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeVisitable<'tcx>>( ControlFlow::CONTINUE } } - ty::Projection(ref data) + ty::Alias(ty::Projection, ref data) if self.tcx.def_kind(data.def_id) == DefKind::ImplTraitPlaceholder => { // We'll deny these later in their own pass ControlFlow::CONTINUE } - ty::Projection(ref data) => { + ty::Alias(ty::Projection, ref data) => { // This is a projected type `::X`. // Compute supertraits of current trait lazily. @@ -861,7 +861,7 @@ pub fn contains_illegal_impl_trait_in_trait<'tcx>( // FIXME(RPITIT): Perhaps we should use a visitor here? ty.skip_binder().walk().find_map(|arg| { if let ty::GenericArgKind::Type(ty) = arg.unpack() - && let ty::Projection(proj) = ty.kind() + && let ty::Alias(ty::Projection, proj) = ty.kind() && tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder { Some(MethodViolationCode::ReferencesImplTraitInTrait(tcx.def_span(proj.def_id))) diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index ea9c066566e3d..6e3a83f2a3479 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -496,7 +496,9 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { // This is really important. While we *can* handle this, this has // severe performance implications for large opaque types with // late-bound regions. See `issue-88862` benchmark. - ty::Opaque(ty::AliasTy { def_id, substs }) if !substs.has_escaping_bound_vars() => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) + if !substs.has_escaping_bound_vars() => + { // Only normalize `impl Trait` outside of type inference, usually in codegen. match self.param_env.reveal() { Reveal::UserFacing => ty.super_fold_with(self), @@ -523,7 +525,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { } } - ty::Projection(data) if !data.has_escaping_bound_vars() => { + ty::Alias(ty::Projection, data) if !data.has_escaping_bound_vars() => { // This branch is *mostly* just an optimization: when we don't // have escaping bound vars, we don't need to replace them with // placeholders (see branch below). *Also*, we know that we can @@ -562,7 +564,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> { normalized_ty.ty().unwrap() } - ty::Projection(data) => { + ty::Alias(ty::Projection, data) => { // If there are escaping bound vars, we temporarily replace the // bound vars with placeholders. Note though, that in the case // that we still can't project for whatever reason (e.g. self @@ -1375,8 +1377,10 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>( // Check whether the self-type is itself a projection. // If so, extract what we know from the trait and try to come up with a good answer. let bounds = match *obligation.predicate.self_ty().kind() { - ty::Projection(ref data) => tcx.bound_item_bounds(data.def_id).subst(tcx, data.substs), - ty::Opaque(ty::AliasTy { def_id, substs }) => { + ty::Alias(ty::Projection, ref data) => { + tcx.bound_item_bounds(data.def_id).subst(tcx, data.substs) + } + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { tcx.bound_item_bounds(def_id).subst(tcx, substs) } ty::Infer(ty::TyVar(_)) => { @@ -1616,8 +1620,8 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( // type parameters, opaques, and unnormalized projections have pointer // metadata if they're known (e.g. by the param_env) to be sized ty::Param(_) - | ty::Projection(..) - | ty::Opaque(..) + | ty::Alias(ty::Projection, ..) + | ty::Alias(ty::Opaque, ..) | ty::Bound(..) | ty::Placeholder(..) | ty::Infer(..) @@ -1671,7 +1675,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( // type parameters, opaques, and unnormalized projections have pointer // metadata if they're known (e.g. by the param_env) to be sized - ty::Param(_) | ty::Projection(..) | ty::Opaque(..) + ty::Param(_) | ty::Alias(ty::Projection, ..) | ty::Alias(ty::Opaque, ..) if selcx.infcx.predicate_must_hold_modulo_regions( &obligation.with( selcx.tcx(), @@ -1687,8 +1691,8 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( // FIXME(compiler-errors): are Bound and Placeholder types ever known sized? ty::Param(_) - | ty::Projection(..) - | ty::Opaque(..) + | ty::Alias(ty::Projection, ..) + | ty::Alias(ty::Opaque, ..) | ty::Bound(..) | ty::Placeholder(..) | ty::Infer(..) diff --git a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs index aad3c37f84e5a..03558f04ed295 100644 --- a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs +++ b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs @@ -62,9 +62,9 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { // The following *might* require a destructor: needs deeper inspection. ty::Dynamic(..) - | ty::Projection(..) + | ty::Alias(ty::Projection, ..) | ty::Param(_) - | ty::Opaque(..) + | ty::Alias(ty::Opaque, ..) | ty::Placeholder(..) | ty::Infer(_) | ty::Bound(..) diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 7291965760eff..777de195895b8 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -205,7 +205,9 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { // This is really important. While we *can* handle this, this has // severe performance implications for large opaque types with // late-bound regions. See `issue-88862` benchmark. - ty::Opaque(ty::AliasTy { def_id, substs }) if !substs.has_escaping_bound_vars() => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) + if !substs.has_escaping_bound_vars() => + { // Only normalize `impl Trait` outside of type inference, usually in codegen. match self.param_env.reveal() { Reveal::UserFacing => ty.try_super_fold_with(self), @@ -242,7 +244,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { } } - ty::Projection(data) if !data.has_escaping_bound_vars() => { + ty::Alias(ty::Projection, data) if !data.has_escaping_bound_vars() => { // This branch is just an optimization: when we don't have escaping bound vars, // we don't need to replace them with placeholders (see branch below). @@ -291,7 +293,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> { } } - ty::Projection(data) => { + ty::Alias(ty::Projection, data) => { // See note in `rustc_trait_selection::traits::project` let tcx = self.infcx.tcx; diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index f65e573401d30..db8c73a880765 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -138,7 +138,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Before we go into the whole placeholder thing, just // quickly check if the self-type is a projection at all. match obligation.predicate.skip_binder().trait_ref.self_ty().kind() { - ty::Projection(_) | ty::Opaque(..) => {} + ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..) => {} ty::Infer(ty::TyVar(_)) => { span_bug!( obligation.cause.span, @@ -394,7 +394,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // still be provided by a manual implementation for // this trait and type. } - ty::Param(..) | ty::Projection(..) => { + ty::Param(..) | ty::Alias(ty::Projection, ..) => { // In these cases, we don't know what the actual // type is. Therefore, we cannot break it down // into its constituent types. So we don't @@ -734,13 +734,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let self_ty = self.infcx.shallow_resolve(obligation.self_ty()); match self_ty.skip_binder().kind() { - ty::Opaque(..) + ty::Alias(ty::Opaque, ..) | ty::Dynamic(..) | ty::Error(_) | ty::Bound(..) | ty::Param(_) | ty::Placeholder(_) - | ty::Projection(_) => { + | ty::Alias(ty::Projection, _) => { // We don't know if these are `~const Destruct`, at least // not structurally... so don't push a candidate. } @@ -826,8 +826,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::Generator(_, _, _) | ty::GeneratorWitness(_) | ty::Never - | ty::Projection(_) - | ty::Opaque(ty::AliasTy { def_id: _, substs: _ }) + | ty::Alias(ty::Projection, _) + | ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs: _ }) | ty::Param(_) | ty::Bound(_, _) | ty::Error(_) diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index e945d320b73bc..96c56905f8ae1 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -155,8 +155,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let placeholder_self_ty = placeholder_trait_predicate.self_ty(); let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate); let (def_id, substs) = match *placeholder_self_ty.kind() { - ty::Projection(proj) => (proj.def_id, proj.substs), - ty::Opaque(ty::AliasTy { def_id, substs }) => (def_id, substs), + ty::Alias(ty::Projection, proj) => (proj.def_id, proj.substs), + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => (def_id, substs), _ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty), }; @@ -184,7 +184,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .map_err(|_| Unimplemented) })?); - if let ty::Projection(..) = placeholder_self_ty.kind() { + if let ty::Alias(ty::Projection, ..) = placeholder_self_ty.kind() { let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, substs).predicates; debug!(?predicates, "projection predicates"); for predicate in predicates { @@ -1279,7 +1279,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // If we have a projection type, make sure to normalize it so we replace it // with a fresh infer variable - ty::Projection(..) => { + ty::Alias(ty::Projection, ..) => { let predicate = normalize_with_depth_to( self, obligation.param_env, diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index f26705d63a93e..1f078bef310d5 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1595,8 +1595,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let tcx = self.infcx.tcx; let (def_id, substs) = match *placeholder_trait_predicate.trait_ref.self_ty().kind() { - ty::Projection(ref data) => (data.def_id, data.substs), - ty::Opaque(ty::AliasTy { def_id, substs }) => (def_id, substs), + ty::Alias(ty::Projection, ref data) => (data.def_id, data.substs), + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => (def_id, substs), _ => { span_bug!( obligation.cause.span, @@ -2067,7 +2067,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { })) } - ty::Projection(_) | ty::Param(_) | ty::Opaque(..) => None, + ty::Alias(ty::Projection, _) | ty::Param(_) | ty::Alias(ty::Opaque, ..) => None, ty::Infer(ty::TyVar(_)) => Ambiguous, ty::Placeholder(..) @@ -2167,7 +2167,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::Adt(..) | ty::Projection(..) | ty::Param(..) | ty::Opaque(..) => { + ty::Adt(..) + | ty::Alias(ty::Projection, ..) + | ty::Param(..) + | ty::Alias(ty::Opaque, ..) => { // Fallback to whatever user-defined impls exist in this case. None } @@ -2220,7 +2223,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::Dynamic(..) | ty::Param(..) | ty::Foreign(..) - | ty::Projection(..) + | ty::Alias(ty::Projection, ..) | ty::Bound(..) | ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { bug!("asked to assemble constituent types of unexpected type: {:?}", t); @@ -2260,7 +2263,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { t.rebind(def.all_fields().map(|f| f.ty(self.tcx(), substs)).collect()) } - ty::Opaque(ty::AliasTy { def_id, substs }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { // We can resolve the `impl Trait` to its concrete type, // which enforces a DAG between the functions requiring // the auto trait bounds in question. diff --git a/compiler/rustc_trait_selection/src/traits/structural_match.rs b/compiler/rustc_trait_selection/src/traits/structural_match.rs index 4dc08e0f9dab0..62881b67f5ec2 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_match.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_match.rs @@ -95,10 +95,10 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> { ty::Foreign(_) => { return ControlFlow::Break(ty); } - ty::Opaque(..) => { + ty::Alias(ty::Opaque, ..) => { return ControlFlow::Break(ty); } - ty::Projection(..) => { + ty::Alias(ty::Projection, ..) => { return ControlFlow::Break(ty); } ty::Closure(..) => { diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 60283a46c8ade..74c4ae8854c34 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -234,7 +234,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( // projection coming from another associated type. See // `src/test/ui/associated-types/point-at-type-on-obligation-failure.rs` and // `traits-assoc-type-in-supertrait-bad.rs`. - if let Some(ty::Projection(projection_ty)) = proj.term.ty().map(|ty| ty.kind()) + if let Some(ty::Alias(ty::Projection, projection_ty)) = proj.term.ty().map(|ty| ty.kind()) && let Some(&impl_item_id) = tcx.impl_item_implementor_ids(impl_def_id).get(&projection_ty.def_id) && let Some(impl_item_span) = items @@ -249,7 +249,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>( // An associated item obligation born out of the `trait` failed to be met. An example // can be seen in `ui/associated-types/point-at-type-on-obligation-failure-2.rs`. debug!("extended_cause_with_original_assoc_item_obligation trait proj {:?}", pred); - if let ty::Projection(ty::AliasTy { def_id, .. }) = *pred.self_ty().kind() + if let ty::Alias(ty::Projection, ty::AliasTy { def_id, .. }) = *pred.self_ty().kind() && let Some(&impl_item_id) = tcx.impl_item_implementor_ids(impl_def_id).get(&def_id) && let Some(impl_item_span) = items @@ -556,7 +556,7 @@ impl<'tcx> WfPredicates<'tcx> { // Simple cases that are WF if their type args are WF. } - ty::Projection(data) => { + ty::Alias(ty::Projection, data) => { walker.skip_current_subtree(); // Subtree handled by compute_projection. self.compute_projection(data); } @@ -648,7 +648,7 @@ impl<'tcx> WfPredicates<'tcx> { // types appearing in the fn signature } - ty::Opaque(ty::AliasTy { def_id, substs }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { // All of the requirements on type parameters // have already been checked for `impl Trait` in // return position. We do need to check type-alias-impl-trait though. diff --git a/compiler/rustc_traits/src/chalk/db.rs b/compiler/rustc_traits/src/chalk/db.rs index 30482cea26290..53bafde0ea20e 100644 --- a/compiler/rustc_traits/src/chalk/db.rs +++ b/compiler/rustc_traits/src/chalk/db.rs @@ -432,9 +432,10 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t (ast::Mutability::Not, chalk_ir::Mutability::Not) => true, } } - (&ty::Opaque(ty::AliasTy { def_id, substs: _ }), OpaqueType(opaque_ty_id, ..)) => { - def_id == opaque_ty_id.0 - } + ( + &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), + OpaqueType(opaque_ty_id, ..), + ) => def_id == opaque_ty_id.0, (&ty::FnDef(def_id, ..), FnDef(fn_def_id, ..)) => def_id == fn_def_id.0, (&ty::Str, Str) => true, (&ty::Never, Never) => true, @@ -788,7 +789,7 @@ impl<'tcx> ty::TypeFolder<'tcx> for ReplaceOpaqueTyFolder<'tcx> { } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Opaque(ty::AliasTy { def_id, substs }) = *ty.kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) = *ty.kind() { if def_id == self.opaque_ty_id.0 && substs == self.identity_substs { return self.tcx.mk_ty(ty::Bound( self.binder_index, diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index fb89b0cd4c27e..7fbf3270627dc 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -353,8 +353,8 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty>> for Ty<'tcx> { ty::Tuple(types) => { chalk_ir::TyKind::Tuple(types.len(), types.as_substs().lower_into(interner)) } - ty::Projection(proj) => chalk_ir::TyKind::Alias(proj.lower_into(interner)), - ty::Opaque(ty::AliasTy { def_id, substs }) => { + ty::Alias(ty::Projection, proj) => chalk_ir::TyKind::Alias(proj.lower_into(interner)), + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { opaque_ty_id: chalk_ir::OpaqueTyId(def_id), substitution: substs.lower_into(interner), @@ -442,14 +442,14 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty> { mutbl.lower_into(interner), ), TyKind::Str => ty::Str, - TyKind::OpaqueType(opaque_ty, substitution) => ty::Opaque(ty::AliasTy { - def_id: opaque_ty.0, - substs: substitution.lower_into(interner), - }), - TyKind::AssociatedType(assoc_ty, substitution) => ty::Projection(ty::AliasTy { - substs: substitution.lower_into(interner), - def_id: assoc_ty.0, - }), + TyKind::OpaqueType(opaque_ty, substitution) => ty::Alias( + ty::Opaque, + ty::AliasTy { def_id: opaque_ty.0, substs: substitution.lower_into(interner) }, + ), + TyKind::AssociatedType(assoc_ty, substitution) => ty::Alias( + ty::Projection, + ty::AliasTy { substs: substitution.lower_into(interner), def_id: assoc_ty.0 }, + ), TyKind::Foreign(def_id) => ty::Foreign(def_id.0), TyKind::Error => return interner.tcx.ty_error(), TyKind::Placeholder(placeholder) => ty::Placeholder(ty::Placeholder { @@ -457,14 +457,20 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty> { name: ty::BoundVar::from_usize(placeholder.idx), }), TyKind::Alias(alias_ty) => match alias_ty { - chalk_ir::AliasTy::Projection(projection) => ty::Projection(ty::AliasTy { - def_id: projection.associated_ty_id.0, - substs: projection.substitution.lower_into(interner), - }), - chalk_ir::AliasTy::Opaque(opaque) => ty::Opaque(ty::AliasTy { - def_id: opaque.opaque_ty_id.0, - substs: opaque.substitution.lower_into(interner), - }), + chalk_ir::AliasTy::Projection(projection) => ty::Alias( + ty::Projection, + ty::AliasTy { + def_id: projection.associated_ty_id.0, + substs: projection.substitution.lower_into(interner), + }, + ), + chalk_ir::AliasTy::Opaque(opaque) => ty::Alias( + ty::Opaque, + ty::AliasTy { + def_id: opaque.opaque_ty_id.0, + substs: opaque.substitution.lower_into(interner), + }, + ), }, TyKind::Function(_quantified_ty) => unimplemented!(), TyKind::BoundVar(_bound) => ty::Bound( diff --git a/compiler/rustc_traits/src/dropck_outlives.rs b/compiler/rustc_traits/src/dropck_outlives.rs index 66ab742f15782..f9503fae94c24 100644 --- a/compiler/rustc_traits/src/dropck_outlives.rs +++ b/compiler/rustc_traits/src/dropck_outlives.rs @@ -112,7 +112,7 @@ fn dropck_outlives<'tcx>( // A projection that we couldn't resolve - it // might have a destructor. - ty::Projection(..) | ty::Opaque(..) => { + ty::Alias(ty::Projection, ..) | ty::Alias(ty::Opaque, ..) => { result.kinds.push(ty.into()); } @@ -268,7 +268,7 @@ fn dtorck_constraint_for_ty<'tcx>( } // Types that can't be resolved. Pass them forward. - ty::Projection(..) | ty::Opaque(..) | ty::Param(..) => { + ty::Alias(ty::Projection, ..) | ty::Alias(ty::Opaque, ..) | ty::Param(..) => { constraints.dtorck_types.push(ty); } diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index f4672a70072b2..3d5fa2de57930 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -444,7 +444,7 @@ fn layout_of_uncached<'tcx>( } // Types with no meaningful known layout. - ty::Projection(_) | ty::Opaque(..) => { + ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..) => { // NOTE(eddyb) `layout_of` query should've normalized these away, // if that was possible, so there's no reason to try again here. return Err(LayoutError::Unknown(ty)); diff --git a/compiler/rustc_ty_utils/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs index 024dcd591bd77..3f17715a5ebb4 100644 --- a/compiler/rustc_ty_utils/src/needs_drop.rs +++ b/compiler/rustc_ty_utils/src/needs_drop.rs @@ -152,7 +152,10 @@ where queue_type(self, required); } } - ty::Array(..) | ty::Opaque(..) | ty::Projection(..) | ty::Param(_) => { + ty::Array(..) + | ty::Alias(ty::Opaque, ..) + | ty::Alias(ty::Projection, ..) + | ty::Param(_) => { if ty == component { // Return the type to the caller: they may be able // to normalize further than we can. diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 5fc9bcac1b19e..5279fc69a31b3 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -37,7 +37,7 @@ fn sized_constraint_for_ty<'tcx>( .collect() } - Projection(..) | Opaque(..) => { + Alias(..) => { // must calculate explicitly. // FIXME: consider special-casing always-Sized projections vec![ty] diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index 983fc9d992ade..c992dbccd62d5 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -42,9 +42,8 @@ pub trait Interner { type ListBinderExistentialPredicate: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type BinderListTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type ListTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; - type ProjectionTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; + type AliasTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type ParamTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; - type OpaqueTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type BoundTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type PlaceholderType: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; type InferTy: Clone + Debug + Hash + PartialEq + Eq + PartialOrd + Ord; diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/sty.rs index 8303d8de08716..96c53392449dc 100644 --- a/compiler/rustc_type_ir/src/sty.rs +++ b/compiler/rustc_type_ir/src/sty.rs @@ -19,19 +19,8 @@ use rustc_data_structures::stable_hasher::HashStable; use rustc_serialize::{Decodable, Decoder, Encodable}; /// Specifies how a trait object is represented. -#[derive( - Clone, - Copy, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - Debug, - Encodable, - Decodable, - HashStable_Generic -)] +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Encodable, Decodable, HashStable_Generic)] pub enum DynKind { /// An unsized `dyn Trait` object Dyn, @@ -46,6 +35,13 @@ pub enum DynKind { DynStar, } +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] +#[derive(Encodable, Decodable, HashStable_Generic)] +pub enum AliasKind { + Projection, + Opaque, +} + /// Defines the kinds of types used by the type system. /// /// Types written by the user start out as `hir::TyKind` and get @@ -171,19 +167,7 @@ pub enum TyKind { Tuple(I::ListTy), /// A projection or opaque type. Both of these types - Projection(I::ProjectionTy), - - /// Opaque (`impl Trait`) type found in a return type. - /// - /// The `DefId` comes either from - /// * the `impl Trait` ast::Ty node, - /// * or the `type Foo = impl Trait` declaration - /// - /// For RPIT the substitutions are for the generics of the function, - /// while for TAIT it is used for the generic parameters of the alias. - /// - /// During codegen, `tcx.type_of(def_id)` can be used to get the underlying type. - Opaque(I::OpaqueTy), + Alias(AliasKind, I::AliasTy), /// A type parameter; for example, `T` in `fn f(x: T) {}`. Param(I::ParamTy), @@ -251,13 +235,12 @@ const fn tykind_discriminant(value: &TyKind) -> usize { GeneratorWitness(_) => 17, Never => 18, Tuple(_) => 19, - Projection(_) => 20, - Opaque(_) => 21, - Param(_) => 22, - Bound(_, _) => 23, - Placeholder(_) => 24, - Infer(_) => 25, - Error(_) => 26, + Alias(_, _) => 20, + Param(_) => 21, + Bound(_, _) => 22, + Placeholder(_) => 23, + Infer(_) => 24, + Error(_) => 25, } } @@ -285,8 +268,7 @@ impl Clone for TyKind { GeneratorWitness(g) => GeneratorWitness(g.clone()), Never => Never, Tuple(t) => Tuple(t.clone()), - Projection(p) => Projection(p.clone()), - Opaque(o) => Opaque(o.clone()), + Alias(k, p) => Alias(*k, p.clone()), Param(p) => Param(p.clone()), Bound(d, b) => Bound(d.clone(), b.clone()), Placeholder(p) => Placeholder(p.clone()), @@ -322,8 +304,7 @@ impl PartialEq for TyKind { } (GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g == b_g, (Tuple(a_t), Tuple(b_t)) => a_t == b_t, - (Projection(a_p), Projection(b_p)) => a_p == b_p, - (Opaque(a_o), Opaque(b_o)) => a_o == b_o, + (Alias(a_i, a_p), Alias(b_i, b_p)) => a_i == b_i && a_p == b_p, (Param(a_p), Param(b_p)) => a_p == b_p, (Bound(a_d, a_b), Bound(b_d, b_b)) => a_d == b_d && a_b == b_b, (Placeholder(a_p), Placeholder(b_p)) => a_p == b_p, @@ -380,8 +361,7 @@ impl Ord for TyKind { } (GeneratorWitness(a_g), GeneratorWitness(b_g)) => a_g.cmp(b_g), (Tuple(a_t), Tuple(b_t)) => a_t.cmp(b_t), - (Projection(a_p), Projection(b_p)) => a_p.cmp(b_p), - (Opaque(a_o), Opaque(b_o)) => a_o.cmp(b_o), + (Alias(a_i, a_p), Alias(b_i, b_p)) => a_i.cmp(b_i).then_with(|| a_p.cmp(b_p)), (Param(a_p), Param(b_p)) => a_p.cmp(b_p), (Bound(a_d, a_b), Bound(b_d, b_b)) => a_d.cmp(b_d).then_with(|| a_b.cmp(b_b)), (Placeholder(a_p), Placeholder(b_p)) => a_p.cmp(b_p), @@ -442,9 +422,9 @@ impl hash::Hash for TyKind { } GeneratorWitness(g) => g.hash(state), Tuple(t) => t.hash(state), - Projection(p) => p.hash(state), - Opaque(o) => { - o.hash(state); + Alias(i, p) => { + i.hash(state); + p.hash(state); } Param(p) => p.hash(state), Bound(d, b) => { @@ -483,8 +463,7 @@ impl fmt::Debug for TyKind { GeneratorWitness(g) => f.debug_tuple_field1_finish("GeneratorWitness", g), Never => f.write_str("Never"), Tuple(t) => f.debug_tuple_field1_finish("Tuple", t), - Projection(p) => f.debug_tuple_field1_finish("Projection", p), - Opaque(o) => f.debug_tuple_field1_finish("Opaque", o), + Alias(i, a) => f.debug_tuple_field2_finish("Alias", i, a), Param(p) => f.debug_tuple_field1_finish("Param", p), Bound(d, b) => f.debug_tuple_field2_finish("Bound", d, b), Placeholder(p) => f.debug_tuple_field1_finish("Placeholder", p), @@ -511,9 +490,8 @@ where I::ListBinderExistentialPredicate: Encodable, I::BinderListTy: Encodable, I::ListTy: Encodable, - I::ProjectionTy: Encodable, + I::AliasTy: Encodable, I::ParamTy: Encodable, - I::OpaqueTy: Encodable, I::BoundTy: Encodable, I::PlaceholderType: Encodable, I::InferTy: Encodable, @@ -585,12 +563,10 @@ where Tuple(substs) => e.emit_enum_variant(disc, |e| { substs.encode(e); }), - Projection(p) => e.emit_enum_variant(disc, |e| { + Alias(k, p) => e.emit_enum_variant(disc, |e| { + k.encode(e); p.encode(e); }), - Opaque(o) => e.emit_enum_variant(disc, |e| { - o.encode(e); - }), Param(p) => e.emit_enum_variant(disc, |e| { p.encode(e); }), @@ -628,9 +604,9 @@ where I::ListBinderExistentialPredicate: Decodable, I::BinderListTy: Decodable, I::ListTy: Decodable, - I::ProjectionTy: Decodable, + I::AliasTy: Decodable, I::ParamTy: Decodable, - I::OpaqueTy: Decodable, + I::AliasTy: Decodable, I::BoundTy: Decodable, I::PlaceholderType: Decodable, I::InferTy: Decodable, @@ -659,8 +635,7 @@ where 17 => GeneratorWitness(Decodable::decode(d)), 18 => Never, 19 => Tuple(Decodable::decode(d)), - 20 => Projection(Decodable::decode(d)), - 21 => Opaque(Decodable::decode(d)), + 20 => Alias(Decodable::decode(d), Decodable::decode(d)), 22 => Param(Decodable::decode(d)), 23 => Bound(Decodable::decode(d), Decodable::decode(d)), 24 => Placeholder(Decodable::decode(d)), @@ -694,10 +669,9 @@ where I::Mutability: HashStable, I::BinderListTy: HashStable, I::ListTy: HashStable, - I::ProjectionTy: HashStable, + I::AliasTy: HashStable, I::BoundTy: HashStable, I::ParamTy: HashStable, - I::OpaqueTy: HashStable, I::PlaceholderType: HashStable, I::InferTy: HashStable, I::ErrorGuaranteed: HashStable, @@ -772,12 +746,10 @@ where Tuple(substs) => { substs.hash_stable(__hcx, __hasher); } - Projection(p) => { + Alias(k, p) => { + k.hash_stable(__hcx, __hasher); p.hash_stable(__hcx, __hasher); } - Opaque(o) => { - o.hash_stable(__hcx, __hasher); - } Param(p) => { p.hash_stable(__hcx, __hasher); } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 98aaff4fb0849..4a4dc899ba9a3 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1487,7 +1487,9 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type hir::QPath::TypeRelative(qself, segment) => { let ty = hir_ty_to_ty(cx.tcx, hir_ty); let res = match ty.kind() { - ty::Projection(proj) => Res::Def(DefKind::Trait, proj.trait_ref(cx.tcx).def_id), + ty::Alias(ty::Projection, proj) => { + Res::Def(DefKind::Trait, proj.trait_ref(cx.tcx).def_id) + } // Rustdoc handles `ty::Error`s by turning them into `Type::Infer`s. ty::Error(_) => return Type::Infer, // Otherwise, this is an inherent associated type. @@ -1823,7 +1825,7 @@ pub(crate) fn clean_middle_ty<'tcx>( Tuple(t.iter().map(|t| clean_middle_ty(bound_ty.rebind(t), cx, None)).collect()) } - ty::Projection(ref data) => clean_projection(bound_ty.rebind(*data), cx, def_id), + ty::Alias(ty::Projection, ref data) => clean_projection(bound_ty.rebind(*data), cx, def_id), ty::Param(ref p) => { if let Some(bounds) = cx.impl_trait_bounds.remove(&p.index.into()) { @@ -1833,7 +1835,7 @@ pub(crate) fn clean_middle_ty<'tcx>( } } - ty::Opaque(ty::AliasTy { def_id, substs }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { // Grab the "TraitA + TraitB" from `impl TraitA + TraitB`, // by looking up the bounds associated with the def_id. let bounds = cx diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 37a28b6b7bd84..4f0eb8b8076e5 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -538,11 +538,10 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did, .. }, _)), _) | ty::Foreign(did) => { Res::from_def_id(self.cx.tcx, did) } - ty::Projection(_) + ty::Alias(..) | ty::Closure(..) | ty::Generator(..) | ty::GeneratorWitness(_) - | ty::Opaque(..) | ty::Dynamic(..) | ty::Param(_) | ty::Bound(..) diff --git a/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs index 2cb1ed6fcb76b..3f7429a5fccf8 100644 --- a/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs +++ b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.rs @@ -33,8 +33,7 @@ fn main() { TyKind::GeneratorWitness(..) => (), //~ ERROR usage of `ty::TyKind::` TyKind::Never => (), //~ ERROR usage of `ty::TyKind::` TyKind::Tuple(..) => (), //~ ERROR usage of `ty::TyKind::` - TyKind::Projection(..) => (), //~ ERROR usage of `ty::TyKind::` - TyKind::Opaque(..) => (), //~ ERROR usage of `ty::TyKind::` + TyKind::Alias(..) => (), //~ ERROR usage of `ty::TyKind::` TyKind::Param(..) => (), //~ ERROR usage of `ty::TyKind::` TyKind::Bound(..) => (), //~ ERROR usage of `ty::TyKind::` TyKind::Placeholder(..) => (), //~ ERROR usage of `ty::TyKind::` diff --git a/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr index 171f49087d695..1f49d6b64646f 100644 --- a/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr +++ b/src/test/ui-fulldeps/internal-lints/ty_tykind_usage.stderr @@ -133,53 +133,47 @@ LL | TyKind::Tuple(..) => (), error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:36:9 | -LL | TyKind::Projection(..) => (), +LL | TyKind::Alias(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` --> $DIR/ty_tykind_usage.rs:37:9 | -LL | TyKind::Opaque(..) => (), - | ^^^^^^ help: try using `ty::` directly: `ty` - -error: usage of `ty::TyKind::` - --> $DIR/ty_tykind_usage.rs:38:9 - | LL | TyKind::Param(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` - --> $DIR/ty_tykind_usage.rs:39:9 + --> $DIR/ty_tykind_usage.rs:38:9 | LL | TyKind::Bound(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` - --> $DIR/ty_tykind_usage.rs:40:9 + --> $DIR/ty_tykind_usage.rs:39:9 | LL | TyKind::Placeholder(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` - --> $DIR/ty_tykind_usage.rs:41:9 + --> $DIR/ty_tykind_usage.rs:40:9 | LL | TyKind::Infer(..) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` - --> $DIR/ty_tykind_usage.rs:42:9 + --> $DIR/ty_tykind_usage.rs:41:9 | LL | TyKind::Error(_) => (), | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind::` - --> $DIR/ty_tykind_usage.rs:47:12 + --> $DIR/ty_tykind_usage.rs:46:12 | LL | if let TyKind::Int(int_ty) = kind {} | ^^^^^^ help: try using `ty::` directly: `ty` error: usage of `ty::TyKind` - --> $DIR/ty_tykind_usage.rs:49:24 + --> $DIR/ty_tykind_usage.rs:48:24 | LL | fn ty_kind(ty_bad: TyKind<'_>, ty_good: Ty<'_>) {} | ^^^^^^^^^^ @@ -187,7 +181,7 @@ LL | fn ty_kind(ty_bad: TyKind<'_>, ty_good: Ty<'_>) {} = help: try using `Ty` instead error: usage of `ty::TyKind` - --> $DIR/ty_tykind_usage.rs:51:37 + --> $DIR/ty_tykind_usage.rs:50:37 | LL | fn ir_ty_kind(bad: IrTyKind) -> IrTyKind { | ^^^^^^^^^^^ @@ -195,7 +189,7 @@ LL | fn ir_ty_kind(bad: IrTyKind) -> IrTyKind { = help: try using `Ty` instead error: usage of `ty::TyKind` - --> $DIR/ty_tykind_usage.rs:51:53 + --> $DIR/ty_tykind_usage.rs:50:53 | LL | fn ir_ty_kind(bad: IrTyKind) -> IrTyKind { | ^^^^^^^^^^^ @@ -203,12 +197,12 @@ LL | fn ir_ty_kind(bad: IrTyKind) -> IrTyKind { = help: try using `Ty` instead error: usage of `ty::TyKind::` - --> $DIR/ty_tykind_usage.rs:54:9 + --> $DIR/ty_tykind_usage.rs:53:9 | LL | IrTyKind::Bool | --------^^^^^^ | | | help: try using `ty::` directly: `ty` -error: aborting due to 33 previous errors +error: aborting due to 32 previous errors diff --git a/src/tools/clippy/clippy_lints/src/dereference.rs b/src/tools/clippy/clippy_lints/src/dereference.rs index ad5a1b2beb70c..31183266acfcb 100644 --- a/src/tools/clippy/clippy_lints/src/dereference.rs +++ b/src/tools/clippy/clippy_lints/src/dereference.rs @@ -1244,7 +1244,7 @@ fn is_mixed_projection_predicate<'tcx>( let mut projection_ty = projection_predicate.projection_ty; loop { match projection_ty.self_ty().kind() { - ty::Projection(inner_projection_ty) => { + ty::Alias(ty::Projection, inner_projection_ty) => { projection_ty = *inner_projection_ty; } ty::Param(param_ty) => { @@ -1390,8 +1390,8 @@ fn ty_auto_deref_stability<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, precedenc continue; }, ty::Param(_) => TyPosition::new_deref_stable_for_result(precedence, ty), - ty::Projection(_) if ty.has_non_region_param() => TyPosition::new_deref_stable_for_result(precedence, ty), - ty::Infer(_) | ty::Error(_) | ty::Bound(..) | ty::Opaque(..) | ty::Placeholder(_) | ty::Dynamic(..) => { + ty::Alias(ty::Projection, _) if ty.has_non_region_param() => TyPosition::new_deref_stable_for_result(precedence, ty), + ty::Infer(_) | ty::Error(_) | ty::Bound(..) | ty::Alias(ty::Opaque, ..) | ty::Placeholder(_) | ty::Dynamic(..) => { Position::ReborrowStable(precedence).into() }, ty::Adt(..) if ty.has_placeholders() || ty.has_opaque_types() => { @@ -1417,7 +1417,7 @@ fn ty_auto_deref_stability<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, precedenc | ty::Closure(..) | ty::Never | ty::Tuple(_) - | ty::Projection(_) => { + | ty::Alias(ty::Projection, _) => { Position::DerefStable(precedence, ty.is_sized(cx.tcx, cx.param_env.without_caller_bounds())).into() }, }; diff --git a/src/tools/clippy/clippy_lints/src/future_not_send.rs b/src/tools/clippy/clippy_lints/src/future_not_send.rs index 3ff774867b1ef..fcdac90fc237a 100644 --- a/src/tools/clippy/clippy_lints/src/future_not_send.rs +++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs @@ -4,7 +4,7 @@ use rustc_hir::intravisit::FnKind; use rustc_hir::{Body, FnDecl, HirId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{AliasTy, Clause, EarlyBinder, Opaque, PredicateKind}; +use rustc_middle::ty::{self, AliasTy, Clause, EarlyBinder, PredicateKind}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::{sym, Span}; use rustc_trait_selection::traits::error_reporting::suggestions::TypeErrCtxtExt; @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { return; } let ret_ty = return_ty(cx, hir_id); - if let Opaque(AliasTy { def_id, substs }) = *ret_ty.kind() { + if let ty::Alias(ty::Opaque, AliasTy { def_id, substs }) = *ret_ty.kind() { let preds = cx.tcx.explicit_item_bounds(def_id); let mut is_future = false; for &(p, _span) in preds { diff --git a/src/tools/clippy/clippy_lints/src/len_zero.rs b/src/tools/clippy/clippy_lints/src/len_zero.rs index 982f99c271639..73841f9aa9a21 100644 --- a/src/tools/clippy/clippy_lints/src/len_zero.rs +++ b/src/tools/clippy/clippy_lints/src/len_zero.rs @@ -493,7 +493,7 @@ fn has_is_empty(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { .filter_by_name_unhygienic(is_empty) .any(|item| is_is_empty(cx, item)) }), - ty::Projection(ref proj) => has_is_empty_impl(cx, proj.def_id), + ty::Alias(ty::Projection, ref proj) => has_is_empty_impl(cx, proj.def_id), ty::Adt(id, _) => has_is_empty_impl(cx, id.did()), ty::Array(..) | ty::Slice(..) | ty::Str => true, _ => false, diff --git a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs index e053a9dc8881a..8bf542ada04dd 100644 --- a/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs +++ b/src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs @@ -82,7 +82,7 @@ fn check_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) -> McfResult { ty::Ref(_, _, hir::Mutability::Mut) => { return Err((span, "mutable references in const fn are unstable".into())); }, - ty::Opaque(..) => return Err((span, "`impl Trait` in const fn is unstable".into())), + ty::Alias(ty::Opaque, ..) => return Err((span, "`impl Trait` in const fn is unstable".into())), ty::FnPtr(..) => { return Err((span, "function pointers in const fn are unstable".into())); }, diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index bddab7eca53ba..33f3b3af3dc02 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -79,7 +79,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<' return true; } - if let ty::Opaque(ty::AliasTy { def_id, substs: _ }) = *inner_ty.kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *inner_ty.kind() { for &(predicate, _span) in cx.tcx.explicit_item_bounds(def_id) { match predicate.kind().skip_binder() { // For `impl Trait`, it will register a predicate of `T: Trait`, so we go through @@ -250,7 +250,7 @@ pub fn is_must_use_ty<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> bool { is_must_use_ty(cx, *ty) }, ty::Tuple(substs) => substs.iter().any(|ty| is_must_use_ty(cx, ty)), - ty::Opaque(ty::AliasTy { def_id, substs: _ }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => { for (predicate, _) in cx.tcx.explicit_item_bounds(*def_id) { if let ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) = predicate.kind().skip_binder() { if cx.tcx.has_attr(trait_predicate.trait_ref.def_id, sym::must_use) { @@ -631,7 +631,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs), Some(id))), - ty::Opaque(ty::AliasTy { def_id, substs: _ }) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id)), + ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => sig_from_bounds(cx, ty, cx.tcx.item_bounds(def_id), cx.tcx.opt_parent(def_id)), ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)), ty::Dynamic(bounds, _, _) => { let lang_items = cx.tcx.lang_items(); @@ -650,7 +650,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option None, } }, - ty::Projection(proj) => match cx.tcx.try_normalize_erasing_regions(cx.param_env, ty) { + ty::Alias(ty::Projection, proj) => match cx.tcx.try_normalize_erasing_regions(cx.param_env, ty) { Ok(normalized_ty) if normalized_ty != ty => ty_sig(cx, normalized_ty), _ => sig_for_projection(cx, proj).or_else(|| sig_from_bounds(cx, ty, cx.param_env.caller_bounds(), None)), }, From 96cb18e864eb31f164fdfee5cb011d3576415b5d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 27 Nov 2022 17:52:17 +0000 Subject: [PATCH 06/11] Combine identical alias arms --- .../src/debuginfo/type_names.rs | 3 +- .../src/const_eval/valtrees.rs | 8 ++--- .../src/interpret/intrinsics.rs | 8 ++--- .../src/interpret/validity.rs | 3 +- .../rustc_const_eval/src/util/type_name.rs | 3 +- .../src/coherence/inherent_impls.rs | 2 +- .../src/variance/constraints.rs | 6 +--- .../src/infer/canonical/canonicalizer.rs | 5 ++-- .../rustc_infer/src/infer/opaque_types.rs | 4 +-- compiler/rustc_middle/src/ty/layout.rs | 5 ++-- compiler/rustc_middle/src/ty/print/mod.rs | 3 +- .../rustc_middle/src/ty/structural_impls.rs | 12 ++------ compiler/rustc_middle/src/ty/sty.rs | 16 +++++----- compiler/rustc_middle/src/ty/util.rs | 30 +++++++------------ compiler/rustc_middle/src/ty/visit.rs | 2 +- compiler/rustc_middle/src/ty/walk.rs | 3 +- compiler/rustc_symbol_mangling/src/legacy.rs | 3 +- .../src/typeid/typeid_itanium_cxx_abi.rs | 10 +++---- compiler/rustc_symbol_mangling/src/v0.rs | 3 +- .../src/traits/project.rs | 8 ++--- .../src/traits/query/dropck_outlives.rs | 3 +- .../src/traits/select/candidate_assembly.rs | 10 +++---- .../src/traits/select/confirmation.rs | 3 +- .../src/traits/select/mod.rs | 10 ++----- .../src/traits/structural_match.rs | 5 +--- compiler/rustc_traits/src/dropck_outlives.rs | 4 +-- compiler/rustc_ty_utils/src/layout.rs | 2 +- compiler/rustc_ty_utils/src/needs_drop.rs | 5 +--- compiler/rustc_type_ir/src/sty.rs | 10 +++---- 29 files changed, 69 insertions(+), 120 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index c260de699ced8..819c2678d6c4d 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -411,9 +411,8 @@ fn push_debuginfo_type_name<'tcx>( ty::Error(_) | ty::Infer(_) | ty::Placeholder(..) - | ty::Alias(ty::Projection, ..) + | ty::Alias(..) | ty::Bound(..) - | ty::Alias(ty::Opaque, ..) | ty::GeneratorWitness(..) => { bug!( "debuginfo: Trying to create type name for \ diff --git a/compiler/rustc_const_eval/src/const_eval/valtrees.rs b/compiler/rustc_const_eval/src/const_eval/valtrees.rs index 5cc9ff8f85539..498c008738793 100644 --- a/compiler/rustc_const_eval/src/const_eval/valtrees.rs +++ b/compiler/rustc_const_eval/src/const_eval/valtrees.rs @@ -142,12 +142,11 @@ pub(crate) fn const_to_valtree_inner<'tcx>( | ty::Foreign(..) | ty::Infer(ty::FreshIntTy(_)) | ty::Infer(ty::FreshFloatTy(_)) - | ty::Alias(ty::Projection, ..) + // FIXME(oli-obk): we could look behind opaque types + | ty::Alias(..) | ty::Param(_) | ty::Bound(..) | ty::Placeholder(..) - // FIXME(oli-obk): we could look behind opaque types - | ty::Alias(ty::Opaque, ..) | ty::Infer(_) // FIXME(oli-obk): we can probably encode closures just like structs | ty::Closure(..) @@ -307,11 +306,10 @@ pub fn valtree_to_const_value<'tcx>( | ty::Foreign(..) | ty::Infer(ty::FreshIntTy(_)) | ty::Infer(ty::FreshFloatTy(_)) - | ty::Alias(ty::Projection, ..) + | ty::Alias(..) | ty::Param(_) | ty::Bound(..) | ty::Placeholder(..) - | ty::Alias(ty::Opaque, ..) | ty::Infer(_) | ty::Closure(..) | ty::Generator(..) diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 4fc664b70f8d7..9b56757eb3951 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -82,11 +82,9 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>( ty::Adt(ref adt, _) => { ConstValue::from_machine_usize(adt.variants().len() as u64, &tcx) } - ty::Alias(ty::Projection, _) - | ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs: _ }) - | ty::Param(_) - | ty::Placeholder(_) - | ty::Infer(_) => throw_inval!(TooGeneric), + ty::Alias(..) | ty::Param(_) | ty::Placeholder(_) | ty::Infer(_) => { + throw_inval!(TooGeneric) + } ty::Bound(_, _) => bug!("bound ty during ctfe"), ty::Bool | ty::Char diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index b7dd2517d69ee..f905d3fb479a0 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -601,8 +601,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' | ty::Placeholder(..) | ty::Bound(..) | ty::Param(..) - | ty::Alias(ty::Opaque, ..) - | ty::Alias(ty::Projection, ..) + | ty::Alias(..) | ty::GeneratorWitness(..) => bug!("Encountered invalid type {:?}", ty), } } diff --git a/compiler/rustc_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index c31cd94699063..dd65d4fd591e5 100644 --- a/compiler/rustc_const_eval/src/util/type_name.rs +++ b/compiler/rustc_const_eval/src/util/type_name.rs @@ -58,8 +58,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> { // Types with identity (print the module path). ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs) | ty::FnDef(def_id, substs) - | ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) - | ty::Alias(ty::Projection, ty::AliasTy { def_id, substs }) + | ty::Alias(_, ty::AliasTy { def_id, substs }) | ty::Closure(def_id, substs) | ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs), ty::Foreign(def_id) => self.print_def_path(def_id, &[]), diff --git a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs index 32c3e95688b87..6469f389bf91b 100644 --- a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs +++ b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs @@ -223,7 +223,7 @@ impl<'tcx> InherentCollect<'tcx> { | ty::Tuple(..) => { self.check_primitive_impl(item.owner_id.def_id, self_ty, items, ty.span) } - ty::Alias(ty::Projection, ..) | ty::Alias(ty::Opaque, ..) | ty::Param(_) => { + ty::Alias(..) | ty::Param(_) => { let mut err = struct_span_err!( self.tcx.sess, ty.span, diff --git a/compiler/rustc_hir_analysis/src/variance/constraints.rs b/compiler/rustc_hir_analysis/src/variance/constraints.rs index 75bb7abf0ed2e..5e4d82b6fd569 100644 --- a/compiler/rustc_hir_analysis/src/variance/constraints.rs +++ b/compiler/rustc_hir_analysis/src/variance/constraints.rs @@ -249,14 +249,10 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { self.add_constraints_from_substs(current, def.did(), substs, variance); } - ty::Alias(ty::Projection, ref data) => { + ty::Alias(_, ref data) => { self.add_constraints_from_invariant_substs(current, data.substs, variance); } - ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs }) => { - self.add_constraints_from_invariant_substs(current, substs, variance); - } - ty::Dynamic(data, r, _) => { // The type `Foo` is contravariant w/r/t `'a`: let contra = self.contravariant(variance); diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index 79a55c5883acc..ec5221379d2c9 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -453,10 +453,9 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> { | ty::Dynamic(..) | ty::Never | ty::Tuple(..) - | ty::Alias(ty::Projection, ..) + | ty::Alias(..) | ty::Foreign(..) - | ty::Param(..) - | ty::Alias(ty::Opaque, ..) => { + | ty::Param(..) => { if t.flags().intersects(self.needs_canonical_flags) { t.super_fold_with(self) } else { diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index 98f08e831735c..67e4554c4c707 100644 --- a/compiler/rustc_infer/src/infer/opaque_types.rs +++ b/compiler/rustc_infer/src/infer/opaque_types.rs @@ -589,8 +589,8 @@ impl<'tcx> InferCtxt<'tcx> { hidden_ty } // FIXME(RPITIT): This can go away when we move to associated types - ty::Alias(ty::Projection, proj) - if def_id.to_def_id() == proj.def_id && substs == proj.substs => + ty::Alias(ty::Projection, ty::AliasTy { def_id: def_id2, substs: substs2 }) + if def_id.to_def_id() == def_id2 && substs == substs2 => { hidden_ty } diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 40297492bb642..7f66b993646a3 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -349,7 +349,7 @@ impl<'tcx> SizeSkeleton<'tcx> { } } - ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..) => { + ty::Alias(..) => { let normalized = tcx.normalize_erasing_regions(param_env, ty); if ty == normalized { Err(err) @@ -757,10 +757,9 @@ where } } - ty::Alias(ty::Projection, _) + ty::Alias(..) | ty::Bound(..) | ty::Placeholder(..) - | ty::Alias(ty::Opaque, ..) | ty::Param(_) | ty::Infer(_) | ty::Error(_) => bug!("TyAndLayout::field: unexpected type `{}`", this.ty), diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index 8de8fd5246c48..3fad349bff812 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -275,10 +275,9 @@ fn characteristic_def_id_of_type_cached<'a>( | ty::Uint(_) | ty::Str | ty::FnPtr(_) - | ty::Alias(ty::Projection, _) + | ty::Alias(..) | ty::Placeholder(..) | ty::Param(_) - | ty::Alias(ty::Opaque, ..) | ty::Infer(_) | ty::Bound(..) | ty::Error(_) diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 3d85ae3584ba8..3c6800cf293de 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -651,12 +651,7 @@ impl<'tcx> TypeSuperFoldable<'tcx> for Ty<'tcx> { } ty::GeneratorWitness(types) => ty::GeneratorWitness(types.try_fold_with(folder)?), ty::Closure(did, substs) => ty::Closure(did, substs.try_fold_with(folder)?), - ty::Alias(ty::Projection, data) => { - ty::Alias(ty::Projection, data.try_fold_with(folder)?) - } - ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { - ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: substs.try_fold_with(folder)? }) - } + ty::Alias(kind, data) => ty::Alias(kind, data.try_fold_with(folder)?), ty::Bool | ty::Char @@ -701,10 +696,7 @@ impl<'tcx> TypeSuperVisitable<'tcx> for Ty<'tcx> { ty::Generator(_did, ref substs, _) => substs.visit_with(visitor), ty::GeneratorWitness(ref types) => types.visit_with(visitor), ty::Closure(_did, ref substs) => substs.visit_with(visitor), - ty::Alias(ty::Projection, ref data) => data.visit_with(visitor), - ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, ref substs }) => { - substs.visit_with(visitor) - } + ty::Alias(_, ref data) => data.visit_with(visitor), ty::Bool | ty::Char diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index a1c15f4044cf9..2f1e32900e5a5 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -2047,10 +2047,7 @@ impl<'tcx> Ty<'tcx> { ty::Adt(adt, _) if adt.is_enum() => adt.repr().discr_type().to_ty(tcx), ty::Generator(_, substs, _) => substs.as_generator().discr_ty(tcx), - ty::Param(_) - | ty::Alias(ty::Projection, _) - | ty::Alias(ty::Opaque, ..) - | ty::Infer(ty::TyVar(_)) => { + ty::Param(_) | ty::Alias(..) | ty::Infer(ty::TyVar(_)) => { let assoc_items = tcx.associated_item_def_ids( tcx.require_lang_item(hir::LangItem::DiscriminantKind, None), ); @@ -2130,7 +2127,7 @@ impl<'tcx> Ty<'tcx> { // type parameters only have unit metadata if they're sized, so return true // to make sure we double check this during confirmation - ty::Param(_) | ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..) => (tcx.types.unit, true), + ty::Param(_) | ty::Alias(..) => (tcx.types.unit, true), ty::Infer(ty::TyVar(_)) | ty::Bound(..) @@ -2206,7 +2203,7 @@ impl<'tcx> Ty<'tcx> { ty::Adt(def, _substs) => def.sized_constraint(tcx).0.is_empty(), - ty::Alias(ty::Projection, _) | ty::Param(_) | ty::Alias(ty::Opaque, ..) => false, + ty::Alias(..) | ty::Param(_) => false, ty::Infer(ty::TyVar(_)) => false, @@ -2262,9 +2259,12 @@ impl<'tcx> Ty<'tcx> { ty::Generator(..) | ty::GeneratorWitness(..) => false, // Might be, but not "trivial" so just giving the safe answer. - ty::Adt(..) | ty::Closure(..) | ty::Alias(ty::Opaque, ..) => false, + ty::Adt(..) | ty::Closure(..) => false, - ty::Alias(ty::Projection, ..) | ty::Param(..) | ty::Infer(..) | ty::Error(..) => false, + // Needs normalization or revealing to determine, so no is the safe answer. + ty::Alias(..) => false, + + ty::Param(..) | ty::Infer(..) | ty::Error(..) => false, ty::Bound(..) | ty::Placeholder(..) => { bug!("`is_trivially_pure_clone_copy` applied to unexpected type: {:?}", self); diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index cf35240f165bd..b8a19e582c9dc 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -259,7 +259,7 @@ impl<'tcx> TyCtxt<'tcx> { ty::Tuple(_) => break, - ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..) => { + ty::Alias(..) => { let normalized = normalize(ty); if ty == normalized { return ty; @@ -332,8 +332,7 @@ impl<'tcx> TyCtxt<'tcx> { break; } } - (ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..), _) - | (_, ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..)) => { + (ty::Alias(..), _) | (_, ty::Alias(..)) => { // If either side is a projection, attempt to // progress via normalization. (Should be safe to // apply to both sides as normalization is @@ -938,10 +937,9 @@ impl<'tcx> Ty<'tcx> { | ty::Generator(..) | ty::GeneratorWitness(_) | ty::Infer(_) - | ty::Alias(ty::Opaque, ..) + | ty::Alias(..) | ty::Param(_) - | ty::Placeholder(_) - | ty::Alias(ty::Projection, _) => false, + | ty::Placeholder(_) => false, } } @@ -978,10 +976,9 @@ impl<'tcx> Ty<'tcx> { | ty::Generator(..) | ty::GeneratorWitness(_) | ty::Infer(_) - | ty::Alias(ty::Opaque, ..) + | ty::Alias(..) | ty::Param(_) - | ty::Placeholder(_) - | ty::Alias(ty::Projection, _) => false, + | ty::Placeholder(_) => false, } } @@ -1101,12 +1098,9 @@ impl<'tcx> Ty<'tcx> { // // FIXME(ecstaticmorse): Maybe we should `bug` here? This should probably only be // called for known, fully-monomorphized types. - ty::Alias(ty::Projection, _) - | ty::Alias(ty::Opaque, ..) - | ty::Param(_) - | ty::Bound(..) - | ty::Placeholder(_) - | ty::Infer(_) => false, + ty::Alias(..) | ty::Param(_) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) => { + false + } ty::Foreign(_) | ty::GeneratorWitness(..) | ty::Error(_) => false, } @@ -1237,11 +1231,10 @@ pub fn needs_drop_components<'tcx>( // These require checking for `Copy` bounds or `Adt` destructors. ty::Adt(..) - | ty::Alias(ty::Projection, ..) + | ty::Alias(..) | ty::Param(_) | ty::Bound(..) | ty::Placeholder(..) - | ty::Alias(ty::Opaque, ..) | ty::Infer(_) | ty::Closure(..) | ty::Generator(..) => Ok(smallvec![ty]), @@ -1265,13 +1258,12 @@ pub fn is_trivially_const_drop<'tcx>(ty: Ty<'tcx>) -> bool { | ty::Never | ty::Foreign(_) => true, - ty::Alias(ty::Opaque, ..) + ty::Alias(..) | ty::Dynamic(..) | ty::Error(_) | ty::Bound(..) | ty::Param(_) | ty::Placeholder(_) - | ty::Alias(ty::Projection, _) | ty::Infer(_) => false, // Not trivial because they have components, and instead of looking inside, diff --git a/compiler/rustc_middle/src/ty/visit.rs b/compiler/rustc_middle/src/ty/visit.rs index 085232a47cc57..b302572f3cabd 100644 --- a/compiler/rustc_middle/src/ty/visit.rs +++ b/compiler/rustc_middle/src/ty/visit.rs @@ -654,7 +654,7 @@ impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector { // ignore the inputs to a projection, as they may not appear // in the normalized form if self.just_constrained { - if let ty::Alias(ty::Projection, ..) | ty::Alias(ty::Opaque, ..) = t.kind() { + if let ty::Alias(..) = t.kind() { return ControlFlow::CONTINUE; } } diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index f4876d019cee0..34dbb6e9f68ea 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -165,7 +165,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) stack.push(ty.into()); stack.push(lt.into()); } - ty::Alias(ty::Projection, data) => { + ty::Alias(_, data) => { stack.extend(data.substs.iter().rev()); } ty::Dynamic(obj, lt, _) => { @@ -188,7 +188,6 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) })); } ty::Adt(_, substs) - | ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs }) | ty::Closure(_, substs) | ty::Generator(_, substs, _) | ty::FnDef(_, substs) => { diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index a82fee8cf4bdf..281b2d88f483b 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -216,8 +216,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> { match *ty.kind() { // Print all nominal types as paths (unlike `pretty_print_type`). ty::FnDef(def_id, substs) - | ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) - | ty::Alias(ty::Projection, ty::AliasTy { def_id, substs }) + | ty::Alias(_, ty::AliasTy { def_id, substs }) | ty::Closure(def_id, substs) | ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs), diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs index cff6a276eecef..c9ddb084d63a1 100644 --- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs +++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs @@ -646,10 +646,9 @@ fn encode_ty<'tcx>( | ty::Error(..) | ty::GeneratorWitness(..) | ty::Infer(..) - | ty::Alias(ty::Opaque, ..) + | ty::Alias(..) | ty::Param(..) - | ty::Placeholder(..) - | ty::Alias(ty::Projection, ..) => { + | ty::Placeholder(..) => { bug!("encode_ty: unexpected `{:?}`", ty.kind()); } }; @@ -799,10 +798,9 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio | ty::Error(..) | ty::GeneratorWitness(..) | ty::Infer(..) - | ty::Alias(ty::Opaque, ..) + | ty::Alias(..) | ty::Param(..) - | ty::Placeholder(..) - | ty::Alias(ty::Projection, ..) => { + | ty::Placeholder(..) => { bug!("transform_ty: unexpected `{:?}`", ty.kind()); } } diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index 175367ad41436..b7f055d9146a0 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -439,8 +439,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { // Mangle all nominal types as paths. ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), substs) | ty::FnDef(def_id, substs) - | ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) - | ty::Alias(ty::Projection, ty::AliasTy { def_id, substs }) + | ty::Alias(_, ty::AliasTy { def_id, substs }) | ty::Closure(def_id, substs) | ty::Generator(def_id, substs, _) => { self = self.print_def_path(def_id, substs)?; diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 6e3a83f2a3479..f016fa0a2e672 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -1620,8 +1620,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( // type parameters, opaques, and unnormalized projections have pointer // metadata if they're known (e.g. by the param_env) to be sized ty::Param(_) - | ty::Alias(ty::Projection, ..) - | ty::Alias(ty::Opaque, ..) + | ty::Alias(..) | ty::Bound(..) | ty::Placeholder(..) | ty::Infer(..) @@ -1675,7 +1674,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( // type parameters, opaques, and unnormalized projections have pointer // metadata if they're known (e.g. by the param_env) to be sized - ty::Param(_) | ty::Alias(ty::Projection, ..) | ty::Alias(ty::Opaque, ..) + ty::Param(_) | ty::Alias(..) if selcx.infcx.predicate_must_hold_modulo_regions( &obligation.with( selcx.tcx(), @@ -1691,8 +1690,7 @@ fn assemble_candidates_from_impls<'cx, 'tcx>( // FIXME(compiler-errors): are Bound and Placeholder types ever known sized? ty::Param(_) - | ty::Alias(ty::Projection, ..) - | ty::Alias(ty::Opaque, ..) + | ty::Alias(..) | ty::Bound(..) | ty::Placeholder(..) | ty::Infer(..) diff --git a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs index 03558f04ed295..0f21813bc40ae 100644 --- a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs +++ b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs @@ -62,9 +62,8 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool { // The following *might* require a destructor: needs deeper inspection. ty::Dynamic(..) - | ty::Alias(ty::Projection, ..) + | ty::Alias(..) | ty::Param(_) - | ty::Alias(ty::Opaque, ..) | ty::Placeholder(..) | ty::Infer(_) | ty::Bound(..) diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index db8c73a880765..829d4f6098605 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -138,7 +138,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Before we go into the whole placeholder thing, just // quickly check if the self-type is a projection at all. match obligation.predicate.skip_binder().trait_ref.self_ty().kind() { - ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..) => {} + ty::Alias(..) => {} ty::Infer(ty::TyVar(_)) => { span_bug!( obligation.cause.span, @@ -734,13 +734,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let self_ty = self.infcx.shallow_resolve(obligation.self_ty()); match self_ty.skip_binder().kind() { - ty::Alias(ty::Opaque, ..) + ty::Alias(..) | ty::Dynamic(..) | ty::Error(_) | ty::Bound(..) | ty::Param(_) - | ty::Placeholder(_) - | ty::Alias(ty::Projection, _) => { + | ty::Placeholder(_) => { // We don't know if these are `~const Destruct`, at least // not structurally... so don't push a candidate. } @@ -826,8 +825,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { | ty::Generator(_, _, _) | ty::GeneratorWitness(_) | ty::Never - | ty::Alias(ty::Projection, _) - | ty::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs: _ }) + | ty::Alias(..) | ty::Param(_) | ty::Bound(_, _) | ty::Error(_) diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 96c56905f8ae1..85456853ce08c 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -155,8 +155,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let placeholder_self_ty = placeholder_trait_predicate.self_ty(); let placeholder_trait_predicate = ty::Binder::dummy(placeholder_trait_predicate); let (def_id, substs) = match *placeholder_self_ty.kind() { - ty::Alias(ty::Projection, proj) => (proj.def_id, proj.substs), - ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => (def_id, substs), + ty::Alias(_, ty::AliasTy { def_id, substs }) => (def_id, substs), _ => bug!("projection candidate for unexpected type: {:?}", placeholder_self_ty), }; diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 1f078bef310d5..115897851d673 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1595,8 +1595,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let tcx = self.infcx.tcx; let (def_id, substs) = match *placeholder_trait_predicate.trait_ref.self_ty().kind() { - ty::Alias(ty::Projection, ref data) => (data.def_id, data.substs), - ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => (def_id, substs), + ty::Alias(_, ty::AliasTy { def_id, substs }) => (def_id, substs), _ => { span_bug!( obligation.cause.span, @@ -2067,7 +2066,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { })) } - ty::Alias(ty::Projection, _) | ty::Param(_) | ty::Alias(ty::Opaque, ..) => None, + ty::Alias(..) | ty::Param(_) => None, ty::Infer(ty::TyVar(_)) => Ambiguous, ty::Placeholder(..) @@ -2167,10 +2166,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } - ty::Adt(..) - | ty::Alias(ty::Projection, ..) - | ty::Param(..) - | ty::Alias(ty::Opaque, ..) => { + ty::Adt(..) | ty::Alias(..) | ty::Param(..) => { // Fallback to whatever user-defined impls exist in this case. None } diff --git a/compiler/rustc_trait_selection/src/traits/structural_match.rs b/compiler/rustc_trait_selection/src/traits/structural_match.rs index 62881b67f5ec2..892a7afd799c7 100644 --- a/compiler/rustc_trait_selection/src/traits/structural_match.rs +++ b/compiler/rustc_trait_selection/src/traits/structural_match.rs @@ -95,10 +95,7 @@ impl<'tcx> TypeVisitor<'tcx> for Search<'tcx> { ty::Foreign(_) => { return ControlFlow::Break(ty); } - ty::Alias(ty::Opaque, ..) => { - return ControlFlow::Break(ty); - } - ty::Alias(ty::Projection, ..) => { + ty::Alias(..) => { return ControlFlow::Break(ty); } ty::Closure(..) => { diff --git a/compiler/rustc_traits/src/dropck_outlives.rs b/compiler/rustc_traits/src/dropck_outlives.rs index f9503fae94c24..3f661ce69235c 100644 --- a/compiler/rustc_traits/src/dropck_outlives.rs +++ b/compiler/rustc_traits/src/dropck_outlives.rs @@ -112,7 +112,7 @@ fn dropck_outlives<'tcx>( // A projection that we couldn't resolve - it // might have a destructor. - ty::Alias(ty::Projection, ..) | ty::Alias(ty::Opaque, ..) => { + ty::Alias(..) => { result.kinds.push(ty.into()); } @@ -268,7 +268,7 @@ fn dtorck_constraint_for_ty<'tcx>( } // Types that can't be resolved. Pass them forward. - ty::Alias(ty::Projection, ..) | ty::Alias(ty::Opaque, ..) | ty::Param(..) => { + ty::Alias(..) | ty::Param(..) => { constraints.dtorck_types.push(ty); } diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 3d5fa2de57930..9589342b3c73f 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -444,7 +444,7 @@ fn layout_of_uncached<'tcx>( } // Types with no meaningful known layout. - ty::Alias(ty::Projection, _) | ty::Alias(ty::Opaque, ..) => { + ty::Alias(..) => { // NOTE(eddyb) `layout_of` query should've normalized these away, // if that was possible, so there's no reason to try again here. return Err(LayoutError::Unknown(ty)); diff --git a/compiler/rustc_ty_utils/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs index 3f17715a5ebb4..0df060fc5fb71 100644 --- a/compiler/rustc_ty_utils/src/needs_drop.rs +++ b/compiler/rustc_ty_utils/src/needs_drop.rs @@ -152,10 +152,7 @@ where queue_type(self, required); } } - ty::Array(..) - | ty::Alias(ty::Opaque, ..) - | ty::Alias(ty::Projection, ..) - | ty::Param(_) => { + ty::Array(..) | ty::Alias(..) | ty::Param(_) => { if ty == component { // Return the type to the caller: they may be able // to normalize further than we can. diff --git a/compiler/rustc_type_ir/src/sty.rs b/compiler/rustc_type_ir/src/sty.rs index 96c53392449dc..e9ffbca96280d 100644 --- a/compiler/rustc_type_ir/src/sty.rs +++ b/compiler/rustc_type_ir/src/sty.rs @@ -636,11 +636,11 @@ where 18 => Never, 19 => Tuple(Decodable::decode(d)), 20 => Alias(Decodable::decode(d), Decodable::decode(d)), - 22 => Param(Decodable::decode(d)), - 23 => Bound(Decodable::decode(d), Decodable::decode(d)), - 24 => Placeholder(Decodable::decode(d)), - 25 => Infer(Decodable::decode(d)), - 26 => Error(Decodable::decode(d)), + 21 => Param(Decodable::decode(d)), + 22 => Bound(Decodable::decode(d), Decodable::decode(d)), + 23 => Placeholder(Decodable::decode(d)), + 24 => Infer(Decodable::decode(d)), + 25 => Error(Decodable::decode(d)), _ => panic!( "{}", format!( From 4b19a2c119a7764ec81a122c4d6257715462e956 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 6 Dec 2022 02:49:06 +0000 Subject: [PATCH 07/11] Combine OfOpaque and OfProjection --- compiler/rustc_hir_typeck/src/cast.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/cast.rs b/compiler/rustc_hir_typeck/src/cast.rs index 235e9c661a909..b050ad20afbdb 100644 --- a/compiler/rustc_hir_typeck/src/cast.rs +++ b/compiler/rustc_hir_typeck/src/cast.rs @@ -38,7 +38,6 @@ use rustc_middle::mir::Mutability; use rustc_middle::ty::adjustment::AllowTwoPhase; use rustc_middle::ty::cast::{CastKind, CastTy}; use rustc_middle::ty::error::TypeError; -use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, Ty, TypeAndMut, TypeVisitable, VariantDef}; use rustc_session::lint; use rustc_session::Session; @@ -75,10 +74,8 @@ enum PointerKind<'tcx> { VTable(Option), /// Slice Length, - /// The unsize info of this projection - OfProjection(ty::AliasTy<'tcx>), - /// The unsize info of this opaque ty - OfOpaque(DefId, SubstsRef<'tcx>), + /// The unsize info of this projection or opaque type + OfAlias(ty::AliasTy<'tcx>), /// The unsize info of this parameter OfParam(ty::ParamTy), } @@ -118,10 +115,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Pointers to foreign types are thin, despite being unsized ty::Foreign(..) => Some(PointerKind::Thin), // We should really try to normalize here. - ty::Alias(ty::Projection, pi) => Some(PointerKind::OfProjection(pi)), - ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { - Some(PointerKind::OfOpaque(def_id, substs)) - } + ty::Alias(_, pi) => Some(PointerKind::OfAlias(pi)), ty::Param(p) => Some(PointerKind::OfParam(p)), // Insufficient type information. ty::Placeholder(..) | ty::Bound(..) | ty::Infer(_) => None, @@ -978,11 +972,9 @@ impl<'a, 'tcx> CastCheck<'tcx> { Some(PointerKind::Thin) => Ok(CastKind::AddrPtrCast), Some(PointerKind::VTable(_)) => Err(CastError::IntToFatCast(Some("a vtable"))), Some(PointerKind::Length) => Err(CastError::IntToFatCast(Some("a length"))), - Some( - PointerKind::OfProjection(_) - | PointerKind::OfOpaque(_, _) - | PointerKind::OfParam(_), - ) => Err(CastError::IntToFatCast(None)), + Some(PointerKind::OfAlias(_) | PointerKind::OfParam(_)) => { + Err(CastError::IntToFatCast(None)) + } } } From 0f9e41409290411ab656fe99b84474c786073691 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 6 Dec 2022 03:30:58 +0000 Subject: [PATCH 08/11] nit: docs --- compiler/rustc_middle/src/ty/sty.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 2f1e32900e5a5..27de48c1f8345 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1148,14 +1148,23 @@ impl<'tcx, T: IntoIterator> Binder<'tcx, T> { #[derive(HashStable, TypeFoldable, TypeVisitable, Lift)] pub struct AliasTy<'tcx> { /// The parameters of the associated or opaque item. + /// + /// For a projection, these are the substitutions for the trait and the + /// GAT substitutions, if there are any. + /// + /// For RPIT the substitutions are for the generics of the function, + /// while for TAIT it is used for the generic parameters of the alias. pub substs: SubstsRef<'tcx>, /// The `DefId` of the `TraitItem` for the associated type `N` if this is a projection, /// or the `OpaqueType` item if this is an opaque. /// - /// Note that this is not the `DefId` of the `TraitRef` containing this - /// associated type, which is in `tcx.associated_item(item_def_id).container`, - /// aka. `tcx.parent(item_def_id).unwrap()`. + /// During codegen, `tcx.type_of(def_id)` can be used to get the type of the + /// underlying type if the type is an opaque. + /// + /// Note that if this is an associated type, this is not the `DefId` of the + /// `TraitRef` containing this associated type, which is in `tcx.associated_item(def_id).container`, + /// aka. `tcx.parent(def_id)`. pub def_id: DefId, } From 7196973c3eae42d4f20eb55e71930d3e35aac329 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 6 Dec 2022 03:35:47 +0000 Subject: [PATCH 09/11] Remove chalk lowering for AliasTy --- compiler/rustc_traits/src/chalk/lowering.rs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 7fbf3270627dc..f3fd315c71ee5 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -66,15 +66,6 @@ impl<'tcx> LowerInto<'tcx, SubstsRef<'tcx>> for &chalk_ir::Substitution LowerInto<'tcx, chalk_ir::AliasTy>> for ty::AliasTy<'tcx> { - fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::AliasTy> { - chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { - associated_ty_id: chalk_ir::AssocTypeId(self.def_id), - substitution: self.substs.lower_into(interner), - }) - } -} - impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment>>> for ChalkEnvironmentAndGoal<'tcx> { @@ -255,7 +246,10 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::AliasEq>> // FIXME(associated_const_equality): teach chalk about terms for alias eq. chalk_ir::AliasEq { ty: self.term.ty().unwrap().lower_into(interner), - alias: self.projection_ty.lower_into(interner), + alias: chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { + associated_ty_id: chalk_ir::AssocTypeId(self.projection_ty.def_id), + substitution: self.projection_ty.substs.lower_into(interner), + }), } } } @@ -353,7 +347,12 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty>> for Ty<'tcx> { ty::Tuple(types) => { chalk_ir::TyKind::Tuple(types.len(), types.as_substs().lower_into(interner)) } - ty::Alias(ty::Projection, proj) => chalk_ir::TyKind::Alias(proj.lower_into(interner)), + ty::Alias(ty::Projection, ty::AliasTy { def_id, substs }) => { + chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { + associated_ty_id: chalk_ir::AssocTypeId(def_id), + substitution: substs.lower_into(interner), + })) + } ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { opaque_ty_id: chalk_ir::OpaqueTyId(def_id), From fbe66a6ef36e219f40b07607f558acbd94b19293 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 13 Dec 2022 09:50:52 -0800 Subject: [PATCH 10/11] Address nits Co-authored-by: Oli Scherer --- compiler/rustc_hir_analysis/src/check/mod.rs | 2 +- compiler/rustc_middle/src/ty/fast_reject.rs | 11 +++-------- compiler/rustc_trait_selection/src/traits/project.rs | 7 +------ 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index 1c7b83f99a873..57f0cae12bb31 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -352,7 +352,7 @@ fn bounds_from_generic_predicates<'tcx>( // insert the associated types where they correspond, but for now let's be "lazy" and // propose this instead of the following valid resugaring: // `T: Trait, Trait::Assoc = K` → `T: Trait` - where_clauses.push(format!("{} = {}", tcx.def_path_str(p.projection_ty.def_id), p.term,)); + where_clauses.push(format!("{} = {}", tcx.def_path_str(p.projection_ty.def_id), p.term)); } let where_clauses = if where_clauses.is_empty() { String::new() diff --git a/compiler/rustc_middle/src/ty/fast_reject.rs b/compiler/rustc_middle/src/ty/fast_reject.rs index 2771eb51a9b18..44650827810ab 100644 --- a/compiler/rustc_middle/src/ty/fast_reject.rs +++ b/compiler/rustc_middle/src/ty/fast_reject.rs @@ -126,7 +126,7 @@ pub fn simplify_type<'tcx>( TreatParams::AsPlaceholder => Some(PlaceholderSimplifiedType), TreatParams::AsInfer => None, }, - ty::Alias(ty::Opaque, ..) | ty::Alias(ty::Projection, _) => match treat_params { + ty::Alias(..) => match treat_params { // When treating `ty::Param` as a placeholder, projections also // don't unify with anything else as long as they are fully normalized. // @@ -225,10 +225,7 @@ impl DeepRejectCtxt { match impl_ty.kind() { // Start by checking whether the type in the impl may unify with // pretty much everything. Just return `true` in that case. - ty::Param(_) - | ty::Alias(ty::Projection, _) - | ty::Error(_) - | ty::Alias(ty::Opaque, ..) => return true, + ty::Param(_) | ty::Error(_) | ty::Alias(..) => return true, // These types only unify with inference variables or their own // variant. ty::Bool @@ -326,8 +323,6 @@ impl DeepRejectCtxt { _ => false, }, - ty::Alias(ty::Opaque, ..) => true, - // Impls cannot contain these types as these cannot be named directly. ty::FnDef(..) | ty::Closure(..) | ty::Generator(..) => false, @@ -347,7 +342,7 @@ impl DeepRejectCtxt { // projections can unify with other stuff. // // Looking forward to lazy normalization this is the safer strategy anyways. - ty::Alias(ty::Projection, _) => true, + ty::Alias(..) => true, ty::Error(_) => true, diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index f016fa0a2e672..ca9ee04c58c10 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -1377,12 +1377,7 @@ fn assemble_candidates_from_trait_def<'cx, 'tcx>( // Check whether the self-type is itself a projection. // If so, extract what we know from the trait and try to come up with a good answer. let bounds = match *obligation.predicate.self_ty().kind() { - ty::Alias(ty::Projection, ref data) => { - tcx.bound_item_bounds(data.def_id).subst(tcx, data.substs) - } - ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { - tcx.bound_item_bounds(def_id).subst(tcx, substs) - } + ty::Alias(_, ref data) => tcx.bound_item_bounds(data.def_id).subst(tcx, data.substs), ty::Infer(ty::TyVar(_)) => { // If the self-type is an inference variable, then it MAY wind up // being a projected type, so induce an ambiguity. From 99417d54afe7a9f8a74c9eea4338d039f36b9a45 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 13 Dec 2022 17:54:52 +0000 Subject: [PATCH 11/11] Address a few more nits --- compiler/rustc_hir_analysis/src/variance/mod.rs | 11 ++++++----- .../rustc_infer/src/infer/error_reporting/mod.rs | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_hir_analysis/src/variance/mod.rs b/compiler/rustc_hir_analysis/src/variance/mod.rs index feb49ed1e30fe..3c29c72841e44 100644 --- a/compiler/rustc_hir_analysis/src/variance/mod.rs +++ b/compiler/rustc_hir_analysis/src/variance/mod.rs @@ -110,13 +110,14 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc #[instrument(level = "trace", skip(self), ret)] fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { - // FIXME(alias): merge these match t.kind() { - ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => self.visit_opaque(*def_id, substs), - ty::Alias(ty::Projection, proj) - if self.tcx.def_kind(proj.def_id) == DefKind::ImplTraitPlaceholder => + ty::Alias(_, ty::AliasTy { def_id, substs }) + if matches!( + self.tcx.def_kind(*def_id), + DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder + ) => { - self.visit_opaque(proj.def_id, proj.substs) + self.visit_opaque(*def_id, substs) } _ => t.super_visit_with(self), } diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 7079322a4a460..3d2b2c6ff2dad 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -338,13 +338,14 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>( impl<'tcx> InferCtxt<'tcx> { pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option> { - // FIXME(alias): Merge these let (def_id, substs) = match *ty.kind() { - ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => (def_id, substs), - ty::Alias(ty::Projection, data) - if self.tcx.def_kind(data.def_id) == DefKind::ImplTraitPlaceholder => + ty::Alias(_, ty::AliasTy { def_id, substs }) + if matches!( + self.tcx.def_kind(def_id), + DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder + ) => { - (data.def_id, data.substs) + (def_id, substs) } _ => return None, }; @@ -1730,7 +1731,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { TypeError::Sorts(values) => { let extra = expected == found; let sort_string = |ty: Ty<'tcx>, path: Option| { - // FIXME(alias): Merge these let mut s = match (extra, ty.kind()) { (true, ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) => { let sm = self.tcx.sess.source_map();