Skip to content

Commit dadfa04

Browse files
committed
Remove Const::ty method in favor of field access via the Deref impl
1 parent 9421f74 commit dadfa04

File tree

41 files changed

+74
-81
lines changed

Some content is hidden

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

41 files changed

+74
-81
lines changed

Diff for: compiler/rustc_codegen_cranelift/src/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
7474
ConstantKind::Ty(const_) => match const_.kind() {
7575
ty::ConstKind::Unevaluated(uv) => uv.expand(),
7676
ty::ConstKind::Value(val) => {
77-
return Some((fx.tcx.valtree_to_const_val((const_.ty(), val)), const_.ty()));
77+
return Some((fx.tcx.valtree_to_const_val((const_.ty, val)), const_.ty));
7878
}
7979
err => span_bug!(
8080
constant.span,

Diff for: compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -639,14 +639,14 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
639639
ty::ConstKind::Param(param) => {
640640
write!(output, "{}", param.name)
641641
}
642-
_ => match ct.ty().kind() {
642+
_ => match ct.ty.kind() {
643643
ty::Int(ity) => {
644-
let bits = ct.eval_bits(tcx, ty::ParamEnv::reveal_all(), ct.ty());
644+
let bits = ct.eval_bits(tcx, ty::ParamEnv::reveal_all(), ct.ty);
645645
let val = Integer::from_int_ty(&tcx, *ity).size().sign_extend(bits) as i128;
646646
write!(output, "{}", val)
647647
}
648648
ty::Uint(_) => {
649-
let val = ct.eval_bits(tcx, ty::ParamEnv::reveal_all(), ct.ty());
649+
let val = ct.eval_bits(tcx, ty::ParamEnv::reveal_all(), ct.ty);
650650
write!(output, "{}", val)
651651
}
652652
ty::Bool => {

Diff for: compiler/rustc_codegen_ssa/src/mir/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
2929
mir::ConstantKind::Ty(ct) => match ct.kind() {
3030
ty::ConstKind::Unevaluated(uv) => uv.expand(),
3131
ty::ConstKind::Value(val) => {
32-
return Ok(self.cx.tcx().valtree_to_const_val((ct.ty(), val)));
32+
return Ok(self.cx.tcx().valtree_to_const_val((ct.ty, val)));
3333
}
3434
err => span_bug!(
3535
constant.span,

Diff for: compiler/rustc_const_eval/src/interpret/operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
592592
let val = self.tcx.normalize_erasing_regions(self.param_env, *val);
593593
match val {
594594
mir::ConstantKind::Ty(ct) => {
595-
let ty = ct.ty();
595+
let ty = ct.ty;
596596
let valtree = self.eval_ty_constant(ct, span)?;
597597
let const_val = self.tcx.valtree_to_const_val((ty, valtree));
598598
self.const_val_to_op(const_val, ty, layout)

Diff for: compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13941394
let references_self = match pred.skip_binder().term.unpack() {
13951395
ty::TermKind::Ty(ty) => ty.walk().any(|arg| arg == dummy_self.into()),
13961396
ty::TermKind::Const(c) => {
1397-
c.ty().walk().any(|arg| arg == dummy_self.into())
1397+
c.ty.walk().any(|arg| arg == dummy_self.into())
13981398
}
13991399
};
14001400

Diff for: compiler/rustc_hir_analysis/src/constrained_generic_params.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'tcx> TypeVisitor<'tcx> for ParameterCollector {
8383
match c.kind() {
8484
ty::ConstKind::Unevaluated(..) if !self.include_nonconstraining => {
8585
// Constant expressions are not injective
86-
return c.ty().visit_with(self);
86+
return c.ty.visit_with(self);
8787
}
8888
ty::ConstKind::Param(data) => {
8989
self.parameters.push(Parameter::from(data));

Diff for: compiler/rustc_hir_typeck/src/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11211121
.into(),
11221122
GenericArgKind::Const(arg) => self
11231123
.next_const_var(
1124-
arg.ty(),
1124+
arg.ty,
11251125
ConstVariableOrigin {
11261126
span: rustc_span::DUMMY_SP,
11271127
kind: ConstVariableOriginKind::MiscVariable,

Diff for: compiler/rustc_hir_typeck/src/writeback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> {
793793
debug!("Resolver::fold_const: input const `{:?}` not fully resolvable", ct);
794794
let e = self.report_error(ct);
795795
self.replaced_with_error = Some(e);
796-
self.tcx().const_error_with_guaranteed(ct.ty(), e)
796+
self.tcx().const_error_with_guaranteed(ct.ty, e)
797797
}
798798
}
799799
}

Diff for: compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
484484
ui = ty::UniverseIndex::ROOT;
485485
}
486486
return self.canonicalize_const_var(
487-
CanonicalVarInfo { kind: CanonicalVarKind::Const(ui, ct.ty()) },
487+
CanonicalVarInfo { kind: CanonicalVarKind::Const(ui, ct.ty) },
488488
ct,
489489
);
490490
}
@@ -503,7 +503,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
503503
ty::ConstKind::Placeholder(placeholder) => {
504504
return self.canonicalize_const_var(
505505
CanonicalVarInfo {
506-
kind: CanonicalVarKind::PlaceholderConst(placeholder, ct.ty()),
506+
kind: CanonicalVarKind::PlaceholderConst(placeholder, ct.ty),
507507
},
508508
ct,
509509
);
@@ -773,10 +773,8 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
773773
self.fold_const(bound_to)
774774
} else {
775775
let var = self.canonical_var(info, const_var.into());
776-
self.tcx().mk_const(
777-
ty::ConstKind::Bound(self.binder_index, var),
778-
self.fold_ty(const_var.ty()),
779-
)
776+
self.tcx()
777+
.mk_const(ty::ConstKind::Bound(self.binder_index, var), self.fold_ty(const_var.ty))
780778
}
781779
}
782780
}

Diff for: compiler/rustc_infer/src/infer/combine.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
753753
origin: var_value.origin,
754754
val: ConstVariableValue::Unknown { universe: self.for_universe },
755755
});
756-
Ok(self.tcx().mk_const_var(new_var_id, c.ty()))
756+
Ok(self.tcx().mk_const_var(new_var_id, c.ty))
757757
}
758758
}
759759
}
@@ -767,7 +767,7 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
767767
)?;
768768
Ok(self.tcx().mk_const(
769769
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
770-
c.ty(),
770+
c.ty,
771771
))
772772
}
773773
_ => relate::super_relate_consts(self, c, c),
@@ -975,7 +975,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
975975
},
976976
},
977977
);
978-
Ok(self.tcx().mk_const_var(new_var_id, c.ty()))
978+
Ok(self.tcx().mk_const_var(new_var_id, c.ty))
979979
}
980980
}
981981
}
@@ -990,7 +990,7 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
990990

