Skip to content

Commit c97fd81

Browse files
committed
Refactor tcx mk_const parameters.
1 parent 6330c27 commit c97fd81

File tree

21 files changed

+74
-104
lines changed

21 files changed

+74
-104
lines changed

compiler/rustc_hir_analysis/src/check/compare_method.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,13 +1655,10 @@ pub fn check_type_bounds<'tcx>(
16551655
GenericParamDefKind::Const { .. } => {
16561656
let bound_var = ty::BoundVariableKind::Const;
16571657
bound_vars.push(bound_var);
1658-
tcx.mk_const(ty::ConstS {
1659-
ty: tcx.type_of(param.def_id),
1660-
kind: ty::ConstKind::Bound(
1661-
ty::INNERMOST,
1662-
ty::BoundVar::from_usize(bound_vars.len() - 1),
1663-
),
1664-
})
1658+
tcx.mk_const(
1659+
ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_usize(bound_vars.len() - 1)),
1660+
tcx.type_of(param.def_id),
1661+
)
16651662
.into()
16661663
}
16671664
});

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -773,10 +773,10 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
773773
self.fold_const(bound_to)
774774
} else {
775775
let var = self.canonical_var(info, const_var.into());
776-
self.tcx().mk_const(ty::ConstS {
777-
kind: ty::ConstKind::Bound(self.binder_index, var),
778-
ty: self.fold_ty(const_var.ty()),
779-
})
776+
self.tcx().mk_const(
777+
ty::ConstKind::Bound(self.binder_index, var),
778+
self.fold_ty(const_var.ty()),
779+
)
780780
}
781781
}
782782
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,7 @@ impl<'tcx> InferCtxt<'tcx> {
147147
CanonicalVarKind::PlaceholderConst(ty::PlaceholderConst { universe, name }, ty) => {
148148
let universe_mapped = universe_map(universe);
149149
let placeholder_mapped = ty::PlaceholderConst { universe: universe_mapped, name };
150-
self.tcx
151-
.mk_const(ty::ConstS {
152-
kind: ty::ConstKind::Placeholder(placeholder_mapped),
153-
ty,
154-
})
155-
.into()
150+
self.tcx.mk_const(ty::ConstKind::Placeholder(placeholder_mapped), ty).into()
156151
}
157152
}
158153
}

compiler/rustc_infer/src/infer/combine.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -741,10 +741,10 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
741741
substs,
742742
substs,
743743
)?;
744-
Ok(self.tcx().mk_const(ty::ConstS {
745-
ty: c.ty(),
746-
kind: ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
747-
}))
744+
Ok(self.tcx().mk_const(
745+
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
746+
c.ty(),
747+
))
748748
}
749749
_ => relate::super_relate_consts(self, c, c),
750750
}
@@ -955,10 +955,10 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
955955
substs,
956956
)?;
957957

