Skip to content

Commit 58feec9

Browse files
committed
Basic removal of Ty from places (boring)
1 parent 7ebd2bd commit 58feec9

File tree

71 files changed

+331
-581
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

+331
-581
lines changed

compiler/rustc_borrowck/src/type_check/relate_tys.rs

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2198,9 +2198,6 @@ fn param_env_with_gat_bounds<'tcx>(
21982198
tcx,
21992199
ty::INNERMOST,
22002200
ty::BoundVar::from_usize(bound_vars.len() - 1),
2201-
tcx.type_of(param.def_id)
2202-
.no_bound_vars()
2203-
.expect("const parameter types cannot be generic"),
22042201
)
22052202
.into()
22062203
}

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -396,16 +396,8 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
396396
Ty::new_error_with_message(self.tcx(), span, "bad placeholder type")
397397
}
398398

399-
fn ct_infer(&self, ty: Ty<'tcx>, _: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> {
400-
let ty = self.tcx.fold_regions(ty, |r, _| match *r {
401-
rustc_type_ir::RegionKind::ReStatic => r,
402-
403-
// This is never reached in practice. If it ever is reached,
404-
// `ReErased` should be changed to `ReStatic`, and any other region
405-
// left alone.
406-
r => bug!("unexpected region: {r:?}"),
407-
});
408-
ty::Const::new_error_with_message(self.tcx(), ty, span, "bad placeholder constant")
399+
fn ct_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> {
400+
ty::Const::new_error_with_message(self.tcx(), span, "bad placeholder constant")
409401
}
410402

411403
fn probe_ty_param_bounds(

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

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

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
368368
},
369369
)
370370
});
371-
let ty = tcx
372-
.type_of(param.def_id)
373-
.no_bound_vars()
374-
.expect("ct params cannot have early bound vars");
375-
ty::Const::new_error(tcx, guar, ty).into()
371+
ty::Const::new_error(tcx, guar).into()
376372
}
377373
};
378374
num_bound_vars += 1;

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,7 @@ pub trait HirTyLowerer<'tcx> {
111111
fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx>;
112112

113113
/// Returns the const to use when a const is omitted.
114-
fn ct_infer(
115-
&self,
116-
ty: Ty<'tcx>,
117-
param: Option<&ty::GenericParamDef>,
118-
span: Span,
119-
) -> Const<'tcx>;
114+
fn ct_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx>;
120115

121116
/// Probe bounds in scope where the bounded type coincides with the given type parameter.
122117
///
@@ -439,15 +434,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
439434

