Skip to content

Commit 592d43f

Browse files
committed
Basic removal of Ty from places (boring)
1 parent e8ec393 commit 592d43f

File tree

71 files changed

+332
-580
lines changed

Some content is hidden

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

71 files changed

+332
-580
lines changed

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
193193
types: &mut |_bound_ty: ty::BoundTy| {
194194
unreachable!("we only replace regions in nll_relate, not types")
195195
},
196-
consts: &mut |_bound_var: ty::BoundVar, _ty| {
196+
consts: &mut |_bound_var: ty::BoundVar| {
197197
unreachable!("we only replace regions in nll_relate, not consts")
198198
},
199199
};
@@ -231,7 +231,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
231231
types: &mut |_bound_ty: ty::BoundTy| {
232232
unreachable!("we only replace regions in nll_relate, not types")
233233
},
234-
consts: &mut |_bound_var: ty::BoundVar, _ty| {
234+
consts: &mut |_bound_var: ty::BoundVar| {
235235
unreachable!("we only replace regions in nll_relate, not consts")
236236
},
237237
};

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,8 @@ fn push_const_param<'tcx>(tcx: TyCtxt<'tcx>, ct: ty::Const<'tcx>, output: &mut S
693693
ty::ConstKind::Param(param) => {
694694
write!(output, "{}", param.name)
695695
}
696-
_ => match ct.ty().kind() {
696+
// THISPR
697+
_ => match { todo!() as Ty<'tcx> }.kind() {
697698
ty::Int(ity) => {
698699
let bits = ct.eval_bits(tcx, ty::ParamEnv::reveal_all());
699700
let val = Integer::from_int_ty(&tcx, *ity).size().sign_extend(bits) as i128;

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

-3
Original file line numberDiff line numberDiff line change
@@ -2192,9 +2192,6 @@ fn param_env_with_gat_bounds<'tcx>(
21922192
tcx,
21932193
ty::INNERMOST,
21942194
ty::BoundVar::from_usize(bound_vars.len() - 1),
2195-
tcx.type_of(param.def_id)
2196-
.no_bound_vars()
2197-
.expect("const parameter types cannot be generic"),
21982195
)
21992196
.into()
22002197
}

compiler/rustc_hir_analysis/src/collect.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -386,16 +386,8 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
386386
Ty::new_error_with_message(self.tcx(), span, "bad placeholder type")
387387
}
388388

389-
fn ct_infer(&self, ty: Ty<'tcx>, _: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> {
390-
let ty = self.tcx.fold_regions(ty, |r, _| match *r {
391-
rustc_type_ir::RegionKind::ReStatic => r,
392-
393-
// This is never reached in practice. If it ever is reached,
394-
// `ReErased` should be changed to `ReStatic`, and any other region
395-
// left alone.
396-
r => bug!("unexpected region: {r:?}"),
397-
});
398-
ty::Const::new_error_with_message(self.tcx(), ty, span, "bad placeholder constant")
389+
fn ct_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> {
390+
ty::Const::new_error_with_message(self.tcx(), span, "bad placeholder constant")
399391
}
400392

401393
fn probe_ty_param_bounds(

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
197197
.type_of(param.def_id.to_def_id())
198198
.no_bound_vars()
199199
.expect("const parameters cannot be generic");
200-
let ct = icx.lowerer().lower_const_param(param.hir_id, ct_ty);
200+
let ct = icx.lowerer().lower_const_param(param.hir_id);
201201
predicates
202202
.insert((ty::ClauseKind::ConstArgHasType(ct, ct_ty).upcast(tcx), param.span));
203203
}

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
366366
},
367367
)
368368
});
369-
let ty = tcx
370-
.type_of(param.def_id)
371-
.no_bound_vars()
372-
.expect("ct params cannot have early bound vars");
373-
ty::Const::new_error(tcx, guar, ty).into()
369+
ty::Const::new_error(tcx, guar).into()
374370
}
375371
};
376372
num_bound_vars += 1;

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+17-26
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,7 @@ pub trait HirTyLowerer<'tcx> {
103103
fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx>;
104104

105105
/// Returns the const to use when a const is omitted.
106-
fn ct_infer(
107-
&self,
108-
ty: Ty<'tcx>,
109-
param: Option<&ty::GenericParamDef>,
110-
span: Span,
111-
) -> Const<'tcx>;
106+
fn ct_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx>;
112107