958-
Ok(self.tcx().mk_const(ty::ConstS {
959-
ty: c.ty(),
960-
kind: ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
961-
}))
958+
Ok(self.tcx().mk_const(
959+
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
960+
c.ty(),
961+
))
962962
}
963963
_ => relate::super_relate_consts(self, c, c),
964964
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ impl<'tcx> InferCtxt<'tcx> {
9494
}))
9595
},
9696
consts: &mut |bound_var: ty::BoundVar, ty| {
97-
self.tcx.mk_const(ty::ConstS {
98-
kind: ty::ConstKind::Placeholder(ty::PlaceholderConst {
97+
self.tcx.mk_const(
98+
ty::ConstKind::Placeholder(ty::PlaceholderConst {
9999
universe: next_universe,
100100
name: bound_var,
101101
}),
102102
ty,
103-
})
103+
)
104104
},
105105
};
106106

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,13 +2065,13 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
20652065
if ty.has_non_region_param() || ty.has_non_region_infer() {
20662066
bug!("const `{ct}`'s type should not reference params or types");
20672067
}
2068-
tcx.mk_const(ty::ConstS {
2069-
ty,
2070-
kind: ty::ConstKind::Placeholder(ty::PlaceholderConst {
2068+
tcx.mk_const(
2069+
ty::ConstKind::Placeholder(ty::PlaceholderConst {
20712070
universe: ty::UniverseIndex::ROOT,
20722071
name: ty::BoundVar::from_usize(idx),
20732072
}),
2074-
})
2073+
ty,
2074+
)
20752075
.into()
20762076
}
20772077
_ => arg,

compiler/rustc_middle/src/infer/canonical.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,10 @@ impl<'tcx> CanonicalVarValues<'tcx> {
341341
tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)).into()
342342
}
343343
GenericArgKind::Const(ct) => tcx
344-
.mk_const(ty::ConstS {
345-
ty: ct.ty(),
346-
kind: ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_u32(i)),
347-
})
344+
.mk_const(
345+
ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_u32(i)),
346+
ct.ty(),
347+
)
348348
.into(),
349349
})
350350
.collect(),

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2414,10 +2414,8 @@ impl<'tcx> ConstantKind<'tcx> {
24142414
let generics = tcx.generics_of(item_def_id.to_def_id());
24152415
let index = generics.param_def_id_to_index[&def_id];
24162416
let name = tcx.hir().name(hir_id);
2417-
let ty_const = tcx.mk_const(ty::ConstS {
2418-
kind: ty::ConstKind::Param(ty::ParamConst::new(index, name)),
2419-
ty,
2420-
});
2417+
let ty_const =
2418+
tcx.mk_const(ty::ConstKind::Param(ty::ParamConst::new(index, name)), ty);
24212419
debug!(?ty_const);
24222420

24232421
return Self::Ty(ty_const);

compiler/rustc_middle/src/ty/codec.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
310310

311311
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Const<'tcx> {
312312
fn decode(decoder: &mut D) -> Self {
313-
decoder.interner().mk_const(Decodable::decode(decoder))
313+
let consts: ty::ConstS<'tcx> = Decodable::decode(decoder);
314+
decoder.interner().mk_const(consts.kind, consts.ty)
314315
}
315316
}
316317

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ impl<'tcx> Const<'tcx> {
7777

7878
match Self::try_eval_lit_or_param(tcx, ty, expr) {
7979
Some(v) => v,
80-
None => tcx.mk_const(ty::ConstS {
81-
kind: ty::ConstKind::Unevaluated(ty::UnevaluatedConst {
80+
None => tcx.mk_const(
81+
ty::ConstKind::Unevaluated(ty::UnevaluatedConst {
8282
def: def.to_global(),
8383
substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()),
8484
}),
8585
ty,
86-
}),
86+
),
8787
}
8888
}
8989

@@ -138,10 +138,7 @@ impl<'tcx> Const<'tcx> {
138138
let generics = tcx.generics_of(item_def_id.to_def_id());
139139
let index = generics.param_def_id_to_index[&def_id];
140140
let name = tcx.hir().name(hir_id);
141-
Some(tcx.mk_const(ty::ConstS {
142-
kind: ty::ConstKind::Param(ty::ParamConst::new(index, name)),
143-
ty,
144-
}))
141+
Some(tcx.mk_const(ty::ConstKind::Param(ty::ParamConst::new(index, name)), ty))
145142
}
146143
_ => None,
147144
}
@@ -150,7 +147,7 @@ impl<'tcx> Const<'tcx> {
150147
/// Interns the given value as a constant.
151148
#[inline]
152149
pub fn from_value(tcx: TyCtxt<'tcx>, val: ty::ValTree<'tcx>, ty: Ty<'tcx>) -> Self {
153-
tcx.mk_const(ConstS { kind: ConstKind::Value(val), ty })
150+
tcx.mk_const(ConstKind::Value(val), ty)
154151
}
155152

156153
/// Panics if self.kind != ty::ConstKind::Value

0 commit comments

Comments
 (0)