Add bound_const_param_default

This commit is contained in:
Jack Huey 2022-07-07 20:56:22 -04:00
parent f16584357d
commit 9935796645
5 changed files with 15 additions and 10 deletions

View File

@ -85,10 +85,10 @@ impl GenericParamDef {
) -> Option<EarlyBinder<ty::GenericArg<'tcx>>> {
match self.kind {
GenericParamDefKind::Type { has_default, .. } if has_default => {
Some(EarlyBinder(tcx.type_of(self.def_id).into()))
Some(tcx.bound_type_of(self.def_id).map_bound(|t| t.into()))
}
GenericParamDefKind::Const { has_default } if has_default => {
Some(EarlyBinder(tcx.const_param_default(self.def_id).into()))
Some(tcx.bound_const_param_default(self.def_id).map_bound(|c| c.into()))
}
_ => None,
}

View File

@ -676,6 +676,10 @@ impl<'tcx> TyCtxt<'tcx> {
) -> ty::EarlyBinder<&'tcx ty::List<ty::Predicate<'tcx>>> {
ty::EarlyBinder(self.item_bounds(def_id))
}
pub fn bound_const_param_default(self, def_id: DefId) -> ty::EarlyBinder<ty::Const<'tcx>> {
ty::EarlyBinder(self.const_param_default(def_id))
}
}
struct OpaqueTypeExpander<'tcx> {

View File

@ -550,7 +550,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
GenericParamDefKind::Const { has_default } => {
let ty = tcx.at(self.span).type_of(param.def_id);
if !infer_args && has_default {
EarlyBinder(tcx.const_param_default(param.def_id))
tcx.bound_const_param_default(param.def_id)
.subst(tcx, substs.unwrap())
.into()
} else {

View File

@ -1426,7 +1426,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
GenericParamDefKind::Const { has_default } => {
if !infer_args && has_default {
EarlyBinder(tcx.const_param_default(param.def_id))
tcx.bound_const_param_default(param.def_id)
.subst(tcx, substs.unwrap())
.into()
} else {

View File

@ -21,9 +21,7 @@ use rustc_middle::middle::stability;
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
use rustc_middle::ty::GenericParamDefKind;
use rustc_middle::ty::{
self, EarlyBinder, ParamEnvAnd, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeVisitable,
};
use rustc_middle::ty::{self, ParamEnvAnd, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeVisitable};
use rustc_session::lint;
use rustc_span::def_id::LocalDefId;
use rustc_span::lev_distance::{
@ -713,7 +711,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
let (impl_ty, impl_substs) = self.impl_ty_and_substs(impl_def_id);
let impl_ty = EarlyBinder(impl_ty).subst(self.tcx, impl_substs);
let impl_ty = impl_ty.subst(self.tcx, impl_substs);
debug!("impl_ty: {:?}", impl_ty);
@ -1812,8 +1810,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
}
/// Gets the type of an impl and generate substitutions with placeholders.
fn impl_ty_and_substs(&self, impl_def_id: DefId) -> (Ty<'tcx>, SubstsRef<'tcx>) {
(self.tcx.type_of(impl_def_id), self.fresh_item_substs(impl_def_id))
fn impl_ty_and_substs(
&self,
impl_def_id: DefId,
) -> (ty::EarlyBinder<Ty<'tcx>>, SubstsRef<'tcx>) {
(self.tcx.bound_type_of(impl_def_id), self.fresh_item_substs(impl_def_id))
}
fn fresh_item_substs(&self, def_id: DefId) -> SubstsRef<'tcx> {