mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
Deduplicate fresh_item_substs
This commit is contained in:
parent
6eb6455c46
commit
569ca2bad0
@ -2239,7 +2239,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
let ocx = ObligationCtxt::new_in_snapshot(&infcx);
|
||||
|
||||
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 = ocx.normalize(&cause, param_env, impl_ty);
|
||||
|
||||
@ -2306,36 +2306,6 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
))
|
||||
}
|
||||
|
||||
// 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(
|
||||
&self,
|
||||
name: Ident,
|
||||
@ -3531,3 +3501,36 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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_data_structures::fx::FxHashSet;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir_analysis::astconv::InferCtxtExt as _;
|
||||
use rustc_hir_analysis::autoderef::{self, Autoderef};
|
||||
use rustc_infer::infer::canonical::OriginalQueryValues;
|
||||
use rustc_infer::infer::canonical::{Canonical, QueryResponse};
|
||||
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
|
||||
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;
|
||||
@ -1941,33 +1940,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
(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
|
||||
/// `ty::erase_late_bound_regions`.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user