Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit bfaf13a

Browse files
committed
make unevaluated const substs optional
1 parent f4b606f commit bfaf13a

File tree

46 files changed

+234
-188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+234
-188
lines changed

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ pub(crate) fn codegen_constant<'tcx>(
129129
};
130130
let const_val = match const_.val {
131131
ConstKind::Value(const_val) => const_val,
132-
ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted })
133-
if fx.tcx.is_static(def.did) =>
132+
ConstKind::Unevaluated(uv)
133+
if fx.tcx.is_static(uv.def.did) =>
134134
{
135-
assert!(substs.is_empty());
136-
assert!(promoted.is_none());
135+
assert!(uv.substs(fx.tcx).is_empty());
136+
assert!(uv.promoted.is_none());
137137

138-
return codegen_static_ref(fx, def.did, fx.layout_of(const_.ty)).to_cvalue(fx);
138+
return codegen_static_ref(fx, uv.def.did, fx.layout_of(const_.ty)).to_cvalue(fx);
139139
}
140140
ConstKind::Unevaluated(unevaluated) => {
141141
match fx.tcx.const_eval_resolve(ParamEnv::reveal_all(), unevaluated, None) {

compiler/rustc_infer/src/infer/combine.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,9 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
742742
}
743743
}
744744
}
745-
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted })
746-
if self.tcx().lazy_normalization() =>
747-
{
748-
assert_eq!(promoted, None);
745+
ty::ConstKind::Unevaluated(uv) if self.tcx().lazy_normalization() => {
746+
assert_eq!(uv.promoted, None);
747+
let substs = uv.substs(self.tcx());
749748
let substs = self.relate_with_variance(
750749
ty::Variance::Invariant,
751750
ty::VarianceDiagInfo::default(),
@@ -754,7 +753,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
754753
)?;
755754
Ok(self.tcx().mk_const(ty::Const {
756755
ty: c.ty,
757-
val: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }),
756+
val: ty::ConstKind::Unevaluated(ty::Unevaluated::new(uv.def, substs)),
758757
}))
759758
}
760759
_ => relate::super_relate_consts(self, c, c),
@@ -976,10 +975,9 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
976975
}
977976
}
978977
}
979-
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted })
980-
if self.tcx().lazy_normalization() =>
981-
{
982-
assert_eq!(promoted, None);
978+
ty::ConstKind::Unevaluated(uv) if self.tcx().lazy_normalization() => {
979+
assert_eq!(uv.promoted, None);
980+
let substs = uv.substs(self.tcx());
983981
let substs = self.relate_with_variance(
984982
ty::Variance::Invariant,
985983
ty::VarianceDiagInfo::default(),
@@ -988,7 +986,7 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
988986
)?;
989987
Ok(self.tcx().mk_const(ty::Const {
990988
ty: c.ty,
991-
val: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }),
989+
val: ty::ConstKind::Unevaluated(ty::Unevaluated::new(uv.def, substs)),
992990
}))
993991
}
994992
_ => relate::super_relate_consts(self, c, c),

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,8 +1537,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15371537
}
15381538

15391539
impl<'tcx> ty::fold::TypeVisitor<'tcx> for OpaqueTypesVisitor<'tcx> {
1540-
fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> {
1541-
self.tcx
1540+
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
1541+
Some(self.tcx)
15421542
}
15431543

15441544
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/static_impl_trait.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
479479
pub(super) struct TraitObjectVisitor(pub(super) FxHashSet<DefId>);
480480

