mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 16:54:01 +00:00
Rollup merge of #111410 - kylematsuda:earlybinder-abstract-const, r=BoxyUwU
Switch to `EarlyBinder` for `thir_abstract_const` query Part of the work to finish https://github.com/rust-lang/rust/issues/105779. This PR adds `EarlyBinder` to the return type of the `thir_abstract_const` query and removes `bound_abstract_const`. r? `@compiler-errors`
This commit is contained in:
commit
70d5bf7fae
@ -1530,7 +1530,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
// variables
|
||||
let tcx = self.tcx;
|
||||
if substs.has_non_region_infer() {
|
||||
if let Some(ct) = tcx.bound_abstract_const(unevaluated.def)? {
|
||||
if let Some(ct) = tcx.thir_abstract_const(unevaluated.def)? {
|
||||
let ct = tcx.expand_abstract_consts(ct.subst(tcx, substs));
|
||||
if let Err(e) = ct.error_reported() {
|
||||
return Err(ErrorHandled::Reported(e));
|
||||
|
@ -394,7 +394,7 @@ define_tables! {
|
||||
mir_for_ctfe: Table<DefIndex, LazyValue<mir::Body<'static>>>,
|
||||
mir_generator_witnesses: Table<DefIndex, LazyValue<mir::GeneratorLayout<'static>>>,
|
||||
promoted_mir: Table<DefIndex, LazyValue<IndexVec<mir::Promoted, mir::Body<'static>>>>,
|
||||
thir_abstract_const: Table<DefIndex, LazyValue<ty::Const<'static>>>,
|
||||
thir_abstract_const: Table<DefIndex, LazyValue<ty::EarlyBinder<ty::Const<'static>>>>,
|
||||
impl_parent: Table<DefIndex, RawDefId>,
|
||||
impl_polarity: Table<DefIndex, ty::ImplPolarity>,
|
||||
constness: Table<DefIndex, hir::Constness>,
|
||||
|
@ -82,9 +82,10 @@ impl EraseType for Result<Option<ty::Instance<'_>>, rustc_errors::ErrorGuarantee
|
||||
[u8; size_of::<Result<Option<ty::Instance<'static>>, rustc_errors::ErrorGuaranteed>>()];
|
||||
}
|
||||
|
||||
impl EraseType for Result<Option<ty::Const<'_>>, rustc_errors::ErrorGuaranteed> {
|
||||
type Result =
|
||||
[u8; size_of::<Result<Option<ty::Const<'static>>, rustc_errors::ErrorGuaranteed>>()];
|
||||
impl EraseType for Result<Option<ty::EarlyBinder<ty::Const<'_>>>, rustc_errors::ErrorGuaranteed> {
|
||||
type Result = [u8; size_of::<
|
||||
Result<Option<ty::EarlyBinder<ty::Const<'static>>>, rustc_errors::ErrorGuaranteed>,
|
||||
>()];
|
||||
}
|
||||
|
||||
impl EraseType for Result<ty::GenericArg<'_>, traits::query::NoSolution> {
|
||||
|
@ -402,7 +402,7 @@ rustc_queries! {
|
||||
/// Try to build an abstract representation of the given constant.
|
||||
query thir_abstract_const(
|
||||
key: DefId
|
||||
) -> Result<Option<ty::Const<'tcx>>, ErrorGuaranteed> {
|
||||
) -> Result<Option<ty::EarlyBinder<ty::Const<'tcx>>>, ErrorGuaranteed> {
|
||||
desc {
|
||||
|tcx| "building an abstract representation for `{}`", tcx.def_path_str(key),
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ use crate::ty::{
|
||||
TypeVisitableExt,
|
||||
};
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir::def_id::DefId;
|
||||
|
||||
#[derive(Hash, Debug, Clone, Copy, Ord, PartialOrd, PartialEq, Eq)]
|
||||
#[derive(TyDecodable, TyEncodable, HashStable, TypeVisitable, TypeFoldable)]
|
||||
@ -35,12 +34,6 @@ TrivialTypeTraversalAndLiftImpls! {
|
||||
pub type BoundAbstractConst<'tcx> = Result<Option<EarlyBinder<ty::Const<'tcx>>>, ErrorGuaranteed>;
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
/// Returns a const without substs applied
|
||||
pub fn bound_abstract_const(self, uv: DefId) -> BoundAbstractConst<'tcx> {
|
||||
let ac = self.thir_abstract_const(uv);
|
||||
Ok(ac?.map(|ac| EarlyBinder(ac)))
|
||||
}
|
||||
|
||||
pub fn expand_abstract_consts<T: TypeFoldable<TyCtxt<'tcx>>>(self, ac: T) -> T {
|
||||
struct Expander<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
@ -59,7 +52,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
}
|
||||
fn fold_const(&mut self, c: Const<'tcx>) -> Const<'tcx> {
|
||||
let ct = match c.kind() {
|
||||
ty::ConstKind::Unevaluated(uv) => match self.tcx.bound_abstract_const(uv.def) {
|
||||
ty::ConstKind::Unevaluated(uv) => match self.tcx.thir_abstract_const(uv.def) {
|
||||
Err(e) => self.tcx.const_error_with_guaranteed(c.ty(), e),
|
||||
Ok(Some(bac)) => {
|
||||
let substs = self.tcx.erase_regions(uv.substs);
|
||||
|
@ -394,7 +394,7 @@ impl<'a, 'tcx> visit::Visitor<'a, 'tcx> for IsThirPolymorphic<'a, 'tcx> {
|
||||
pub fn thir_abstract_const(
|
||||
tcx: TyCtxt<'_>,
|
||||
def: LocalDefId,
|
||||
) -> Result<Option<ty::Const<'_>>, ErrorGuaranteed> {
|
||||
) -> Result<Option<ty::EarlyBinder<ty::Const<'_>>>, ErrorGuaranteed> {
|
||||
if !tcx.features().generic_const_exprs {
|
||||
return Ok(None);
|
||||
}
|
||||
@ -420,7 +420,7 @@ pub fn thir_abstract_const(
|
||||
|
||||
let root_span = body.exprs[body_id].span;
|
||||
|
||||
Some(recurse_build(tcx, body, body_id, root_span)).transpose()
|
||||
Ok(Some(ty::EarlyBinder(recurse_build(tcx, body, body_id, root_span)?)))
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut ty::query::Providers) {
|
||||
|
Loading…
Reference in New Issue
Block a user