440435
fn provided_kind(
441436
&mut self,
442-
preceding_args: &[ty::GenericArg<'tcx>],
437+
_preceding_args: &[ty::GenericArg<'tcx>],
443438
param: &ty::GenericParamDef,
444439
arg: &GenericArg<'tcx>,
445440
) -> ty::GenericArg<'tcx> {
446441
let tcx = self.lowerer.tcx();
447442

448443
if let Err(incorrect) = self.incorrect_args {
449444
if incorrect.invalid_args.contains(&(param.index as usize)) {
450-
return param.to_error(tcx, preceding_args);
445+
return param.to_error(tcx);
451446
}
452447
}
453448

@@ -487,12 +482,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
487482
ty::Const::from_anon_const(tcx, did).into()
488483
}
489484
(&GenericParamDefKind::Const { .. }, hir::GenericArg::Infer(inf)) => {
490-
let ty = tcx
491-
.at(self.span)
492-
.type_of(param.def_id)
493-
.no_bound_vars()
494-
.expect("const parameter types cannot be generic");
495-
self.lowerer.ct_infer(ty, Some(param), inf.span).into()
485+
self.lowerer.ct_infer(Some(param), inf.span).into()
496486
}
497487
(kind, arg) => span_bug!(
498488
self.span,
@@ -511,7 +501,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
511501

512502
if let Err(incorrect) = self.incorrect_args {
513503
if incorrect.invalid_args.contains(&(param.index as usize)) {
514-
return param.to_error(tcx, preceding_args);
504+
return param.to_error(tcx);
515505
}
516506
}
517507
match param.kind {
@@ -548,7 +538,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
548538
.no_bound_vars()
549539
.expect("const parameter types cannot be generic");
550540
if let Err(guar) = ty.error_reported() {
551-
return ty::Const::new_error(tcx, guar, ty).into();
541+
return ty::Const::new_error(tcx, guar).into();
552542
}
553543
// FIXME(effects) see if we should special case effect params here
554544
if !infer_args && has_default {
@@ -557,10 +547,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
557547
.into()
558548
} else {
559549
if infer_args {
560-
self.lowerer.ct_infer(ty, Some(param), self.span).into()
550+
self.lowerer.ct_infer(Some(param), self.span).into()
561551
} else {
562552
// We've already errored above about the mismatch.
563-
ty::Const::new_misc_error(tcx, ty).into()
553+
ty::Const::new_misc_error(tcx).into()
564554
}
565555
}
566556
}
@@ -1908,7 +1898,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
19081898
///
19091899
/// Early-bound const parameters get lowered to [`ty::ConstKind::Param`]
19101900
/// and late-bound ones to [`ty::ConstKind::Bound`].
1911-
pub(crate) fn lower_const_param(&self, hir_id: HirId, param_ty: Ty<'tcx>) -> Const<'tcx> {
1901+
pub(crate) fn lower_const_param(&self, hir_id: HirId) -> Const<'tcx> {
19121902
let tcx = self.tcx();
19131903
match tcx.named_bound_var(hir_id) {
19141904
Some(rbv::ResolvedArg::EarlyBound(def_id)) => {
@@ -1918,12 +1908,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
19181908
let generics = tcx.generics_of(item_def_id);
19191909
let index = generics.param_def_id_to_index[&def_id];
19201910
let name = tcx.item_name(def_id);
1921-
ty::Const::new_param(tcx, ty::ParamConst::new(index, name), param_ty)
1911+
ty::Const::new_param(tcx, ty::ParamConst::new(index, name))
19221912
}
19231913
Some(rbv::ResolvedArg::LateBound(debruijn, index, _)) => {
1924-
ty::Const::new_bound(tcx, debruijn, ty::BoundVar::from_u32(index), param_ty)
1914+
ty::Const::new_bound(tcx, debruijn, ty::BoundVar::from_u32(index))
19251915
}
1926-
Some(rbv::ResolvedArg::Error(guar)) => ty::Const::new_error(tcx, guar, param_ty),
1916+
Some(rbv::ResolvedArg::Error(guar)) => ty::Const::new_error(tcx, guar),
19271917
arg => bug!("unexpected bound var resolution for {:?}: {arg:?}", hir_id),
19281918
}
19291919
}
@@ -2139,7 +2129,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21392129
}
21402130
hir::TyKind::Array(ty, length) => {
21412131
let length = match length {
2142-
hir::ArrayLen::Infer(inf) => self.ct_infer(tcx.types.usize, None, inf.span),
2132+
hir::ArrayLen::Infer(inf) => self.ct_infer(None, inf.span),
21432133
hir::ArrayLen::Body(constant) => {
21442134
ty::Const::from_anon_const(tcx, constant.def_id)
21452135
}
@@ -2177,7 +2167,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21772167
match tcx.lit_to_const(lit_input) {
21782168
Ok(c) => c,
21792169
Err(LitToConstError::Reported(err)) => {
2180-
ty::Const::new_error(tcx, err, ty)
2170+
ty::Const::new_error(tcx, err)
21812171
}
21822172
Err(LitToConstError::TypeError) => todo!(),
21832173
}
@@ -2198,19 +2188,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21982188
.type_of(def_id)
21992189
.no_bound_vars()
22002190
.expect("const parameter types cannot be generic");
2201-
self.lower_const_param(expr.hir_id, ty)
2191+
self.lower_const_param(expr.hir_id)
22022192
}
22032193

22042194
_ => {
22052195
let err = tcx
22062196
.dcx()
22072197
.emit_err(crate::errors::NonConstRange { span: expr.span });
2208-
ty::Const::new_error(tcx, err, ty)
2198+
ty::Const::new_error(tcx, err)
22092199
}
22102200
};
2211-
self.record_ty(expr.hir_id, c.ty(), expr.span);
2201+
// THISPR
2202+
self.record_ty(expr.hir_id, todo!(), expr.span);
22122203
if let Some((id, span)) = neg {
2213-
self.record_ty(id, c.ty(), span);
2204+
self.record_ty(id, todo!(), span);
22142205
}
22152206
c
22162207
};

compiler/rustc_hir_analysis/src/hir_ty_lowering/object_safety.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
144144
let references_self = match pred.skip_binder().term.unpack() {
145145
ty::TermKind::Ty(ty) => ty.walk().any(|arg| arg == dummy_self.into()),
146146
ty::TermKind::Const(c) => {
147-
c.ty().walk().any(|arg| arg == dummy_self.into())
147+
// THISPR
148+
false
148149
}
149150
};
150151

compiler/rustc_hir_typeck/src/demand.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 12 deletions
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);
@@ -1292,20 +1292,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12921292
&GenericParamDefKind::Const { has_default, is_host_effect },
12931293
GenericArg::Infer(inf),
12941294
) => {
1295-
let tcx = self.fcx.tcx();
1296-
12971295
if has_default && is_host_effect {
12981296
self.fcx.var_for_effect(param)
12991297
} else {
1300-
self.fcx
1301-
.ct_infer(
1302-
tcx.type_of(param.def_id)
1303-
.no_bound_vars()
1304-
.expect("const parameter types cannot be generic"),
1305-
Some(param),
1306-
inf.span,
1307-
)
1308-
.into()
1298+
self.fcx.ct_infer(Some(param), inf.span).into()
13091299
}
13101300
}
13111301
_ => unreachable!(),

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,7 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
237237
}
238238
}
239239

