diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index a92cb6bb38d47..72c0257756ef2 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::Alias(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 e6520301818d8..f8ec5e5e79914 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::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *output_ty.kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *output_ty.kind() { output_ty = self.infcx.tcx.type_of(def_id) }; diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index decddf47b715d..bb897b95b2c53 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::Alias(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_const_eval/src/util/type_name.rs b/compiler/rustc_const_eval/src/util/type_name.rs index dd65d4fd591e5..c4122f6649814 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::Alias(_, 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/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index c8c10385f0cd6..71f26eb60c962 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -680,7 +680,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let assoc_bindings = self.create_assoc_bindings_for_generic_args(args); let poly_trait_ref = - ty::Binder::bind_with_vars(ty::TraitRef::new(trait_def_id, substs), bound_vars); + ty::Binder::bind_with_vars(tcx.mk_trait_ref(trait_def_id, substs), bound_vars); debug!(?poly_trait_ref, ?assoc_bindings); bounds.trait_bounds.push((poly_trait_ref, span, constness)); @@ -813,7 +813,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { if let Some(b) = trait_segment.args().bindings.first() { Self::prohibit_assoc_ty_binding(self.tcx(), b.span); } - ty::TraitRef::new(trait_def_id, substs) + self.tcx().mk_trait_ref(trait_def_id, substs) } #[instrument(level = "debug", skip(self, span))] @@ -1146,7 +1146,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { debug!(?substs_trait_ref_and_assoc_item); - ty::AliasTy { def_id: assoc_item.def_id, substs: substs_trait_ref_and_assoc_item } + self.tcx().mk_alias_ty(assoc_item.def_id, 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 dd841707b2906..aa01feb3a1ea4 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -570,7 +570,7 @@ fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, id: hir::ItemId) { assoc_item, assoc_item, default.span, - ty::TraitRef { def_id: it.owner_id.to_def_id(), substs: trait_substs }, + tcx.mk_trait_ref(it.owner_id.to_def_id(), trait_substs), ); } _ => {} @@ -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::Alias(ty::Opaque, ty::AliasTy { def_id: def, substs: _ }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => { 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 ba7d31cea2e2f..4f4e9a89fc741 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_method.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_method.rs @@ -1746,10 +1746,7 @@ pub fn check_type_bounds<'tcx>( _ => predicates.push( ty::Binder::bind_with_vars( ty::ProjectionPredicate { - projection_ty: ty::AliasTy { - def_id: trait_ty.def_id, - substs: rebased_substs, - }, + projection_ty: tcx.mk_alias_ty(trait_ty.def_id, rebased_substs), term: impl_ty_value.into(), }, bound_vars, diff --git a/compiler/rustc_hir_analysis/src/variance/mod.rs b/compiler/rustc_hir_analysis/src/variance/mod.rs index 3c29c72841e44..24008f8881433 100644 --- a/compiler/rustc_hir_analysis/src/variance/mod.rs +++ b/compiler/rustc_hir_analysis/src/variance/mod.rs @@ -111,7 +111,7 @@ 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::Alias(_, ty::AliasTy { def_id, substs }) + ty::Alias(_, ty::AliasTy { def_id, substs, .. }) if matches!( self.tcx.def_kind(*def_id), DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder @@ -160,7 +160,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc // instead of requiring an additional `+ 'a`. match pred.kind().skip_binder() { ty::PredicateKind::Clause(ty::Clause::Trait(ty::TraitPredicate { - trait_ref: ty::TraitRef { def_id: _, substs }, + trait_ref: ty::TraitRef { def_id: _, substs, .. }, constness: _, polarity: _, })) => { @@ -169,7 +169,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc } } ty::PredicateKind::Clause(ty::Clause::Projection(ty::ProjectionPredicate { - projection_ty: ty::AliasTy { substs, def_id: _ }, + projection_ty: ty::AliasTy { substs, .. }, 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 a86bd80a668b0..ab12cae4e2b08 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::Alias(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) @@ -542,15 +542,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::PredicateKind::Clause(ty::Clause::Trait(trait_pred)) => { assert_eq!(trait_pred.trait_ref.self_ty(), opaque_ty); ty::PredicateKind::Clause(ty::Clause::Trait( - trait_pred.with_self_type(self.tcx, ty), + trait_pred.with_self_ty(self.tcx, ty), )) } ty::PredicateKind::Clause(ty::Clause::Projection(mut proj_pred)) => { assert_eq!(proj_pred.projection_ty.self_ty(), opaque_ty); - proj_pred.projection_ty.substs = self.tcx.mk_substs_trait( - ty, - proj_pred.projection_ty.substs.iter().skip(1), - ); + proj_pred = proj_pred.with_self_ty(self.tcx, ty); ty::PredicateKind::Clause(ty::Clause::Projection(proj_pred)) } _ => continue, diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index a96d27868a6d5..72d8a936ab39d 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::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => self + 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), ), @@ -678,7 +678,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { get_future_output(obligation.predicate, obligation.cause.span) })? } - ty::Alias(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) diff --git a/compiler/rustc_hir_typeck/src/coercion.rs b/compiler/rustc_hir_typeck/src/coercion.rs index a4ca7571142b6..36cf4791492dd 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::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = ty.kind() + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = 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 4e2a785622407..866090260b272 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::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs: _ }) => { + ty::Alias(ty::Opaque, _) => { 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 c8ea8ba5ab065..1a4e6bf763821 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::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *ty.kind() + && let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *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 615f374b2ec0b..8e520e563ff63 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::Alias(ty::Opaque, ty::AliasTy { def_id: new_def_id, substs: _ }) + ty::Alias(ty::Opaque, ty::AliasTy { def_id: new_def_id, .. }) | ty::Closure(new_def_id, _) | ty::FnDef(new_def_id, _) => { def_id = new_def_id; @@ -2132,19 +2132,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => { // Look for a user-provided impl of a `Fn` trait, and point to it. let new_def_id = self.probe(|_| { - let trait_ref = ty::TraitRef::new( + let trait_ref = self.tcx.mk_trait_ref( call_kind.to_def_id(self.tcx), - self.tcx.mk_substs( - [ - ty::GenericArg::from(callee_ty), - self.next_ty_var(TypeVariableOrigin { - kind: TypeVariableOriginKind::MiscVariable, - span: rustc_span::DUMMY_SP, - }) - .into(), - ] - .into_iter(), - ), + [ + callee_ty, + self.next_ty_var(TypeVariableOrigin { + kind: TypeVariableOriginKind::MiscVariable, + span: rustc_span::DUMMY_SP, + }), + ], ); let obligation = traits::Obligation::new( self.tcx, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index e6e1098e33d74..719f44f9f665a 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -13,7 +13,7 @@ use rustc_hir_analysis::astconv::AstConv; use rustc_infer::infer; use rustc_infer::traits::{self, StatementAsExpression}; use rustc_middle::lint::in_external_macro; -use rustc_middle::ty::{self, Binder, DefIdTree, IsSuggestable, ToPredicate, Ty}; +use rustc_middle::ty::{self, Binder, DefIdTree, IsSuggestable, Ty}; use rustc_session::errors::ExprParenthesesNeeded; use rustc_span::symbol::sym; use rustc_span::Span; @@ -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::Alias(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() @@ -1277,17 +1277,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Check that we're in fact trying to clone into the expected type && self.can_coerce(*pointee_ty, expected_ty) // And the expected type doesn't implement `Clone` - && !self.predicate_must_hold_considering_regions(&traits::Obligation { - cause: traits::ObligationCause::dummy(), - param_env: self.param_env, - recursion_depth: 0, - predicate: ty::Binder::dummy(ty::TraitRef { - def_id: clone_trait_did, - substs: self.tcx.mk_substs([expected_ty.into()].iter()), - }) - .without_const() - .to_predicate(self.tcx), - }) + && !self.predicate_must_hold_considering_regions(&traits::Obligation::new( + self.tcx, + traits::ObligationCause::dummy(), + self.param_env, + ty::Binder::dummy(self.tcx.mk_trait_ref( + clone_trait_did, + [expected_ty], + )), + )) { diag.span_note( callee_expr.span, diff --git a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs index d83b9eb995d2b..93f2ceed777b5 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::Alias(ty::Opaque, ty::AliasTy { def_id: def, substs: _ }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => { 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/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index a7eae392de1dd..3f3af53d199b1 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -285,7 +285,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.var_for_def(span, param) }); - let trait_ref = ty::TraitRef::new(trait_def_id, substs); + let trait_ref = self.tcx.mk_trait_ref(trait_def_id, substs); // Construct an obligation let poly_trait_ref = ty::Binder::dummy(trait_ref); @@ -326,7 +326,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.var_for_def(span, param) }); - let trait_ref = ty::TraitRef::new(trait_def_id, substs); + let trait_ref = self.tcx.mk_trait_ref(trait_def_id, substs); // Construct an obligation let poly_trait_ref = ty::Binder::dummy(trait_ref); diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index 070359e71becc..b9e7830bf0792 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -920,7 +920,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { ) { debug!("assemble_extension_candidates_for_trait(trait_def_id={:?})", trait_def_id); let trait_substs = self.fresh_item_substs(trait_def_id); - let trait_ref = ty::TraitRef::new(trait_def_id, trait_substs); + let trait_ref = self.tcx.mk_trait_ref(trait_def_id, trait_substs); if self.tcx.is_trait_alias(trait_def_id) { // For trait aliases, assume all supertraits are relevant. diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 41cd6bf314ebf..0103f58d0614c 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -557,10 +557,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .chain(projection_ty.substs.iter().skip(1)), ); - let quiet_projection_ty = ty::AliasTy { - substs: substs_with_infer_self, - def_id: projection_ty.def_id, - }; + let quiet_projection_ty = + tcx.mk_alias_ty(projection_ty.def_id, substs_with_infer_self); let term = pred.skip_binder().term; diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index d25d9672c36d0..bb956ddc78042 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::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *t.kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *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 316077f69d99b..9a1c49c1aa6af 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::Alias(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 9fd4bdee096ac..46e7813d99e56 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::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }), - &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }), ) if a_def_id == b_def_id => { self.fields.infcx.super_combine_tys(self, a, b)?; } - (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _) - | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ })) + (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _) + | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) 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 3d2b2c6ff2dad..397fa43175f73 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -339,7 +339,7 @@ pub fn unexpected_hidden_region_diagnostic<'tcx>( impl<'tcx> InferCtxt<'tcx> { pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option> { let (def_id, substs) = match *ty.kind() { - ty::Alias(_, ty::AliasTy { def_id, substs }) + ty::Alias(_, ty::AliasTy { def_id, substs, .. }) if matches!( self.tcx.def_kind(def_id), DefKind::OpaqueTy | DefKind::ImplTraitPlaceholder @@ -2767,9 +2767,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::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => { - Some((Self::Opaque, def_id)) - } + ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => 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/nice_region_error/placeholder_error.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs index 1f554c81eff8e..fed9fda74bfb3 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -226,13 +226,11 @@ impl<'tcx> NiceRegionError<'_, 'tcx> { false }; - let expected_trait_ref = self.cx.resolve_vars_if_possible(ty::TraitRef { - def_id: trait_def_id, - substs: expected_substs, - }); - let actual_trait_ref = self + let expected_trait_ref = self .cx - .resolve_vars_if_possible(ty::TraitRef { def_id: trait_def_id, substs: actual_substs }); + .resolve_vars_if_possible(self.cx.tcx.mk_trait_ref(trait_def_id, expected_substs)); + let actual_trait_ref = + self.cx.resolve_vars_if_possible(self.cx.tcx.mk_trait_ref(trait_def_id, actual_substs)); // Search the expected and actual trait references to see (a) // whether the sub/sup placeholders appear in them (sometimes diff --git a/compiler/rustc_infer/src/infer/error_reporting/suggest.rs b/compiler/rustc_infer/src/infer/error_reporting/suggest.rs index 62655d11ca309..30ca9f41d6e6f 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::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, substs: _ }), - ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, substs: _ }), + ty::Alias(ty::Opaque, ty::AliasTy { def_id: last_def_id, .. }), + ty::Alias(ty::Opaque, ty::AliasTy { def_id: exp_def_id, .. }), ) if last_def_id == exp_def_id => StatementAsExpression::CorrectType, ( - 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 }), + 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/lattice.rs b/compiler/rustc_infer/src/infer/lattice.rs index 47d76dc5bdf02..0ebc6d55bcba9 100644 --- a/compiler/rustc_infer/src/infer/lattice.rs +++ b/compiler/rustc_infer/src/infer/lattice.rs @@ -106,11 +106,11 @@ where } ( - &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }), - &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }), ) if a_def_id == b_def_id => infcx.super_combine_tys(this, a, b), - (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _) - | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ })) + (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _) + | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) 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 3b9683e5b5933..1f9d86a78d6e5 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -611,8 +611,8 @@ where (&ty::Infer(ty::TyVar(vid)), _) => self.relate_ty_var((vid, b)), ( - &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }), - &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: 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(), @@ -620,8 +620,8 @@ where ); if a_def_id.is_local() { self.relate_opaques(a, b) } else { Err(err) } }), - (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _) - | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ })) + (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _) + | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) 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 67e4554c4c707..a130fde47ed5c 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::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) + ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) 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::Alias(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,9 +149,7 @@ impl<'tcx> InferCtxt<'tcx> { DefiningAnchor::Bubble => self.opaque_ty_origin_unchecked(def_id, cause.span), DefiningAnchor::Error => return None, }; - if let ty::Alias(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, .. }) = *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. @@ -480,7 +478,7 @@ where substs.as_generator().resume_ty().visit_with(self); } - ty::Alias(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); @@ -583,17 +581,16 @@ 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::Alias(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::Alias(ty::Projection, ty::AliasTy { def_id: def_id2, substs: substs2 }) - if def_id.to_def_id() == def_id2 && substs == substs2 => - { - hidden_ty - } + ty::Alias( + ty::Projection, + ty::AliasTy { def_id: def_id2, substs: substs2, .. }, + ) if def_id.to_def_id() == def_id2 && substs == substs2 => hidden_ty, _ => ty, }, lt_op: |lt| lt, diff --git a/compiler/rustc_infer/src/infer/outlives/components.rs b/compiler/rustc_infer/src/infer/outlives/components.rs index 984bbe169e6cf..aa2b5d067d266 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::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) => { + ty::Alias(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 da85de6019932..ccae7165d80d2 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::Alias(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), }, ); diff --git a/compiler/rustc_infer/src/infer/sub.rs b/compiler/rustc_infer/src/infer/sub.rs index 58e27f8b21d63..bd38b52ba34a7 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::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, substs: _ }), - &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, substs: _ }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: a_def_id, .. }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id: b_def_id, .. }), ) if a_def_id == b_def_id => { self.fields.infcx.super_combine_tys(self, a, b)?; Ok(a) } - (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), _) - | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ })) + (&ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), _) + | (_, &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. })) if self.fields.define_opaque_types && def_id.is_local() => { self.fields.obligations.extend( diff --git a/compiler/rustc_lint/src/context.rs b/compiler/rustc_lint/src/context.rs index e6a0d7e60ca77..40b2588388d66 100644 --- a/compiler/rustc_lint/src/context.rs +++ b/compiler/rustc_lint/src/context.rs @@ -1258,7 +1258,7 @@ impl<'tcx> LateContext<'tcx> { tcx.associated_items(trait_id) .find_by_name_and_kind(tcx, Ident::from_str(name), ty::AssocKind::Type, trait_id) .and_then(|assoc| { - let proj = tcx.mk_projection(assoc.def_id, tcx.mk_substs_trait(self_ty, [])); + let proj = tcx.mk_projection(assoc.def_id, [self_ty]); tcx.try_normalize_erasing_regions(self.param_env, proj).ok() }) } diff --git a/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs b/compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs index 3808d308186c0..42442cfb1904d 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::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), + ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), 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 fb2c8b1ef647c..d628a18dd01c5 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::Alias(ty::Opaque, ty::AliasTy { def_id: future_def_id, substs: _ }) = ty.kind() + && let ty::Alias(ty::Opaque, ty::AliasTy { def_id: future_def_id, .. }) = 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::Alias(ty::Opaque, ty::AliasTy { def_id: def, substs: _ }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => { elaborate_predicates_with_span( cx.tcx, cx.tcx.explicit_item_bounds(def).iter().cloned(), diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index db4fe6f886b25..3bc331e19c1cc 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1847,7 +1847,7 @@ impl<'tcx> Operand<'tcx> { pub fn function_handle( tcx: TyCtxt<'tcx>, def_id: DefId, - substs: SubstsRef<'tcx>, + substs: impl IntoIterator>, span: Span, ) -> Self { let ty = tcx.mk_fn_def(def_id, substs); diff --git a/compiler/rustc_middle/src/ty/adjustment.rs b/compiler/rustc_middle/src/ty/adjustment.rs index 7036c4a7b27d6..8ce06404de081 100644 --- a/compiler/rustc_middle/src/ty/adjustment.rs +++ b/compiler/rustc_middle/src/ty/adjustment.rs @@ -131,7 +131,7 @@ impl<'tcx> OverloadedDeref<'tcx> { .find(|m| m.kind == ty::AssocKind::Fn) .unwrap() .def_id; - tcx.mk_fn_def(method_def_id, tcx.mk_substs_trait(source, [])) + tcx.mk_fn_def(method_def_id, [source]) } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index dc333b4702f39..70ac5acb40ead 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -18,7 +18,7 @@ use crate::thir::Thir; use crate::traits; use crate::ty::query::{self, TyCtxtAt}; use crate::ty::{ - self, AdtDef, AdtDefData, AdtKind, AliasTy, Binder, BindingMode, BoundVar, CanonicalPolyFnSig, + self, AdtDef, AdtDefData, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig, ClosureSizeProfileData, Const, ConstS, DefIdTree, FloatTy, FloatVar, FloatVid, GenericParamDefKind, InferTy, IntTy, IntVar, IntVid, List, ParamConst, ParamTy, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, Region, RegionKind, ReprOptions, @@ -2321,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::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = ty.kind() else { return false }; + let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = ty.kind() else { return false }; let future_trait = self.require_lang_item(LangItem::Future, None); self.explicit_item_bounds(def_id).iter().any(|(predicate, _)| { @@ -2565,15 +2565,35 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] - pub fn mk_fn_def(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> { - debug_assert_eq!( - self.generics_of(def_id).count(), - substs.len(), - "wrong number of generic parameters for {def_id:?}: {substs:?}", - ); + pub fn mk_fn_def( + self, + def_id: DefId, + substs: impl IntoIterator>>, + ) -> Ty<'tcx> { + let substs = self.check_substs(def_id, substs); self.mk_ty(FnDef(def_id, substs)) } + #[inline(always)] + fn check_substs( + self, + _def_id: DefId, + substs: impl IntoIterator>>, + ) -> SubstsRef<'tcx> { + let substs = substs.into_iter().map(Into::into); + #[cfg(debug_assertions)] + { + let n = self.generics_of(_def_id).count(); + assert_eq!( + (n, Some(n)), + substs.size_hint(), + "wrong number of generic parameters for {_def_id:?}: {:?}", + substs.collect::>(), + ); + } + self.mk_substs(substs) + } + #[inline] pub fn mk_fn_ptr(self, fty: PolyFnSig<'tcx>) -> Ty<'tcx> { self.mk_ty(FnPtr(fty)) @@ -2590,13 +2610,12 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] - pub fn mk_projection(self, item_def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> { - debug_assert_eq!( - self.generics_of(item_def_id).count(), - substs.len(), - "wrong number of generic parameters for {item_def_id:?}: {substs:?}", - ); - self.mk_ty(Alias(ty::Projection, AliasTy { def_id: item_def_id, substs })) + pub fn mk_projection( + self, + item_def_id: DefId, + substs: impl IntoIterator>>, + ) -> Ty<'tcx> { + self.mk_ty(Alias(ty::Projection, self.mk_alias_ty(item_def_id, substs))) } #[inline] @@ -2666,7 +2685,7 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> { - self.mk_ty(Alias(ty::Opaque, ty::AliasTy { def_id, substs })) + self.mk_ty(Alias(ty::Opaque, self.mk_alias_ty(def_id, substs))) } pub fn mk_place_field(self, place: Place<'tcx>, f: Field, ty: Ty<'tcx>) -> Place<'tcx> { @@ -2855,16 +2874,17 @@ impl<'tcx> TyCtxt<'tcx> { trait_def_id: DefId, substs: impl IntoIterator>>, ) -> ty::TraitRef<'tcx> { - let substs = substs.into_iter().map(Into::into); - let n = self.generics_of(trait_def_id).count(); - debug_assert_eq!( - (n, Some(n)), - substs.size_hint(), - "wrong number of generic parameters for {trait_def_id:?}: {:?} \nDid you accidentally include the self-type in the params list?", - substs.collect::>(), - ); - let substs = self.mk_substs(substs); - ty::TraitRef::new(trait_def_id, substs) + let substs = self.check_substs(trait_def_id, substs); + ty::TraitRef { def_id: trait_def_id, substs, _use_mk_trait_ref_instead: () } + } + + pub fn mk_alias_ty( + self, + def_id: DefId, + substs: impl IntoIterator>>, + ) -> ty::AliasTy<'tcx> { + let substs = self.check_substs(def_id, substs); + ty::AliasTy { def_id, substs, _use_mk_alias_ty_instead: () } } pub fn mk_bound_variable_kinds< diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index d7880a32ea9cd..d8d476d3fefe2 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -457,10 +457,10 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> { return ControlFlow::Break(()); } - Alias(Opaque, AliasTy { def_id, substs: _ }) => { + Alias(Opaque, AliasTy { def_id, .. }) => { let parent = self.tcx.parent(*def_id); if let hir::def::DefKind::TyAlias | hir::def::DefKind::AssocTy = self.tcx.def_kind(parent) - && let Alias(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, .. }) = 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 22dc921aba1ca..14d07608a780e 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -779,8 +779,7 @@ fn foo(&self) -> Self::T { String::new() } ty: Ty<'tcx>, ) -> bool { let assoc = self.associated_item(proj_ty.def_id); - if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *proj_ty.self_ty().kind() - { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *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 174ac74fc9e61..d283ccc3ad8a2 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::Alias(ty::Opaque, ty::AliasTy { def_id: _, substs }) => { + &ty::Alias(ty::Opaque, ty::AliasTy { substs, .. }) => { self.add_flags(TypeFlags::HAS_TY_OPAQUE); self.add_substs(substs); } diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 6cb28a0fd8077..5232c1e1cc0f8 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -781,8 +781,8 @@ impl<'tcx> TraitPredicate<'tcx> { } } - pub fn with_self_type(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self { - Self { trait_ref: self.trait_ref.with_self_type(tcx, self_ty), ..self } + pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self { + Self { trait_ref: self.trait_ref.with_self_ty(tcx, self_ty), ..self } } pub fn def_id(self) -> DefId { @@ -1050,6 +1050,18 @@ impl<'tcx> PolyProjectionPredicate<'tcx> { } } +impl<'tcx> ProjectionPredicate<'tcx> { + pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self { + Self { + projection_ty: tcx.mk_alias_ty( + self.projection_ty.def_id, + [self_ty.into()].into_iter().chain(self.projection_ty.substs.iter().skip(1)), + ), + ..self + } + } +} + pub trait ToPolyTraitRef<'tcx> { fn to_poly_trait_ref(&self) -> PolyTraitRef<'tcx>; } diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index 3fad349bff812..29bad33e4bc0f 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -169,10 +169,8 @@ pub trait Printer<'tcx>: Sized { self.path_append( |cx: Self| { if trait_qualify_parent { - let trait_ref = ty::TraitRef::new( - parent_def_id, - cx.tcx().intern_substs(parent_substs), - ); + let trait_ref = + cx.tcx().mk_trait_ref(parent_def_id, parent_substs.iter().copied()); cx.path_qualified(trait_ref.self_ty(), Some(trait_ref)) } else { cx.print_def_path(parent_def_id, parent_substs) diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 6acc2dc65d369..b1bc6eb8b81c5 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::Alias(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::Alias(ty::Opaque, ty::AliasTy { def_id: d, substs: _ }) = + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id: d, .. }) = *self.tcx().type_of(parent).kind() { if d == def_id { diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 1eac8859ca934..c4116558bd27b 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -280,7 +280,7 @@ impl<'tcx> Relate<'tcx> for ty::AliasTy<'tcx> { Err(TypeError::ProjectionMismatched(expected_found(relation, a.def_id, b.def_id))) } else { let substs = relation.relate(a.substs, b.substs)?; - Ok(ty::AliasTy { def_id: a.def_id, substs: &substs }) + Ok(relation.tcx().mk_alias_ty(a.def_id, substs)) } } } @@ -322,7 +322,7 @@ impl<'tcx> Relate<'tcx> for ty::TraitRef<'tcx> { Err(TypeError::Traits(expected_found(relation, a.def_id, b.def_id))) } else { let substs = relate_substs(relation, a.substs, b.substs)?; - Ok(ty::TraitRef { def_id: a.def_id, substs }) + Ok(relation.tcx().mk_trait_ref(a.def_id, substs)) } } } @@ -557,8 +557,8 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( } ( - &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 }), + &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/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 27de48c1f8345..66aeebab88ba0 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -816,14 +816,13 @@ impl<'tcx> List> { pub struct TraitRef<'tcx> { pub def_id: DefId, pub substs: SubstsRef<'tcx>, + /// This field exists to prevent the creation of `TraitRef` without + /// calling [TyCtxt::mk_trait_ref]. + pub(super) _use_mk_trait_ref_instead: (), } impl<'tcx> TraitRef<'tcx> { - pub fn new(def_id: DefId, substs: SubstsRef<'tcx>) -> TraitRef<'tcx> { - TraitRef { def_id, substs } - } - - pub fn with_self_type(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self { + pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self { tcx.mk_trait_ref( self.def_id, [self_ty.into()].into_iter().chain(self.substs.iter().skip(1)), @@ -833,10 +832,7 @@ impl<'tcx> TraitRef<'tcx> { /// Returns a `TraitRef` of the form `P0: Foo` where `Pi` /// are the parameters defined on trait. pub fn identity(tcx: TyCtxt<'tcx>, def_id: DefId) -> Binder<'tcx, TraitRef<'tcx>> { - ty::Binder::dummy(TraitRef { - def_id, - substs: InternalSubsts::identity_for_item(tcx, def_id), - }) + ty::Binder::dummy(tcx.mk_trait_ref(def_id, InternalSubsts::identity_for_item(tcx, def_id))) } #[inline] @@ -850,7 +846,7 @@ impl<'tcx> TraitRef<'tcx> { substs: SubstsRef<'tcx>, ) -> ty::TraitRef<'tcx> { let defs = tcx.generics_of(trait_id); - ty::TraitRef { def_id: trait_id, substs: tcx.intern_substs(&substs[..defs.params.len()]) } + tcx.mk_trait_ref(trait_id, tcx.intern_substs(&substs[..defs.params.len()])) } } @@ -1166,6 +1162,10 @@ pub struct AliasTy<'tcx> { /// `TraitRef` containing this associated type, which is in `tcx.associated_item(def_id).container`, /// aka. `tcx.parent(def_id)`. pub def_id: DefId, + + /// This field exists to prevent the creation of `ProjectionTy` without using + /// [TyCtxt::mk_alias_ty]. + pub(super) _use_mk_alias_ty_instead: (), } impl<'tcx> AliasTy<'tcx> { @@ -1190,10 +1190,7 @@ impl<'tcx> AliasTy<'tcx> { let trait_def_id = self.trait_def_id(tcx); let trait_generics = tcx.generics_of(trait_def_id); ( - ty::TraitRef { - def_id: trait_def_id, - substs: self.substs.truncate_to(tcx, trait_generics), - }, + tcx.mk_trait_ref(trait_def_id, self.substs.truncate_to(tcx, trait_generics)), &self.substs[trait_generics.count()..], ) } @@ -1207,7 +1204,7 @@ impl<'tcx> AliasTy<'tcx> { /// as well. pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> { let def_id = self.trait_def_id(tcx); - ty::TraitRef { def_id, substs: self.substs.truncate_to(tcx, tcx.generics_of(def_id)) } + tcx.mk_trait_ref(def_id, self.substs.truncate_to(tcx, tcx.generics_of(def_id))) } pub fn self_ty(&self) -> Ty<'tcx> { @@ -1449,10 +1446,8 @@ impl<'tcx> ExistentialProjection<'tcx> { debug_assert!(!self_ty.has_escaping_bound_vars()); ty::ProjectionPredicate { - projection_ty: ty::AliasTy { - def_id: self.def_id, - substs: tcx.mk_substs_trait(self_ty, self.substs), - }, + projection_ty: tcx + .mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.substs)), term: self.term, } } diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index b8a19e582c9dc..857f52c8a2456 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -825,7 +825,7 @@ impl<'tcx> TypeFolder<'tcx> for OpaqueTypeExpander<'tcx> { } fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Alias(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) diff --git a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs index 0814793f27790..c7b3eb44dc5fb 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs @@ -142,7 +142,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let exchange_malloc = Operand::function_handle( tcx, tcx.require_lang_item(LangItem::ExchangeMalloc, Some(expr_span)), - ty::List::empty(), + [], expr_span, ); let storage = this.temp(tcx.mk_mut_ptr(tcx.types.u8), expr_span); diff --git a/compiler/rustc_mir_build/src/build/matches/test.rs b/compiler/rustc_mir_build/src/build/matches/test.rs index 6d5a98342d293..de6a48f7cc411 100644 --- a/compiler/rustc_mir_build/src/build/matches/test.rs +++ b/compiler/rustc_mir_build/src/build/matches/test.rs @@ -838,8 +838,6 @@ fn trait_method<'tcx>( method_name: Symbol, substs: impl IntoIterator>>, ) -> ConstantKind<'tcx> { - let substs = tcx.mk_substs(substs.into_iter().map(Into::into)); - // The unhygienic comparison here is acceptable because this is only // used on known traits. let item = tcx diff --git a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs index 8610792c0eb5d..7836ae2e7b76f 100644 --- a/compiler/rustc_mir_dataflow/src/elaborate_drops.rs +++ b/compiler/rustc_mir_dataflow/src/elaborate_drops.rs @@ -614,7 +614,6 @@ where let drop_trait = tcx.require_lang_item(LangItem::Drop, None); let drop_fn = tcx.associated_item_def_ids(drop_trait)[0]; let ty = self.place_ty(self.place); - let substs = tcx.mk_substs_trait(ty, []); let ref_ty = tcx.mk_ref(tcx.lifetimes.re_erased, ty::TypeAndMut { ty, mutbl: hir::Mutability::Mut }); @@ -632,7 +631,12 @@ where )], terminator: Some(Terminator { kind: TerminatorKind::Call { - func: Operand::function_handle(tcx, drop_fn, substs, self.source_info.span), + func: Operand::function_handle( + tcx, + drop_fn, + [ty.into()], + self.source_info.span, + ), args: vec![Operand::Move(Place::from(ref_place))], destination: unit_temp, target: Some(succ), diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index ef7589d3ef231..9d560f5c837e2 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::Alias(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/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index f92a0e826dcdf..f8b55c862875e 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -336,8 +336,7 @@ impl<'tcx> CloneShimBuilder<'tcx> { // we must subst the self_ty because it's // otherwise going to be TySelf and we can't index // or access fields of a Place of type TySelf. - let substs = tcx.mk_substs_trait(self_ty, []); - let sig = tcx.bound_fn_sig(def_id).subst(tcx, substs); + let sig = tcx.bound_fn_sig(def_id).subst(tcx, &[self_ty.into()]); let sig = tcx.erase_late_bound_regions(sig); let span = tcx.def_span(def_id); @@ -417,10 +416,8 @@ impl<'tcx> CloneShimBuilder<'tcx> { ) { let tcx = self.tcx; - let substs = tcx.mk_substs_trait(ty, []); - // `func == Clone::clone(&ty) -> ty` - let func_ty = tcx.mk_fn_def(self.def_id, substs); + let func_ty = tcx.mk_fn_def(self.def_id, [ty]); let func = Operand::Constant(Box::new(Constant { span: self.span, user_ty: None, @@ -575,9 +572,8 @@ fn build_call_shim<'tcx>( // Create substitutions for the `Self` and `Args` generic parameters of the shim body. let arg_tup = tcx.mk_tup(untuple_args.iter()); - let sig_substs = tcx.mk_substs_trait(ty, [ty::subst::GenericArg::from(arg_tup)]); - (Some(sig_substs), Some(untuple_args)) + (Some([ty.into(), arg_tup.into()]), Some(untuple_args)) } else { (None, None) }; @@ -588,7 +584,7 @@ fn build_call_shim<'tcx>( assert_eq!(sig_substs.is_some(), !instance.has_polymorphic_mir_body()); let mut sig = - if let Some(sig_substs) = sig_substs { sig.subst(tcx, sig_substs) } else { sig.0 }; + if let Some(sig_substs) = sig_substs { sig.subst(tcx, &sig_substs) } else { sig.0 }; if let CallKind::Indirect(fnty) = call_kind { // `sig` determines our local decls, and thus the callee type in the `Call` terminator. This diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index d80c05d6b3826..72d38aeac7a0c 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -110,26 +110,25 @@ where V: DefIdVisitor<'tcx> + ?Sized, { fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> ControlFlow { - let TraitRef { def_id, substs } = trait_ref; + let TraitRef { def_id, substs, .. } = trait_ref; self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref.print_only_trait_path())?; if self.def_id_visitor.shallow() { ControlFlow::CONTINUE } else { substs.visit_with(self) } } 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 - { - 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.def_id); - let trait_generics = tcx.generics_of(def_id); - ( - ty::TraitRef { def_id, substs: projection.substs.truncate_to(tcx, trait_generics) }, - &projection.substs[trait_generics.count()..], - ) - }; + 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.def_id); + let trait_generics = tcx.generics_of(def_id); + ( + tcx.mk_trait_ref(def_id, projection.substs.truncate_to(tcx, trait_generics)), + &projection.substs[trait_generics.count()..], + ) + }; self.visit_trait(trait_ref)?; if self.def_id_visitor.shallow() { ControlFlow::CONTINUE @@ -235,7 +234,7 @@ where self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref)?; } } - ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { // 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 281b2d88f483b..a59c9011ab21a 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::Alias(_, 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/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index b7f055d9146a0..4285aa62cb963 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::Alias(_, 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/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index c68da3e24a190..3d8dfe81748c2 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1036,7 +1036,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { && self.fallback_has_occurred { let predicate = trait_predicate.map_bound(|trait_pred| { - trait_pred.with_self_type(self.tcx, self.tcx.mk_unit()) + trait_pred.with_self_ty(self.tcx, self.tcx.mk_unit()) }); let unit_obligation = obligation.with(tcx, predicate); if self.predicate_may_hold(&unit_obligation) { @@ -2085,8 +2085,8 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { param_env: ty::ParamEnv<'tcx>, trait_ref_and_ty: ty::Binder<'tcx, (ty::TraitPredicate<'tcx>, Ty<'tcx>)>, ) -> PredicateObligation<'tcx> { - let trait_pred = trait_ref_and_ty - .map_bound(|(tr, new_self_ty)| tr.with_self_type(self.tcx, new_self_ty)); + let trait_pred = + trait_ref_and_ty.map_bound(|(tr, new_self_ty)| tr.with_self_ty(self.tcx, new_self_ty)); Obligation::new(self.tcx, ObligationCause::dummy(), param_env, trait_pred) } 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 55a05df763fe6..dd5085bf4f300 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -878,7 +878,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { fn_sig.inputs().map_bound(|inputs| &inputs[1..]), )) } - ty::Alias(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() @@ -2662,7 +2662,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { Some(ident) => err.span_note(ident.span, &msg), None => err.note(&msg), }, - ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { // Avoid printing the future from `core::future::identity_future`, it's not helpful if tcx.parent(*def_id) == identity_future { break 'print; @@ -2975,7 +2975,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { self.tcx.mk_projection( item_def_id, // Future::Output has no substs - self.tcx.mk_substs_trait(trait_pred.self_ty(), []), + [trait_pred.self_ty()], ) }); let InferOk { value: projection_ty, .. } = @@ -3265,9 +3265,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // in. For example, this would be what `Iterator::Item` is here. let ty_var = self.infcx.next_ty_var(origin); // This corresponds to `::Item = _`. - let trait_ref = ty::Binder::dummy(ty::PredicateKind::Clause( + let projection = ty::Binder::dummy(ty::PredicateKind::Clause( ty::Clause::Projection(ty::ProjectionPredicate { - projection_ty: ty::AliasTy { substs, def_id: proj.def_id }, + projection_ty: tcx.mk_alias_ty(proj.def_id, substs), term: ty_var.into(), }), )); @@ -3277,7 +3277,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { span, expr.hir_id, param_env, - trait_ref, + projection, )); if ocx.select_where_possible().is_empty() { // `ty_var` now holds the type that `Item` is for `ExprTy`. diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index ea4bf42c515b5..2566d793d78da 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -425,13 +425,8 @@ pub fn fully_solve_bound<'tcx>( bound: DefId, ) -> Vec> { let tcx = infcx.tcx; - let trait_ref = ty::TraitRef { def_id: bound, substs: tcx.mk_substs_trait(ty, []) }; - let obligation = Obligation { - cause, - recursion_depth: 0, - param_env, - predicate: ty::Binder::dummy(trait_ref).without_const().to_predicate(tcx), - }; + let trait_ref = tcx.mk_trait_ref(bound, [ty]); + let obligation = Obligation::new(tcx, cause, param_env, ty::Binder::dummy(trait_ref)); fully_solve_obligation(infcx, obligation) } diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 3e85ea69635e6..8b1ced78f4e8a 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -694,18 +694,12 @@ fn receiver_is_dispatchable<'tcx>( // U: Trait let trait_predicate = { - let substs = - InternalSubsts::for_item(tcx, method.trait_container(tcx).unwrap(), |param, _| { - if param.index == 0 { - unsized_self_ty.into() - } else { - tcx.mk_param_from_def(param) - } - }); + let trait_def_id = method.trait_container(tcx).unwrap(); + let substs = InternalSubsts::for_item(tcx, trait_def_id, |param, _| { + if param.index == 0 { unsized_self_ty.into() } else { tcx.mk_param_from_def(param) } + }); - ty::Binder::dummy(ty::TraitRef { def_id: unsize_did, substs }) - .without_const() - .to_predicate(tcx) + ty::Binder::dummy(tcx.mk_trait_ref(trait_def_id, substs)).to_predicate(tcx) }; let caller_bounds: Vec> = diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index ca9ee04c58c10..84d7244c1db78 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::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) + 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. @@ -1309,8 +1309,7 @@ fn assemble_candidate_for_impl_trait_in_trait<'cx, 'tcx>( let trait_substs = obligation.predicate.substs.truncate_to(tcx, tcx.generics_of(trait_def_id)); // FIXME(named-returns): Binders - let trait_predicate = - ty::Binder::dummy(ty::TraitRef { def_id: trait_def_id, substs: trait_substs }); + let trait_predicate = ty::Binder::dummy(tcx.mk_trait_ref(trait_def_id, trait_substs)); let _ = selcx.infcx.commit_if_ok(|_| { match selcx.select(&obligation.with(tcx, trait_predicate)) { @@ -1867,10 +1866,7 @@ fn confirm_generator_candidate<'cx, 'tcx>( }; ty::ProjectionPredicate { - projection_ty: ty::AliasTy { - substs: trait_ref.substs, - def_id: obligation.predicate.def_id, - }, + projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.substs), term: ty.into(), } }); @@ -1909,10 +1905,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::AliasTy { - substs: trait_ref.substs, - def_id: obligation.predicate.def_id, - }, + projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.substs), term: return_ty.into(), } }); @@ -1965,10 +1958,8 @@ fn confirm_builtin_candidate<'cx, 'tcx>( bug!("unexpected builtin trait with associated type: {:?}", obligation.predicate); }; - let predicate = ty::ProjectionPredicate { - projection_ty: ty::AliasTy { substs, def_id: item_def_id }, - term, - }; + let predicate = + ty::ProjectionPredicate { projection_ty: tcx.mk_alias_ty(item_def_id, substs), term }; confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false) .with_addl_obligations(obligations) @@ -2037,7 +2028,7 @@ fn confirm_callable_candidate<'cx, 'tcx>( flag, ) .map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate { - projection_ty: ty::AliasTy { substs: trait_ref.substs, def_id: fn_once_output_def_id }, + projection_ty: tcx.mk_alias_ty(fn_once_output_def_id, trait_ref.substs), 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 777de195895b8..c6ef13e185b2d 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::Alias(ty::Opaque, ty::AliasTy { def_id, substs }) + 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. diff --git a/compiler/rustc_trait_selection/src/traits/relationships.rs b/compiler/rustc_trait_selection/src/traits/relationships.rs index bfa318787e546..34b5fc4891eb3 100644 --- a/compiler/rustc_trait_selection/src/traits/relationships.rs +++ b/compiler/rustc_trait_selection/src/traits/relationships.rs @@ -26,7 +26,7 @@ pub(crate) fn update<'tcx, T>( .kind() .rebind( // (*) binder moved here - ty::PredicateKind::Clause(ty::Clause::Trait(tpred.with_self_type(infcx.tcx, new_self_ty))) + ty::PredicateKind::Clause(ty::Clause::Trait(tpred.with_self_ty(infcx.tcx, new_self_ty))) ), ); // Don't report overflow errors. Otherwise equivalent to may_hold. 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 829d4f6098605..c54d901e9b10a 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -536,7 +536,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { let ty = traits::normalize_projection_type( self, param_env, - ty::AliasTy { def_id: tcx.lang_items().deref_target()?, substs: trait_ref.substs }, + tcx.mk_alias_ty(tcx.lang_items().deref_target()?, trait_ref.substs), cause.clone(), 0, // We're *intentionally* throwing these away, diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 85456853ce08c..f6fe71fbd4f88 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::Alias(_, 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 115897851d673..792933096b15c 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::Alias(_, ty::AliasTy { def_id, substs }) => (def_id, substs), + ty::Alias(_, ty::AliasTy { def_id, substs, .. }) => (def_id, substs), _ => { span_bug!( obligation.cause.span, @@ -2259,7 +2259,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { t.rebind(def.all_fields().map(|f| f.ty(self.tcx(), substs)).collect()) } - ty::Alias(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/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 74c4ae8854c34..a995eeb9a7afb 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -648,7 +648,7 @@ impl<'tcx> WfPredicates<'tcx> { // types appearing in the fn signature } - ty::Alias(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 53bafde0ea20e..bc4a52c5040d1 100644 --- a/compiler/rustc_traits/src/chalk/db.rs +++ b/compiler/rustc_traits/src/chalk/db.rs @@ -433,7 +433,7 @@ impl<'tcx> chalk_solve::RustIrDatabase> for RustIrDatabase<'t } } ( - &ty::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }), + &ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }), OpaqueType(opaque_ty_id, ..), ) => def_id == opaque_ty_id.0, (&ty::FnDef(def_id, ..), FnDef(fn_def_id, ..)) => def_id == fn_def_id.0, @@ -789,7 +789,7 @@ impl<'tcx> ty::TypeFolder<'tcx> for ReplaceOpaqueTyFolder<'tcx> { } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Alias(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 f3fd315c71ee5..9712abb708f27 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -347,13 +347,13 @@ 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, ty::AliasTy { def_id, substs }) => { + 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 }) => { + 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), @@ -443,11 +443,11 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty> { TyKind::Str => ty::Str, TyKind::OpaqueType(opaque_ty, substitution) => ty::Alias( ty::Opaque, - ty::AliasTy { def_id: opaque_ty.0, substs: substitution.lower_into(interner) }, + interner.tcx.mk_alias_ty(opaque_ty.0, 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 }, + interner.tcx.mk_alias_ty(assoc_ty.0, substitution.lower_into(interner)), ), TyKind::Foreign(def_id) => ty::Foreign(def_id.0), TyKind::Error => return interner.tcx.ty_error(), @@ -458,17 +458,17 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty> { TyKind::Alias(alias_ty) => match alias_ty { chalk_ir::AliasTy::Projection(projection) => ty::Alias( ty::Projection, - ty::AliasTy { - def_id: projection.associated_ty_id.0, - substs: projection.substitution.lower_into(interner), - }, + interner.tcx.mk_alias_ty( + projection.associated_ty_id.0, + 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), - }, + interner.tcx.mk_alias_ty( + opaque.opaque_ty_id.0, + opaque.substitution.lower_into(interner), + ), ), }, TyKind::Function(_quantified_ty) => unimplemented!(), diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 4a4dc899ba9a3..92886bbfe26b4 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1835,7 +1835,7 @@ pub(crate) fn clean_middle_ty<'tcx>( } } - ty::Alias(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/tools/clippy/clippy_lints/src/derive.rs b/src/tools/clippy/clippy_lints/src/derive.rs index 9e596ca8157eb..3f0b165f2b604 100644 --- a/src/tools/clippy/clippy_lints/src/derive.rs +++ b/src/tools/clippy/clippy_lints/src/derive.rs @@ -15,7 +15,7 @@ use rustc_middle::hir::nested_filter; use rustc_middle::traits::Reveal; use rustc_middle::ty::{ self, Binder, BoundConstness, Clause, GenericParamDefKind, ImplPolarity, ParamEnv, PredicateKind, TraitPredicate, - TraitRef, Ty, TyCtxt, + Ty, TyCtxt, }; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::source_map::Span; @@ -513,9 +513,9 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> tcx.mk_predicates(ty_predicates.iter().map(|&(p, _)| p).chain( params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| { tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate { - trait_ref: TraitRef::new( + trait_ref: tcx.mk_trait_ref( eq_trait_id, - tcx.mk_substs(std::iter::once(tcx.mk_param_from_def(param))), + [tcx.mk_param_from_def(param)], ), constness: BoundConstness::NotConst, polarity: ImplPolarity::Positive, 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 fcdac90fc237a..989f83cf80d59 100644 --- a/src/tools/clippy/clippy_lints/src/future_not_send.rs +++ b/src/tools/clippy/clippy_lints/src/future_not_send.rs @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend { return; } let ret_ty = return_ty(cx, hir_id); - if let ty::Alias(ty::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_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index 33f3b3af3dc02..a6bcb134d4080 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::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) = *inner_ty.kind() { + if let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = *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::Alias(ty::Opaque, ty::AliasTy { def_id, substs: _ }) => { + ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => { 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::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::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => 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(); @@ -1039,10 +1039,10 @@ pub fn make_projection<'tcx>( } } - Some(AliasTy { + Some(tcx.mk_alias_ty( + assoc_item.def_id, substs, - def_id: assoc_item.def_id, - }) + )) } helper( tcx,