Make const bound handling more like types/regions.

Currently there is `Ty` and `BoundTy`, and `Region` and `BoundRegion`,
and `Const` and... `BoundVar`. An annoying inconsistency.

This commit repurposes the existing `BoundConst`, which was barely used,
so it's the partner to `Const`. Unlike `BoundTy`/`BoundRegion` it lacks
a `kind` field but it's still nice to have because it makes the const
code more similar to the ty/region code everywhere.

The commit also removes `impl From<BoundVar> for BoundTy`, which has a
single use and doesn't seem worth it.

These changes fix the "FIXME: We really should have a separate
`BoundConst` for consts".
This commit is contained in:
Nicholas Nethercote
2025-07-30 14:21:00 +10:00
parent 94cc5bb962
commit 507dec4dc3
21 changed files with 82 additions and 69 deletions

View File

@@ -535,7 +535,10 @@ fn plug_infer_with_placeholders<'tcx>(
ct,
ty::Const::new_placeholder(
self.infcx.tcx,
ty::Placeholder { universe: self.universe, bound: self.next_var() },
ty::Placeholder {
universe: self.universe,
bound: ty::BoundConst { var: self.next_var() },
},
),
)
else {

View File

@@ -706,7 +706,10 @@ fn replace_param_and_infer_args_with_placeholder<'tcx>(
self.idx += 1;
ty::Const::new_placeholder(
self.tcx,
ty::PlaceholderConst { universe: ty::UniverseIndex::ROOT, bound: idx },
ty::PlaceholderConst {
universe: ty::UniverseIndex::ROOT,
bound: ty::BoundConst { var: idx },
},
)
} else {
c.super_fold_with(self)

View File

@@ -222,7 +222,7 @@ pub struct PlaceholderReplacer<'a, 'tcx> {
infcx: &'a InferCtxt<'tcx>,
mapped_regions: FxIndexMap<ty::PlaceholderRegion, ty::BoundRegion>,
mapped_types: FxIndexMap<ty::PlaceholderType, ty::BoundTy>,
mapped_consts: FxIndexMap<ty::PlaceholderConst, ty::BoundVar>,
mapped_consts: FxIndexMap<ty::PlaceholderConst, ty::BoundConst>,
universe_indices: &'a [Option<ty::UniverseIndex>],
current_index: ty::DebruijnIndex,
}
@@ -232,7 +232,7 @@ impl<'a, 'tcx> PlaceholderReplacer<'a, 'tcx> {
infcx: &'a InferCtxt<'tcx>,
mapped_regions: FxIndexMap<ty::PlaceholderRegion, ty::BoundRegion>,
mapped_types: FxIndexMap<ty::PlaceholderType, ty::BoundTy>,
mapped_consts: FxIndexMap<ty::PlaceholderConst, ty::BoundVar>,
mapped_consts: FxIndexMap<ty::PlaceholderConst, ty::BoundConst>,
universe_indices: &'a [Option<ty::UniverseIndex>],
value: T,
) -> T {