diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 5e0b7b6d06a2..9bc1f13febc9 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -792,7 +792,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { PredicateKind::Clause(ty::Clause::Trait(predicate)) => { match predicate.self_ty().kind() { ty::Param(param_ty) => Ok(( - generics.type_param(param_ty, tcx), + generics.type_param(*param_ty, tcx), predicate.trait_ref.print_only_trait_path().to_string(), )), ty::HKT(_param_ty, ..) => { diff --git a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs index 4b86c13db798..fdf69adf3100 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/ops.rs @@ -13,7 +13,7 @@ use rustc_middle::mir; use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::subst::{GenericArgKind, SubstsRef}; use rustc_middle::ty::{ - suggest_constraining_type_param, Adt, Closure, DefIdTree, FnDef, FnPtr, Param, Ty, HKT, + suggest_constraining_type_param, Adt, Closure, DefIdTree, FnDef, FnPtr, Param, Ty, HKT, TypeParameter }; use rustc_middle::ty::{Binder, TraitRef}; use rustc_session::parse::feature_err; diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 32b59002e1f0..c9289599b855 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -21,7 +21,7 @@ use rustc_middle::middle::stability::EvalResult; use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES}; use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::util::{Discr, IntTypeExt}; -use rustc_middle::ty::{self, AdtDef, ParamEnv, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable}; +use rustc_middle::ty::{self, AdtDef, ParamEnv, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeParameter}; use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS}; use rustc_span::symbol::sym; use rustc_span::{self, Span}; diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index 04f7d31d650e..bce73772fa48 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -80,7 +80,7 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::Visitor; use rustc_index::bit_set::BitSet; use rustc_middle::ty::query::Providers; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeParameter}; use rustc_middle::ty::{InternalSubsts, SubstsRef}; use rustc_session::parse::feature_err; use rustc_span::source_map::DUMMY_SP; diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 4d202ca690a2..8433c921dad4 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -13,10 +13,7 @@ use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt}; use rustc_middle::mir::ConstraintCategory; use rustc_middle::ty::query::Providers; use rustc_middle::ty::trait_def::TraitSpecializationKind; -use rustc_middle::ty::{ - self, AdtKind, DefIdTree, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, - TypeVisitable, TypeVisitor, -}; +use rustc_middle::ty::{self, AdtKind, DefIdTree, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeParameter, TypeSuperVisitable, TypeVisitable, TypeVisitor}; use rustc_middle::ty::{GenericArgKind, InternalSubsts}; use rustc_session::parse::feature_err; use rustc_span::symbol::{sym, Ident, Symbol}; @@ -592,7 +589,7 @@ fn gather_gat_bounds<'tcx, T: TypeFoldable<'tcx>>( // `Self` in the GAT. let ty_param = gat_generics.param_at(*ty_idx, tcx); let ty_param = tcx - .mk_ty(ty::Param(ty::ParamTy::Param { index: ty_param.index, name: ty_param.name })); + .mk_ty(ty::Param(ty::ParamTy::new(ty_param.index, ty_param.name))); // Same for the region. In our example, 'a corresponds // to the 'me parameter. let region_param = gat_generics.param_at(*region_a_idx, tcx); diff --git a/compiler/rustc_hir_analysis/src/collect/lifetimes.rs b/compiler/rustc_hir_analysis/src/collect/lifetimes.rs index bf322cab47d2..d4745503706a 100644 --- a/compiler/rustc_hir_analysis/src/collect/lifetimes.rs +++ b/compiler/rustc_hir_analysis/src/collect/lifetimes.rs @@ -17,7 +17,7 @@ use rustc_hir::{GenericArg, GenericParam, GenericParamKind, HirIdMap, LifetimeNa use rustc_middle::bug; use rustc_middle::hir::nested_filter; use rustc_middle::middle::resolve_lifetime::*; -use rustc_middle::ty::{self, DefIdTree, TyCtxt, TypeSuperVisitable, TypeVisitor}; +use rustc_middle::ty::{self, DefIdTree, TyCtxt, TypeSuperVisitable, TypeVisitor, TypeParameter}; use rustc_span::def_id::DefId; use rustc_span::symbol::{sym, Ident}; use rustc_span::Span; diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index c29889dc73a7..c20a173663e4 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -9,7 +9,7 @@ use rustc_hir::def::DefKind; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::{self, Visitor}; use rustc_middle::ty::subst::InternalSubsts; -use rustc_middle::ty::{ArgumentDef, GenericParamDefKind, ParamEnv, ToPredicate}; +use rustc_middle::ty::{ArgumentDef, GenericParamDefKind, ParamEnv, ToPredicate, TypeParameter}; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_span::symbol::{sym, Ident}; use rustc_span::{Span, DUMMY_SP}; @@ -208,7 +208,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP GenericParamKind::Lifetime { .. } => (), GenericParamKind::Type { .. } => { let name = param.name.ident().name; - let param_ty = ty::ParamTy::new_param(index, name).to_ty(tcx); + let param_ty = ty::ParamTy::new(index, name).to_ty(tcx); index += 1; let mut bounds = Bounds::default(); @@ -230,8 +230,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP } GenericParamKind::HKT(..) => { let name = param.name.ident().name; - let param_ty = ty::ParamTy::new_hkt(param.def_id.to_def_id(), index, name).to_ty(tcx); - + let param_ty = ty::HKTTy::new(param.def_id.to_def_id(), index, name).to_ty(tcx); let mut bounds = Bounds::default(); // Params are implicitly sized unless a `?Sized` bound is found diff --git a/compiler/rustc_hir_analysis/src/constrained_generic_params.rs b/compiler/rustc_hir_analysis/src/constrained_generic_params.rs index f6a9f88e1b49..a071a4d2dd46 100644 --- a/compiler/rustc_hir_analysis/src/constrained_generic_params.rs +++ b/compiler/rustc_hir_analysis/src/constrained_generic_params.rs @@ -1,6 +1,6 @@ use rustc_data_structures::fx::FxHashSet; use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor}; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeParameter}; use rustc_span::source_map::Span; use std::ops::ControlFlow; diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check.rs b/compiler/rustc_hir_analysis/src/impl_wf_check.rs index 1891d7f9d77e..c30d151965c2 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check.rs @@ -16,7 +16,7 @@ use rustc_errors::struct_span_err; use rustc_hir::def::DefKind; use rustc_hir::def_id::LocalDefId; use rustc_middle::ty::query::Providers; -use rustc_middle::ty::{self, TyCtxt, TypeVisitable}; +use rustc_middle::ty::{self, TyCtxt, TypeParameter, TypeVisitable}; use rustc_span::{Span, Symbol}; mod min_specialization; diff --git a/compiler/rustc_hir_analysis/src/outlives/utils.rs b/compiler/rustc_hir_analysis/src/outlives/utils.rs index d8ae4efeea93..0668e9106993 100644 --- a/compiler/rustc_hir_analysis/src/outlives/utils.rs +++ b/compiler/rustc_hir_analysis/src/outlives/utils.rs @@ -1,6 +1,6 @@ use rustc_infer::infer::outlives::components::{push_outlives_components, Component}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind}; -use rustc_middle::ty::{self, Region, Ty, TyCtxt}; +use rustc_middle::ty::{self, Region, Ty, TyCtxt, TypeParameter}; use rustc_span::Span; use smallvec::smallvec; use std::collections::BTreeMap; diff --git a/compiler/rustc_hir_analysis/src/variance/constraints.rs b/compiler/rustc_hir_analysis/src/variance/constraints.rs index 15a868a69169..0e79b7c203b9 100644 --- a/compiler/rustc_hir_analysis/src/variance/constraints.rs +++ b/compiler/rustc_hir_analysis/src/variance/constraints.rs @@ -7,7 +7,7 @@ use hir::def_id::{DefId, LocalDefId}; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_middle::ty::subst::{GenericArgKind, SubstsRef}; -use rustc_middle::ty::{self, Ty, TyCtxt}; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeParameter}; use super::terms::VarianceTerm::*; use super::terms::*; diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index ef7afef16fee..5d4aea3afab4 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -2628,7 +2628,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn point_at_param_definition(&self, err: &mut Diagnostic, param: ty::ParamTy) { let generics = self.tcx.generics_of(self.body_id.owner.to_def_id()); - let generic_param = generics.type_param(¶m, self.tcx); + let generic_param = generics.type_param(param, self.tcx); if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param.kind { return; } diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 9f5057de4adb..cc5960564706 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -26,7 +26,7 @@ use rustc_infer::infer::InferOk; use rustc_infer::infer::TypeTrace; use rustc_middle::ty::adjustment::AllowTwoPhase; use rustc_middle::ty::visit::TypeVisitable; -use rustc_middle::ty::{self, DefIdTree, IsSuggestable, Ty, TypeSuperVisitable, TypeVisitor}; +use rustc_middle::ty::{self, DefIdTree, IsSuggestable, Ty, TypeParameter, TypeParamResult, TypeSuperVisitable, TypeVisitor}; use rustc_session::Session; use rustc_span::symbol::{kw, Ident}; use rustc_span::{self, sym, Span}; @@ -1790,18 +1790,18 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { _ => ty::List::empty(), }; - let find_param_matching = |matches: &dyn Fn(&ty::ParamTy) -> bool| { + let find_param_matching = |matches: &dyn Fn(&TypeParamResult) -> bool| { predicate_substs.types().find_map(|ty| { ty.walk().find_map(|arg| { // TODO(hoch) if let ty::GenericArgKind::Type(ty) = arg.unpack() && let ty::Param(param_ty) = ty.kind() - && matches(param_ty) + && matches(&TypeParamResult::Param(*param_ty)) { Some(arg) } else if let ty::GenericArgKind::Type(ty) = arg.unpack() && let ty::HKT(_, param_ty, ..) = ty.kind() - && matches(param_ty) + && matches(&TypeParamResult::HKT(*param_ty)) { todo!("hoch") } else { @@ -1815,13 +1815,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Prefer generics that are local to the fn item, since these are likely // to be the cause of the unsatisfied predicate. let mut param_to_point_at = find_param_matching(&|param_ty| { - self.tcx.parent(generics.type_param(param_ty, self.tcx).def_id) == def_id + match param_ty { + TypeParamResult::Param(p) => self.tcx.parent(generics.type_param(*p, self.tcx).def_id) == def_id, + TypeParamResult::HKT(h) => self.tcx.parent(generics.type_param(*h, self.tcx).def_id) == def_id + } + }); // Fall back to generic that isn't local to the fn item. This will come // from a trait or impl, for example. let mut fallback_param_to_point_at = find_param_matching(&|param_ty| { - self.tcx.parent(generics.type_param(param_ty, self.tcx).def_id) != def_id - && param_ty.name() != rustc_span::symbol::kw::SelfUpper + match param_ty { + TypeParamResult::Param(p) => self.tcx.parent(generics.type_param(*p, self.tcx).def_id) != def_id + && p.name() != rustc_span::symbol::kw::SelfUpper, + TypeParamResult::HKT(h) => self.tcx.parent(generics.type_param(*h, self.tcx).def_id) != def_id + && h.name() != rustc_span::symbol::kw::SelfUpper + } + }); // Finally, the `Self` parameter is possibly the reason that the predicate // is unsatisfied. This is less likely to be true for methods, because @@ -2155,7 +2164,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } ty::Param(ref param) => { let param = - self.tcx.generics_of(self.body_id.owner).type_param(param, self.tcx); + self.tcx.generics_of(self.body_id.owner).type_param(*param, self.tcx); if param.kind.is_synthetic() { // if it's `impl Fn() -> ..` then just fall down to the def-id based logic def_id = param.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 ab845d9752c5..175c04a3fd19 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -16,7 +16,7 @@ use rustc_infer::traits::{self, StatementAsExpression}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::{ self, suggest_constraining_type_params, Binder, DefIdTree, IsSuggestable, ToPredicate, Ty, - TypeVisitable, + TypeVisitable, TypeParameter }; use rustc_session::errors::ExprParenthesesNeeded; use rustc_span::source_map::Spanned; @@ -214,7 +214,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }) } ty::Param(ref param) => { - let def_id = self.tcx.generics_of(self.body_id.owner).type_param(param, self.tcx).def_id; + let def_id = self.tcx.generics_of(self.body_id.owner).type_param(*param, 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.def_id) == self.tcx.lang_items().fn_once_output() diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index e44ef9a786d8..284f6f4f1c88 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -16,7 +16,7 @@ use rustc_infer::infer::{self, InferOk, TyCtxtInferExt}; use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; use rustc_middle::middle::stability; use rustc_middle::ty::fast_reject::{simplify_type, TreatParams}; -use rustc_middle::ty::AssocItem; +use rustc_middle::ty::{AssocItem, TypeParamResult}; use rustc_middle::ty::GenericParamDefKind; use rustc_middle::ty::ToPredicate; use rustc_middle::ty::{self, ParamEnvAnd, Ty, TyCtxt, TypeFoldable, TypeVisitable}; @@ -680,10 +680,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { } } ty::Param(ref p) => { - self.assemble_inherent_candidates_from_param(p.clone()); + self.assemble_inherent_candidates_from_param(TypeParamResult::Param(p.clone())); } ty::HKT(_, ref p, ..) => { - self.assemble_inherent_candidates_from_param(p.clone()); + self.assemble_inherent_candidates_from_param(TypeParamResult::HKT(p.clone())); } ty::Bool | ty::Char @@ -812,19 +812,26 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> { }); } - fn assemble_inherent_candidates_from_param(&mut self, param_ty: ty::ParamTy) { + fn assemble_inherent_candidates_from_param(&mut self, param_ty: TypeParamResult) { // FIXME: do we want to commit to this behavior for param bounds? - debug!("assemble_inherent_candidates_from_param(param_ty={:?})", param_ty); + match param_ty { + TypeParamResult::Param(p) => { + debug!("assemble_inherent_candidates_from_param(param_ty={:?})", p); + } + TypeParamResult::HKT(h) => { + debug!("assemble_inherent_candidates_from_param(param_ty={:?})", h); + } + } let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| { let bound_predicate = predicate.kind(); match bound_predicate.skip_binder() { ty::PredicateKind::Clause(ty::Clause::Trait(trait_predicate)) => { match *trait_predicate.trait_ref.self_ty().kind() { - ty::Param(ref p) if p.clone() == param_ty => { + ty::Param(ref p) if let TypeParamResult::Param(param) = param_ty && p.clone() == param => { Some(bound_predicate.rebind(trait_predicate.trait_ref)) } - ty::HKT(_, ref p, ..) if p.clone() == param_ty => { + ty::HKT(_, ref p, ..) if let TypeParamResult::HKT(param) = param_ty && p.clone() == param => { // TODO(hoch) Some(bound_predicate.rebind(trait_predicate.trait_ref)) } diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index 6453bfc81e61..5d6f2203458e 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -26,7 +26,7 @@ use rustc_middle::traits::util::supertraits; use rustc_middle::ty::fast_reject::DeepRejectCtxt; use rustc_middle::ty::fast_reject::{simplify_type, TreatParams}; use rustc_middle::ty::print::{with_crate_prefix, with_forced_trimmed_paths}; -use rustc_middle::ty::{self, DefIdTree, GenericArgKind, Ty, TyCtxt, TypeVisitable}; +use rustc_middle::ty::{self, DefIdTree, GenericArgKind, Ty, TyCtxt, TypeVisitable, TypeParameter, TypeParamResult}; use rustc_middle::ty::{IsSuggestable, ToPolyTraitRef}; use rustc_span::symbol::{kw, sym, Ident}; use rustc_span::Symbol; @@ -2377,11 +2377,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { candidates.dedup(); let param_type = match rcvr_ty.kind() { - ty::Param(param) => Some(param), - ty::HKT(_, param, ..) => Some(param), + ty::Param(param) => Some(TypeParamResult::Param(*param)), + ty::HKT(_, param, ..) => Some(TypeParamResult::HKT(*param)), ty::Ref(_, ty, _) => match ty.kind() { - ty::Param(param) => Some(param), - ty::HKT(_, param, ..) => Some(param), + ty::Param(param) => Some(TypeParamResult::Param(*param)), + ty::HKT(_, param, ..) => Some(TypeParamResult::HKT(*param)), _ => None, }, _ => None, @@ -2404,87 +2404,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) }; // Obtain the span for `param` and use it for a structured suggestion. - if let Some(param) = param_type { - let generics = self.tcx.generics_of(self.body_id.owner.to_def_id()); - let type_param = generics.type_param(param, self.tcx); - let hir = self.tcx.hir(); - if let Some(def_id) = type_param.def_id.as_local() { - let id = hir.local_def_id_to_hir_id(def_id); - // Get the `hir::Param` to verify whether it already has any bounds. - // We do this to avoid suggesting code that ends up as `T: FooBar`, - // instead we suggest `T: Foo + Bar` in that case. - match hir.get(id) { - Node::GenericParam(param) => { - enum Introducer { - Plus, - Colon, - Nothing, - } - let ast_generics = hir.get_generics(id.owner.def_id).unwrap(); - let (sp, mut introducer) = if let Some(span) = - ast_generics.bounds_span_for_suggestions(def_id) - { - (span, Introducer::Plus) - } else if let Some(colon_span) = param.colon_span { - (colon_span.shrink_to_hi(), Introducer::Nothing) - } else { - (param.span.shrink_to_hi(), Introducer::Colon) - }; - if matches!( - param.kind, - hir::GenericParamKind::Type { synthetic: true, .. }, - ) { - introducer = Introducer::Plus - } - let trait_def_ids: FxHashSet = ast_generics - .bounds_for_param(def_id) - .flat_map(|bp| bp.bounds.iter()) - .filter_map(|bound| bound.trait_ref()?.trait_def_id()) - .collect(); - if !candidates.iter().any(|t| trait_def_ids.contains(&t.def_id)) { - err.span_suggestions( - sp, - &message(format!( - "restrict type parameter `{}` with", - param.name.ident(), - )), - candidates.iter().map(|t| { - format!( - "{} {}", - match introducer { - Introducer::Plus => " +", - Introducer::Colon => ":", - Introducer::Nothing => "", - }, - self.tcx.def_path_str(t.def_id), - ) - }), - Applicability::MaybeIncorrect, - ); - } - return; - } - Node::Item(hir::Item { - kind: hir::ItemKind::Trait(.., bounds, _), - ident, - .. - }) => { - let (sp, sep, article) = if bounds.is_empty() { - (ident.span.shrink_to_hi(), ":", "a") - } else { - (bounds.last().unwrap().span().shrink_to_hi(), " +", "another") - }; - err.span_suggestions( - sp, - &message(format!("add {} supertrait for", article)), - candidates.iter().map(|t| { - format!("{} {}", sep, self.tcx.def_path_str(t.def_id),) - }), - Applicability::MaybeIncorrect, - ); - return; - } - _ => {} + if let Some(param) = ¶m_type { + + match param { + TypeParamResult::Param(param_ty) => { + self.use_param_span_for_structured_suggestion(err, &mut candidates, &message, param_ty) + } + TypeParamResult::HKT(hkt_ty) => { + self.use_param_span_for_structured_suggestion(err, &mut candidates, &message, hkt_ty) } } } @@ -2524,8 +2451,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { (candidates, Vec::new()) }; - let action = if let Some(param) = param_type { - format!("restrict type parameter `{}` with", param) + let action = if let Some(param) = ¶m_type { + match param { + TypeParamResult::Param(param_ty) => { + format!("restrict type parameter `{}` with", *param_ty) + } + TypeParamResult::HKT(hkt_ty) => { + format!("restrict type parameter `{}` with", *hkt_ty) + } + } } else { // FIXME: it might only need to be imported into scope, not implemented. "implement".to_string() @@ -2579,6 +2513,97 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } + fn use_param_span_for_structured_suggestion( + &self, + err: &mut Diagnostic, + candidates: &mut Vec, + message: &impl Fn(String) -> String, + param: &impl TypeParameter<'tcx> + ) { + let generics = self.tcx.generics_of(self.body_id.owner.to_def_id()); + let type_param = generics.type_param(*param, self.tcx); + let hir = self.tcx.hir(); + if let Some(def_id) = type_param.def_id.as_local() { + let id = hir.local_def_id_to_hir_id(def_id); + // Get the `hir::Param` to verify whether it already has any bounds. + // We do this to avoid suggesting code that ends up as `T: FooBar`, + // instead we suggest `T: Foo + Bar` in that case. + match hir.get(id) { + Node::GenericParam(param) => { + enum Introducer { + Plus, + Colon, + Nothing, + } + let ast_generics = hir.get_generics(id.owner.def_id).unwrap(); + let (sp, mut introducer) = if let Some(span) = + ast_generics.bounds_span_for_suggestions(def_id) + { + (span, Introducer::Plus) + } else if let Some(colon_span) = param.colon_span { + (colon_span.shrink_to_hi(), Introducer::Nothing) + } else { + (param.span.shrink_to_hi(), Introducer::Colon) + }; + if matches!( + param.kind, + hir::GenericParamKind::Type { synthetic: true, .. }, + ) { + introducer = Introducer::Plus + } + let trait_def_ids: FxHashSet = ast_generics + .bounds_for_param(def_id) + .flat_map(|bp| bp.bounds.iter()) + .filter_map(|bound| bound.trait_ref()?.trait_def_id()) + .collect(); + if !candidates.iter().any(|t| trait_def_ids.contains(&t.def_id)) { + err.span_suggestions( + sp, + &message(format!( + "restrict type parameter `{}` with", + param.name.ident(), + )), + candidates.iter().map(|t| { + format!( + "{} {}", + match introducer { + Introducer::Plus => " +", + Introducer::Colon => ":", + Introducer::Nothing => "", + }, + self.tcx.def_path_str(t.def_id), + ) + }), + Applicability::MaybeIncorrect, + ); + } + return; + } + Node::Item(hir::Item { + kind: hir::ItemKind::Trait(.., bounds, _), + ident, + .. + }) => { + let (sp, sep, article) = if bounds.is_empty() { + (ident.span.shrink_to_hi(), ":", "a") + } else { + (bounds.last().unwrap().span().shrink_to_hi(), " +", "another") + }; + err.span_suggestions( + sp, + &message(format!("add {} supertrait for", article)), + candidates.iter().map(|t| { + format!("{} {}", sep, self.tcx.def_path_str(t.def_id), ) + }), + Applicability::MaybeIncorrect, + ); + return; + } + _ => {} + } + } + } + /// issue #102320, for `unwrap_or` with closure as argument, suggest `unwrap_or_else` /// FIXME: currently not working for suggesting `map_or_else`, see #102408 pub(crate) fn suggest_else_fn_with_closure( diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 23fb82427488..a431e9b24928 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -68,10 +68,7 @@ use rustc_hir::lang_items::LangItem; use rustc_hir::Node; use rustc_middle::dep_graph::DepContext; use rustc_middle::ty::relate::{self, RelateResult, TypeRelation}; -use rustc_middle::ty::{ - self, error::TypeError, List, Region, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, - TypeVisitable, -}; +use rustc_middle::ty::{self, error::TypeError, List, Region, Ty, TyCtxt, TypeFoldable, TypeParameter, TypeSuperVisitable, TypeVisitable}; use rustc_span::{sym, symbol::kw, BytePos, DesugaringKind, Pos, Span}; use rustc_target::spec::abi; use std::ops::{ControlFlow, Deref}; @@ -2134,7 +2131,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { // Account for the case where `param` corresponds to `Self`, // which doesn't have the expected type argument. if !(generics.has_self && param.index() == 0) { - let type_param = generics.type_param(param, self.tcx); + let type_param = generics.type_param(*param, self.tcx); type_param.def_id.as_local().map(|def_id| { // Get the `hir::Param` to verify whether it already has any bounds. // We do this to avoid suggesting code that ends up as `T: 'a'b`, @@ -2155,7 +2152,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { } else { None } - } + }, + GenericKind::HKT(_param) => todo!("hoch"), _ => None, }; diff --git a/compiler/rustc_infer/src/infer/outlives/components.rs b/compiler/rustc_infer/src/infer/outlives/components.rs index 446c8ce3967f..8c8574fecfa7 100644 --- a/compiler/rustc_infer/src/infer/outlives/components.rs +++ b/compiler/rustc_infer/src/infer/outlives/components.rs @@ -12,8 +12,7 @@ use smallvec::{smallvec, SmallVec}; pub enum Component<'tcx> { Region(ty::Region<'tcx>), Param(ty::ParamTy), - // TODO muki change to HKTTy - HKT(ty::ParamTy), + HKT(ty::HKTTy), UnresolvedInferenceVariable(ty::InferTy), // Projections like `T::Foo` are tricky because a constraint like diff --git a/compiler/rustc_infer/src/infer/outlives/obligations.rs b/compiler/rustc_infer/src/infer/outlives/obligations.rs index ea2d17cb8738..873b93adda6c 100644 --- a/compiler/rustc_infer/src/infer/outlives/obligations.rs +++ b/compiler/rustc_infer/src/infer/outlives/obligations.rs @@ -330,7 +330,7 @@ where &mut self, origin: infer::SubregionOrigin<'tcx>, region: ty::Region<'tcx>, - hkt_ty: ty::ParamTy, + hkt_ty: ty::HKTTy, ) { debug!( "hkt_ty_must_outlive(region={:?}, hkt_ty={:?}, origin={:?})", @@ -338,7 +338,7 @@ where ); let generic = GenericKind::HKT(hkt_ty.clone()); - let verify_bound = self.verify_bound.hkt_bound(hkt_ty); + let verify_bound = self.verify_bound.param_bound(hkt_ty); self.delegate.push_verify(origin, generic, region, verify_bound); } diff --git a/compiler/rustc_infer/src/infer/outlives/verify.rs b/compiler/rustc_infer/src/infer/outlives/verify.rs index 0283cf70b318..795e036cc9d6 100644 --- a/compiler/rustc_infer/src/infer/outlives/verify.rs +++ b/compiler/rustc_infer/src/infer/outlives/verify.rs @@ -4,7 +4,7 @@ use crate::infer::region_constraints::VerifyIfEq; use crate::infer::{GenericKind, VerifyBound}; use rustc_data_structures::sso::SsoHashSet; use rustc_hir::def_id::DefId; -use rustc_middle::ty::{GenericArg}; +use rustc_middle::ty::{GenericArg, TypeParameter}; use rustc_middle::ty::{self, OutlivesPredicate, SubstsRef, Ty, TyCtxt}; use smallvec::smallvec; @@ -38,7 +38,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { } #[instrument(level = "debug", skip(self))] - pub fn param_bound(&self, param_ty: ty::ParamTy) -> VerifyBound<'tcx> { + pub fn param_bound(&self, param_ty: impl TypeParameter<'tcx>) -> VerifyBound<'tcx> { // Start with anything like `T: 'a` we can scrape from the // environment. If the environment contains something like // `for<'a> T: 'a`, then we know that `T` outlives everything. @@ -79,49 +79,6 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { } } - #[instrument(level = "debug", skip(self))] - pub fn hkt_bound(&self, hkt_ty: ty::ParamTy) -> VerifyBound<'tcx> { - // TODO muki ParamTy change - // Start with anything like `T: 'a` we can scrape from the - // environment. If the environment contains something like - // `for<'a> T: 'a`, then we know that `T` outlives everything. - let declared_bounds_from_env = self.declared_generic_bounds_from_env(hkt_ty.clone()); - debug!(?declared_bounds_from_env); - let mut hkt_bounds = vec![]; - for declared_bound in declared_bounds_from_env { - let bound_region = declared_bound.map_bound(|outlives| outlives.1); - if let Some(region) = bound_region.no_bound_vars() { - // This is `T: 'a` for some free region `'a`. - hkt_bounds.push(VerifyBound::OutlivedBy(region)); - } else { - // This is `for<'a> T: 'a`. This means that `T` outlives everything! All done here. - debug!("found that {hkt_ty:?} outlives any lifetime, returning empty vector"); - return VerifyBound::AllBounds(vec![]); - } - } - - // Add in the default bound of fn body that applies to all in - // scope type parameters: - if let Some(r) = self.implicit_region_bound { - debug!("adding implicit region bound of {r:?}"); - hkt_bounds.push(VerifyBound::OutlivedBy(r)); - } - - if hkt_bounds.is_empty() { - // We know that all types `T` outlive `'empty`, so if we - // can find no other bound, then check that the region - // being tested is `'empty`. - VerifyBound::IsEmpty - } else if hkt_bounds.len() == 1 { - // Micro-opt: no need to store the vector if it's just len 1 - hkt_bounds.pop().unwrap() - } else { - // If we can find any other bound `R` such that `T: R`, then - // we don't need to check for `'empty`, because `R: 'empty`. - VerifyBound::AnyBound(hkt_bounds) - } - } - /// Given a projection like `T::Item`, searches the environment /// for where-clauses like `T::Item: 'a`. Returns the set of /// regions `'a` that it finds. @@ -253,7 +210,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> { /// bounds, but all the bounds it returns can be relied upon. fn declared_generic_bounds_from_env( &self, - param_ty: ty::ParamTy, + param_ty: impl TypeParameter<'tcx>, ) -> Vec, ty::Region<'tcx>>>> { // FIXMIG: muki make copy with HKTTy let generic_ty = param_ty.to_ty(self.tcx); diff --git a/compiler/rustc_infer/src/infer/region_constraints/mod.rs b/compiler/rustc_infer/src/infer/region_constraints/mod.rs index f4c058f08c23..8bac5c056812 100644 --- a/compiler/rustc_infer/src/infer/region_constraints/mod.rs +++ b/compiler/rustc_infer/src/infer/region_constraints/mod.rs @@ -16,7 +16,7 @@ use rustc_hir::def_id::DefId; use rustc_index::vec::IndexVec; use rustc_middle::infer::unify_key::{RegionVidKey, UnifiedRegion}; use rustc_middle::ty::subst::SubstsRef; -use rustc_middle::ty::ReStatic; +use rustc_middle::ty::{ReStatic, TypeParameter}; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{ReLateBound, ReVar}; use rustc_middle::ty::{Region, RegionVid}; @@ -169,8 +169,7 @@ pub struct Verify<'tcx> { #[derive(Clone, PartialEq, Eq, Hash, TypeFoldable, TypeVisitable)] pub enum GenericKind<'tcx> { Param(ty::ParamTy), - // TODO muki replace ParamTy - HKT(ty::ParamTy), + HKT(ty::HKTTy), Projection(ty::AliasTy<'tcx>), Opaque(DefId, SubstsRef<'tcx>), } diff --git a/compiler/rustc_infer/src/traits/util.rs b/compiler/rustc_infer/src/traits/util.rs index da7be1b7a359..6a6053336b1c 100644 --- a/compiler/rustc_infer/src/traits/util.rs +++ b/compiler/rustc_infer/src/traits/util.rs @@ -3,7 +3,7 @@ use smallvec::smallvec; use crate::infer::outlives::components::{push_outlives_components, Component}; use crate::traits::{Obligation, ObligationCause, PredicateObligation}; use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; -use rustc_middle::ty::{self, ToPredicate, TyCtxt}; +use rustc_middle::ty::{self, ToPredicate, TyCtxt, TypeParameter}; use rustc_span::symbol::Ident; use rustc_span::Span; diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 03190156498d..7e3596ae7bd5 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -75,7 +75,7 @@ use std::iter; use std::mem; use std::ops::{Bound, Deref}; use std::sync::Arc; -use rustc_middle::ty::Generics; +use rustc_middle::ty::{HKTTy, Generics}; pub trait OnDiskCache<'tcx>: rustc_data_structures::sync::Sync { /// Creates a new `OnDiskCache` instance from the serialized data in `data`. @@ -110,6 +110,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { type ListTy = &'tcx List>; type AliasTy = ty::AliasTy<'tcx>; type ParamTy = ParamTy; + type HKTTy = HKTTy; type BoundTy = ty::BoundTy; type PlaceholderType = ty::PlaceholderType; type InferTy = InferTy; @@ -305,8 +306,8 @@ impl<'tcx> CommonTypes<'tcx> { f32: mk(Float(ty::FloatTy::F32)), f64: mk(Float(ty::FloatTy::F64)), str_: mk(Str), - self_param: mk(ty::Param(ty::ParamTy::Param { index: 0, name: kw::SelfUpper })), - + self_param: mk(ty::Param(ty::ParamTy::new(0,kw::SelfUpper ))), + //TODO: hoch, make one for HKT? trait_object_dummy_self: mk(Infer(ty::FreshTy(0))), } } @@ -2001,12 +2002,12 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_ty_param(self, index: u32, name: Symbol) -> Ty<'tcx> { - self.mk_ty(Param(ParamTy::Param { index, name })) + self.mk_ty(Param(ParamTy::new(index, name))) } #[inline] pub fn mk_hkt_param(self, def_id: DefId, index: u32, name: Symbol, subst: SubstsRef<'tcx>) -> Ty<'tcx> { - self.mk_ty(HKT(def_id, ParamTy::HKT { def_id, index, name }, subst)) + self.mk_ty(HKT(def_id, HKTTy::new(def_id, index, name), subst)) } pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> { diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 450be263125d..ec3b788da1a7 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -14,6 +14,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::WherePredicate; use rustc_span::Span; use rustc_type_ir::sty::TyKind::*; +use rustc_middle::ty::TypeParameter; impl<'tcx> IntoDiagnosticArg for Ty<'tcx> { fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> { @@ -481,7 +482,7 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> { // sufficient info to determine if it is synthetic, and we don't // always have a convenient way of getting `ty::Generics` at the call // sites we invoke `IsSuggestable::is_suggestable`. - if param.name().as_str().starts_with("impl ") { + if (*param).name().as_str().starts_with("impl ") { return ControlFlow::Break(()); } } diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 7e91b12e54ed..e54d1721dac2 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -428,11 +428,11 @@ impl<'tcx> TyCtxt<'tcx> { } (ty::Param(expected), ty::Param(found)) => { let generics = self.generics_of(body_owner_def_id); - let e_span = self.def_span(generics.type_param(expected, self).def_id); + let e_span = self.def_span(generics.type_param(*expected, self).def_id); if !sp.contains(e_span) { diag.span_label(e_span, "expected type parameter"); } - let f_span = self.def_span(generics.type_param(found, self).def_id); + let f_span = self.def_span(generics.type_param(*found, self).def_id); if !sp.contains(f_span) { diag.span_label(f_span, "found type parameter"); } @@ -454,14 +454,14 @@ impl<'tcx> TyCtxt<'tcx> { 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); + let p_span = self.def_span(generics.type_param(*p, self).def_id); if !sp.contains(p_span) { diag.span_label(p_span, "this type parameter"); } let hir = self.hir(); let mut note = true; if let Some(generics) = generics - .type_param(p, self) + .type_param(*p, self) .def_id .as_local() .map(|id| hir.local_def_id_to_hir_id(id)) @@ -504,7 +504,7 @@ impl<'tcx> TyCtxt<'tcx> { (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); + let p_span = self.def_span(generics.type_param(*p, self).def_id); if !sp.contains(p_span) { diag.span_label(p_span, "this type parameter"); } @@ -544,7 +544,7 @@ impl Trait for X { } (ty::Param(p), ty::Closure(..) | ty::Generator(..)) => { let generics = self.generics_of(body_owner_def_id); - let p_span = self.def_span(generics.type_param(p, self).def_id); + let p_span = self.def_span(generics.type_param(*p, self).def_id); if !sp.contains(p_span) { diag.span_label(p_span, "this type parameter"); } @@ -559,7 +559,7 @@ impl Trait for X { } (ty::Param(p), _) | (_, 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); + let p_span = self.def_span(generics.type_param(*p, self).def_id); if !sp.contains(p_span) { diag.span_label(p_span, "this type parameter"); } @@ -646,7 +646,7 @@ impl Trait for X { // This will also work for `impl Trait`. let def_id = if let ty::Param(param_ty) = proj_ty.self_ty().kind() { let generics = self.generics_of(body_owner_def_id); - generics.type_param(param_ty, self).def_id + generics.type_param(*param_ty, self).def_id } else if let ty::HKT(..) = proj_ty.self_ty().kind() { //let generics = self.generics_of(body_owner_def_id); //generics.type_param(param_ty, self).def_id diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index 2312e986aca3..49f813ef5d4a 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -3,10 +3,11 @@ use crate::ty::{EarlyBinder, SubstsRef}; use rustc_ast as ast; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::DefId; +use rustc_middle::ty::sty::TypeParameter; use rustc_span::symbol::{kw, Symbol}; use rustc_span::Span; -use super::{EarlyBoundRegion, InstantiatedPredicates, ParamConst, ParamTy, Predicate, TyCtxt}; +use super::{EarlyBoundRegion, InstantiatedPredicates, ParamConst, Predicate, TyCtxt}; #[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)] pub enum GenericParamDefKind { @@ -268,7 +269,7 @@ impl<'tcx> Generics { } /// Returns the `GenericParamDef` associated with this `ParamTy`. - pub fn type_param(&'tcx self, param: &ParamTy, tcx: TyCtxt<'tcx>) -> &'tcx GenericParamDef { + pub fn type_param(&'tcx self, param: impl TypeParameter<'tcx>, tcx: TyCtxt<'tcx>) -> &'tcx GenericParamDef { let param = self.param_at(param.index() as usize, tcx); match param.kind { GenericParamDefKind::Type { .. } => param, diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 7bb2764d2b2e..8bf77b9f852f 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -96,7 +96,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, ParamConst, TypeParameter, TypeParamResult, ParamTy, HKTTy, PolyExistentialPredicate, PolyExistentialProjection, PolyExistentialTraitRef, PolyFnSig, PolyGenSig, PolyTraitRef, Region, RegionKind, RegionVid, TraitRef, TyKind, TypeAndMut, UpvarSubsts, VarianceDiagInfo, }; diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index a160d3324537..827d0a35bc1b 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -28,6 +28,8 @@ use std::fmt::{self, Write as _}; use std::iter; use std::ops::{ControlFlow, Deref, DerefMut}; +use rustc_middle::ty::TypeParameter; + // `pretty` is a separate module only for organization. use super::*; @@ -2724,6 +2726,10 @@ define_print_and_forward_display! { p!(write("{}", self.name())) } + ty::HKTTy { + p!(write("{}", self.name())) + } + ty::ArgumentDef { p!(write("{}", self.name)) } diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 5f6e5a498df2..173587535bda 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -11,6 +11,7 @@ use rustc_hir as ast; use rustc_hir::def_id::DefId; use rustc_span::DUMMY_SP; use rustc_target::spec::abi; +use rustc_middle::ty::TypeParameter; use std::iter; pub type RelateResult<'tcx, T> = Result>; diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 5205357f7279..77ec770adcad 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -7,7 +7,7 @@ use crate::mir::{Field, ProjectionKind}; use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable}; use crate::ty::print::{with_no_trimmed_paths, FmtPrinter, Printer}; use crate::ty::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor}; -use crate::ty::{self, InferConst, Lift, ParamTy, Term, TermKind, Ty, TyCtxt}; +use crate::ty::{self, InferConst, Lift, Term, TermKind, Ty, TyCtxt}; use rustc_data_structures::functor::IdFunctor; use rustc_hir::def::Namespace; use rustc_index::vec::{Idx, IndexVec}; @@ -17,6 +17,7 @@ use std::mem::ManuallyDrop; use std::ops::ControlFlow; use std::rc::Rc; use std::sync::Arc; +use rustc_middle::ty::{HKTTy, ParamTy, TypeParameter}; impl fmt::Debug for ty::TraitDef { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -112,16 +113,23 @@ impl<'tcx> fmt::Debug for Ty<'tcx> { } } -impl fmt::Debug for ty::ParamTy { +impl fmt::Debug for ParamTy { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - ParamTy::Param { .. } => { - write!(f, "{}/#{}", self.name(), self.index()) - } - ParamTy::HKT { .. } => { - write!(f, "{}/{}", self.name(), self.index()) - } - } + f.debug_struct("ParamTy") + .field("name", &self.name()) + .field("index", &self.index()) + .finish() + //TODO: hoch, is this implemented correctly in the correct place? + } +} + +impl fmt::Debug for HKTTy { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("HKTTy") + .field("name", &self.name()) + .field("index", &self.index()) + .finish() + //TODO: hoch, is this implemented correctly in the correct place? } } @@ -248,6 +256,7 @@ TrivialTypeTraversalAndLiftImpls! { crate::ty::IntVarValue, crate::ty::ParamConst, crate::ty::ParamTy, + crate::ty::HKTTy, crate::ty::ArgumentDef, crate::ty::adjustment::PointerCast, crate::ty::RegionVid, diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 1867fbc8f409..66c022035112 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -24,6 +24,8 @@ use rustc_target::spec::abi; use std::borrow::Cow; use std::cmp::Ordering; use std::fmt; +use std::fmt::{Debug}; +use std::hash::Hash; use std::marker::PhantomData; use std::ops::{ControlFlow, Deref, Range}; use ty::util::IntTypeExt; @@ -1309,103 +1311,144 @@ impl PartialEq for ArgumentDef { } } -#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] -#[derive(HashStable)] -pub enum ParamTy { - Param { - index: u32, - name: Symbol, - }, - HKT { - def_id: DefId, - index: u32, - name: Symbol, +pub trait TypeParameter<'tcx>: Clone + Copy + PartialEq + Eq + PartialOrd + Ord + Hash + Debug { + fn for_def(def: &ty::GenericParamDef) -> Self; + fn to_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx>; + fn index(&self) -> u32; + fn name(&self) -> Symbol; + fn def_id(&self) -> DefId; + fn span_from_generics(&self, tcx: TyCtxt<'tcx>, item_with_generics: DefId) -> Span { + let generics = tcx.generics_of(item_with_generics); + let type_param = generics.type_param(*self, tcx); + tcx.def_span(type_param.def_id) } } -impl<'tcx> ParamTy { - pub fn new_param(index: u32, name: Symbol) -> ParamTy { - ParamTy::Param { index, name } +pub enum TypeParamResult { + Param(ParamTy), + HKT(HKTTy) +} + +impl TypeParamResult { + pub fn name(&self) -> Symbol { + match self { + TypeParamResult::Param(p) => p.name, + TypeParamResult::HKT(h) => h.name + } } - pub fn new_hkt(def_id: DefId, index: u32, name: Symbol) -> ParamTy { - ParamTy::HKT { def_id, index, name } + pub fn index(&self) -> u32 { + match self { + TypeParamResult::Param(p) => p.index, + TypeParamResult::HKT(h) => h.index + } } +} - pub fn for_def(def: &ty::GenericParamDef) -> ParamTy { +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] +#[derive(HashStable)] +pub struct ParamTy { + index: u32, + name: Symbol, +} + +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)] +#[derive(HashStable)] +pub struct HKTTy { + def_id: DefId, + index: u32, + name: Symbol, +} + +impl ParamTy { + pub fn new(index: u32, name: Symbol) -> ParamTy { + Self { index, name } + } +} + +impl HKTTy { + pub fn new(def_id: DefId, index: u32, name: Symbol) -> HKTTy { + Self {def_id, index, name } + } +} + + +impl<'tcx> TypeParameter<'tcx> for ParamTy { + + fn for_def(def: &ty::GenericParamDef) -> ParamTy { match def.kind { GenericParamDefKind::Lifetime | GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => { - ParamTy::new_param(def.index, def.name) + ParamTy::new(def.index, def.name) } GenericParamDefKind::HKT => { - ParamTy::new_hkt(def.def_id, def.index, def.name) + bug!("Cannot convert Lifetime, Type, or Const to a HKT"); } } } #[inline] - pub fn to_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { - match self { - ParamTy::Param { index, name } => tcx.mk_ty_param(*index, *name), - ParamTy::HKT { def_id, index, name } => { - let generics: &ty::Generics = tcx.generics_of(def_id); - - let generics = generics.params.iter().map(|param| { - tcx.mk_ty(ty::Argument(ArgumentDef { - def_id: *def_id, - index: param.index, - name: param.name, - })).into() - }).collect::>(); - - tcx.mk_hkt_param(*def_id, *index, *name, tcx.intern_substs(&generics)).into() - }, - } + fn to_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { + tcx.mk_ty_param(self.index, self.name) } #[inline] - pub fn index(&self) -> u32 { - match *self { - ParamTy::Param { index, .. } => { - index - } - ParamTy::HKT { index, .. } => { - index - } - } + fn index(&self) -> u32 { + self.index } #[inline] - pub fn def_id(&self) -> DefId { - match *self { - ParamTy::Param { .. } => { - todo!("What to do here") - } - ParamTy::HKT { def_id, .. } => { - def_id - } - } + fn name(&self) -> Symbol { + self.name } #[inline] - pub fn name(&self) -> Symbol { - match *self { - ParamTy::Param { name, .. } => { - name + fn def_id(&self) -> DefId { todo!("What to do here") } +} + +impl<'tcx> TypeParameter<'tcx> for HKTTy { + + fn for_def(def: &ty::GenericParamDef) -> HKTTy { + match def.kind { + GenericParamDefKind::Lifetime | + GenericParamDefKind::Type { .. } | + GenericParamDefKind::Const { .. } => { + bug!("Cannot convert HKT to Lifetime, Type, or Const"); } - ParamTy::HKT { name, .. } => { - name + GenericParamDefKind::HKT => { + HKTTy::new(def.def_id, def.index, def.name) } } } - pub fn span_from_generics(&self, tcx: TyCtxt<'tcx>, item_with_generics: DefId) -> Span { - let generics = tcx.generics_of(item_with_generics); - let type_param = generics.type_param(self, tcx); - tcx.def_span(type_param.def_id) + #[inline] + fn to_ty(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { + let generics: &ty::Generics = tcx.generics_of(self.def_id); + + let generics = generics.params.iter().map(|param| { + tcx.mk_ty(ty::Argument(ArgumentDef { + def_id: self.def_id, + index: param.index, + name: param.name, + })).into() + }).collect::>(); + + tcx.mk_hkt_param(self.def_id, self.index, self.name, tcx.intern_substs(&generics)).into() } + + #[inline] + fn index(&self) -> u32 { + self.index + } + + #[inline] + fn name(&self) -> Symbol { + self.name + } + + #[inline] + fn def_id(&self) -> DefId { self.def_id } } #[derive(Copy, Clone, Hash, TyEncodable, TyDecodable, Eq, PartialEq, Ord, PartialOrd)] diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index a705bff204d1..8571b5a622a0 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -21,6 +21,7 @@ use std::mem; use std::num::NonZeroUsize; use std::ops::{ControlFlow, Deref}; use std::slice; +use rustc_middle::ty::TypeParameter; use rustc_span::Symbol; /// An entity in the Rust type system, which can be one of @@ -810,7 +811,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> { } impl<'a, 'tcx> SubstFolder<'a, 'tcx> { - fn ty_for_param(&self, p: ty::ParamTy, source_ty: Ty<'tcx>) -> Ty<'tcx> { + fn ty_for_param(&self, p: impl TypeParameter<'tcx>, source_ty: Ty<'tcx>) -> Ty<'tcx> { // Look up the type in the substitutions. It really should be in there. let opt_ty = self.substs.get(p.index() as usize).map(|k| k.unpack()); //println!("Replace: {:?} with {:?}", source_ty.kind(), opt_ty); @@ -824,7 +825,7 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> { self.shift_vars_through_binders(ty) } - fn hkt_for_param(&self, p: ty::ParamTy, substs: SubstsRef<'tcx>, source_ty: Ty<'tcx>) -> Ty<'tcx> { + fn hkt_for_param(&self, p: impl TypeParameter<'tcx>, substs: SubstsRef<'tcx>, source_ty: Ty<'tcx>) -> Ty<'tcx> { // Look up the type in the substitutions. It really should be in there. let opt_ty = self.substs.get(p.index() as usize).map(|k| k.unpack()); @@ -898,7 +899,7 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> { #[cold] #[inline(never)] - fn type_param_expected(&self, p: ty::ParamTy, ty: Ty<'tcx>, kind: GenericArgKind<'tcx>) -> ! { + fn type_param_expected(&self, p: impl TypeParameter<'tcx>, ty: Ty<'tcx>, kind: GenericArgKind<'tcx>) -> ! { bug!( "expected type for `{:?}` ({:?}/{}) but found {:?} when substituting, substs={:?}", p, @@ -911,7 +912,7 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> { #[cold] #[inline(never)] - fn type_param_out_of_range(&self, p: ty::ParamTy, ty: Ty<'tcx>) -> ! { + fn type_param_out_of_range(&self, p: impl TypeParameter<'tcx>, ty: Ty<'tcx>) -> ! { bug!( "type parameter `{:?}` ({:?}/{}) out of range when substituting, substs={:?}", p, diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 062ad8892db4..9eb01ad64f09 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -22,6 +22,7 @@ use rustc_macros::HashStable; use rustc_span::{sym, DUMMY_SP}; use rustc_target::abi::{Integer, IntegerType, Size, TargetDataLayout}; use rustc_target::spec::abi::Abi; +use rustc_middle::ty::TypeParameter; use smallvec::SmallVec; use std::{fmt, iter}; @@ -437,8 +438,8 @@ impl<'tcx> TyCtxt<'tcx> { _ => false, }, GenericArgKind::Type(ty) => match ty.kind() { - ty::Param(ref pt) => !impl_generics.type_param(pt, self).pure_wrt_drop, - ty::HKT(_, ref pt, ..) => !impl_generics.type_param(pt, self).pure_wrt_drop, + ty::Param(ref pt) => !impl_generics.type_param(*pt, self).pure_wrt_drop, + ty::HKT(_, ref pt, ..) => !impl_generics.type_param(*pt, self).pure_wrt_drop, // Error: not a type param _ => false, }, @@ -478,12 +479,12 @@ impl<'tcx> TyCtxt<'tcx> { } GenericArgKind::Type(t) => match t.kind() { ty::Param(p) => { - if !seen.insert(p.index()) { + if !seen.insert((*p).index()) { return Err(NotUniqueParam::DuplicateParam(t.into())); } } ty::HKT(_, p, ..) => { - if !seen.insert(p.index()) { + if !seen.insert((*p).index()) { return Err(NotUniqueParam::DuplicateParam(t.into())); } } diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index 701028844821..d3cd53264c94 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -17,7 +17,7 @@ use rustc_middle::ty::{ query::Providers, subst::SubstsRef, visit::{TypeSuperVisitable, TypeVisitable, TypeVisitor}, - Const, Ty, TyCtxt, + Const, Ty, TyCtxt, TypeParameter }; use rustc_span::symbol::sym; use std::ops::ControlFlow; 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 69f7737bcd71..0925c1ae1fe8 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -38,7 +38,7 @@ use rustc_middle::ty::fold::{TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::print::{with_forced_trimmed_paths, FmtPrinter, Print}; use rustc_middle::ty::{ self, SubtypePredicate, ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt, TypeFoldable, - TypeVisitable, + TypeVisitable, TypeParameter }; use rustc_session::config::TraitSolver; use rustc_session::Limit; @@ -2585,20 +2585,20 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { } fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Param(ty::ParamTy::Param { name, .. }) = *ty.kind() { + if let ty::Param(p) = *ty.kind() { let infcx = self.infcx; *self.var_map.entry(ty).or_insert_with(|| { infcx.next_ty_var(TypeVariableOrigin { - kind: TypeVariableOriginKind::TypeParameterDefinition(name, None), + kind: TypeVariableOriginKind::TypeParameterDefinition(p.name(), None), span: DUMMY_SP, }) }) - } else if let ty::HKT(_, ty::ParamTy::HKT { name, .. }, ..) = *ty.kind() { + } else if let ty::HKT(_, p, ..) = *ty.kind() { // TODO(hoch) let infcx = self.infcx; *self.var_map.entry(ty).or_insert_with(|| { infcx.next_ty_var(TypeVariableOrigin { - kind: TypeVariableOriginKind::TypeParameterDefinition(name, None), + kind: TypeVariableOriginKind::TypeParameterDefinition(p.name(), None), span: DUMMY_SP, }) }) 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 fe066eae518f..21ed1f2d7075 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -29,7 +29,7 @@ use rustc_infer::infer::{InferOk, LateBoundRegionConversionTime}; use rustc_middle::hir::map; use rustc_middle::ty::error::TypeError::{self, Sorts}; use rustc_middle::ty::relate::TypeRelation; -use rustc_middle::ty::{self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, DefIdTree, GeneratorDiagnosticData, GeneratorInteriorTypeCause, Infer, InferTy, InternalSubsts, IsSuggestable, ToPredicate, Ty, TyCtxt, TypeAndMut, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitable, TypeckResults, GenericParamDefKind}; +use rustc_middle::ty::{self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, DefIdTree, GeneratorDiagnosticData, GeneratorInteriorTypeCause, Infer, InferTy, InternalSubsts, IsSuggestable, ToPredicate, Ty, TyCtxt, TypeAndMut, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitable, TypeckResults, GenericParamDefKind, TypeParameter}; use rustc_span::symbol::{sym, Ident, Symbol}; use rustc_span::{BytePos, DesugaringKind, ExpnKind, Span, DUMMY_SP}; use rustc_target::spec::abi; @@ -405,14 +405,15 @@ fn suggest_restriction<'tcx>( fn_sig.zip(projection).and_then(|(sig, p)| match p.self_ty().kind() { // Shenanigans to get the `Trait` from the `impl Trait`. ty::Param(param) => { - let param_def = generics.type_param(param, tcx); + let param_def = generics.type_param(*param, tcx); if param_def.kind.is_synthetic() { let bound_str = param_def.name.as_str().strip_prefix("impl ")?.trim_start().to_string(); return Some((param_def, bound_str, sig)); } None - } + }, + ty::HKT(_param, ..) => todo!("hoch"), _ => None, }) { @@ -420,7 +421,7 @@ fn suggest_restriction<'tcx>( let trait_pred = trait_pred.fold_with(&mut ReplaceImplTraitFolder { tcx, param, - replace_ty: ty::ParamTy::new_param(generics.count() as u32, Symbol::intern(&type_param_name)) + replace_ty: ty::ParamTy::new(generics.count() as u32, Symbol::intern(&type_param_name)) .to_ty(tcx), }); // TODO: new_param or new_hkt @@ -3766,8 +3767,8 @@ struct ReplaceImplTraitFolder<'tcx> { impl<'tcx> TypeFolder<'tcx> for ReplaceImplTraitFolder<'tcx> { fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Param(ty::ParamTy::Param { index, .. }) = t.kind() { - if self.param.index == *index { + if let ty::Param(p) = t.kind() { + if self.param.index == (*p).index() { return self.replace_ty; } } diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index ddae3919ad8c..c560206f2133 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -495,13 +495,13 @@ fn is_impossible_method(tcx: TyCtxt<'_>, (impl_def_id, trait_item_def_id): (DefI fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { // If this is a parameter from the trait item's own generics, then bail if let ty::Param(param) = t.kind() - && let param_def_id = self.generics.type_param(param, self.tcx).def_id + && let param_def_id = self.generics.type_param(*param, self.tcx).def_id && self.tcx.parent(param_def_id) == self.trait_item_def_id { return ControlFlow::BREAK; } if let ty::HKT(_, param, ..) = t.kind() - && let param_def_id = self.generics.type_param(param, self.tcx).def_id + && let param_def_id = self.generics.type_param(*param, self.tcx).def_id && self.tcx.parent(param_def_id) == self.trait_item_def_id { return ControlFlow::BREAK; diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 7dc45ea3e28b..c98ad69b7c8e 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -13,7 +13,7 @@ use rustc_infer::infer::InferOk; use rustc_infer::infer::LateBoundRegionConversionTime::HigherRankedType; use rustc_middle::ty::{ self, Binder, GenericArg, GenericArgKind, GenericParamDefKind, InternalSubsts, SubstsRef, - ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt, + ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt, TypeParameter }; use rustc_session::config::TraitSolver; use rustc_span::def_id::DefId; @@ -1069,7 +1069,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { (&ty::Adt(def, substs_a), &ty::Adt(_, substs_b)) => { let maybe_unsizing_param_idx = |arg: GenericArg<'tcx>| match arg.unpack() { GenericArgKind::Type(ty) => match ty.kind() { - ty::Param(p) => Some(p.index()), + ty::Param(p) => Some((*p).index()), ty::HKT(..) => todo!("hoch"), _ => None, }, diff --git a/compiler/rustc_ty_utils/src/representability.rs b/compiler/rustc_ty_utils/src/representability.rs index 97ebc5302cc8..829b6d20d9aa 100644 --- a/compiler/rustc_ty_utils/src/representability.rs +++ b/compiler/rustc_ty_utils/src/representability.rs @@ -3,7 +3,7 @@ use rustc_hir::def::DefKind; use rustc_index::bit_set::BitSet; use rustc_middle::ty::query::Providers; -use rustc_middle::ty::{self, Representability, Ty, TyCtxt}; +use rustc_middle::ty::{self, Representability, Ty, TyCtxt, TypeParameter}; use rustc_span::def_id::{DefId, LocalDefId}; pub fn provide(providers: &mut Providers) { diff --git a/compiler/rustc_type_ir/src/lib.rs b/compiler/rustc_type_ir/src/lib.rs index 954469484bcc..8fcc6c04c4da 100644 --- a/compiler/rustc_type_ir/src/lib.rs +++ b/compiler/rustc_type_ir/src/lib.rs @@ -45,6 +45,7 @@ pub trait Interner { type ListTy: 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 HKTTy: 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 0f31e1c18b1a..f733019e0dac 100644 --- a/compiler/rustc_type_ir/src/sty.rs +++ b/compiler/rustc_type_ir/src/sty.rs @@ -178,7 +178,7 @@ pub enum TyKind { /// expected to be provided. /// Furthermore it contains a substsref, which contains the corresponding /// values that are substituted with the parameter names. - HKT(I::DefId, I::ParamTy, I::SubstsRef), + HKT(I::DefId, I::HKTTy, I::SubstsRef), /// Bound type variable, used to represent the `'a` in `for<'a> fn(&'a ())`. /// @@ -519,6 +519,7 @@ where I::ListTy: Encodable, I::AliasTy: Encodable, I::ParamTy: Encodable, + I::HKTTy: Encodable, I::BoundTy: Encodable, I::PlaceholderType: Encodable, I::InferTy: Encodable, @@ -642,6 +643,7 @@ where I::ListTy: Decodable, I::AliasTy: Decodable, I::ParamTy: Decodable, + I::HKTTy: Decodable, I::AliasTy: Decodable, I::BoundTy: Decodable, I::PlaceholderType: Decodable, @@ -711,6 +713,7 @@ where I::AliasTy: HashStable, I::BoundTy: HashStable, I::ParamTy: HashStable, + I::HKTTy: HashStable, I::PlaceholderType: HashStable, I::InferTy: HashStable, I::ErrorGuaranteed: HashStable,