Skip to content

Commit 70d5bf7

Browse files
authored
Rollup merge of #111410 - kylematsuda:earlybinder-abstract-const, r=BoxyUwU
Switch to `EarlyBinder` for `thir_abstract_const` query Part of the work to finish #105779. This PR adds `EarlyBinder` to the return type of the `thir_abstract_const` query and removes `bound_abstract_const`. r? `@compiler-errors`
2 parents f60a174 + 26dc139 commit 70d5bf7

File tree

6 files changed

+10
-16
lines changed

6 files changed

+10
-16
lines changed

compiler/rustc_infer/src/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ impl<'tcx> InferCtxt<'tcx> {
15301530
// variables
15311531
let tcx = self.tcx;
15321532
if substs.has_non_region_infer() {
1533-
if let Some(ct) = tcx.bound_abstract_const(unevaluated.def)? {
1533+
if let Some(ct) = tcx.thir_abstract_const(unevaluated.def)? {
15341534
let ct = tcx.expand_abstract_consts(ct.subst(tcx, substs));
15351535
if let Err(e) = ct.error_reported() {
15361536
return Err(ErrorHandled::Reported(e));

compiler/rustc_metadata/src/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ define_tables! {
394394
mir_for_ctfe: Table<DefIndex, LazyValue<mir::Body<'static>>>,
395395
mir_generator_witnesses: Table<DefIndex, LazyValue<mir::GeneratorLayout<'static>>>,
396396
promoted_mir: Table<DefIndex, LazyValue<IndexVec<mir::Promoted, mir::Body<'static>>>>,
397-
thir_abstract_const: Table<DefIndex, LazyValue<ty::Const<'static>>>,
397+
thir_abstract_const: Table<DefIndex, LazyValue<ty::EarlyBinder<ty::Const<'static>>>>,
398398
impl_parent: Table<DefIndex, RawDefId>,
399399
impl_polarity: Table<DefIndex, ty::ImplPolarity>,
400400
constness: Table<DefIndex, hir::Constness>,

compiler/rustc_middle/src/query/erase.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ impl EraseType for Result<Option<ty::Instance<'_>>, rustc_errors::ErrorGuarantee
8282
[u8; size_of::<Result<Option<ty::Instance<'static>>, rustc_errors::ErrorGuaranteed>>()];
8383
}
8484

85-
impl EraseType for Result<Option<ty::Const<'_>>, rustc_errors::ErrorGuaranteed> {
86-
type Result =
87-
[u8; size_of::<Result<Option<ty::Const<'static>>, rustc_errors::ErrorGuaranteed>>()];
85+
impl EraseType for Result<Option<ty::EarlyBinder<ty::Const<'_>>>, rustc_errors::ErrorGuaranteed> {
86+
type Result = [u8; size_of::<
87+
Result<Option<ty::EarlyBinder<ty::Const<'static>>>, rustc_errors::ErrorGuaranteed>,
88+
>()];
8889
}
8990

9091
impl EraseType for Result<ty::GenericArg<'_>, traits::query::NoSolution> {

compiler/rustc_middle/src/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ rustc_queries! {
402402
/// Try to build an abstract representation of the given constant.
403403
query thir_abstract_const(
404404
key: DefId
405-
) -> Result<Option<ty::Const<'tcx>>, ErrorGuaranteed> {
405+
) -> Result<Option<ty::EarlyBinder<ty::Const<'tcx>>>, ErrorGuaranteed> {
406406
desc {
407407
|tcx| "building an abstract representation for `{}`", tcx.def_path_str(key),
408408
}

compiler/rustc_middle/src/ty/abstract_const.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::ty::{
44
TypeVisitableExt,
55
};
66
use rustc_errors::ErrorGuaranteed;
7-
use rustc_hir::def_id::DefId;
87

98
#[derive(Hash, Debug, Clone, Copy, Ord, PartialOrd, PartialEq, Eq)]
109
#[derive(TyDecodable, TyEncodable, HashStable, TypeVisitable, TypeFoldable)]
@@ -35,12 +34,6 @@ TrivialTypeTraversalAndLiftImpls! {
3534
pub type BoundAbstractConst<'tcx> = Result<Option<EarlyBinder<ty::Const<'tcx>>>, ErrorGuaranteed>;
3635

3736
impl<'tcx> TyCtxt<'tcx> {
38-
/// Returns a const without substs applied
39-
pub fn bound_abstract_const(self, uv: DefId) -> BoundAbstractConst<'tcx> {
40-
let ac = self.thir_abstract_const(uv);
41-
Ok(ac?.map(|ac| EarlyBinder(ac)))
42-
}
43-
4437
pub fn expand_abstract_consts<T: TypeFoldable<TyCtxt<'tcx>>>(self, ac: T) -> T {
4538
struct Expander<'tcx> {
4639
tcx: TyCtxt<'tcx>,
@@ -59,7 +52,7 @@ impl<'tcx> TyCtxt<'tcx> {
5952
}
6053
fn fold_const(&mut self, c: Const<'tcx>) -> Const<'tcx> {
6154
let ct = match c.kind() {
62-
ty::ConstKind::Unevaluated(uv) => match self.tcx.bound_abstract_const(uv.def) {
55+
ty::ConstKind::Unevaluated(uv) => match self.tcx.thir_abstract_const(uv.def) {
6356
Err(e) => self.tcx.const_error_with_guaranteed(c.ty(), e),
6457
Ok(Some(bac)) => {
6558
let substs = self.tcx.erase_regions(uv.substs);

compiler/rustc_ty_utils/src/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ impl<'a, 'tcx> visit::Visitor<'a, 'tcx> for IsThirPolymorphic<'a, 'tcx> {
394394
pub fn thir_abstract_const(
395395
tcx: TyCtxt<'_>,
396396
def: LocalDefId,
397-
) -> Result<Option<ty::Const<'_>>, ErrorGuaranteed> {
397+
) -> Result<Option<ty::EarlyBinder<ty::Const<'_>>>, ErrorGuaranteed> {
398398
if !tcx.features().generic_const_exprs {
399399
return Ok(None);
400400
}
@@ -420,7 +420,7 @@ pub fn thir_abstract_const(
420420

421421
let root_span = body.exprs[body_id].span;
422422

423-
Some(recurse_build(tcx, body, body_id, root_span)).transpose()
423+
Ok(Some(ty::EarlyBinder(recurse_build(tcx, body, body_id, root_span)?)))
424424
}
425425

426426
pub fn provide(providers: &mut ty::query::Providers) {

0 commit comments

Comments
 (0)