Skip to content

Commit 1bc1691

Browse files
committed
make unevaluated const substs optional
1 parent 3372f27 commit 1bc1691

File tree

47 files changed

+232
-185
lines changed

Some content is hidden

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

47 files changed

+232
-185
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
@@ -737,10 +737,9 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
737737
}
738738
}
739739
}
740-
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted })
741-
if self.tcx().lazy_normalization() =>
742-
{
743-
assert_eq!(promoted, None);
740+
ty::ConstKind::Unevaluated(uv) if self.tcx().lazy_normalization() => {
741+
assert_eq!(uv.promoted, None);
742+
let substs = uv.substs(self.tcx());
744743
let substs = self.relate_with_variance(
745744
ty::Variance::Invariant,
746745
ty::VarianceDiagInfo::default(),
@@ -749,7 +748,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
749748
)?;
750749
Ok(self.tcx().mk_const(ty::Const {
751750
ty: c.ty,
752-
val: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }),
751+
val: ty::ConstKind::Unevaluated(ty::Unevaluated::new(uv.def, substs)),
753752
}))
754753
}
755754
_ => relate::super_relate_consts(self, c, c),
@@ -971,10 +970,9 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
971970
}
972971
}
973972
}
974-
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted })
975-
if self.tcx().lazy_normalization() =>
976-
{
977-
assert_eq!(promoted, None);
973+
ty::ConstKind::Unevaluated(uv) if self.tcx().lazy_normalization() => {
974+
assert_eq!(uv.promoted, None);
975+
let substs = uv.substs(self.tcx());
978976
let substs = self.relate_with_variance(
979977
ty::Variance::Invariant,
980978
ty::VarianceDiagInfo::default(),
@@ -983,7 +981,7 @@ impl TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
983981
)?;
984982
Ok(self.tcx().mk_const(ty::Const {
985983
ty: c.ty,
986-
val: ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }),
984+
val: ty::ConstKind::Unevaluated(ty::Unevaluated::new(uv.def, substs)),
987985
}))
988986
}
989987
_ => 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
@@ -1517,8 +1517,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15171517
}
15181518

15191519
impl<'tcx> ty::fold::TypeVisitor<'tcx> for OpaqueTypesVisitor<'tcx> {
1520-
fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> {
1521-
self.tcx
1520+
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
1521+
Some(self.tcx)
15221522
}
15231523

15241524
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
@@ -473,8 +473,10 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
473473
struct TraitObjectVisitor(Vec<DefId>);
474474

475475
impl<'tcx> TypeVisitor<'tcx> for TraitObjectVisitor {
476-
fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx> {
477-
bug!("tcx_for_anon_const_substs called for TraitObjectVisitor");
476+
fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>> {
477+
// The default anon const substs cannot include
478+
// trait objects, so we don't have to bother looking.
479+
None
478480
}
479481

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

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,16 +1487,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14871487
pub fn const_eval_resolve(
14881488
&self,
14891489
param_env: ty::ParamEnv<'tcx>,
1490-
ty::Unevaluated { def, substs, promoted }: ty::Unevaluated<'tcx>,
1490+
unevaluated: ty::Unevaluated<'tcx>,
14911491
span: Option<Span>,
14921492
) -> EvalToConstValueResult<'tcx> {
14931493
let mut original_values = OriginalQueryValues::default();
1494-
let canonical = self.canonicalize_query((param_env, substs), &mut original_values);
1494+
let canonical = self.canonicalize_query((param_env, unevaluated), &mut original_values);
14951495

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

15021502
/// 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
@@ -765,8 +765,8 @@ struct ScopeInstantiator<'me, 'tcx> {
765765
}
766766

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

772772
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)