From 9421f7488408dc8ca69e5a9f5b72ae97f295d77b Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 25 Nov 2022 15:14:58 +0000 Subject: [PATCH 1/4] Allow direct field accesses through `Const` to the `ConstKind` and the `Ty` fields without the helper method --- compiler/rustc_middle/src/ty/consts.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 9a58a196ed721..b68843b5dca54 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -19,6 +19,14 @@ pub use valtree::*; #[rustc_pass_by_value] pub struct Const<'tcx>(pub Interned<'tcx, ConstS<'tcx>>); +impl<'tcx> std::ops::Deref for Const<'tcx> { + type Target = ConstS<'tcx>; + + fn deref(&self) -> &Self::Target { + &self.0.0 + } +} + impl<'tcx> fmt::Debug for Const<'tcx> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { // This reflects what `Const` looked liked before `Interned` was @@ -41,12 +49,12 @@ static_assert_size!(ConstS<'_>, 40); impl<'tcx> Const<'tcx> { #[inline] pub fn ty(self) -> Ty<'tcx> { - self.0.ty + self.ty } #[inline] pub fn kind(self) -> ConstKind<'tcx> { - self.0.kind + self.kind } /// Literals and const generic parameters are eagerly converted to a constant, everything else From dadfa046dc14a224dc9b9344a41241ec4c52f4a8 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 25 Nov 2022 15:21:06 +0000 Subject: [PATCH 2/4] Remove Const::ty method in favor of field access via the Deref impl --- compiler/rustc_codegen_cranelift/src/constant.rs | 2 +- .../rustc_codegen_ssa/src/debuginfo/type_names.rs | 6 +++--- compiler/rustc_codegen_ssa/src/mir/constant.rs | 2 +- compiler/rustc_const_eval/src/interpret/operand.rs | 2 +- compiler/rustc_hir_analysis/src/astconv/mod.rs | 2 +- .../src/constrained_generic_params.rs | 2 +- compiler/rustc_hir_typeck/src/method/suggest.rs | 2 +- compiler/rustc_hir_typeck/src/writeback.rs | 2 +- .../src/infer/canonical/canonicalizer.rs | 10 ++++------ compiler/rustc_infer/src/infer/combine.rs | 8 ++++---- .../src/infer/error_reporting/need_type_info.rs | 2 +- compiler/rustc_infer/src/infer/freshen.rs | 2 +- compiler/rustc_infer/src/infer/fudge.rs | 2 +- compiler/rustc_infer/src/infer/mod.rs | 2 +- compiler/rustc_infer/src/infer/nll_relate/mod.rs | 2 +- compiler/rustc_middle/src/infer/canonical.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 12 ++++++------ compiler/rustc_middle/src/ty/consts.rs | 13 ++++--------- compiler/rustc_middle/src/ty/flags.rs | 2 +- compiler/rustc_middle/src/ty/fold.rs | 4 ++-- compiler/rustc_middle/src/ty/opaque_types.rs | 2 +- compiler/rustc_middle/src/ty/print/pretty.rs | 6 +++--- compiler/rustc_middle/src/ty/relate.rs | 10 +++++----- compiler/rustc_middle/src/ty/structural_impls.rs | 6 +++--- compiler/rustc_middle/src/ty/walk.rs | 2 +- compiler/rustc_monomorphize/src/collector.rs | 2 +- compiler/rustc_privacy/src/lib.rs | 2 +- compiler/rustc_symbol_mangling/src/legacy.rs | 6 +++--- .../src/typeid/typeid_itanium_cxx_abi.rs | 6 +++--- compiler/rustc_symbol_mangling/src/v0.rs | 8 ++++---- .../rustc_trait_selection/src/traits/auto_trait.rs | 2 +- .../src/traits/const_evaluatable.rs | 2 +- .../rustc_trait_selection/src/traits/fulfill.rs | 2 +- .../rustc_trait_selection/src/traits/project.rs | 4 ++-- .../rustc_trait_selection/src/traits/select/mod.rs | 2 +- compiler/rustc_traits/src/chalk/db.rs | 2 +- compiler/rustc_traits/src/chalk/lowering.rs | 2 +- compiler/rustc_transmute/src/lib.rs | 2 +- compiler/rustc_ty_utils/src/consts.rs | 2 +- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/clean/utils.rs | 2 +- 41 files changed, 74 insertions(+), 81 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index 077f33bb99cf7..07e97353badab 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/src/constant.rs @@ -74,7 +74,7 @@ pub(crate) fn eval_mir_constant<'tcx>( ConstantKind::Ty(const_) => match const_.kind() { ty::ConstKind::Unevaluated(uv) => uv.expand(), ty::ConstKind::Value(val) => { - return Some((fx.tcx.valtree_to_const_val((const_.ty(), val)), const_.ty())); + return Some((fx.tcx.valtree_to_const_val((const_.ty, val)), const_.ty)); } err => span_bug!( constant.span, diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index 8647fbace2a75..72f9c4730d1d0 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -639,14 +639,14 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S ty::ConstKind::Param(param) => { write!(output, "{}", param.name) } - _ => match ct.ty().kind() { + _ => match ct.ty.kind() { ty::Int(ity) => { - let bits = ct.eval_bits(tcx, ty::ParamEnv::reveal_all(), ct.ty()); + let bits = ct.eval_bits(tcx, ty::ParamEnv::reveal_all(), ct.ty); let val = Integer::from_int_ty(&tcx, *ity).size().sign_extend(bits) as i128; write!(output, "{}", val) } ty::Uint(_) => { - let val = ct.eval_bits(tcx, ty::ParamEnv::reveal_all(), ct.ty()); + let val = ct.eval_bits(tcx, ty::ParamEnv::reveal_all(), ct.ty); write!(output, "{}", val) } ty::Bool => { diff --git a/compiler/rustc_codegen_ssa/src/mir/constant.rs b/compiler/rustc_codegen_ssa/src/mir/constant.rs index 53ff3c2409626..f1536c054e9e3 100644 --- a/compiler/rustc_codegen_ssa/src/mir/constant.rs +++ b/compiler/rustc_codegen_ssa/src/mir/constant.rs @@ -29,7 +29,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { mir::ConstantKind::Ty(ct) => match ct.kind() { ty::ConstKind::Unevaluated(uv) => uv.expand(), ty::ConstKind::Value(val) => { - return Ok(self.cx.tcx().valtree_to_const_val((ct.ty(), val))); + return Ok(self.cx.tcx().valtree_to_const_val((ct.ty, val))); } err => span_bug!( constant.span, diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 3eb2b3a0b1b63..37a00b496b946 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -592,7 +592,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let val = self.tcx.normalize_erasing_regions(self.param_env, *val); match val { mir::ConstantKind::Ty(ct) => { - let ty = ct.ty(); + let ty = ct.ty; let valtree = self.eval_ty_constant(ct, span)?; let const_val = self.tcx.valtree_to_const_val((ty, valtree)); self.const_val_to_op(const_val, ty, layout) diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index e744ed2dcc547..809efcbd8d1d0 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -1394,7 +1394,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { let references_self = match pred.skip_binder().term.unpack() { ty::TermKind::Ty(ty) => ty.walk().any(|arg| arg == dummy_self.into()), ty::TermKind::Const(c) => { - c.ty().walk().any(|arg| arg == dummy_self.into()) + c.ty.walk().any(|arg| arg == dummy_self.into()) } }; diff --git a/compiler/rustc_hir_analysis/src/constrained_generic_params.rs b/compiler/rustc_hir_analysis/src/constrained_generic_params.rs index 213b89fc7843c..5ca2093cf58d8 100644 --- a/compiler/rustc_hir_analysis/src/constrained_generic_params.rs +++ b/compiler/rustc_hir_analysis/src/constrained_generic_params.rs @@ -83,7 +83,7 @@ impl<'tcx> TypeVisitor<'tcx> for ParameterCollector { match c.kind() { ty::ConstKind::Unevaluated(..) if !self.include_nonconstraining => { // Constant expressions are not injective - return c.ty().visit_with(self); + return c.ty.visit_with(self); } ty::ConstKind::Param(data) => { self.parameters.push(Parameter::from(data)); diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index d0ea2b0e66475..de08646b50416 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -1121,7 +1121,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .into(), GenericArgKind::Const(arg) => self .next_const_var( - arg.ty(), + arg.ty, ConstVariableOrigin { span: rustc_span::DUMMY_SP, kind: ConstVariableOriginKind::MiscVariable, diff --git a/compiler/rustc_hir_typeck/src/writeback.rs b/compiler/rustc_hir_typeck/src/writeback.rs index 58ced6a1d3b4f..5f1ed9b1f42a9 100644 --- a/compiler/rustc_hir_typeck/src/writeback.rs +++ b/compiler/rustc_hir_typeck/src/writeback.rs @@ -793,7 +793,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> { debug!("Resolver::fold_const: input const `{:?}` not fully resolvable", ct); let e = self.report_error(ct); self.replaced_with_error = Some(e); - self.tcx().const_error_with_guaranteed(ct.ty(), e) + self.tcx().const_error_with_guaranteed(ct.ty, e) } } } diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index 3dc0d60b1eb0f..4c8facad27906 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -484,7 +484,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> { ui = ty::UniverseIndex::ROOT; } return self.canonicalize_const_var( - CanonicalVarInfo { kind: CanonicalVarKind::Const(ui, ct.ty()) }, + CanonicalVarInfo { kind: CanonicalVarKind::Const(ui, ct.ty) }, ct, ); } @@ -503,7 +503,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> { ty::ConstKind::Placeholder(placeholder) => { return self.canonicalize_const_var( CanonicalVarInfo { - kind: CanonicalVarKind::PlaceholderConst(placeholder, ct.ty()), + kind: CanonicalVarKind::PlaceholderConst(placeholder, ct.ty), }, ct, ); @@ -773,10 +773,8 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> { self.fold_const(bound_to) } else { let var = self.canonical_var(info, const_var.into()); - self.tcx().mk_const( - ty::ConstKind::Bound(self.binder_index, var), - self.fold_ty(const_var.ty()), - ) + self.tcx() + .mk_const(ty::ConstKind::Bound(self.binder_index, var), self.fold_ty(const_var.ty)) } } } diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index eec938cefbb70..fd6047234466f 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -753,7 +753,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> { origin: var_value.origin, val: ConstVariableValue::Unknown { universe: self.for_universe }, }); - Ok(self.tcx().mk_const_var(new_var_id, c.ty())) + Ok(self.tcx().mk_const_var(new_var_id, c.ty)) } } } @@ -767,7 +767,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> { )?; Ok(self.tcx().mk_const( ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }), - c.ty(), + c.ty, )) } _ => relate::super_relate_consts(self, c, c), @@ -975,7 +975,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> { }, }, ); - Ok(self.tcx().mk_const_var(new_var_id, c.ty())) + Ok(self.tcx().mk_const_var(new_var_id, c.ty)) } } } @@ -990,7 +990,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> { Ok(self.tcx().mk_const( ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }), - c.ty(), + c.ty, )) } _ => relate::super_relate_consts(self, c, c), diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index 7b3178e610fe4..a0324e9cfdb34 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -472,7 +472,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { .into(), GenericArgKind::Const(arg) => self .next_const_var( - arg.ty(), + arg.ty, ConstVariableOrigin { span: rustc_span::DUMMY_SP, kind: ConstVariableOriginKind::MiscVariable, diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index ff5d1a05a7062..0078d5f52f6b6 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -227,7 +227,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> { .probe_value(v) .val .known(); - self.freshen_const(opt_ct, ty::InferConst::Var(v), ty::InferConst::Fresh, ct.ty()) + self.freshen_const(opt_ct, ty::InferConst::Var(v), ty::InferConst::Fresh, ct.ty) } ty::ConstKind::Infer(ty::InferConst::Fresh(i)) => { if i >= self.const_freshen_count { diff --git a/compiler/rustc_infer/src/infer/fudge.rs b/compiler/rustc_infer/src/infer/fudge.rs index 6dd6c4e1f5ee8..70129e52f2069 100644 --- a/compiler/rustc_infer/src/infer/fudge.rs +++ b/compiler/rustc_infer/src/infer/fudge.rs @@ -235,7 +235,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for InferenceFudger<'a, 'tcx> { // Recreate it with a fresh variable here. let idx = (vid.index - self.const_vars.0.start.index) as usize; let origin = self.const_vars.1[idx]; - self.infcx.next_const_var(ct.ty(), origin) + self.infcx.next_const_var(ct.ty, origin) } else { ct } diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 2798477d1815d..5a5f0dabd550f 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -2072,7 +2072,7 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>( .into() } GenericArgKind::Const(ct) if ct.has_non_region_infer() || ct.has_non_region_param() => { - let ty = ct.ty(); + let ty = ct.ty; // If the type references param or infer, replace that too... if ty.has_non_region_param() || ty.has_non_region_infer() { bug!("const `{ct}`'s type should not reference params or types"); diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index 4f8460955c3de..ffd4dd57c93a1 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -1087,7 +1087,7 @@ where origin: var_value.origin, val: ConstVariableValue::Unknown { universe: self.universe }, }); - Ok(self.tcx().mk_const_var(new_var_id, a.ty())) + Ok(self.tcx().mk_const_var(new_var_id, a.ty)) } } } diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index 0331d764b38a1..f00cd0a5a40e3 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -345,7 +345,7 @@ impl<'tcx> CanonicalVarValues<'tcx> { GenericArgKind::Const(ct) => tcx .mk_const( ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_u32(i)), - ct.ty(), + ct.ty, ) .into(), }) diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 364c1b375ae5d..e02423c065786 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2239,7 +2239,7 @@ impl<'tcx> ConstantKind<'tcx> { #[inline(always)] pub fn ty(&self) -> Ty<'tcx> { match self { - ConstantKind::Ty(c) => c.ty(), + ConstantKind::Ty(c) => c.ty, ConstantKind::Val(_, ty) | ConstantKind::Unevaluated(_, ty) => *ty, } } @@ -2248,7 +2248,7 @@ impl<'tcx> ConstantKind<'tcx> { pub fn try_to_value(self, tcx: TyCtxt<'tcx>) -> Option> { match self { ConstantKind::Ty(c) => match c.kind() { - ty::ConstKind::Value(valtree) => Some(tcx.valtree_to_const_val((c.ty(), valtree))), + ty::ConstKind::Value(valtree) => Some(tcx.valtree_to_const_val((c.ty, valtree))), _ => None, }, ConstantKind::Val(val, _) => Some(val), @@ -2292,7 +2292,7 @@ impl<'tcx> ConstantKind<'tcx> { Self::Ty(c) => { if let Some(val) = c.kind().try_eval_for_mir(tcx, param_env) { match val { - Ok(val) => Self::Val(val, c.ty()), + Ok(val) => Self::Val(val, c.ty), Err(_) => Self::Ty(tcx.const_error(self.ty())), } } else { @@ -2582,10 +2582,10 @@ impl<'tcx> ConstantKind<'tcx> { pub fn from_const(c: ty::Const<'tcx>, tcx: TyCtxt<'tcx>) -> Self { match c.kind() { ty::ConstKind::Value(valtree) => { - let const_val = tcx.valtree_to_const_val((c.ty(), valtree)); - Self::Val(const_val, c.ty()) + let const_val = tcx.valtree_to_const_val((c.ty, valtree)); + Self::Val(const_val, c.ty) } - ty::ConstKind::Unevaluated(uv) => Self::Unevaluated(uv.expand(), c.ty()), + ty::ConstKind::Unevaluated(uv) => Self::Unevaluated(uv.expand(), c.ty), _ => Self::Ty(c), } } diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index b68843b5dca54..011274a0d73d5 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -32,7 +32,7 @@ impl<'tcx> fmt::Debug for Const<'tcx> { // This reflects what `Const` looked liked before `Interned` was // introduced. We print it like this to avoid having to update expected // output in a lot of tests. - write!(f, "Const {{ ty: {:?}, kind: {:?} }}", self.ty(), self.kind()) + write!(f, "Const {{ ty: {:?}, kind: {:?} }}", self.ty, self.kind()) } } @@ -47,11 +47,6 @@ pub struct ConstS<'tcx> { static_assert_size!(ConstS<'_>, 40); impl<'tcx> Const<'tcx> { - #[inline] - pub fn ty(self) -> Ty<'tcx> { - self.ty - } - #[inline] pub fn kind(self) -> ConstKind<'tcx> { self.kind @@ -206,7 +201,7 @@ impl<'tcx> Const<'tcx> { param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, ) -> Option { - assert_eq!(self.ty(), ty); + assert_eq!(self.ty, ty); let size = tcx.layout_of(param_env.with_reveal_all_normalized(tcx).and(ty)).ok()?.size; // if `ty` does not depend on generic parameters, use an empty param_env self.kind().eval(tcx, param_env).try_to_bits(size) @@ -228,8 +223,8 @@ impl<'tcx> Const<'tcx> { pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Const<'tcx> { if let Some(val) = self.kind().try_eval_for_typeck(tcx, param_env) { match val { - Ok(val) => Const::from_value(tcx, val, self.ty()), - Err(guar) => tcx.const_error_with_guaranteed(self.ty(), guar), + Ok(val) => Const::from_value(tcx, val, self.ty), + Err(guar) => tcx.const_error_with_guaranteed(self.ty, guar), } } else { // Either the constant isn't evaluatable or ValTree creation failed. diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index ee4b8f91c5487..c51df67c07b64 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -282,7 +282,7 @@ impl FlagComputation { } fn add_const(&mut self, c: ty::Const<'_>) { - self.add_ty(c.ty()); + self.add_ty(c.ty); match c.kind() { ty::ConstKind::Unevaluated(uv) => { self.add_substs(uv.substs); diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 2842b3c3102d2..5d8f0c8a5738c 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -436,7 +436,7 @@ where fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { match ct.kind() { ty::ConstKind::Bound(debruijn, bound_const) if debruijn == self.current_index => { - let ct = self.delegate.replace_const(bound_const, ct.ty()); + let ct = self.delegate.replace_const(bound_const, ct.ty); ty::fold::shift_vars(self.tcx, ct, self.current_index.as_u32()) } _ => ct.super_fold_with(self), @@ -731,7 +731,7 @@ impl<'tcx> TypeFolder<'tcx> for Shifter<'tcx> { ct } else { let debruijn = debruijn.shifted_in(self.amount); - self.tcx.mk_const(ty::ConstKind::Bound(debruijn, bound_ct), ct.ty()) + self.tcx.mk_const(ty::ConstKind::Bound(debruijn, bound_ct), ct.ty) } } else { ct.super_fold_with(self) diff --git a/compiler/rustc_middle/src/ty/opaque_types.rs b/compiler/rustc_middle/src/ty/opaque_types.rs index 98cd92007c2b2..3faee5c8854ab 100644 --- a/compiler/rustc_middle/src/ty/opaque_types.rs +++ b/compiler/rustc_middle/src/ty/opaque_types.rs @@ -208,7 +208,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> { }); } - self.tcx().const_error(ct.ty()) + self.tcx().const_error(ct.ty) } } } diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index c54edf10c2d8f..89efb045516c2 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -1195,7 +1195,7 @@ pub trait PrettyPrinter<'tcx>: define_scoped_cx!(self); if self.should_print_verbose() { - p!(write("Const({:?}: {:?})", ct.kind(), ct.ty())); + p!(write("Const({:?}: {:?})", ct.kind(), ct.ty)); return Ok(self); } @@ -1207,7 +1207,7 @@ pub trait PrettyPrinter<'tcx>: write!(this, "_")?; Ok(this) }, - |this| this.print_type(ct.ty()), + |this| this.print_type(ct.ty), ": ", )?; } else { @@ -1246,7 +1246,7 @@ pub trait PrettyPrinter<'tcx>: } ty::ConstKind::Param(ParamConst { name, .. }) => p!(write("{}", name)), ty::ConstKind::Value(value) => { - return self.pretty_print_const_valtree(value, ct.ty(), print_ty); + return self.pretty_print_const_valtree(value, ct.ty, print_ty); } ty::ConstKind::Bound(debruijn, bound_var) => { diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 3d47b71b7ce62..e3663480a38af 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -604,11 +604,11 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>( let a_ty; let b_ty; if relation.tcx().features().adt_const_params { - a_ty = tcx.normalize_erasing_regions(relation.param_env(), a.ty()); - b_ty = tcx.normalize_erasing_regions(relation.param_env(), b.ty()); + a_ty = tcx.normalize_erasing_regions(relation.param_env(), a.ty); + b_ty = tcx.normalize_erasing_regions(relation.param_env(), b.ty); } else { - a_ty = tcx.erase_regions(a.ty()); - b_ty = tcx.erase_regions(b.ty()); + a_ty = tcx.erase_regions(a.ty); + b_ty = tcx.erase_regions(b.ty); } if a_ty != b_ty { relation.tcx().sess.delay_span_bug( @@ -662,7 +662,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>( )?; return Ok(tcx.mk_const( ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def: au.def, substs }), - a.ty(), + a.ty, )); } _ => false, diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 64b4fd1176252..3950970992dd7 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -803,9 +803,9 @@ impl<'tcx> TypeSuperFoldable<'tcx> for ty::Const<'tcx> { self, folder: &mut F, ) -> Result { - let ty = self.ty().try_fold_with(folder)?; + let ty = self.ty.try_fold_with(folder)?; let kind = self.kind().try_fold_with(folder)?; - if ty != self.ty() || kind != self.kind() { + if ty != self.ty || kind != self.kind() { Ok(folder.tcx().mk_const(kind, ty)) } else { Ok(self) @@ -815,7 +815,7 @@ impl<'tcx> TypeSuperFoldable<'tcx> for ty::Const<'tcx> { impl<'tcx> TypeSuperVisitable<'tcx> for ty::Const<'tcx> { fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { - self.ty().visit_with(visitor)?; + self.ty.visit_with(visitor)?; self.kind().visit_with(visitor) } } diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index 91db9698c41b2..c4da75fccc391 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -205,7 +205,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) }, GenericArgKind::Lifetime(_) => {} GenericArgKind::Const(parent_ct) => { - stack.push(parent_ct.ty().into()); + stack.push(parent_ct.ty.into()); match parent_ct.kind() { ty::ConstKind::Infer(_) | ty::ConstKind::Param(_) diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 559ce227454de..15521008cf09c 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -760,7 +760,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { let val = match literal { mir::ConstantKind::Val(val, _) => val, mir::ConstantKind::Ty(ct) => match ct.kind() { - ty::ConstKind::Value(val) => self.tcx.valtree_to_const_val((ct.ty(), val)), + ty::ConstKind::Value(val) => self.tcx.valtree_to_const_val((ct.ty, val)), ty::ConstKind::Unevaluated(ct) => { debug!(?ct); let param_env = ty::ParamEnv::reveal_all(); diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 1d9ae539b60dd..b1f4de7222caf 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -284,7 +284,7 @@ where } fn visit_const(&mut self, c: Const<'tcx>) -> ControlFlow { - self.visit_ty(c.ty())?; + self.visit_ty(c.ty)?; let tcx = self.def_id_visitor.tcx(); if let Ok(Some(ct)) = AbstractConst::from_const(tcx, c) { walk_abstract_const(tcx, ct, |node| match node.root(tcx) { diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index c60a2f4671d6c..f79a4d6729c4d 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -259,15 +259,15 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> { fn print_const(self, ct: ty::Const<'tcx>) -> Result { // only print integers - match (ct.kind(), ct.ty().kind()) { + match (ct.kind(), ct.ty.kind()) { (ty::ConstKind::Value(ty::ValTree::Leaf(scalar)), ty::Int(_) | ty::Uint(_)) => { // The `pretty_print_const` formatting depends on -Zverbose // flag, so we cannot reuse it here. - let signed = matches!(ct.ty().kind(), ty::Int(_)); + let signed = matches!(ct.ty.kind(), ty::Int(_)); write!( self, "{:#?}", - ty::ConstInt::new(scalar, signed, ct.ty().is_ptr_sized_integral()) + ty::ConstInt::new(scalar, signed, ct.ty.is_ptr_sized_integral()) )?; } _ => self.write_str("_")?, diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs index 87128e0f893a2..196b968587470 100644 --- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs +++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs @@ -123,7 +123,7 @@ fn encode_const<'tcx>( let mut s = String::from('L'); // Element type - s.push_str(&encode_ty(tcx, c.ty(), dict, options)); + s.push_str(&encode_ty(tcx, c.ty, dict, options)); // The only allowed types of const parameters are bool, u8, u16, u32, u64, u128, usize i8, i16, // i32, i64, i128, isize, and char. The bool value false is encoded as 0 and true as 1. @@ -139,7 +139,7 @@ fn encode_const<'tcx>( } if let Some(scalar_int) = c.kind().try_to_scalar_int() { - let signed = c.ty().is_signed(); + let signed = c.ty.is_signed(); match scalar_int.size().bits() { 8 if signed => push_signed_value(&mut s, scalar_int.try_to_i8().unwrap(), 0), 16 if signed => push_signed_value(&mut s, scalar_int.try_to_i16().unwrap(), 0), @@ -156,7 +156,7 @@ fn encode_const<'tcx>( } }; } else { - bug!("encode_const: unexpected type `{:?}`", c.ty()); + bug!("encode_const: unexpected type `{:?}`", c.ty); } // Close the "L..E" pair diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index d1a2aee207dcd..fdecb0e07b2a0 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -591,7 +591,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { } let start = self.out.len(); - let ty = ct.ty(); + let ty = ct.ty; match ty.kind() { ty::Uint(_) | ty::Int(_) | ty::Bool | ty::Char => { @@ -650,7 +650,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { } _ => { let pointee_ty = ct - .ty() + .ty .builtin_deref(true) .expect("tried to dereference on non-ptr type") .ty; @@ -672,7 +672,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { Ok(this) }; - match *ct.ty().kind() { + match *ct.ty.kind() { ty::Array(..) | ty::Slice(_) => { self.push("A"); self = print_field_list(self)?; @@ -721,7 +721,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { } } _ => { - bug!("symbol_names: unsupported constant of type `{}` ({:?})", ct.ty(), ct); + bug!("symbol_names: unsupported constant of type `{}` ({:?})", ct.ty, ct); } } diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 78af187cd8f80..34c5e4b794048 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -797,7 +797,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { Some(obligation.cause.span), ) { Ok(Some(valtree)) => { - Ok(ty::Const::from_value(select.tcx(), valtree, c.ty())) + Ok(ty::Const::from_value(select.tcx(), valtree, c.ty)) } Ok(None) => { let tcx = self.tcx; diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index db3ddc9208ae2..ce682f9582cee 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -72,7 +72,7 @@ impl<'tcx> ConstUnifyCtxt<'tcx> { let b_ct = b_ct.eval(self.tcx, self.param_env); debug!("b_ct evaluated: {:?}", b_ct); - if a_ct.ty() != b_ct.ty() { + if a_ct.ty != b_ct.ty { return false; } diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index e7513255dc401..b3debf2794839 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -476,7 +476,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { match self.selcx.infcx().try_const_eval_resolve( obligation.param_env, unevaluated, - c.ty(), + c.ty, Some(obligation.cause.span), ) { Ok(val) => Ok(val), diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index f17d702d421bd..6745667e44c9a 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -818,7 +818,7 @@ impl<'tcx> TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> { let universe = self.universe_for(debruijn); let p = ty::PlaceholderConst { universe, name: bound_const }; self.mapped_consts.insert(p, bound_const); - self.infcx.tcx.mk_const(ty::ConstKind::Placeholder(p), ct.ty()) + self.infcx.tcx.mk_const(ty::ConstKind::Placeholder(p), ct.ty) } _ => ct.super_fold_with(self), } @@ -953,7 +953,7 @@ impl<'tcx> TypeFolder<'tcx> for PlaceholderReplacer<'_, 'tcx> { let db = ty::DebruijnIndex::from_usize( self.universe_indices.len() - index + self.current_index.as_usize() - 1, ); - self.tcx().mk_const(ty::ConstKind::Bound(db, *replace_var), ct.ty()) + self.tcx().mk_const(ty::ConstKind::Bound(db, *replace_var), ct.ty) } None => ct, } diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 9fe13fe296a16..35a236bc2bdbe 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -680,7 +680,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { match self.infcx.try_const_eval_resolve( obligation.param_env, unevaluated, - c.ty(), + c.ty, Some(obligation.cause.span), ) { Ok(val) => Ok(val), diff --git a/compiler/rustc_traits/src/chalk/db.rs b/compiler/rustc_traits/src/chalk/db.rs index 344c8b93c1704..dd948da44397a 100644 --- a/compiler/rustc_traits/src/chalk/db.rs +++ b/compiler/rustc_traits/src/chalk/db.rs @@ -757,7 +757,7 @@ fn binders_for<'tcx>( chalk_ir::VariableKind::Ty(chalk_ir::TyVariableKind::General) } ty::subst::GenericArgKind::Const(c) => { - chalk_ir::VariableKind::Const(c.ty().lower_into(interner)) + chalk_ir::VariableKind::Const(c.ty.lower_into(interner)) } }), ) diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 9931a7f32ef77..6fbeef0ccfa61 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -522,7 +522,7 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime LowerInto<'tcx, chalk_ir::Const>> for ty::Const<'tcx> { fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Const> { - let ty = self.ty().lower_into(interner); + let ty = self.ty.lower_into(interner); let value = match self.kind() { ty::ConstKind::Value(val) => { chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: val }) diff --git a/compiler/rustc_transmute/src/lib.rs b/compiler/rustc_transmute/src/lib.rs index 384d03106b1e8..611aeef55ef6b 100644 --- a/compiler/rustc_transmute/src/lib.rs +++ b/compiler/rustc_transmute/src/lib.rs @@ -131,7 +131,7 @@ mod rustc { }); } - let adt_def = c.ty().ty_adt_def()?; + let adt_def = c.ty.ty_adt_def()?; assert_eq!( tcx.require_lang_item(LangItem::TransmuteOpts, None), diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index cb41c4f94e2e6..ca5a6144e8592 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -28,7 +28,7 @@ pub(crate) fn destructure_const<'tcx>( _ => bug!("cannot destructure constant {:?}", const_), }; - let (fields, variant) = match const_.ty().kind() { + let (fields, variant) = match const_.ty.kind() { ty::Array(inner_ty, _) | ty::Slice(inner_ty) => { // construct the consts for the elements of the array/slice let field_consts = branches diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b5d4ab55b4a83..16f4766b0c04a 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -225,7 +225,7 @@ pub(crate) fn clean_middle_const<'tcx>( ) -> Constant { // FIXME: instead of storing the stringified expression, store `self` directly instead. Constant { - type_: clean_middle_ty(constant.ty(), cx, None), + type_: clean_middle_ty(constant.ty, cx, None), kind: ConstantKind::TyConst { expr: constant.to_string().into() }, } } diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 35e2720fdff89..f7bbda75dda50 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -244,7 +244,7 @@ pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String { } // array lengths are obviously usize ty::ConstKind::Value(ty::ValTree::Leaf(scalar)) - if *n.ty().kind() == ty::Uint(ty::UintTy::Usize) => + if *n.ty.kind() == ty::Uint(ty::UintTy::Usize) => { scalar.to_string() } From 08f38c4c6ff2da1b605f5ee8adebea51f0c7e735 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 25 Nov 2022 15:30:55 +0000 Subject: [PATCH 3/4] Remove Const::kind method in favor of field access via the Deref impl --- .../src/region_infer/opaque_types.rs | 2 +- compiler/rustc_borrowck/src/type_check/mod.rs | 2 +- compiler/rustc_codegen_cranelift/src/base.rs | 2 +- .../rustc_codegen_cranelift/src/constant.rs | 2 +- .../src/debuginfo/type_names.rs | 6 +++--- .../rustc_codegen_ssa/src/mir/constant.rs | 2 +- .../rustc_const_eval/src/interpret/operand.rs | 2 +- .../rustc_const_eval/src/interpret/util.rs | 2 +- .../src/transform/check_consts/qualifs.rs | 2 +- .../rustc_hir_analysis/src/check/wfcheck.rs | 2 +- .../src/collect/predicates_of.rs | 2 +- .../src/constrained_generic_params.rs | 2 +- .../src/variance/constraints.rs | 2 +- .../src/infer/canonical/canonicalizer.rs | 2 +- .../src/infer/canonical/query_response.rs | 2 +- compiler/rustc_infer/src/infer/combine.rs | 6 +++--- .../infer/error_reporting/need_type_info.rs | 6 +++--- compiler/rustc_infer/src/infer/freshen.rs | 2 +- compiler/rustc_infer/src/infer/fudge.rs | 2 +- compiler/rustc_infer/src/infer/mod.rs | 4 ++-- .../rustc_infer/src/infer/nll_relate/mod.rs | 4 ++-- compiler/rustc_infer/src/infer/resolve.rs | 2 +- compiler/rustc_lint/src/builtin.rs | 2 +- compiler/rustc_middle/src/mir/mod.rs | 10 ++++----- compiler/rustc_middle/src/mir/pretty.rs | 2 +- compiler/rustc_middle/src/ty/_match.rs | 2 +- .../rustc_middle/src/ty/abstract_const.rs | 2 +- compiler/rustc_middle/src/ty/consts.rs | 21 +++++++------------ compiler/rustc_middle/src/ty/context.rs | 2 +- compiler/rustc_middle/src/ty/diagnostics.rs | 2 +- compiler/rustc_middle/src/ty/error.rs | 2 +- compiler/rustc_middle/src/ty/fast_reject.rs | 6 +++--- compiler/rustc_middle/src/ty/flags.rs | 2 +- compiler/rustc_middle/src/ty/fold.rs | 4 ++-- .../ty/inhabitedness/inhabited_predicate.rs | 2 +- .../rustc_middle/src/ty/inhabitedness/mod.rs | 2 +- compiler/rustc_middle/src/ty/opaque_types.rs | 2 +- compiler/rustc_middle/src/ty/print/pretty.rs | 12 +++++------ compiler/rustc_middle/src/ty/relate.rs | 2 +- .../rustc_middle/src/ty/structural_impls.rs | 6 +++--- compiler/rustc_middle/src/ty/subst.rs | 2 +- compiler/rustc_middle/src/ty/util.rs | 6 +++--- compiler/rustc_middle/src/ty/visit.rs | 6 +++--- compiler/rustc_middle/src/ty/walk.rs | 2 +- .../src/thir/pattern/deconstruct_pat.rs | 2 +- .../rustc_mir_build/src/thir/pattern/mod.rs | 2 +- .../rustc_mir_transform/src/const_prop.rs | 2 +- .../src/required_consts.rs | 2 +- compiler/rustc_monomorphize/src/collector.rs | 2 +- .../rustc_monomorphize/src/polymorphize.rs | 4 ++-- compiler/rustc_symbol_mangling/src/legacy.rs | 6 +++--- .../src/typeid/typeid_itanium_cxx_abi.rs | 6 +++--- compiler/rustc_symbol_mangling/src/v0.rs | 6 +++--- .../src/traits/auto_trait.rs | 2 +- .../src/traits/const_evaluatable.rs | 4 ++-- .../src/traits/error_reporting/mod.rs | 2 +- .../error_reporting/on_unimplemented.rs | 2 +- .../src/traits/fulfill.rs | 4 ++-- .../rustc_trait_selection/src/traits/mod.rs | 2 +- .../src/traits/project.rs | 4 ++-- .../src/traits/query/normalize.rs | 2 +- .../src/traits/select/confirmation.rs | 2 +- .../src/traits/select/mod.rs | 4 ++-- .../rustc_trait_selection/src/traits/wf.rs | 4 ++-- compiler/rustc_traits/src/chalk/lowering.rs | 2 +- compiler/rustc_ty_utils/src/consts.rs | 2 +- src/librustdoc/clean/utils.rs | 2 +- .../clippy_lints/src/large_const_arrays.rs | 2 +- .../clippy_lints/src/large_stack_arrays.rs | 2 +- .../src/only_used_in_recursion.rs | 2 +- src/tools/clippy/clippy_utils/src/consts.rs | 4 ++-- 71 files changed, 117 insertions(+), 122 deletions(-) diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index d82d4cc39fb1c..3285965731b44 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -381,7 +381,7 @@ fn check_opaque_type_parameter_valid( GenericArgKind::Lifetime(lt) => { matches!(*lt, ty::ReEarlyBound(_) | ty::ReFree(_)) } - GenericArgKind::Const(ct) => matches!(ct.kind(), ty::ConstKind::Param(_)), + GenericArgKind::Const(ct) => matches!(ct.kind, ty::ConstKind::Param(_)), }; if arg_is_param { diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index b268eac97d0b0..878e06b2d41e3 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -353,7 +353,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { } else { let tcx = self.tcx(); let maybe_uneval = match constant.literal { - ConstantKind::Ty(ct) => match ct.kind() { + ConstantKind::Ty(ct) => match ct.kind { ty::ConstKind::Unevaluated(_) => { bug!("should not encounter unevaluated ConstantKind::Ty here, got {:?}", ct) } diff --git a/compiler/rustc_codegen_cranelift/src/base.rs b/compiler/rustc_codegen_cranelift/src/base.rs index 1db44502742e9..f697b70ce2819 100644 --- a/compiler/rustc_codegen_cranelift/src/base.rs +++ b/compiler/rustc_codegen_cranelift/src/base.rs @@ -722,7 +722,7 @@ fn codegen_stmt<'tcx>( let times = fx .monomorphize(times) .eval(fx.tcx, ParamEnv::reveal_all()) - .kind() + .kind .try_to_bits(fx.tcx.data_layout.pointer_size) .unwrap(); if operand.layout().size.bytes() == 0 { diff --git a/compiler/rustc_codegen_cranelift/src/constant.rs b/compiler/rustc_codegen_cranelift/src/constant.rs index 07e97353badab..eb55b769c1ac6 100644 --- a/compiler/rustc_codegen_cranelift/src/constant.rs +++ b/compiler/rustc_codegen_cranelift/src/constant.rs @@ -71,7 +71,7 @@ pub(crate) fn eval_mir_constant<'tcx>( ) -> Option<(ConstValue<'tcx>, Ty<'tcx>)> { let constant_kind = fx.monomorphize(constant.literal); let uv = match constant_kind { - ConstantKind::Ty(const_) => match const_.kind() { + ConstantKind::Ty(const_) => match const_.kind { ty::ConstKind::Unevaluated(uv) => uv.expand(), ty::ConstKind::Value(val) => { return Some((fx.tcx.valtree_to_const_val((const_.ty, val)), const_.ty)); diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index 72f9c4730d1d0..d7fdae00193f3 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -178,7 +178,7 @@ fn push_debuginfo_type_name<'tcx>( if cpp_like_debuginfo { output.push_str("array$<"); push_debuginfo_type_name(tcx, inner_type, true, output, visited); - match len.kind() { + match len.kind { ty::ConstKind::Param(param) => write!(output, ",{}>", param.name).unwrap(), _ => write!(output, ",{}>", len.eval_usize(tcx, ty::ParamEnv::reveal_all())) .unwrap(), @@ -186,7 +186,7 @@ fn push_debuginfo_type_name<'tcx>( } else { output.push('['); push_debuginfo_type_name(tcx, inner_type, true, output, visited); - match len.kind() { + match len.kind { ty::ConstKind::Param(param) => write!(output, "; {}]", param.name).unwrap(), _ => write!(output, "; {}]", len.eval_usize(tcx, ty::ParamEnv::reveal_all())) .unwrap(), @@ -635,7 +635,7 @@ fn push_generic_params_internal<'tcx>( } fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut String) { - match ct.kind() { + match ct.kind { ty::ConstKind::Param(param) => { write!(output, "{}", param.name) } diff --git a/compiler/rustc_codegen_ssa/src/mir/constant.rs b/compiler/rustc_codegen_ssa/src/mir/constant.rs index f1536c054e9e3..38b8613ca8d5c 100644 --- a/compiler/rustc_codegen_ssa/src/mir/constant.rs +++ b/compiler/rustc_codegen_ssa/src/mir/constant.rs @@ -26,7 +26,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ) -> Result, ErrorHandled> { let ct = self.monomorphize(constant.literal); let uv = match ct { - mir::ConstantKind::Ty(ct) => match ct.kind() { + mir::ConstantKind::Ty(ct) => match ct.kind { ty::ConstKind::Unevaluated(uv) => uv.expand(), ty::ConstKind::Value(val) => { return Ok(self.cx.tcx().valtree_to_const_val((ct.ty, val))); diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 37a00b496b946..d02656dc272f1 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -557,7 +557,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { val: ty::Const<'tcx>, span: Option, ) -> InterpResult<'tcx, ValTree<'tcx>> { - Ok(match val.kind() { + Ok(match val.kind { ty::ConstKind::Param(_) | ty::ConstKind::Placeholder(..) => { throw_inval!(TooGeneric) } diff --git a/compiler/rustc_const_eval/src/interpret/util.rs b/compiler/rustc_const_eval/src/interpret/util.rs index 2bc521d5bbe0b..a2e7dfa10fece 100644 --- a/compiler/rustc_const_eval/src/interpret/util.rs +++ b/compiler/rustc_const_eval/src/interpret/util.rs @@ -57,7 +57,7 @@ where } fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow { - match c.kind() { + match c.kind { ty::ConstKind::Param(..) => ControlFlow::Break(FoundParam), _ => c.super_visit_with(self), } diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs index e7b3df9b7288b..d761150d2c00e 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs @@ -348,7 +348,7 @@ where // way for type and mir constants. let uneval = match constant.literal { ConstantKind::Ty(ct) - if matches!(ct.kind(), ty::ConstKind::Param(_) | ty::ConstKind::Error(_)) => + if matches!(ct.kind, ty::ConstKind::Param(_) | ty::ConstKind::Error(_)) => { None } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 7119f3a238697..db6607ff3dcdb 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1417,7 +1417,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id } fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow { - if let ty::ConstKind::Param(param) = c.kind() { + if let ty::ConstKind::Param(param) = c.kind { self.params.insert(param.index); } c.super_visit_with(self) diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index c3f1bb457f701..fe20265386661 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -336,7 +336,7 @@ fn const_evaluatable_predicates_of<'tcx>( impl<'tcx> intravisit::Visitor<'tcx> for ConstCollector<'tcx> { fn visit_anon_const(&mut self, c: &'tcx hir::AnonConst) { let ct = ty::Const::from_anon_const(self.tcx, c.def_id); - if let ty::ConstKind::Unevaluated(_) = ct.kind() { + if let ty::ConstKind::Unevaluated(_) = ct.kind { let span = self.tcx.def_span(c.def_id); self.preds.insert(( ty::Binder::dummy(ty::PredicateKind::ConstEvaluatable(ct)) diff --git a/compiler/rustc_hir_analysis/src/constrained_generic_params.rs b/compiler/rustc_hir_analysis/src/constrained_generic_params.rs index 5ca2093cf58d8..b41bc09538b11 100644 --- a/compiler/rustc_hir_analysis/src/constrained_generic_params.rs +++ b/compiler/rustc_hir_analysis/src/constrained_generic_params.rs @@ -80,7 +80,7 @@ impl<'tcx> TypeVisitor<'tcx> for ParameterCollector { } fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow { - match c.kind() { + match c.kind { ty::ConstKind::Unevaluated(..) if !self.include_nonconstraining => { // Constant expressions are not injective return c.ty.visit_with(self); diff --git a/compiler/rustc_hir_analysis/src/variance/constraints.rs b/compiler/rustc_hir_analysis/src/variance/constraints.rs index 6ce0c18bf45f1..4242acb12e04a 100644 --- a/compiler/rustc_hir_analysis/src/variance/constraints.rs +++ b/compiler/rustc_hir_analysis/src/variance/constraints.rs @@ -368,7 +368,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { ) { debug!("add_constraints_from_const(c={:?}, variance={:?})", c, variance); - match &c.kind() { + match &c.kind { ty::ConstKind::Unevaluated(uv) => { self.add_constraints_from_invariant_substs(current, uv.substs, variance); } diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index 4c8facad27906..62751d2723c4d 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -467,7 +467,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> { } fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { - match ct.kind() { + match ct.kind { ty::ConstKind::Infer(InferConst::Var(vid)) => { debug!("canonical: const var found with vid {:?}", vid); match self.infcx.probe_const_var(vid) { diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index b4a427a5d419a..f8e9f5979ea61 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -466,7 +466,7 @@ impl<'tcx> InferCtxt<'tcx> { } } GenericArgKind::Const(result_value) => { - if let ty::ConstKind::Bound(debrujin, b) = result_value.kind() { + if let ty::ConstKind::Bound(debrujin, b) = result_value.kind { // ...in which case we would set `canonical_vars[0]` to `Some(const X)`. // We only allow a `ty::INNERMOST` index in substitutions. diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index fd6047234466f..afa80aeaeafd2 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -142,7 +142,7 @@ impl<'tcx> InferCtxt<'tcx> { let a_is_expected = relation.a_is_expected(); - match (a.kind(), b.kind()) { + match (a.kind, b.kind) { ( ty::ConstKind::Infer(InferConst::Var(a_vid)), ty::ConstKind::Infer(InferConst::Var(b_vid)), @@ -735,7 +735,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> { ) -> RelateResult<'tcx, ty::Const<'tcx>> { assert_eq!(c, c2); // we are abusing TypeRelation here; both LHS and RHS ought to be == - match c.kind() { + match c.kind { ty::ConstKind::Infer(InferConst::Var(vid)) => { let mut inner = self.infcx.inner.borrow_mut(); let variable_table = &mut inner.const_unification_table(); @@ -941,7 +941,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> { ) -> RelateResult<'tcx, ty::Const<'tcx>> { debug_assert_eq!(c, _c); - match c.kind() { + match c.kind { ty::ConstKind::Infer(InferConst::Var(vid)) => { // Check if the current unification would end up // unifying `target_vid` with a const which contains diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs index a0324e9cfdb34..c192dc1089fa6 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs @@ -270,7 +270,7 @@ impl<'tcx> InferCtxt<'tcx> { } } GenericArgKind::Const(ct) => { - if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.kind() { + if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.kind { let origin = self.inner.borrow_mut().const_unification_table().probe_value(vid).origin; if let ConstVariableOriginKind::ConstParameterDefinition(name, def_id) = @@ -830,7 +830,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { } (GenericArgKind::Const(inner_ct), GenericArgKind::Const(target_ct)) => { use ty::InferConst::*; - match (inner_ct.kind(), target_ct.kind()) { + match (inner_ct.kind, target_ct.kind) { (ty::ConstKind::Infer(Var(a_vid)), ty::ConstKind::Infer(Var(b_vid))) => self .infcx .inner @@ -870,7 +870,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> { } } GenericArgKind::Const(ct) => { - if matches!(ct.kind(), ty::ConstKind::Unevaluated(..)) { + if matches!(ct.kind, ty::ConstKind::Unevaluated(..)) { // You can't write the generic arguments for // unevaluated constants. walker.skip_current_subtree(); diff --git a/compiler/rustc_infer/src/infer/freshen.rs b/compiler/rustc_infer/src/infer/freshen.rs index 0078d5f52f6b6..1baadbc02cde8 100644 --- a/compiler/rustc_infer/src/infer/freshen.rs +++ b/compiler/rustc_infer/src/infer/freshen.rs @@ -217,7 +217,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> { } fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { - match ct.kind() { + match ct.kind { ty::ConstKind::Infer(ty::InferConst::Var(v)) => { let opt_ct = self .infcx diff --git a/compiler/rustc_infer/src/infer/fudge.rs b/compiler/rustc_infer/src/infer/fudge.rs index 70129e52f2069..7a55b7a8c04f5 100644 --- a/compiler/rustc_infer/src/infer/fudge.rs +++ b/compiler/rustc_infer/src/infer/fudge.rs @@ -229,7 +229,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for InferenceFudger<'a, 'tcx> { } fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { - if let ty::ConstKind::Infer(ty::InferConst::Var(vid)) = ct.kind() { + if let ty::ConstKind::Infer(ty::InferConst::Var(vid)) = ct.kind { if self.const_vars.0.contains(&vid) { // This variable was created during the fudging. // Recreate it with a fresh variable here. diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index 5a5f0dabd550f..b9bc0da67f34d 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -1849,7 +1849,7 @@ impl<'tcx> TyOrConstInferVar<'tcx> { /// Tries to extract an inference variable from a constant, returns `None` /// for constants other than `ty::ConstKind::Infer(_)` (or `InferConst::Fresh`). fn maybe_from_const(ct: ty::Const<'tcx>) -> Option { - match ct.kind() { + match ct.kind { ty::ConstKind::Infer(InferConst::Var(v)) => Some(TyOrConstInferVar::Const(v)), _ => None, } @@ -1928,7 +1928,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for ShallowResolver<'a, 'tcx> { } fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { - if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.kind() { + if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.kind { self.infcx .inner .borrow_mut() diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index ffd4dd57c93a1..e38b5f657f22d 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -680,7 +680,7 @@ where b = self.infcx.shallow_resolve(b); } - match b.kind() { + match b.kind { ty::ConstKind::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => { // Forbid inference variables in the RHS. self.infcx.tcx.sess.delay_span_bug( @@ -1072,7 +1072,7 @@ where a: ty::Const<'tcx>, _: ty::Const<'tcx>, ) -> RelateResult<'tcx, ty::Const<'tcx>> { - match a.kind() { + match a.kind { ty::ConstKind::Infer(InferConst::Var(_)) if D::forbid_inference_vars() => { bug!("unexpected inference variable encountered in NLL generalization: {:?}", a); } diff --git a/compiler/rustc_infer/src/infer/resolve.rs b/compiler/rustc_infer/src/infer/resolve.rs index 4db4ff2388d77..d292b2bf1abe3 100644 --- a/compiler/rustc_infer/src/infer/resolve.rs +++ b/compiler/rustc_infer/src/infer/resolve.rs @@ -217,7 +217,7 @@ impl<'a, 'tcx> FallibleTypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> { Ok(c) // micro-optimize -- if there is nothing in this const that this fold affects... } else { let c = self.infcx.shallow_resolve(c); - match c.kind() { + match c.kind { ty::ConstKind::Infer(InferConst::Var(vid)) => { return Err(FixupError::UnresolvedConst(vid)); } diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index ada3c3b67fb05..8de64e8d4f2b1 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -2896,7 +2896,7 @@ impl ClashingExternDeclarations { } (Array(a_ty, a_const), Array(b_ty, b_const)) => { // For arrays, we also check the constness of the type. - a_const.kind() == b_const.kind() + a_const.kind == b_const.kind && structurally_same_type_impl(seen_types, cx, *a_ty, *b_ty, ckind) } (Slice(a_ty), Slice(b_ty)) => { diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index e02423c065786..51dda4bcfbf87 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2247,7 +2247,7 @@ impl<'tcx> ConstantKind<'tcx> { #[inline] pub fn try_to_value(self, tcx: TyCtxt<'tcx>) -> Option> { match self { - ConstantKind::Ty(c) => match c.kind() { + ConstantKind::Ty(c) => match c.kind { ty::ConstKind::Value(valtree) => Some(tcx.valtree_to_const_val((c.ty, valtree))), _ => None, }, @@ -2259,7 +2259,7 @@ impl<'tcx> ConstantKind<'tcx> { #[inline] pub fn try_to_scalar(self) -> Option { match self { - ConstantKind::Ty(c) => match c.kind() { + ConstantKind::Ty(c) => match c.kind { ty::ConstKind::Value(valtree) => match valtree { ty::ValTree::Leaf(scalar_int) => Some(Scalar::Int(scalar_int)), ty::ValTree::Branch(_) => None, @@ -2290,7 +2290,7 @@ impl<'tcx> ConstantKind<'tcx> { pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self { match self { Self::Ty(c) => { - if let Some(val) = c.kind().try_eval_for_mir(tcx, param_env) { + if let Some(val) = c.kind.try_eval_for_mir(tcx, param_env) { match val { Ok(val) => Self::Val(val, c.ty), Err(_) => Self::Ty(tcx.const_error(self.ty())), @@ -2580,7 +2580,7 @@ impl<'tcx> ConstantKind<'tcx> { } pub fn from_const(c: ty::Const<'tcx>, tcx: TyCtxt<'tcx>) -> Self { - match c.kind() { + match c.kind { ty::ConstKind::Value(valtree) => { let const_val = tcx.valtree_to_const_val((c.ty, valtree)); Self::Val(const_val, c.ty) @@ -2902,7 +2902,7 @@ fn pretty_print_const_value<'tcx>( } } (ConstValue::ByRef { alloc, offset }, ty::Array(t, n)) if *t == u8_type => { - let n = n.kind().try_to_bits(tcx.data_layout.pointer_size).unwrap(); + let n = n.kind.try_to_bits(tcx.data_layout.pointer_size).unwrap(); // cast is ok because we already checked for pointer size (32 or 64 bit) above let range = AllocRange { start: offset, size: Size::from_bytes(n) }; let byte_str = alloc.inner().get_bytes_strip_provenance(&tcx, range).unwrap(); diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs index 2b3f2c0241189..86a8433418f98 100644 --- a/compiler/rustc_middle/src/mir/pretty.rs +++ b/compiler/rustc_middle/src/mir/pretty.rs @@ -462,7 +462,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> { }; let val = match literal { - ConstantKind::Ty(ct) => match ct.kind() { + ConstantKind::Ty(ct) => match ct.kind { ty::ConstKind::Param(p) => format!("Param({})", p), ty::ConstKind::Unevaluated(uv) => { format!( diff --git a/compiler/rustc_middle/src/ty/_match.rs b/compiler/rustc_middle/src/ty/_match.rs index cd147d7e55813..f11644cb4b08c 100644 --- a/compiler/rustc_middle/src/ty/_match.rs +++ b/compiler/rustc_middle/src/ty/_match.rs @@ -105,7 +105,7 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> { return Ok(a); } - match (a.kind(), b.kind()) { + match (a.kind, b.kind) { (_, ty::ConstKind::Infer(InferConst::Fresh(_))) => { return Ok(a); } diff --git a/compiler/rustc_middle/src/ty/abstract_const.rs b/compiler/rustc_middle/src/ty/abstract_const.rs index e5bcd5fb27aa7..2bb6be352a621 100644 --- a/compiler/rustc_middle/src/ty/abstract_const.rs +++ b/compiler/rustc_middle/src/ty/abstract_const.rs @@ -41,7 +41,7 @@ impl<'tcx> AbstractConst<'tcx> { tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, ) -> Result>, ErrorGuaranteed> { - match ct.kind() { + match ct.kind { ty::ConstKind::Unevaluated(uv) => AbstractConst::new(tcx, uv), ty::ConstKind::Error(reported) => Err(reported), _ => Ok(None), diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 011274a0d73d5..0192e30ec2430 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -32,7 +32,7 @@ impl<'tcx> fmt::Debug for Const<'tcx> { // This reflects what `Const` looked liked before `Interned` was // introduced. We print it like this to avoid having to update expected // output in a lot of tests. - write!(f, "Const {{ ty: {:?}, kind: {:?} }}", self.ty, self.kind()) + write!(f, "Const {{ ty: {:?}, kind: {:?} }}", self.ty, self.kind) } } @@ -47,11 +47,6 @@ pub struct ConstS<'tcx> { static_assert_size!(ConstS<'_>, 40); impl<'tcx> Const<'tcx> { - #[inline] - pub fn kind(self) -> ConstKind<'tcx> { - self.kind - } - /// Literals and const generic parameters are eagerly converted to a constant, everything else /// becomes `Unevaluated`. pub fn from_anon_const(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Self { @@ -151,9 +146,9 @@ impl<'tcx> Const<'tcx> { /// Panics if self.kind != ty::ConstKind::Value pub fn to_valtree(self) -> ty::ValTree<'tcx> { - match self.kind() { + match self.kind { ty::ConstKind::Value(valtree) => valtree, - _ => bug!("expected ConstKind::Value, got {:?}", self.kind()), + _ => bug!("expected ConstKind::Value, got {:?}", self.kind), } } @@ -204,24 +199,24 @@ impl<'tcx> Const<'tcx> { assert_eq!(self.ty, ty); let size = tcx.layout_of(param_env.with_reveal_all_normalized(tcx).and(ty)).ok()?.size; // if `ty` does not depend on generic parameters, use an empty param_env - self.kind().eval(tcx, param_env).try_to_bits(size) + self.kind.eval(tcx, param_env).try_to_bits(size) } #[inline] pub fn try_eval_bool(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Option { - self.kind().eval(tcx, param_env).try_to_bool() + self.kind.eval(tcx, param_env).try_to_bool() } #[inline] pub fn try_eval_usize(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Option { - self.kind().eval(tcx, param_env).try_to_machine_usize(tcx) + self.kind.eval(tcx, param_env).try_to_machine_usize(tcx) } #[inline] /// Tries to evaluate the constant if it is `Unevaluated`. If that doesn't succeed, return the /// unevaluated constant. pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Const<'tcx> { - if let Some(val) = self.kind().try_eval_for_typeck(tcx, param_env) { + if let Some(val) = self.kind.try_eval_for_typeck(tcx, param_env) { match val { Ok(val) => Const::from_value(tcx, val, self.ty), Err(guar) => tcx.const_error_with_guaranteed(self.ty, guar), @@ -247,7 +242,7 @@ impl<'tcx> Const<'tcx> { } pub fn is_ct_infer(self) -> bool { - matches!(self.kind(), ty::ConstKind::Infer(_)) + matches!(self.kind, ty::ConstKind::Infer(_)) } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index b5327ad0cecc6..6e690fa6325fb 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -899,7 +899,7 @@ impl<'tcx> CanonicalUserType<'tcx> { _ => false, }, - GenericArgKind::Const(ct) => match ct.kind() { + GenericArgKind::Const(ct) => match ct.kind { ty::ConstKind::Bound(debruijn, b) => { // We only allow a `ty::INNERMOST` index in substitutions. assert_eq!(debruijn, ty::INNERMOST); diff --git a/compiler/rustc_middle/src/ty/diagnostics.rs b/compiler/rustc_middle/src/ty/diagnostics.rs index 69f50df62350f..3caa2a3455b33 100644 --- a/compiler/rustc_middle/src/ty/diagnostics.rs +++ b/compiler/rustc_middle/src/ty/diagnostics.rs @@ -493,7 +493,7 @@ impl<'tcx> TypeVisitor<'tcx> for IsSuggestableVisitor<'tcx> { } fn visit_const(&mut self, c: Const<'tcx>) -> ControlFlow { - match c.kind() { + match c.kind { ConstKind::Infer(InferConst::Var(_)) if self.infer_suggestable => {} ConstKind::Infer(..) diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index a61f41b9c580f..101ba6722983b 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -271,7 +271,7 @@ impl<'tcx> Ty<'tcx> { } let n = tcx.lift(n).unwrap(); - if let ty::ConstKind::Value(v) = n.kind() { + if let ty::ConstKind::Value(v) = n.kind { if let Some(n) = v.try_to_machine_usize(tcx) { return format!("array of {} element{}", n, pluralize!(n)).into(); } diff --git a/compiler/rustc_middle/src/ty/fast_reject.rs b/compiler/rustc_middle/src/ty/fast_reject.rs index 1ee4985cf8de0..312c9fe449701 100644 --- a/compiler/rustc_middle/src/ty/fast_reject.rs +++ b/compiler/rustc_middle/src/ty/fast_reject.rs @@ -355,7 +355,7 @@ impl DeepRejectCtxt { } pub fn consts_may_unify(self, obligation_ct: ty::Const<'_>, impl_ct: ty::Const<'_>) -> bool { - match impl_ct.kind() { + match impl_ct.kind { ty::ConstKind::Param(_) | ty::ConstKind::Unevaluated(_) | ty::ConstKind::Error(_) => { return true; } @@ -365,8 +365,8 @@ impl DeepRejectCtxt { } } - let k = impl_ct.kind(); - match obligation_ct.kind() { + let k = impl_ct.kind; + match obligation_ct.kind { ty::ConstKind::Param(_) => match self.treat_obligation_params { TreatParams::AsPlaceholder => false, TreatParams::AsInfer => true, diff --git a/compiler/rustc_middle/src/ty/flags.rs b/compiler/rustc_middle/src/ty/flags.rs index c51df67c07b64..26e4393ae7445 100644 --- a/compiler/rustc_middle/src/ty/flags.rs +++ b/compiler/rustc_middle/src/ty/flags.rs @@ -283,7 +283,7 @@ impl FlagComputation { fn add_const(&mut self, c: ty::Const<'_>) { self.add_ty(c.ty); - match c.kind() { + match c.kind { ty::ConstKind::Unevaluated(uv) => { self.add_substs(uv.substs); self.add_flags(TypeFlags::HAS_CT_PROJECTION); diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 5d8f0c8a5738c..8d5eef3cb230f 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -434,7 +434,7 @@ where } fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { - match ct.kind() { + match ct.kind { ty::ConstKind::Bound(debruijn, bound_const) if debruijn == self.current_index => { let ct = self.delegate.replace_const(bound_const, ct.ty); ty::fold::shift_vars(self.tcx, ct, self.current_index.as_u32()) @@ -726,7 +726,7 @@ impl<'tcx> TypeFolder<'tcx> for Shifter<'tcx> { } fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { - if let ty::ConstKind::Bound(debruijn, bound_ct) = ct.kind() { + if let ty::ConstKind::Bound(debruijn, bound_ct) = ct.kind { if self.amount == 0 || debruijn < self.current_index { ct } else { diff --git a/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs b/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs index 33f72729798dc..8889ff4d349e5 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/inhabited_predicate.rs @@ -159,7 +159,7 @@ impl<'tcx> InhabitedPredicate<'tcx> { match self { Self::ConstIsZero(c) => { let c = ty::EarlyBinder(c).subst(tcx, substs); - let pred = match c.kind().try_to_machine_usize(tcx) { + let pred = match c.kind.try_to_machine_usize(tcx) { Some(0) => Self::True, Some(1..) => Self::False, None => Self::ConstIsZero(c), diff --git a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs index ace81bc4f8352..2dd33c2b18722 100644 --- a/compiler/rustc_middle/src/ty/inhabitedness/mod.rs +++ b/compiler/rustc_middle/src/ty/inhabitedness/mod.rs @@ -191,7 +191,7 @@ fn inhabited_predicate_type<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> InhabitedP // If we can evaluate the array length before having a `ParamEnv`, then // we can simplify the predicate. This is an optimization. - Array(ty, len) => match len.kind().try_to_machine_usize(tcx) { + Array(ty, len) => match len.kind.try_to_machine_usize(tcx) { Some(0) => InhabitedPredicate::True, Some(1..) => ty.inhabited_predicate(tcx), None => ty.inhabited_predicate(tcx).or(tcx, InhabitedPredicate::ConstIsZero(len)), diff --git a/compiler/rustc_middle/src/ty/opaque_types.rs b/compiler/rustc_middle/src/ty/opaque_types.rs index 3faee5c8854ab..cd6e2f989102c 100644 --- a/compiler/rustc_middle/src/ty/opaque_types.rs +++ b/compiler/rustc_middle/src/ty/opaque_types.rs @@ -192,7 +192,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> { fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { trace!("checking const {:?}", ct); // Find a const parameter - match ct.kind() { + match ct.kind { ty::ConstKind::Param(..) => { // Look it up in the substitution list. match self.map.get(&ct.into()).map(|k| k.unpack()) { diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 89efb045516c2..5eeb9a23339f5 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -774,14 +774,14 @@ pub trait PrettyPrinter<'tcx>: p!("[", print(ty), "; "); if self.should_print_verbose() { p!(write("{:?}", sz)); - } else if let ty::ConstKind::Unevaluated(..) = sz.kind() { + } else if let ty::ConstKind::Unevaluated(..) = sz.kind { // Do not try to evaluate unevaluated constants. If we are const evaluating an // array length anon const, rustc will (with debug assertions) print the // constant's path. Which will end up here again. p!("_"); - } else if let Some(n) = sz.kind().try_to_bits(self.tcx().data_layout.pointer_size) { + } else if let Some(n) = sz.kind.try_to_bits(self.tcx().data_layout.pointer_size) { p!(write("{}", n)); - } else if let ty::ConstKind::Param(param) = sz.kind() { + } else if let ty::ConstKind::Param(param) = sz.kind { p!(print(param)); } else { p!("_"); @@ -1195,7 +1195,7 @@ pub trait PrettyPrinter<'tcx>: define_scoped_cx!(self); if self.should_print_verbose() { - p!(write("Const({:?}: {:?})", ct.kind(), ct.ty)); + p!(write("Const({:?}: {:?})", ct.kind, ct.ty)); return Ok(self); } @@ -1216,7 +1216,7 @@ pub trait PrettyPrinter<'tcx>: }}; } - match ct.kind() { + match ct.kind { ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }) => { match self.tcx().def_kind(def.did) { DefKind::Static(..) | DefKind::Const | DefKind::AssocConst => { @@ -1284,7 +1284,7 @@ pub trait PrettyPrinter<'tcx>: ty::Ref(_, inner, _) => { if let ty::Array(elem, len) = inner.kind() { if let ty::Uint(ty::UintTy::U8) = elem.kind() { - if let ty::ConstKind::Value(ty::ValTree::Leaf(int)) = len.kind() { + if let ty::ConstKind::Value(ty::ValTree::Leaf(int)) = len.kind { match self.tcx().try_get_global_alloc(alloc_id) { Some(GlobalAlloc::Memory(alloc)) => { let len = int.assert_bits(self.tcx().data_layout.pointer_size); diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index e3663480a38af..3a0c1c44d597d 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -631,7 +631,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>( // Currently, the values that can be unified are primitive types, // and those that derive both `PartialEq` and `Eq`, corresponding // to structural-match types. - let is_match = match (a.kind(), b.kind()) { + let is_match = match (a.kind, b.kind) { (ty::ConstKind::Infer(_), _) | (_, ty::ConstKind::Infer(_)) => { // The caller should handle these cases! bug!("var types encountered in super_relate_consts: {:?} {:?}", a, b) diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 3950970992dd7..8d8f13c23eb7b 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -804,8 +804,8 @@ impl<'tcx> TypeSuperFoldable<'tcx> for ty::Const<'tcx> { folder: &mut F, ) -> Result { let ty = self.ty.try_fold_with(folder)?; - let kind = self.kind().try_fold_with(folder)?; - if ty != self.ty || kind != self.kind() { + let kind = self.kind.try_fold_with(folder)?; + if ty != self.ty || kind != self.kind { Ok(folder.tcx().mk_const(kind, ty)) } else { Ok(self) @@ -816,7 +816,7 @@ impl<'tcx> TypeSuperFoldable<'tcx> for ty::Const<'tcx> { impl<'tcx> TypeSuperVisitable<'tcx> for ty::Const<'tcx> { fn super_visit_with>(&self, visitor: &mut V) -> ControlFlow { self.ty.visit_with(visitor)?; - self.kind().visit_with(visitor) + self.kind.visit_with(visitor) } } diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index c1cf7896db59a..f11103ba0bc4d 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -749,7 +749,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> { } fn fold_const(&mut self, c: ty::Const<'tcx>) -> ty::Const<'tcx> { - if let ty::ConstKind::Param(p) = c.kind() { + if let ty::ConstKind::Param(p) = c.kind { self.const_for_param(p, c) } else { c.super_fold_with(self) diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index 6561c4c278d0e..4356eaec4f590 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -439,7 +439,7 @@ impl<'tcx> TyCtxt<'tcx> { // Error: not a type param _ => false, }, - GenericArgKind::Const(ct) => match ct.kind() { + GenericArgKind::Const(ct) => match ct.kind { ty::ConstKind::Param(ref pc) => { !impl_generics.const_param(pc, self).pure_wrt_drop } @@ -481,7 +481,7 @@ impl<'tcx> TyCtxt<'tcx> { } _ => return Err(NotUniqueParam::NotParam(t.into())), }, - GenericArgKind::Const(c) => match c.kind() { + GenericArgKind::Const(c) => match c.kind { ty::ConstKind::Param(p) => { if !seen.insert(p.index) { return Err(NotUniqueParam::DuplicateParam(c.into())); @@ -1141,7 +1141,7 @@ pub fn needs_drop_components<'tcx>( ty::Array(elem_ty, size) => { match needs_drop_components(*elem_ty, target_layout) { Ok(v) if v.is_empty() => Ok(v), - res => match size.kind().try_to_bits(target_layout.pointer_size) { + res => match size.kind.try_to_bits(target_layout.pointer_size) { // Arrays of size zero don't need drop, even if their element // type does. Some(0) => Ok(SmallVec::new()), diff --git a/compiler/rustc_middle/src/ty/visit.rs b/compiler/rustc_middle/src/ty/visit.rs index b04afe549ac55..c097d1bc00fc1 100644 --- a/compiler/rustc_middle/src/ty/visit.rs +++ b/compiler/rustc_middle/src/ty/visit.rs @@ -518,7 +518,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor { // otherwise we do want to remember to visit the rest of the // const, as it has types/regions embedded in a lot of other // places. - match ct.kind() { + match ct.kind { ty::ConstKind::Bound(debruijn, _) if debruijn >= self.outer_index => { ControlFlow::Break(FoundEscapingVars) } @@ -661,7 +661,7 @@ impl<'tcx> TypeVisitor<'tcx> for LateBoundRegionsCollector { // ignore the inputs of an unevaluated const, as they may not appear // in the normalized form if self.just_constrained { - if let ty::ConstKind::Unevaluated(..) = c.kind() { + if let ty::ConstKind::Unevaluated(..) = c.kind { return ControlFlow::CONTINUE; } } @@ -706,7 +706,7 @@ impl<'tcx> TypeVisitor<'tcx> for MaxUniverse { } fn visit_const(&mut self, c: ty::consts::Const<'tcx>) -> ControlFlow { - if let ty::ConstKind::Placeholder(placeholder) = c.kind() { + if let ty::ConstKind::Placeholder(placeholder) = c.kind { self.max_universe = ty::UniverseIndex::from_u32( self.max_universe.as_u32().max(placeholder.universe.as_u32()), ); diff --git a/compiler/rustc_middle/src/ty/walk.rs b/compiler/rustc_middle/src/ty/walk.rs index c4da75fccc391..e61403eb52eb8 100644 --- a/compiler/rustc_middle/src/ty/walk.rs +++ b/compiler/rustc_middle/src/ty/walk.rs @@ -206,7 +206,7 @@ fn push_inner<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent: GenericArg<'tcx>) GenericArgKind::Lifetime(_) => {} GenericArgKind::Const(parent_ct) => { stack.push(parent_ct.ty.into()); - match parent_ct.kind() { + match parent_ct.kind { ty::ConstKind::Infer(_) | ty::ConstKind::Param(_) | ty::ConstKind::Placeholder(_) diff --git a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs index d60e8722cb61d..efd34e8523cf1 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs @@ -149,7 +149,7 @@ impl IntRange { // is more general but much slower.) return scalar.to_bits_or_ptr_internal(target_size).unwrap().left(); } - mir::ConstantKind::Ty(c) => match c.kind() { + mir::ConstantKind::Ty(c) => match c.kind { ty::ConstKind::Value(_) => bug!( "encountered ConstValue in mir::ConstantKind::Ty, whereas this is expected to be in ConstantKind::Val" ), diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index 4c2a80e523f35..8e1143438ae86 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -571,7 +571,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { let value = value.eval(self.tcx, self.param_env); match value { - mir::ConstantKind::Ty(c) => match c.kind() { + mir::ConstantKind::Ty(c) => match c.kind { ConstKind::Param(_) => { self.errors.push(PatternError::ConstParamInPattern(span)); return PatKind::Wild; diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index b0514e033566c..c1c9798b45c72 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -721,7 +721,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { ) { if let Rvalue::Use(Operand::Constant(c)) = rval { match c.literal { - ConstantKind::Ty(c) if matches!(c.kind(), ConstKind::Unevaluated(..)) => {} + ConstantKind::Ty(c) if matches!(c.kind, ConstKind::Unevaluated(..)) => {} _ => { trace!("skipping replace of Rvalue::Use({:?} because it is already a const", c); return; diff --git a/compiler/rustc_mir_transform/src/required_consts.rs b/compiler/rustc_mir_transform/src/required_consts.rs index 0ea8f2ba93fd8..482298cd5604b 100644 --- a/compiler/rustc_mir_transform/src/required_consts.rs +++ b/compiler/rustc_mir_transform/src/required_consts.rs @@ -16,7 +16,7 @@ impl<'tcx> Visitor<'tcx> for RequiredConstsVisitor<'_, 'tcx> { fn visit_constant(&mut self, constant: &Constant<'tcx>, _: Location) { let literal = constant.literal; match literal { - ConstantKind::Ty(c) => match c.kind() { + ConstantKind::Ty(c) => match c.kind { ConstKind::Param(_) | ConstKind::Error(_) => {} _ => bug!("only ConstKind::Param should be encountered here, got {:#?}", c), }, diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index 15521008cf09c..c0aaee238a8b2 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -759,7 +759,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { let literal = self.monomorphize(constant.literal); let val = match literal { mir::ConstantKind::Val(val, _) => val, - mir::ConstantKind::Ty(ct) => match ct.kind() { + mir::ConstantKind::Ty(ct) => match ct.kind { ty::ConstKind::Value(val) => self.tcx.valtree_to_const_val((ct.ty, val)), ty::ConstKind::Unevaluated(ct) => { debug!(?ct); diff --git a/compiler/rustc_monomorphize/src/polymorphize.rs b/compiler/rustc_monomorphize/src/polymorphize.rs index 650076c2213a3..100cfc495df13 100644 --- a/compiler/rustc_monomorphize/src/polymorphize.rs +++ b/compiler/rustc_monomorphize/src/polymorphize.rs @@ -306,7 +306,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for MarkUsedGenericParams<'a, 'tcx> { return ControlFlow::CONTINUE; } - match c.kind() { + match c.kind { ty::ConstKind::Param(param) => { debug!(?param); self.unused_parameters.clear(param.index); @@ -365,7 +365,7 @@ impl<'a, 'tcx> TypeVisitor<'tcx> for HasUsedGenericParams<'a> { return ControlFlow::CONTINUE; } - match c.kind() { + match c.kind { ty::ConstKind::Param(param) => { if self.unused_parameters.contains(param.index).unwrap_or(false) { ControlFlow::CONTINUE diff --git a/compiler/rustc_symbol_mangling/src/legacy.rs b/compiler/rustc_symbol_mangling/src/legacy.rs index f79a4d6729c4d..0b9ad8c763b51 100644 --- a/compiler/rustc_symbol_mangling/src/legacy.rs +++ b/compiler/rustc_symbol_mangling/src/legacy.rs @@ -227,9 +227,9 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> { self.write_str("[")?; self = self.print_type(ty)?; self.write_str("; ")?; - if let Some(size) = size.kind().try_to_bits(self.tcx().data_layout.pointer_size) { + if let Some(size) = size.kind.try_to_bits(self.tcx().data_layout.pointer_size) { write!(self, "{}", size)? - } else if let ty::ConstKind::Param(param) = size.kind() { + } else if let ty::ConstKind::Param(param) = size.kind { self = param.print(self)? } else { self.write_str("_")? @@ -259,7 +259,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolPrinter<'tcx> { fn print_const(self, ct: ty::Const<'tcx>) -> Result { // only print integers - match (ct.kind(), ct.ty.kind()) { + match (ct.kind, ct.ty.kind()) { (ty::ConstKind::Value(ty::ValTree::Leaf(scalar)), ty::Int(_) | ty::Uint(_)) => { // The `pretty_print_const` formatting depends on -Zverbose // flag, so we cannot reuse it here. diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs index 196b968587470..4d4488a3f1f40 100644 --- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs +++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs @@ -138,7 +138,7 @@ fn encode_const<'tcx>( let _ = write!(s, "{}", value); } - if let Some(scalar_int) = c.kind().try_to_scalar_int() { + if let Some(scalar_int) = c.kind.try_to_scalar_int() { let signed = c.ty.is_signed(); match scalar_int.size().bits() { 8 if signed => push_signed_value(&mut s, scalar_int.try_to_i8().unwrap(), 0), @@ -520,7 +520,7 @@ fn encode_ty<'tcx>( ty::Array(ty0, len) => { // A let mut s = String::from("A"); - let _ = write!(s, "{}", &len.kind().try_to_scalar().unwrap().to_u64().unwrap()); + let _ = write!(s, "{}", &len.kind.try_to_scalar().unwrap().to_u64().unwrap()); s.push_str(&encode_ty(tcx, *ty0, dict, options)); compress(dict, DictKey::Ty(ty, TyQ::None), &mut s); typeid.push_str(&s); @@ -681,7 +681,7 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio } ty::Array(ty0, len) => { - let len = len.kind().try_to_scalar().unwrap().to_u64().unwrap(); + let len = len.kind.try_to_scalar().unwrap().to_u64().unwrap(); ty = tcx.mk_array(transform_ty(tcx, *ty0, options), len); } diff --git a/compiler/rustc_symbol_mangling/src/v0.rs b/compiler/rustc_symbol_mangling/src/v0.rs index fdecb0e07b2a0..7c80b1852e8cc 100644 --- a/compiler/rustc_symbol_mangling/src/v0.rs +++ b/compiler/rustc_symbol_mangling/src/v0.rs @@ -567,7 +567,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { fn print_const(mut self, ct: ty::Const<'tcx>) -> Result { // We only mangle a typed value if the const can be evaluated. let ct = ct.eval(self.tcx, ty::ParamEnv::reveal_all()); - match ct.kind() { + match ct.kind { ty::ConstKind::Value(_) => {} // Placeholders (should be demangled as `_`). @@ -622,7 +622,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { match inner_ty.kind() { ty::Str if *mutbl == hir::Mutability::Not => { - match ct.kind() { + match ct.kind { ty::ConstKind::Value(valtree) => { let slice = valtree.try_to_raw_bytes(self.tcx(), ty).unwrap_or_else(|| { @@ -654,7 +654,7 @@ impl<'tcx> Printer<'tcx> for &mut SymbolMangler<'tcx> { .builtin_deref(true) .expect("tried to dereference on non-ptr type") .ty; - let dereferenced_const = self.tcx.mk_const(ct.kind(), pointee_ty); + let dereferenced_const = self.tcx.mk_const(ct.kind, pointee_ty); self = dereferenced_const.print(self)?; } } diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 34c5e4b794048..03673d25033dd 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -790,7 +790,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { } ty::PredicateKind::ConstEquate(c1, c2) => { let evaluate = |c: ty::Const<'tcx>| { - if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() { + if let ty::ConstKind::Unevaluated(unevaluated) = c.kind { match select.infcx().const_eval_resolve( obligation.param_env, unevaluated, diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index ce682f9582cee..d92fa715a423a 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -76,7 +76,7 @@ impl<'tcx> ConstUnifyCtxt<'tcx> { return false; } - match (a_ct.kind(), b_ct.kind()) { + match (a_ct.kind, b_ct.kind) { // We can just unify errors with everything to reduce the amount of // emitted errors here. (ty::ConstKind::Error(_), _) | (_, ty::ConstKind::Error(_)) => true, @@ -164,7 +164,7 @@ pub fn is_const_evaluatable<'tcx>( span: Span, ) -> Result<(), NotConstEvaluatable> { let tcx = infcx.tcx; - let uv = match ct.kind() { + let uv = match ct.kind { ty::ConstKind::Unevaluated(uv) => uv, ty::ConstKind::Param(_) | ty::ConstKind::Bound(_, _) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 5cb0988919d26..f32e2a0ff26e5 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1298,7 +1298,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { match obligation.predicate.kind().skip_binder() { ty::PredicateKind::ConstEvaluatable(ct) => { - let ty::ConstKind::Unevaluated(uv) = ct.kind() else { + let ty::ConstKind::Unevaluated(uv) = ct.kind else { bug!("const evaluatable failed for non-unevaluated const `{ct:?}`"); }; let mut err = diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs index 9bfe527647dee..d08a76254fed2 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs @@ -247,7 +247,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // Arrays give us `[]`, `[{ty}; _]` and `[{ty}; N]` if let ty::Array(aty, len) = self_ty.kind() { flags.push((sym::_Self, Some("[]".to_string()))); - let len = len.kind().try_to_value().and_then(|v| v.try_to_machine_usize(self.tcx)); + let len = len.kind.try_to_value().and_then(|v| v.try_to_machine_usize(self.tcx)); flags.push((sym::_Self, Some(format!("[{}; _]", aty)))); if let Some(n) = len { flags.push((sym::_Self, Some(format!("[{}; {}]", aty, n)))); diff --git a/compiler/rustc_trait_selection/src/traits/fulfill.rs b/compiler/rustc_trait_selection/src/traits/fulfill.rs index b3debf2794839..021700ecb74fc 100644 --- a/compiler/rustc_trait_selection/src/traits/fulfill.rs +++ b/compiler/rustc_trait_selection/src/traits/fulfill.rs @@ -462,7 +462,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { // // Let's just see where this breaks :shrug: if let (ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b)) = - (c1.kind(), c2.kind()) + (c1.kind, c2.kind) { if infcx.try_unify_abstract_consts(a, b, obligation.param_env) { return ProcessResult::Changed(vec![]); @@ -472,7 +472,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> { let stalled_on = &mut pending_obligation.stalled_on; let mut evaluate = |c: Const<'tcx>| { - if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() { + if let ty::ConstKind::Unevaluated(unevaluated) = c.kind { match self.selcx.infcx().try_const_eval_resolve( obligation.param_env, unevaluated, diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 548ca1c1d7faa..758890a169604 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -522,7 +522,7 @@ fn is_impossible_method<'tcx>( r.super_visit_with(self) } fn visit_const(&mut self, ct: ty::Const<'tcx>) -> ControlFlow { - if let ty::ConstKind::Param(param) = ct.kind() + if let ty::ConstKind::Param(param) = ct.kind && let param_def_id = self.generics.const_param(¶m, self.tcx).def_id && self.tcx.parent(param_def_id) == self.trait_item_def_id { diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 6745667e44c9a..f95c5928dc388 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -807,7 +807,7 @@ impl<'tcx> TypeFolder<'tcx> for BoundVarReplacer<'_, 'tcx> { } fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { - match ct.kind() { + match ct.kind { ty::ConstKind::Bound(debruijn, _) if debruijn.as_usize() + 1 > self.current_index.as_usize() + self.universe_indices.len() => @@ -941,7 +941,7 @@ impl<'tcx> TypeFolder<'tcx> for PlaceholderReplacer<'_, 'tcx> { } fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { - if let ty::ConstKind::Placeholder(p) = ct.kind() { + if let ty::ConstKind::Placeholder(p) = ct.kind { let replace_var = self.mapped_consts.get(&p); match replace_var { Some(replace_var) => { diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index a875ea1578dcb..b057509566a8b 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs @@ -142,7 +142,7 @@ impl<'tcx> TypeVisitor<'tcx> for MaxEscapingBoundVarVisitor { } fn visit_const(&mut self, ct: ty::Const<'tcx>) -> ControlFlow { - match ct.kind() { + match ct.kind { ty::ConstKind::Bound(debruijn, _) if debruijn >= self.outer_index => { self.escaping = self.escaping.max(debruijn.as_usize() - self.outer_index.as_usize()); diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index c0edbebed54ee..b5f7e9fb24bf6 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -1076,7 +1076,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Lifetimes aren't allowed to change during unsizing. GenericArgKind::Lifetime(_) => None, - GenericArgKind::Const(ct) => match ct.kind() { + GenericArgKind::Const(ct) => match ct.kind { ty::ConstKind::Param(p) => Some(p.index), _ => None, }, diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 35a236bc2bdbe..98d835a009473 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -668,7 +668,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // // Let's just see where this breaks :shrug: if let (ty::ConstKind::Unevaluated(a), ty::ConstKind::Unevaluated(b)) = - (c1.kind(), c2.kind()) + (c1.kind, c2.kind) { if self.infcx.try_unify_abstract_consts(a, b, obligation.param_env) { return Ok(EvaluatedToOk); @@ -676,7 +676,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } let evaluate = |c: ty::Const<'tcx>| { - if let ty::ConstKind::Unevaluated(unevaluated) = c.kind() { + if let ty::ConstKind::Unevaluated(unevaluated) = c.kind { match self.infcx.try_const_eval_resolve( obligation.param_env, unevaluated, diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index 5e506a23f383f..8ecfd13c7944b 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -40,7 +40,7 @@ pub fn obligations<'tcx>( .into() } GenericArgKind::Const(ct) => { - match ct.kind() { + match ct.kind { ty::ConstKind::Infer(_) => { let resolved = infcx.shallow_resolve(ct); if resolved == ct { @@ -449,7 +449,7 @@ impl<'tcx> WfPredicates<'tcx> { GenericArgKind::Lifetime(_) => continue, GenericArgKind::Const(ct) => { - match ct.kind() { + match ct.kind { ty::ConstKind::Unevaluated(uv) => { let obligations = self.nominal_obligations(uv.def.did, uv.substs); self.out.extend(obligations); diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 6fbeef0ccfa61..7fc22ed95a544 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -523,7 +523,7 @@ impl<'tcx> LowerInto<'tcx, Region<'tcx>> for &chalk_ir::Lifetime LowerInto<'tcx, chalk_ir::Const>> for ty::Const<'tcx> { fn lower_into(self, interner: RustInterner<'tcx>) -> chalk_ir::Const> { let ty = self.ty.lower_into(interner); - let value = match self.kind() { + let value = match self.kind { ty::ConstKind::Value(val) => { chalk_ir::ConstValue::Concrete(chalk_ir::ConcreteConst { interned: val }) } diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index ca5a6144e8592..12b0c1026713e 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -19,7 +19,7 @@ pub(crate) fn destructure_const<'tcx>( tcx: TyCtxt<'tcx>, const_: ty::Const<'tcx>, ) -> ty::DestructuredConst<'tcx> { - let ty::ConstKind::Value(valtree) = const_.kind() else { + let ty::ConstKind::Value(valtree) = const_.kind else { bug!("cannot destructure constant {:?}", const_) }; diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index f7bbda75dda50..de1ce36615f20 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -232,7 +232,7 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { } pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String { - match n.kind() { + match n.kind { ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs: _ }) => { let s = if let Some(def) = def.as_local() { print_const_expr(cx.tcx, cx.tcx.hir().body_owned_by(def.did)) diff --git a/src/tools/clippy/clippy_lints/src/large_const_arrays.rs b/src/tools/clippy/clippy_lints/src/large_const_arrays.rs index 76c83ab47d095..0f49adf499938 100644 --- a/src/tools/clippy/clippy_lints/src/large_const_arrays.rs +++ b/src/tools/clippy/clippy_lints/src/large_const_arrays.rs @@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays { if let ItemKind::Const(hir_ty, _) = &item.kind; let ty = hir_ty_to_ty(cx.tcx, hir_ty); if let ty::Array(element_type, cst) = ty.kind(); - if let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind(); + if let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind; if let Ok(element_count) = element_count.try_to_machine_usize(cx.tcx); if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()); if self.maximum_allowed_size < element_count * element_size; diff --git a/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs b/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs index 5857d81ab1f20..367703c0daaf7 100644 --- a/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs +++ b/src/tools/clippy/clippy_lints/src/large_stack_arrays.rs @@ -40,7 +40,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays { fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { if let ExprKind::Repeat(_, _) = expr.kind && let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind() - && let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind() + && let ConstKind::Value(ty::ValTree::Leaf(element_count)) = cst.kind && let Ok(element_count) = element_count.try_to_machine_usize(cx.tcx) && let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes()) && !cx.tcx.hir().parent_iter(expr.hir_id) diff --git a/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs b/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs index 7722a476d7b4e..2a660ae5e1840 100644 --- a/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs +++ b/src/tools/clippy/clippy_lints/src/only_used_in_recursion.rs @@ -387,7 +387,7 @@ fn has_matching_substs(kind: FnKind, substs: SubstsRef<'_>) -> bool { FnKind::TraitFn => substs.iter().enumerate().all(|(idx, subst)| match subst.unpack() { GenericArgKind::Lifetime(_) => true, GenericArgKind::Type(ty) => matches!(*ty.kind(), ty::Param(ty) if ty.index as usize == idx), - GenericArgKind::Const(c) => matches!(c.kind(), ConstKind::Param(c) if c.index as usize == idx), + GenericArgKind::Const(c) => matches!(c.kind, ConstKind::Param(c) if c.index as usize == idx), }), #[allow(trivial_casts)] FnKind::ImplTraitFn(expected_substs) => substs as *const _ as usize == expected_substs, diff --git a/src/tools/clippy/clippy_utils/src/consts.rs b/src/tools/clippy/clippy_utils/src/consts.rs index 315aea9aa091b..b488104e28ae1 100644 --- a/src/tools/clippy/clippy_utils/src/consts.rs +++ b/src/tools/clippy/clippy_utils/src/consts.rs @@ -645,7 +645,7 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) - }, mir::ConstantKind::Val(ConstValue::ByRef { alloc, offset: _ }, _) => match result.ty().kind() { ty::Array(sub_type, len) => match sub_type.kind() { - ty::Float(FloatTy::F32) => match len.kind().try_to_machine_usize(tcx) { + ty::Float(FloatTy::F32) => match len.kind.try_to_machine_usize(tcx) { Some(len) => alloc .inner() .inspect_with_uninit_and_ptr_outside_interpreter(0..(4 * usize::try_from(len).unwrap())) @@ -656,7 +656,7 @@ pub fn miri_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::ConstantKind<'tcx>) - .map(Constant::Vec), _ => None, }, - ty::Float(FloatTy::F64) => match len.kind().try_to_machine_usize(tcx) { + ty::Float(FloatTy::F64) => match len.kind.try_to_machine_usize(tcx) { Some(len) => alloc .inner() .inspect_with_uninit_and_ptr_outside_interpreter(0..(8 * usize::try_from(len).unwrap())) From f64704575b6ca23f3f0110a017a7acc6513e277c Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Fri, 25 Nov 2022 15:33:51 +0000 Subject: [PATCH 4/4] Rename ConstS to ConstData --- compiler/rustc_middle/src/arena.rs | 2 +- compiler/rustc_middle/src/ty/codec.rs | 2 +- compiler/rustc_middle/src/ty/consts.rs | 8 ++++---- compiler/rustc_middle/src/ty/context.rs | 10 +++++----- compiler/rustc_middle/src/ty/mod.rs | 6 +++--- compiler/rustc_middle/src/ty/subst.rs | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/compiler/rustc_middle/src/arena.rs b/compiler/rustc_middle/src/arena.rs index 7bd4b6c0c2767..b44cfc459c921 100644 --- a/compiler/rustc_middle/src/arena.rs +++ b/compiler/rustc_middle/src/arena.rs @@ -90,7 +90,7 @@ macro_rules! arena_types { // Interned types [] tys: rustc_data_structures::intern::WithStableHash>, [] predicates: rustc_middle::ty::PredicateS<'tcx>, - [] consts: rustc_middle::ty::ConstS<'tcx>, + [] consts: rustc_middle::ty::ConstData<'tcx>, // Note that this deliberately duplicates items in the `rustc_hir::arena`, // since we need to allocate this type on both the `rustc_hir` arena diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index b469eebfad993..aef1afd9f408e 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -310,7 +310,7 @@ impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> impl<'tcx, D: TyDecoder>> Decodable for ty::Const<'tcx> { fn decode(decoder: &mut D) -> Self { - let consts: ty::ConstS<'tcx> = Decodable::decode(decoder); + let consts: ty::ConstData<'tcx> = Decodable::decode(decoder); decoder.interner().mk_const(consts.kind, consts.ty) } } diff --git a/compiler/rustc_middle/src/ty/consts.rs b/compiler/rustc_middle/src/ty/consts.rs index 0192e30ec2430..dbe53873cc35a 100644 --- a/compiler/rustc_middle/src/ty/consts.rs +++ b/compiler/rustc_middle/src/ty/consts.rs @@ -17,10 +17,10 @@ pub use valtree::*; /// Use this rather than `ConstS`, whenever possible. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable)] #[rustc_pass_by_value] -pub struct Const<'tcx>(pub Interned<'tcx, ConstS<'tcx>>); +pub struct Const<'tcx>(pub Interned<'tcx, ConstData<'tcx>>); impl<'tcx> std::ops::Deref for Const<'tcx> { - type Target = ConstS<'tcx>; + type Target = ConstData<'tcx>; fn deref(&self) -> &Self::Target { &self.0.0 @@ -38,13 +38,13 @@ impl<'tcx> fmt::Debug for Const<'tcx> { /// Typed constant value. #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, HashStable, TyEncodable, TyDecodable)] -pub struct ConstS<'tcx> { +pub struct ConstData<'tcx> { pub ty: Ty<'tcx>, pub kind: ConstKind<'tcx>, } #[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))] -static_assert_size!(ConstS<'_>, 40); +static_assert_size!(ConstData<'_>, 40); impl<'tcx> Const<'tcx> { /// Literals and const generic parameters are eagerly converted to a constant, everything else diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 6e690fa6325fb..e4fba16efcbe6 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -17,7 +17,7 @@ use crate::traits; use crate::ty::query::{self, TyCtxtAt}; use crate::ty::{ self, AdtDef, AdtDefData, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig, - ClosureSizeProfileData, Const, ConstS, ConstVid, DefIdTree, FloatTy, FloatVar, FloatVid, + ClosureSizeProfileData, Const, ConstData, ConstVid, DefIdTree, FloatTy, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, IntTy, IntVar, IntVid, List, ParamConst, ParamTy, PolyExistentialPredicate, PolyFnSig, Predicate, PredicateKind, PredicateS, ProjectionTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, @@ -145,7 +145,7 @@ pub struct CtxtInterners<'tcx> { predicates: InternedSet<'tcx, List>>, projs: InternedSet<'tcx, List>, place_elems: InternedSet<'tcx, List>>, - const_: InternedSet<'tcx, ConstS<'tcx>>, + const_: InternedSet<'tcx, ConstData<'tcx>>, const_allocation: InternedSet<'tcx, Allocation>, bound_variable_kinds: InternedSet<'tcx, List>, layout: InternedSet<'tcx, LayoutS>, @@ -985,7 +985,7 @@ impl<'tcx> CommonConsts<'tcx> { }; CommonConsts { - unit: mk_const(ty::ConstS { + unit: mk_const(ty::ConstData { kind: ty::ConstKind::Value(ty::ValTree::zst()), ty: types.unit, }), @@ -2242,7 +2242,7 @@ macro_rules! direct_interners { direct_interners! { region: mk_region(RegionKind<'tcx>): Region -> Region<'tcx>, - const_: mk_const_internal(ConstS<'tcx>): Const -> Const<'tcx>, + const_: mk_const_internal(ConstData<'tcx>): Const -> Const<'tcx>, const_allocation: intern_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>, layout: intern_layout(LayoutS): Layout -> Layout<'tcx>, adt_def: intern_adt_def(AdtDefData): AdtDef -> AdtDef<'tcx>, @@ -2592,7 +2592,7 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_const(self, kind: ty::ConstKind<'tcx>, ty: Ty<'tcx>) -> Const<'tcx> { - self.mk_const_internal(ty::ConstS { kind, ty }) + self.mk_const_internal(ty::ConstData { kind, ty }) } #[inline] diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 9d778ff2fb6e3..b7d2a2331462c 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -77,7 +77,7 @@ pub use self::closure::{ CAPTURE_STRUCT_LOCAL, }; pub use self::consts::{ - Const, ConstInt, ConstKind, ConstS, InferConst, ScalarInt, UnevaluatedConst, ValTree, + Const, ConstData, ConstInt, ConstKind, InferConst, ScalarInt, UnevaluatedConst, ValTree, }; pub use self::context::{ tls, CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, @@ -1017,7 +1017,7 @@ impl<'tcx> Term<'tcx> { &*((ptr & !TAG_MASK) as *const WithStableHash>), ))), CONST_TAG => TermKind::Const(ty::Const(Interned::new_unchecked( - &*((ptr & !TAG_MASK) as *const ty::ConstS<'tcx>), + &*((ptr & !TAG_MASK) as *const ty::ConstData<'tcx>), ))), _ => core::intrinsics::unreachable(), } @@ -1063,7 +1063,7 @@ impl<'tcx> TermKind<'tcx> { TermKind::Const(ct) => { // Ensure we can use the tag bits. assert_eq!(mem::align_of_val(&*ct.0.0) & TAG_MASK, 0); - (CONST_TAG, ct.0.0 as *const ty::ConstS<'tcx> as usize) + (CONST_TAG, ct.0.0 as *const ty::ConstData<'tcx> as usize) } }; diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index f11103ba0bc4d..b52246d490651 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -89,7 +89,7 @@ impl<'tcx> GenericArgKind<'tcx> { GenericArgKind::Const(ct) => { // Ensure we can use the tag bits. assert_eq!(mem::align_of_val(&*ct.0.0) & TAG_MASK, 0); - (CONST_TAG, ct.0.0 as *const ty::ConstS<'tcx> as usize) + (CONST_TAG, ct.0.0 as *const ty::ConstData<'tcx> as usize) } }; @@ -156,7 +156,7 @@ impl<'tcx> GenericArg<'tcx> { &*((ptr & !TAG_MASK) as *const WithStableHash>), ))), CONST_TAG => GenericArgKind::Const(ty::Const(Interned::new_unchecked( - &*((ptr & !TAG_MASK) as *const ty::ConstS<'tcx>), + &*((ptr & !TAG_MASK) as *const ty::ConstData<'tcx>), ))), _ => intrinsics::unreachable(), }