481481
impl<'tcx> TypeVisitor<'tcx> for TraitObjectVisitor {
482-
fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> {
483-
bug!("tcx_for_anon_const_substs called for TraitObjectVisitor");
482+
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
483+
// The default anon const substs cannot include
484+
// trait objects, so we don't have to bother looking.
485+
None
484486
}
485487

486488
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
679679
b: ty::Unevaluated<'tcx>,
680680
) -> bool {
681681
let canonical = self.canonicalize_query(
682-
((a.def, a.substs), (b.def, b.substs)),
682+
((a.def, a.substs(self.tcx)), (b.def, b.substs(self.tcx))),
683683
&mut OriginalQueryValues::default(),
684684
);
685685
debug!("canonical consts: {:?}", &canonical.value);
@@ -1592,16 +1592,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15921592
pub fn const_eval_resolve(
15931593
&self,
15941594
param_env: ty::ParamEnv<'tcx>,
1595-
ty::Unevaluated { def, substs, promoted }: ty::Unevaluated<'tcx>,
1595+
unevaluated: ty::Unevaluated<'tcx>,
15961596
span: Option<Span>,
15971597
) -> EvalToConstValueResult<'tcx> {
15981598
let mut original_values = OriginalQueryValues::default();
1599-
let canonical = self.canonicalize_query((param_env, substs), &mut original_values);
1599+
let canonical = self.canonicalize_query((param_env, unevaluated), &mut original_values);
16001600

1601-
let (param_env, substs) = canonical.value;
1601+
let (param_env, unevaluated) = canonical.value;
16021602
// The return value is the evaluated value which doesn't contain any reference to inference
16031603
// variables, thus we don't need to substitute back the original values.
1604-
self.tcx.const_eval_resolve(param_env, ty::Unevaluated { def, substs, promoted }, span)
1604+
self.tcx.const_eval_resolve(param_env, unevaluated, span)
16051605
}
16061606

16071607
/// If `typ` is a type variable of some kind, resolve it one level

compiler/rustc_infer/src/infer/nll_relate/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,8 @@ struct ScopeInstantiator<'me, 'tcx> {
766766
}
767767

768768
impl<'me, 'tcx> TypeVisitor<'tcx> for ScopeInstantiator<'me, 'tcx> {
769-
fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> {
770-
self.tcx
769+
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
770+
Some(self.tcx)
771771
}
772772

773773
fn visit_binder<T: TypeFoldable<'tcx>>(

compiler/rustc_infer/src/infer/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ impl<'a, 'tcx> UnresolvedTypeFinder<'a, 'tcx> {
127127
impl<'a, 'tcx> TypeVisitor<'tcx> for UnresolvedTypeFinder<'a, 'tcx> {
128128
type BreakTy = (Ty<'tcx>, Option<Span>);
129129

130-
fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> {
131-
self.infcx.tcx
130+
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
131+
Some(self.infcx.tcx)
132132
}
133133

134134
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {

compiler/rustc_lint/src/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,8 +1160,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
11601160

11611161
impl<'a, 'tcx> ty::fold::TypeVisitor<'tcx> for ProhibitOpaqueTypes<'a, 'tcx> {
11621162
type BreakTy = Ty<'tcx>;
1163-
fn tcx_for_anon_const_substs(&self) -> TyCtxt<'tcx> {
1164-
self.cx.tcx
1163+
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
1164+
Some(self.cx.tcx)
11651165
}
11661166

11671167
fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {

compiler/rustc_middle/src/mir/interpret/queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'tcx> TyCtxt<'tcx> {
3838
ct: ty::Unevaluated<'tcx>,
3939
span: Option<Span>,
4040
) -> EvalToConstValueResult<'tcx> {
41-
match ty::Instance::resolve_opt_const_arg(self, param_env, ct.def, ct.substs) {
41+
match ty::Instance::resolve_opt_const_arg(self, param_env, ct.def, ct.substs(self)) {
4242
Ok(Some(instance)) => {
4343
let cid = GlobalId { instance, promoted: ct.promoted };
4444
self.const_eval_global_id(param_env, cid, span)

compiler/rustc_middle/src/query/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ rustc_queries! {
114114
desc { |tcx| "compute const default for a given parameter `{}`", tcx.def_path_str(param) }
115115
}
116116

117+
query default_anon_const_substs(key: DefId) -> SubstsRef<'tcx> {
118+
desc { |tcx| "computing the default generic arguments for `{}`", tcx.def_path_str(key) }
119+
}
120+
117121
/// Records the type of every item.
118122
query type_of(key: DefId) -> Ty<'tcx> {
119123
desc { |tcx| "computing type of `{}`", tcx.def_path_str(key) }

0 commit comments

Comments
 (0)