240-
fn ct_infer(
241-
&self,
242-
ty: Ty<'tcx>,
243-
param: Option<&ty::GenericParamDef>,
244-
span: Span,
245-
) -> Const<'tcx> {
240+
fn ct_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Const<'tcx> {
246241
// FIXME ideally this shouldn't use unwrap
247242
match param {
248243
Some(
@@ -252,7 +247,7 @@ impl<'tcx> HirTyLowerer<'tcx> for FnCtxt<'_, 'tcx> {
252247
},
253248
) => self.var_for_effect(param).as_const().unwrap(),
254249
Some(param) => self.var_for_def(span, param).as_const().unwrap(),
255-
None => self.next_const_var(ty, span),
250+
None => self.next_const_var(span),
256251
}
257252
}
258253

compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -406,16 +406,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
406406
self.cfcx.ty_infer(Some(param), inf.span).into()
407407
}
408408
(GenericParamDefKind::Const { .. }, GenericArg::Infer(inf)) => {
409-
let tcx = self.cfcx.tcx();
410-
self.cfcx
411-
.ct_infer(
412-
tcx.type_of(param.def_id)
413-
.no_bound_vars()
414-
.expect("const parameter types cannot be generic"),
415-
Some(param),
416-
inf.span,
417-
)
418-
.into()
409+
self.cfcx.ct_infer(Some(param), inf.span).into()
419410
}
420411
(kind, arg) => {
421412
bug!("mismatched method arg kind {kind:?} in turbofish: {arg:?}")

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,9 +2096,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20962096
.next_region_var(RegionVariableOrigin::MiscVariable(DUMMY_SP))
20972097
.into(),
20982098
GenericArgKind::Type(_) => self.next_ty_var(DUMMY_SP).into(),
2099-
GenericArgKind::Const(arg) => {
2100-
self.next_const_var(arg.ty(), DUMMY_SP).into()
2101-
}
2099+
GenericArgKind::Const(_) => self.next_const_var(DUMMY_SP).into(),
21022100
}
21032101
} else {
21042102
arg

compiler/rustc_hir_typeck/src/writeback.rs

Lines changed: 1 addition & 1 deletion
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
}

0 commit comments

Comments
 (0)