Skip to content

Commit 08f38c4

Browse files
committed
Remove Const::kind method in favor of field access via the Deref impl
1 parent dadfa04 commit 08f38c4

File tree

71 files changed

+117
-122
lines changed

Some content is hidden

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

71 files changed

+117
-122
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ fn check_opaque_type_parameter_valid(
381381
GenericArgKind::Lifetime(lt) => {
382382
matches!(*lt, ty::ReEarlyBound(_) | ty::ReFree(_))
383383
}
384-
GenericArgKind::Const(ct) => matches!(ct.kind(), ty::ConstKind::Param(_)),
384+
GenericArgKind::Const(ct) => matches!(ct.kind, ty::ConstKind::Param(_)),
385385
};
386386

387387
if arg_is_param {

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
353353
} else {
354354
let tcx = self.tcx();
355355
let maybe_uneval = match constant.literal {
356-
ConstantKind::Ty(ct) => match ct.kind() {
356+
ConstantKind::Ty(ct) => match ct.kind {
357357
ty::ConstKind::Unevaluated(_) => {
358358
bug!("should not encounter unevaluated ConstantKind::Ty here, got {:?}", ct)
359359
}

compiler/rustc_codegen_cranelift/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ fn codegen_stmt<'tcx>(
722722
let times = fx
723723
.monomorphize(times)
724724
.eval(fx.tcx, ParamEnv::reveal_all())
725-
.kind()
725+
.kind
726726
.try_to_bits(fx.tcx.data_layout.pointer_size)
727727
.unwrap();
728728
if operand.layout().size.bytes() == 0 {

compiler/rustc_codegen_cranelift/src/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
7171
) -> Option<(ConstValue<'tcx>, Ty<'tcx>)> {
7272
let constant_kind = fx.monomorphize(constant.literal);
7373
let uv = match constant_kind {
74-
ConstantKind::Ty(const_) => match const_.kind() {
74+
ConstantKind::Ty(const_) => match const_.kind {
7575
ty::ConstKind::Unevaluated(uv) => uv.expand(),
7676
ty::ConstKind::Value(val) => {
7777
return Some((fx.tcx.valtree_to_const_val((const_.ty, val)), const_.ty));

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -178,15 +178,15 @@ fn push_debuginfo_type_name<'tcx>(
178178
if cpp_like_debuginfo {
179179
output.push_str("array$<");
180180
push_debuginfo_type_name(tcx, inner_type, true, output, visited);
181-
match len.kind() {
181+
match len.kind {
182182
ty::ConstKind::Param(param) => write!(output, ",{}>", param.name).unwrap(),
183183
_ => write!(output, ",{}>", len.eval_usize(tcx, ty::ParamEnv::reveal_all()))
184184
.unwrap(),
185185
}
186186
} else {
187187
output.push('[');
188188
push_debuginfo_type_name(tcx, inner_type, true, output, visited);
189-
match len.kind() {
189+
match len.kind {
190190
ty::ConstKind::Param(param) => write!(output, "; {}]", param.name).unwrap(),
191191
_ => write!(output, "; {}]", len.eval_usize(tcx, ty::ParamEnv::reveal_all()))
192192
.unwrap(),
@@ -635,7 +635,7 @@ fn push_generic_params_internal<'tcx>(
635635
}
636636

637637
fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut String) {
638-
match ct.kind() {
638+
match ct.kind {
639639
ty::ConstKind::Param(param) => {
640640
write!(output, "{}", param.name)
641641
}

compiler/rustc_codegen_ssa/src/mir/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
2626
) -> Result<ConstValue<'tcx>, ErrorHandled> {
2727
let ct = self.monomorphize(constant.literal);
2828
let uv = match ct {
29-
mir::ConstantKind::Ty(ct) => match ct.kind() {
29+
mir::ConstantKind::Ty(ct) => match ct.kind {
3030
ty::ConstKind::Unevaluated(uv) => uv.expand(),
3131
ty::ConstKind::Value(val) => {
3232
return Ok(self.cx.tcx().valtree_to_const_val((ct.ty, val)));

compiler/rustc_const_eval/src/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
557557
val: ty::Const<'tcx>,
558558
span: Option<Span>,
559559
) -> InterpResult<'tcx, ValTree<'tcx>> {
560-
Ok(match val.kind() {
560+
Ok(match val.kind {
561561
ty::ConstKind::Param(_) | ty::ConstKind::Placeholder(..) => {
562562
throw_inval!(TooGeneric)
563563
}

compiler/rustc_const_eval/src/interpret/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ where
5757
}
5858

5959
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
60-
match c.kind() {
60+
match c.kind {
6161
ty::ConstKind::Param(..) => ControlFlow::Break(FoundParam),
6262
_ => c.super_visit_with(self),
6363
}

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ where
348348
// way for type and mir constants.
349349
let uneval = match constant.literal {
350350
ConstantKind::Ty(ct)
351-
if matches!(ct.kind(), ty::ConstKind::Param(_) | ty::ConstKind::Error(_)) =>
351+
if matches!(ct.kind, ty::ConstKind::Param(_) | ty::ConstKind::Error(_)) =>
352352
{
353353
None
354354
}

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1417,7 +1417,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
14171417
}
14181418

14191419
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
1420-
if let ty::ConstKind::Param(param) = c.kind() {
1420+
if let ty::ConstKind::Param(param) = c.kind {
14211421
self.params.insert(param.index);
14221422
}
14231423
c.super_visit_with(self)

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ fn const_evaluatable_predicates_of<'tcx>(
336336
impl<'tcx> intravisit::Visitor<'tcx> for ConstCollector<'tcx> {
337337
fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) {
338338
let ct = ty::Const::from_anon_const(self.tcx, c.def_id);
339-
if let ty::ConstKind::Unevaluated(_) = ct.kind() {
339+
if let ty::ConstKind::Unevaluated(_) = ct.kind {
340340
let span = self.tcx.def_span(c.def_id);
341341
self.preds.insert((
342342
ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(ct))

compiler/rustc_hir_analysis/src/constrained_generic_params.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<'tcx> TypeVisitor<'tcx> for ParameterCollector {
8080
}
8181

8282
fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
83-
match c.kind() {
83+
match c.kind {
8484
ty::ConstKind::Unevaluated(..) if !self.include_nonconstraining => {
8585
// Constant expressions are not injective
8686
return c.ty.visit_with(self);

compiler/rustc_hir_analysis/src/variance/constraints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
368368
) {
369369
debug!("add_constraints_from_const(c={:?}, variance={:?})", c, variance);
370370

371-
match &c.kind() {
371+
match &c.kind {
372372
ty::ConstKind::Unevaluated(uv) => {
373373
self.add_constraints_from_invariant_substs(current, uv.substs, variance);
374374
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
467467
}
468468

469469
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
470-
match ct.kind() {
470+
match ct.kind {
471471
ty::ConstKind::Infer(InferConst::Var(vid)) => {
472472
debug!("canonical: const var found with vid {:?}", vid);
473473
match self.infcx.probe_const_var(vid) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ impl<'tcx> InferCtxt<'tcx> {
466466
}
467467
}
468468
GenericArgKind::Const(result_value) => {
469-
if let ty::ConstKind::Bound(debrujin, b) = result_value.kind() {
469+
if let ty::ConstKind::Bound(debrujin, b) = result_value.kind {
470470
// ...in which case we would set `canonical_vars[0]` to `Some(const X)`.
471471

472472
// We only allow a `ty::INNERMOST` index in substitutions.

compiler/rustc_infer/src/infer/combine.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'tcx> InferCtxt<'tcx> {
142142

143143
let a_is_expected = relation.a_is_expected();
144144

145-
match (a.kind(), b.kind()) {
145+
match (a.kind, b.kind) {
146146
(
147147
ty::ConstKind::Infer(InferConst::Var(a_vid)),
148148
ty::ConstKind::Infer(InferConst::Var(b_vid)),
@@ -735,7 +735,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
735735
) -> RelateResult<'tcx, ty::Const<'tcx>> {
736736
assert_eq!(c, c2); // we are abusing TypeRelation here; both LHS and RHS ought to be ==
737737

738-
match c.kind() {
738+
match c.kind {
739739
ty::ConstKind::Infer(InferConst::Var(vid)) => {
740740
let mut inner = self.infcx.inner.borrow_mut();
741741
let variable_table = &mut inner.const_unification_table();
@@ -941,7 +941,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
941941
) -> RelateResult<'tcx, ty::Const<'tcx>> {
942942
debug_assert_eq!(c, _c);
943943

944-
match c.kind() {
944+
match c.kind {
945945
ty::ConstKind::Infer(InferConst::Var(vid)) => {
946946
// Check if the current unification would end up
947947
// unifying `target_vid` with a const which contains

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl<'tcx> InferCtxt<'tcx> {
270270
}
271271
}
272272
GenericArgKind::Const(ct) => {
273-
if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.kind() {
273+
if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.kind {
274274
let origin =
275275
self.inner.borrow_mut().const_unification_table().probe_value(vid).origin;
276276
if let ConstVariableOriginKind::ConstParameterDefinition(name, def_id) =
@@ -830,7 +830,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
830830
}
831831
(GenericArgKind::Const(inner_ct), GenericArgKind::Const(target_ct)) => {
832832
use ty::InferConst::*;
833-
match (inner_ct.kind(), target_ct.kind()) {
833+
match (inner_ct.kind, target_ct.kind) {
834834
(ty::ConstKind::Infer(Var(a_vid)), ty::ConstKind::Infer(Var(b_vid))) => self
835835
.infcx
836836
.inner
@@ -870,7 +870,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
870870
}
871871
}
872872
GenericArgKind::Const(ct) => {
873-
if matches!(ct.kind(), ty::ConstKind::Unevaluated(..)) {
873+
if matches!(ct.kind, ty::ConstKind::Unevaluated(..)) {
874874
// You can't write the generic arguments for
875875
// unevaluated constants.
876876
walker.skip_current_subtree();

compiler/rustc_infer/src/infer/freshen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
217217
}
218218

219219
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
220-
match ct.kind() {
220+
match ct.kind {
221221
ty::ConstKind::Infer(ty::InferConst::Var(v)) => {
222222
let opt_ct = self
223223
.infcx

compiler/rustc_infer/src/infer/fudge.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for InferenceFudger<'a, 'tcx> {
229229
}
230230

231231
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
232-
if let ty::ConstKind::Infer(ty::InferConst::Var(vid)) = ct.kind() {
232+
if let ty::ConstKind::Infer(ty::InferConst::Var(vid)) = ct.kind {
233233
if self.const_vars.0.contains(&vid) {
234234
// This variable was created during the fudging.
235235
// Recreate it with a fresh variable here.

compiler/rustc_infer/src/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1849,7 +1849,7 @@ impl<'tcx> TyOrConstInferVar<'tcx> {
18491849
/// Tries to extract an inference variable from a constant, returns `None`
18501850
/// for constants other than `ty::ConstKind::Infer(_)` (or `InferConst::Fresh`).
18511851
fn maybe_from_const(ct: ty::Const<'tcx>) -> Option<Self> {
1852-
match ct.kind() {
1852+
match ct.kind {
18531853
ty::ConstKind::Infer(InferConst::Var(v)) => Some(TyOrConstInferVar::Const(v)),
18541854
_ => None,
18551855
}
@@ -1928,7 +1928,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for ShallowResolver<'a, 'tcx> {
19281928
}
19291929

19301930
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
1931-
if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.kind() {
1931+
if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.kind {
19321932
self.infcx
19331933
.inner
19341934
.borrow_mut()

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ where
680680
b = self.infcx.shallow_resolve(b);
681681
}
682682

683-
match b.kind() {
683+
match b.kind {
684684
ty::ConstKind::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => {
685685
// Forbid inference variables in the RHS.
686686
self.infcx.tcx.sess.delay_span_bug(
@@ -1072,7 +1072,7 @@ where
10721072
a: ty::Const<'tcx>,
10731073
_: ty::Const<'tcx>,
10741074
) -> RelateResult<'tcx, ty::Const<'tcx>> {
1075-
match a.kind() {
1075+
match a.kind {
10761076
ty::ConstKind::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => {
10771077
bug!("unexpected inference variable encountered in NLL generalization: {:?}", a);
10781078
}

compiler/rustc_infer/src/infer/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl<'a, 'tcx> FallibleTypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
217217
Ok(c) // micro-optimize -- if there is nothing in this const that this fold affects...
218218
} else {
219219
let c = self.infcx.shallow_resolve(c);
220-
match c.kind() {
220+
match c.kind {
221221
ty::ConstKind::Infer(InferConst::Var(vid)) => {
222222
return Err(FixupError::UnresolvedConst(vid));
223223
}

compiler/rustc_lint/src/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2896,7 +2896,7 @@ impl ClashingExternDeclarations {
28962896
}
28972897
(Array(a_ty, a_const), Array(b_ty, b_const)) => {
28982898
// For arrays, we also check the constness of the type.
2899-
a_const.kind() == b_const.kind()
2899+
a_const.kind == b_const.kind
29002900
&& structurally_same_type_impl(seen_types, cx, *a_ty, *b_ty, ckind)
29012901
}
29022902
(Slice(a_ty), Slice(b_ty)) => {

compiler/rustc_middle/src/mir/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -2247,7 +2247,7 @@ impl<'tcx> ConstantKind<'tcx> {
22472247
#[inline]
22482248
pub fn try_to_value(self, tcx: TyCtxt<'tcx>) -> Option<interpret::ConstValue<'tcx>> {
22492249
match self {
2250-
ConstantKind::Ty(c) => match c.kind() {
2250+
ConstantKind::Ty(c) => match c.kind {
22512251
ty::ConstKind::Value(valtree) => Some(tcx.valtree_to_const_val((c.ty, valtree))),
22522252
_ => None,
22532253
},
@@ -2259,7 +2259,7 @@ impl<'tcx> ConstantKind<'tcx> {
22592259
#[inline]
22602260
pub fn try_to_scalar(self) -> Option<Scalar> {
22612261
match self {
2262-
ConstantKind::Ty(c) => match c.kind() {
2262+
ConstantKind::Ty(c) => match c.kind {
22632263
ty::ConstKind::Value(valtree) => match valtree {
22642264
ty::ValTree::Leaf(scalar_int) => Some(Scalar::Int(scalar_int)),
22652265
ty::ValTree::Branch(_) => None,
@@ -2290,7 +2290,7 @@ impl<'tcx> ConstantKind<'tcx> {
22902290
pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self {
22912291
match self {
22922292
Self::Ty(c) => {
2293-
if let Some(val) = c.kind().try_eval_for_mir(tcx, param_env) {
2293+
if let Some(val) = c.kind.try_eval_for_mir(tcx, param_env) {
22942294
match val {
22952295
Ok(val) => Self::Val(val, c.ty),
22962296
Err(_) => Self::Ty(tcx.const_error(self.ty())),
@@ -2580,7 +2580,7 @@ impl<'tcx> ConstantKind<'tcx> {
25802580
}
25812581

25822582
pub fn from_const(c: ty::Const<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
2583-
match c.kind() {
2583+
match c.kind {
25842584
ty::ConstKind::Value(valtree) => {
25852585
let const_val = tcx.valtree_to_const_val((c.ty, valtree));
25862586
Self::Val(const_val, c.ty)
@@ -2902,7 +2902,7 @@ fn pretty_print_const_value<'tcx>(
29022902
}
29032903
}
29042904
(ConstValue::ByRef { alloc, offset }, ty::Array(t, n)) if *t == u8_type => {
2905-
let n = n.kind().try_to_bits(tcx.data_layout.pointer_size).unwrap();
2905+
let n = n.kind.try_to_bits(tcx.data_layout.pointer_size).unwrap();
29062906
// cast is ok because we already checked for pointer size (32 or 64 bit) above
29072907
let range = AllocRange { start: offset, size: Size::from_bytes(n) };
29082908
let byte_str = alloc.inner().get_bytes_strip_provenance(&tcx, range).unwrap();

compiler/rustc_middle/src/mir/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
462462
};
463463

464464
let val = match literal {
465-
ConstantKind::Ty(ct) => match ct.kind() {
465+
ConstantKind::Ty(ct) => match ct.kind {
466466
ty::ConstKind::Param(p) => format!("Param({})", p),
467467
ty::ConstKind::Unevaluated(uv) => {
468468
format!(

compiler/rustc_middle/src/ty/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
105105
return Ok(a);
106106
}
107107

108-
match (a.kind(), b.kind()) {
108+
match (a.kind, b.kind) {
109109
(_, ty::ConstKind::Infer(InferConst::Fresh(_))) => {
110110
return Ok(a);
111111
}

compiler/rustc_middle/src/ty/abstract_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'tcx> AbstractConst<'tcx> {
4141
tcx: TyCtxt<'tcx>,
4242
ct: ty::Const<'tcx>,
4343
) -> Result<Option<AbstractConst<'tcx>>, ErrorGuaranteed> {
44-
match ct.kind() {
44+
match ct.kind {
4545
ty::ConstKind::Unevaluated(uv) => AbstractConst::new(tcx, uv),
4646
ty::ConstKind::Error(reported) => Err(reported),
4747
_ => Ok(None),

0 commit comments

Comments
 (0)