991991
Ok(self.tcx().mk_const(
992992
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, substs }),
993-
c.ty(),
993+
c.ty,
994994
))
995995
}
996996
_ => relate::super_relate_consts(self, c, c),

Diff for: compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
472472
.into(),
473473
GenericArgKind::Const(arg) => self
474474
.next_const_var(
475-
arg.ty(),
475+
arg.ty,
476476
ConstVariableOrigin {
477477
span: rustc_span::DUMMY_SP,
478478
kind: ConstVariableOriginKind::MiscVariable,

Diff for: compiler/rustc_infer/src/infer/freshen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
227227
.probe_value(v)
228228
.val
229229
.known();
230-
self.freshen_const(opt_ct, ty::InferConst::Var(v), ty::InferConst::Fresh, ct.ty())
230+
self.freshen_const(opt_ct, ty::InferConst::Var(v), ty::InferConst::Fresh, ct.ty)
231231
}
232232
ty::ConstKind::Infer(ty::InferConst::Fresh(i)) => {
233233
if i >= self.const_freshen_count {

Diff for: compiler/rustc_infer/src/infer/fudge.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for InferenceFudger<'a, 'tcx> {
235235
// Recreate it with a fresh variable here.
236236
let idx = (vid.index - self.const_vars.0.start.index) as usize;
237237
let origin = self.const_vars.1[idx];
238-
self.infcx.next_const_var(ct.ty(), origin)
238+
self.infcx.next_const_var(ct.ty, origin)
239239
} else {
240240
ct
241241
}

Diff for: compiler/rustc_infer/src/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,7 @@ fn replace_param_and_infer_substs_with_placeholder<'tcx>(
20722072
.into()
20732073
}
20742074
GenericArgKind::Const(ct) if ct.has_non_region_infer() || ct.has_non_region_param() => {
2075-
let ty = ct.ty();
2075+
let ty = ct.ty;
20762076
// If the type references param or infer, replace that too...
20772077
if ty.has_non_region_param() || ty.has_non_region_infer() {
20782078
bug!("const `{ct}`'s type should not reference params or types");

Diff for: compiler/rustc_infer/src/infer/nll_relate/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ where
10871087
origin: var_value.origin,
10881088
val: ConstVariableValue::Unknown { universe: self.universe },
10891089
});
1090-
Ok(self.tcx().mk_const_var(new_var_id, a.ty()))
1090+
Ok(self.tcx().mk_const_var(new_var_id, a.ty))
10911091
}
10921092
}
10931093
}