113108
/// Probe bounds in scope where the bounded type coincides with the given type parameter.
114109
///
@@ -485,16 +480,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
485480
ty::Const::from_anon_const(tcx, did).into()
486481
}
487482
(&GenericParamDefKind::Const { .. }, hir::GenericArg::Infer(inf)) => {
488-
let ty = tcx
489-
.at(self.span)
490-
.type_of(param.def_id)
491-
.no_bound_vars()
492-
.expect("const parameter types cannot be generic");
493483
if self.lowerer.allow_infer() {
494-
self.lowerer.ct_infer(ty, Some(param), inf.span).into()
484+
self.lowerer.ct_infer(Some(param), inf.span).into()
495485
} else {
496486
self.inferred_params.push(inf.span);
497-
ty::Const::new_misc_error(tcx, ty).into()
487+
ty::Const::new_misc_error(tcx).into()
498488
}
499489
}
500490
(kind, arg) => span_bug!(
@@ -552,7 +542,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
552542
.no_bound_vars()
553543
.expect("const parameter types cannot be generic");
554544
if let Err(guar) = ty.error_reported() {
555-
return ty::Const::new_error(tcx, guar, ty).into();
545+
return ty::Const::new_error(tcx, guar).into();
556546
}
557547
// FIXME(effects) see if we should special case effect params here
558548
if !infer_args && has_default {
@@ -561,10 +551,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
561551
.into()
562552
} else {
563553
if infer_args {
564-
self.lowerer.ct_infer(ty, Some(param), self.span).into()
554+
self.lowerer.ct_infer(Some(param), self.span).into()
565555
} else {
566556
// We've already errored above about the mismatch.
567-
ty::Const::new_misc_error(tcx, ty).into()
557+
ty::Const::new_misc_error(tcx).into()
568558
}
569559
}
570560
}
@@ -1914,7 +1904,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
19141904
///
19151905
/// Early-bound const parameters get lowered to [`ty::ConstKind::Param`]
19161906
/// and late-bound ones to [`ty::ConstKind::Bound`].
1917-
pub(crate) fn lower_const_param(&self, hir_id: HirId, param_ty: Ty<'tcx>) -> Const<'tcx> {
1907+
pub(crate) fn lower_const_param(&self, hir_id: HirId) -> Const<'tcx> {
19181908
let tcx = self.tcx();
19191909
match tcx.named_bound_var(hir_id) {
19201910
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
@@ -1924,12 +1914,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
19241914
let generics = tcx.generics_of(item_def_id);
19251915
let index = generics.param_def_id_to_index[&def_id];
19261916
let name = tcx.item_name(def_id);
1927-
ty::Const::new_param(tcx, ty::ParamConst::new(index, name), param_ty)
1917+
ty::Const::new_param(tcx, ty::ParamConst::new(index, name))
19281918
}
19291919
Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => {
1930-
ty::Const::new_bound(tcx, debruijn, ty::BoundVar::from_u32(index), param_ty)
1920+
ty::Const::new_bound(tcx, debruijn, ty::BoundVar::from_u32(index))
19311921
}
1932-
Some(rbv::ResolvedArg::Error(guar)) => ty::Const::new_error(tcx, guar, param_ty),
1922+
Some(rbv::ResolvedArg::Error(guar)) => ty::Const::new_error(tcx, guar),
19331923
arg => bug!("unexpected bound var resolution for {:?}: {arg:?}", hir_id),
19341924
}
19351925
}
@@ -2145,7 +2135,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21452135
}
21462136
hir::TyKind::Array(ty, length) => {
21472137
let length = match length {
2148-
hir::ArrayLen::Infer(inf) => self.ct_infer(tcx.types.usize, None, inf.span),
2138+
hir::ArrayLen::Infer(inf) => self.ct_infer(None, inf.span),
21492139
hir::ArrayLen::Body(constant) => {
21502140
ty::Const::from_anon_const(tcx, constant.def_id)
21512141
}
@@ -2183,7 +2173,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21832173
match tcx.lit_to_const(lit_input) {
21842174
Ok(c) => c,
21852175
Err(LitToConstError::Reported(err)) => {
2186-
ty::Const::new_error(tcx, err, ty)
2176+
ty::Const::new_error(tcx, err)
21872177
}
21882178
Err(LitToConstError::TypeError) => todo!(),
21892179
}
@@ -2204,19 +2194,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
22042194
.type_of(def_id)
22052195
.no_bound_vars()
22062196
.expect("const parameter types cannot be generic");
2207-
self.lower_const_param(expr.hir_id, ty)
2197+
self.lower_const_param(expr.hir_id)
22082198
}
22092199

22102200
_ => {
22112201
let err = tcx
22122202
.dcx()
22132203
.emit_err(crate::errors::NonConstRange { span: expr.span });
2214-
ty::Const::new_error(tcx, err, ty)
2204+
ty::Const::new_error(tcx, err)
22152205
}
22162206
};
2217-
self.record_ty(expr.hir_id, c.ty(), expr.span);
2207+
// THISPR
2208+
self.record_ty(expr.hir_id, todo!(), expr.span);
22182209
if let Some((id, span)) = neg {
2219-
self.record_ty(id, c.ty(), span);
2210+
self.record_ty(id, todo!(), span);
22202211
}
22212212
c
22222213
};

compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
142142
let references_self = match pred.skip_binder().term.unpack() {
143143
ty::TermKind::Ty(ty) => ty.walk().any(|arg| arg == dummy_self.into()),
144144
ty::TermKind::Const(c) => {
145-
c.ty().walk().any(|arg| arg == dummy_self.into())
145+
// THISPR
146+
false
146147
}
147148
};
148149

compiler/rustc_hir_typeck/src/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
350350
lt_op: |_| self.tcx.lifetimes.re_erased,
351351
ct_op: |ct| {
352352
if let ty::ConstKind::Infer(_) = ct.kind() {
353-
self.next_const_var(ct.ty(), DUMMY_SP)
353+
self.next_const_var(DUMMY_SP)
354354
} else {
355355
ct
356356
}

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+2-12
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
436436

437437
pub fn lower_array_length(&self, length: &hir::ArrayLen<'tcx>) -> ty::Const<'tcx> {
438438
match length {
439-
hir::ArrayLen::Infer(inf) => self.ct_infer(self.tcx.types.usize, None, inf.span),
439+
hir::ArrayLen::Infer(inf) => self.ct_infer(None, inf.span),
440440
hir::ArrayLen::Body(anon_const) => {
441441
let span = self.tcx.def_span(anon_const.def_id);
442442
let c = ty::Const::from_anon_const(self.tcx, anon_const.def_id);
@@ -1291,20 +1291,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12911291
&GenericParamDefKind::Const { has_default, is_host_effect },
12921292
GenericArg::Infer(inf),
12931293
) => {
1294-
let tcx = self.fcx.tcx();
1295-
12961294
if has_default && is_host_effect {
12971295
self.fcx.var_for_effect(param)
12981296
} else {
1299-
self.fcx
1300-
.ct_infer(
1301-
tcx.type_of(param.def_id)
1302-
.no_bound_vars()
1303-
.expect("const parameter types cannot be generic"),
1304-
Some(param),
1305-
inf.span,
1306-
)
1307-
.into()
1297+
self.fcx.ct_infer(Some(param), inf.span).into()
13081298
}
13091299
}
13101300
_ => unreachable!(),

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,7 @@ impl<'a, 'tcx> HirTyLowerer<'tcx> for FnCtxt<'a, 'tcx> {
241241
}
242242
}
243243

244-
fn ct_infer(
245-
&self,
246-
ty: Ty<'tcx>,
247-
param: Option<&ty::GenericParamDef>,
248-
span: Span,
249-
) -> Const<'tcx> {
244+
fn ct_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> {
250245
// FIXME ideally this shouldn't use unwrap
251246
match param {
252247
Some(
@@ -256,7 +251,7 @@ impl<'a, 'tcx> HirTyLowerer<'tcx> for FnCtxt<'a, 'tcx> {
256251
},
257252
) => self.var_for_effect(param).as_const().unwrap(),
258253
Some(param) => self.var_for_def(span, param).as_const().unwrap(),
259-
None => self.next_const_var(ty, span),
254+
None => self.next_const_var(span),
260255
}
261256
}
262257

compiler/rustc_hir_typeck/src/method/confirm.rs

+1-10
Original file line numberDiff line numberDiff line change
@@ -400,16 +400,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
400400
self.cfcx.ty_infer(Some(param), inf.span).into()
401401
}
402402
(GenericParamDefKind::Const { .. }, GenericArg::Infer(inf)) => {
403-
let tcx = self.cfcx.tcx();
404-
self.cfcx
405-
.ct_infer(
406-
tcx.type_of(param.def_id)
407-
.no_bound_vars()
408-
.expect("const parameter types cannot be generic"),
409-
Some(param),
410-
inf.span,
411-
)
412-
.into()
403+
self.cfcx.ct_infer(Some(param), inf.span).into()
413404
}
414405
(kind, arg) => {
415406
bug!("mismatched method arg kind {kind:?} in turbofish: {arg:?}")

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2060,9 +2060,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20602060
.next_region_var(RegionVariableOrigin::MiscVariable(DUMMY_SP))
20612061
.into(),
20622062
GenericArgKind::Type(_) => self.next_ty_var(DUMMY_SP).into(),
2063-
GenericArgKind::Const(arg) => {
2064-
self.next_const_var(arg.ty(), DUMMY_SP).into()
2065-
}
2063+
GenericArgKind::Const(_) => self.next_const_var(DUMMY_SP).into(),
20662064
}
20672065
} else {
20682066
arg

compiler/rustc_hir_typeck/src/writeback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
863863

864864
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
865865
self.handle_term(ct, ty::Const::outer_exclusive_binder, |tcx, guar| {
866-
ty::Const::new_error(tcx, guar, ct.ty())
866+
ty::Const::new_error(tcx, guar)
867867
})
868868
.super_fold_with(self)
869869
}

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

