Deduplicate fresh_item_substs
This commit is contained in:
parent
6eb6455c46
commit
569ca2bad0
@ -2239,7 +2239,7 @@ fn lookup_inherent_assoc_ty(
|
|||||||
let ocx = ObligationCtxt::new_in_snapshot(&infcx);
|
let ocx = ObligationCtxt::new_in_snapshot(&infcx);
|
||||||
|
|
||||||
let impl_ty = tcx.type_of(impl_);
|
let impl_ty = tcx.type_of(impl_);
|
||||||
let impl_substs = self.fresh_item_substs(impl_, &infcx);
|
let impl_substs = infcx.fresh_item_substs(impl_);
|
||||||
let impl_ty = impl_ty.subst(tcx, impl_substs);
|
let impl_ty = impl_ty.subst(tcx, impl_substs);
|
||||||
let impl_ty = ocx.normalize(&cause, param_env, impl_ty);
|
let impl_ty = ocx.normalize(&cause, param_env, impl_ty);
|
||||||
|
|
||||||
@ -2306,36 +2306,6 @@ fn lookup_inherent_assoc_ty(
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME(fmease): Copied from `rustc_hir_typeck::method::probe`. Deduplicate.
|
|
||||||
fn fresh_item_substs(&self, def_id: DefId, infcx: &InferCtxt<'tcx>) -> SubstsRef<'tcx> {
|
|
||||||
let tcx = self.tcx();
|
|
||||||
|
|
||||||
InternalSubsts::for_item(tcx, def_id, |param, _| match param.kind {
|
|
||||||
GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(),
|
|
||||||
GenericParamDefKind::Type { .. } => infcx
|
|
||||||
.next_ty_var(TypeVariableOrigin {
|
|
||||||
kind: TypeVariableOriginKind::SubstitutionPlaceholder,
|
|
||||||
span: tcx.def_span(def_id),
|
|
||||||
})
|
|
||||||
.into(),
|
|
||||||
GenericParamDefKind::Const { .. } => {
|
|
||||||
let span = tcx.def_span(def_id);
|
|
||||||
let origin = ConstVariableOrigin {
|
|
||||||
kind: ConstVariableOriginKind::SubstitutionPlaceholder,
|
|
||||||
span,
|
|
||||||
};
|
|
||||||
infcx
|
|
||||||
.next_const_var(
|
|
||||||
tcx.type_of(param.def_id)
|
|
||||||
.no_bound_vars()
|
|
||||||
.expect("const parameter types cannot be generic"),
|
|
||||||
origin,
|
|
||||||
)
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn lookup_assoc_ty(
|
fn lookup_assoc_ty(
|
||||||
&self,
|
&self,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
@ -3531,3 +3501,36 @@ fn maybe_lint_bare_trait(&self, self_ty: &hir::Ty<'_>, in_path: bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub trait InferCtxtExt<'tcx> {
|
||||||
|
fn fresh_item_substs(&self, def_id: DefId) -> SubstsRef<'tcx>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
||||||
|
fn fresh_item_substs(&self, def_id: DefId) -> SubstsRef<'tcx> {
|
||||||
|
InternalSubsts::for_item(self.tcx, def_id, |param, _| match param.kind {
|
||||||
|
GenericParamDefKind::Lifetime => self.tcx.lifetimes.re_erased.into(),
|
||||||
|
GenericParamDefKind::Type { .. } => self
|
||||||
|
.next_ty_var(TypeVariableOrigin {
|
||||||
|
kind: TypeVariableOriginKind::SubstitutionPlaceholder,
|
||||||
|
span: self.tcx.def_span(def_id),
|
||||||
|
})
|
||||||
|
.into(),
|
||||||
|
GenericParamDefKind::Const { .. } => {
|
||||||
|
let span = self.tcx.def_span(def_id);
|
||||||
|
let origin = ConstVariableOrigin {
|
||||||
|
kind: ConstVariableOriginKind::SubstitutionPlaceholder,
|
||||||
|
span,
|
||||||
|
};
|
||||||
|
self.next_const_var(
|
||||||
|
self.tcx
|
||||||
|
.type_of(param.def_id)
|
||||||
|
.no_bound_vars()
|
||||||
|
.expect("const parameter types cannot be generic"),
|
||||||
|
origin,
|
||||||
|
)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -9,12 +9,11 @@
|
|||||||
use rustc_errors::Applicability;
|
use rustc_errors::Applicability;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def::DefKind;
|
use rustc_hir::def::DefKind;
|
||||||
|
use rustc_hir_analysis::astconv::InferCtxtExt as _;
|
||||||
use rustc_hir_analysis::autoderef::{self, Autoderef};
|
use rustc_hir_analysis::autoderef::{self, Autoderef};
|
||||||
use rustc_infer::infer::canonical::OriginalQueryValues;
|
use rustc_infer::infer::canonical::OriginalQueryValues;
|
||||||
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
|
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
|
||||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
|
||||||
use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
|
use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
|
||||||
use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind};
|
|
||||||
use rustc_middle::middle::stability;
|
use rustc_middle::middle::stability;
|
||||||
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
|
use rustc_middle::ty::fast_reject::{simplify_type, TreatParams};
|
||||||
use rustc_middle::ty::AssocItem;
|
use rustc_middle::ty::AssocItem;
|
||||||
@ -1941,33 +1940,6 @@ fn impl_ty_and_substs(
|
|||||||
(self.tcx.type_of(impl_def_id), self.fresh_item_substs(impl_def_id))
|
(self.tcx.type_of(impl_def_id), self.fresh_item_substs(impl_def_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fresh_item_substs(&self, def_id: DefId) -> SubstsRef<'tcx> {
|
|
||||||
InternalSubsts::for_item(self.tcx, def_id, |param, _| match param.kind {
|
|
||||||
GenericParamDefKind::Lifetime => self.tcx.lifetimes.re_erased.into(),
|
|
||||||
GenericParamDefKind::Type { .. } => self
|
|
||||||
.next_ty_var(TypeVariableOrigin {
|
|
||||||
kind: TypeVariableOriginKind::SubstitutionPlaceholder,
|
|
||||||
span: self.tcx.def_span(def_id),
|
|
||||||
})
|
|
||||||
.into(),
|
|
||||||
GenericParamDefKind::Const { .. } => {
|
|
||||||
let span = self.tcx.def_span(def_id);
|
|
||||||
let origin = ConstVariableOrigin {
|
|
||||||
kind: ConstVariableOriginKind::SubstitutionPlaceholder,
|
|
||||||
span,
|
|
||||||
};
|
|
||||||
self.next_const_var(
|
|
||||||
self.tcx
|
|
||||||
.type_of(param.def_id)
|
|
||||||
.no_bound_vars()
|
|
||||||
.expect("const parameter types cannot be generic"),
|
|
||||||
origin,
|
|
||||||
)
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Replaces late-bound-regions bound by `value` with `'static` using
|
/// Replaces late-bound-regions bound by `value` with `'static` using
|
||||||
/// `ty::erase_late_bound_regions`.
|
/// `ty::erase_late_bound_regions`.
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user