Diff for: compiler/rustc_middle/src/infer/canonical.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ impl<'tcx> CanonicalVarValues<'tcx> {
345345
GenericArgKind::Const(ct) => tcx
346346
.mk_const(
347347
ty::ConstKind::Bound(ty::INNERMOST, ty::BoundVar::from_u32(i)),
348-
ct.ty(),
348+
ct.ty,
349349
)
350350
.into(),
351351
})

Diff for: compiler/rustc_middle/src/mir/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2239,7 +2239,7 @@ impl<'tcx> ConstantKind<'tcx> {
22392239
#[inline(always)]
22402240
pub fn ty(&self) -> Ty<'tcx> {
22412241
match self {
2242-
ConstantKind::Ty(c) => c.ty(),
2242+
ConstantKind::Ty(c) => c.ty,
22432243
ConstantKind::Val(_, ty) | ConstantKind::Unevaluated(_, ty) => *ty,
22442244
}
22452245
}
@@ -2248,7 +2248,7 @@ impl<'tcx> ConstantKind<'tcx> {
22482248
pub fn try_to_value(self, tcx: TyCtxt<'tcx>) -> Option<interpret::ConstValue<'tcx>> {
22492249
match self {
22502250
ConstantKind::Ty(c) => match c.kind() {
2251-
ty::ConstKind::Value(valtree) => Some(tcx.valtree_to_const_val((c.ty(), valtree))),
2251+
ty::ConstKind::Value(valtree) => Some(tcx.valtree_to_const_val((c.ty, valtree))),
22522252
_ => None,
22532253
},
22542254
ConstantKind::Val(val, _) => Some(val),
@@ -2292,7 +2292,7 @@ impl<'tcx> ConstantKind<'tcx> {
22922292
Self::Ty(c) => {
22932293
if let Some(val) = c.kind().try_eval_for_mir(tcx, param_env) {
22942294
match val {
2295-
Ok(val) => Self::Val(val, c.ty()),
2295+
Ok(val) => Self::Val(val, c.ty),
22962296
Err(_) => Self::Ty(tcx.const_error(self.ty())),
22972297
}
22982298
} else {
@@ -2582,10 +2582,10 @@ impl<'tcx> ConstantKind<'tcx> {
25822582
pub fn from_const(c: ty::Const<'tcx>, tcx: TyCtxt<'tcx>) -> Self {
25832583
match c.kind() {
25842584
ty::ConstKind::Value(valtree) => {
2585-
let const_val = tcx.valtree_to_const_val((c.ty(), valtree));
2586-
Self::Val(const_val, c.ty())
2585+
let const_val = tcx.valtree_to_const_val((c.ty, valtree));
2586+
Self::Val(const_val, c.ty)
25872587
}
2588-
ty::ConstKind::Unevaluated(uv) => Self::Unevaluated(uv.expand(), c.ty()),
2588+
ty::ConstKind::Unevaluated(uv) => Self::Unevaluated(uv.expand(), c.ty),
25892589
_ => Self::Ty(c),
25902590
}
25912591
}

Diff for: compiler/rustc_middle/src/ty/consts.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<'tcx> fmt::Debug for Const<'tcx> {
3232
// This reflects what `Const` looked liked before `Interned` was
3333
// introduced. We print it like this to avoid having to update expected
3434
// output in a lot of tests.
35-
write!(f, "Const {{ ty: {:?}, kind: {:?} }}", self.ty(), self.kind())
35+
write!(f, "Const {{ ty: {:?}, kind: {:?} }}", self.ty, self.kind())
3636
}
3737
}
3838

@@ -47,11 +47,6 @@ pub struct ConstS<'tcx> {
4747
static_assert_size!(ConstS<'_>, 40);
4848

4949
impl<'tcx> Const<'tcx> {
50-
#[inline]
51-
pub fn ty(self) -> Ty<'tcx> {
52-
self.ty
53-
}
54-
5550
#[inline]
5651
pub fn kind(self) -> ConstKind<'tcx> {
5752
self.kind
@@ -206,7 +201,7 @@ impl<'tcx> Const<'tcx> {
206201
param_env: ParamEnv<'tcx>,
207202
ty: Ty<'tcx>,
208203
) -> Option<u128> {
209-
assert_eq!(self.ty(), ty);
204+
assert_eq!(self.ty, ty);
210205
let size = tcx.layout_of(param_env.with_reveal_all_normalized(tcx).and(ty)).ok()?.size;
211206
// if `ty` does not depend on generic parameters, use an empty param_env
212207
self.kind().eval(tcx, param_env).try_to_bits(size)
@@ -228,8 +223,8 @@ impl<'tcx> Const<'tcx> {
228223
pub fn eval(self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> Const<'tcx> {
229224
if let Some(val) = self.kind().try_eval_for_typeck(tcx, param_env) {
230225
match val {
231-
Ok(val) => Const::from_value(tcx, val, self.ty()),
232-
Err(guar) => tcx.const_error_with_guaranteed(self.ty(), guar),
226+
Ok(val) => Const::from_value(tcx, val, self.ty),
227+
Err(guar) => tcx.const_error_with_guaranteed(self.ty, guar),
233228
}
234229
} else {
235230
// Either the constant isn't evaluatable or ValTree creation failed.

Diff for: compiler/rustc_middle/src/ty/flags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl FlagComputation {
282282
}
283283

284284
fn add_const(&mut self, c: ty::Const<'_>) {
285-
self.add_ty(c.ty());
285+
self.add_ty(c.ty);
286286
match c.kind() {
287287
ty::ConstKind::Unevaluated(uv) => {
288288
self.add_substs(uv.substs);

Diff for: compiler/rustc_middle/src/ty/fold.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ where
436436
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
437437
match ct.kind() {
438438
ty::ConstKind::Bound(debruijn, bound_const) if debruijn == self.current_index => {
439-
let ct = self.delegate.replace_const(bound_const, ct.ty());
439+
let ct = self.delegate.replace_const(bound_const, ct.ty);
440440
ty::fold::shift_vars(self.tcx, ct, self.current_index.as_u32())
441441
}
442442
_ => ct.super_fold_with(self),
@@ -731,7 +731,7 @@ impl<'tcx> TypeFolder<'tcx> for Shifter<'tcx> {
731731
ct
732732
} else {
733733
let debruijn = debruijn.shifted_in(self.amount);
734-
self.tcx.mk_const(ty::ConstKind::Bound(debruijn, bound_ct), ct.ty())
734+
self.tcx.mk_const(ty::ConstKind::Bound(debruijn, bound_ct), ct.ty)
735735
}
736736
} else {
737737
ct.super_fold_with(self)

Diff for: compiler/rustc_middle/src/ty/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ impl<'tcx> TypeFolder<'tcx> for ReverseMapper<'tcx> {
208208
});
209209
}
210210

211-
self.tcx().const_error(ct.ty())
211+
self.tcx().const_error(ct.ty)
212212
}
213213
}
214214
}

Diff for: compiler/rustc_middle/src/ty/print/pretty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1195,7 +1195,7 @@ pub trait PrettyPrinter<'tcx>:
11951195
define_scoped_cx!(self);
11961196

11971197
if self.should_print_verbose() {
1198-
p!(write("Const({:?}: {:?})", ct.kind(), ct.ty()));
1198+
p!(write("Const({:?}: {:?})", ct.kind(), ct.ty));
11991199
return Ok(self);
12001200
}
12011201

@@ -1207,7 +1207,7 @@ pub trait PrettyPrinter<'tcx>:
12071207
write!(this, "_")?;
12081208
Ok(this)
12091209
},
1210-
|this| this.print_type(ct.ty()),
1210+
|this| this.print_type(ct.ty),
12111211
": ",
12121212
)?;
12131213
} else {
@@ -1246,7 +1246,7 @@ pub trait PrettyPrinter<'tcx>:
12461246
}
12471247
ty::ConstKind::Param(ParamConst { name, .. }) => p!(write("{}", name)),
12481248
ty::ConstKind::Value(value) => {
1249-
return self.pretty_print_const_valtree(value, ct.ty(), print_ty);
1249+
return self.pretty_print_const_valtree(value, ct.ty, print_ty);
12501250
}
12511251

12521252
ty::ConstKind::Bound(debruijn, bound_var) => {

Diff for: compiler/rustc_middle/src/ty/relate.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -604,11 +604,11 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
604604
let a_ty;
605605
let b_ty;
606606
if relation.tcx().features().adt_const_params {
607-
a_ty = tcx.normalize_erasing_regions(relation.param_env(), a.ty());
608-
b_ty = tcx.normalize_erasing_regions(relation.param_env(), b.ty());
607+
a_ty = tcx.normalize_erasing_regions(relation.param_env(), a.ty);
608+
b_ty = tcx.normalize_erasing_regions(relation.param_env(), b.ty);
609609
} else {
610-
a_ty = tcx.erase_regions(a.ty());
611-
b_ty = tcx.erase_regions(b.ty());
610+
a_ty = tcx.erase_regions(a.ty);
611+
b_ty = tcx.erase_regions(b.ty);
612612
}
613613
if a_ty != b_ty {
614614
relation.tcx().sess.delay_span_bug(
@@ -662,7 +662,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>(
662662
)?;
663663
return Ok(tcx.mk_const(
664664
ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def: au.def, substs }),
665-
a.ty(),
665+
a.ty,
666666
));
667667
}
668668
_ => false,

Diff for: compiler/rustc_middle/src/ty/structural_impls.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -803,9 +803,9 @@ impl<'tcx> TypeSuperFoldable<'tcx> for ty::Const<'tcx> {
803803
self,
804804
folder: &mut F,
805805
) -> Result<Self, F::Error> {
806-
let ty = self.ty().try_fold_with(folder)?;
806+
let ty = self.ty.try_fold_with(folder)?;
807807
let kind = self.kind().try_fold_with(folder)?;
808-
if ty != self.ty() || kind != self.kind() {
808+
if ty != self.ty || kind != self.kind() {
809809
Ok(folder.tcx().mk_const(kind, ty))
810810
} else {
811811
Ok(self)
@@ -815,7 +815,7 @@ impl<'tcx> TypeSuperFoldable<'tcx> for ty::Const<'tcx> {
815815

816816
impl<'tcx> TypeSuperVisitable<'tcx> for ty::Const<'tcx> {
817817
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
818-
self.ty().visit_with(visitor)?;
818+
self.ty.visit_with(visitor)?;
819819
self.kind().visit_with(visitor)
820820
}
821821
}

0 commit comments

Comments
 (0)