+10-17
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
462462
// any equated inference vars correctly!
463463
let root_vid = self.infcx.unwrap().root_const_var(vid);
464464
if root_vid != vid {
465-
ct = ty::Const::new_var(self.tcx, root_vid, ct.ty());
465+
ct = ty::Const::new_var(self.tcx, root_vid);
466466
vid = root_vid;
467467
}
468468

@@ -481,7 +481,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
481481
ui = ty::UniverseIndex::ROOT;
482482
}
483483
return self.canonicalize_const_var(
484-
CanonicalVarInfo { kind: CanonicalVarKind::Const(ui, ct.ty()) },
484+
CanonicalVarInfo { kind: CanonicalVarKind::Const(ui) },
485485
ct,
486486
);
487487
}
@@ -510,9 +510,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
510510
}
511511
ty::ConstKind::Placeholder(placeholder) => {
512512
return self.canonicalize_const_var(
513-
CanonicalVarInfo {
514-
kind: CanonicalVarKind::PlaceholderConst(placeholder, ct.ty()),
515-
},
513+
CanonicalVarInfo { kind: CanonicalVarKind::PlaceholderConst(placeholder) },
516514
ct,
517515
);
518516
}
@@ -719,9 +717,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
719717
CanonicalVarKind::Region(u) => {
720718
CanonicalVarKind::Region(reverse_universe_map[&u])
721719
}
722-
CanonicalVarKind::Const(u, t) => {
723-
CanonicalVarKind::Const(reverse_universe_map[&u], t)
724-
}
720+
CanonicalVarKind::Const(u) => CanonicalVarKind::Const(reverse_universe_map[&u]),
725721
CanonicalVarKind::PlaceholderTy(placeholder) => {
726722
CanonicalVarKind::PlaceholderTy(ty::Placeholder {
727723
universe: reverse_universe_map[&placeholder.universe],
@@ -734,14 +730,11 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
734730
..placeholder
735731
})
736732
}
737-
CanonicalVarKind::PlaceholderConst(placeholder, t) => {
738-
CanonicalVarKind::PlaceholderConst(
739-
ty::Placeholder {
740-
universe: reverse_universe_map[&placeholder.universe],
741-
..placeholder
742-
},
743-
t,
744-
)
733+
CanonicalVarKind::PlaceholderConst(placeholder) => {
734+
CanonicalVarKind::PlaceholderConst(ty::Placeholder {
735+
universe: reverse_universe_map[&placeholder.universe],
736+
..placeholder
737+
})
745738
}
746739
},
747740
})
@@ -806,6 +799,6 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
806799
!self.infcx.is_some_and(|infcx| const_var != infcx.shallow_resolve_const(const_var))
807800
);
808801
let var = self.canonical_var(info, const_var.into());
809-
ty::Const::new_bound(self.tcx, self.binder_index, var, self.fold_ty(const_var.ty()))
802+
ty::Const::new_bound(self.tcx, self.binder_index, var)
810803
}
811804
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ where
7070
GenericArgKind::Type(ty) => ty,
7171
r => bug!("{:?} is a type but value is {:?}", bound_ty, r),
7272
},
73-
consts: &mut |bound_ct: ty::BoundVar, _| match var_values[bound_ct].unpack() {
73+
consts: &mut |bound_ct: ty::BoundVar| match var_values[bound_ct].unpack() {
7474
GenericArgKind::Const(ct) => ct,
7575
c => bug!("{:?} is a const but value is {:?}", bound_ct, c),
7676
},

0 commit comments

Comments
 (0)