Skip to content

Commit 8d18c32

Browse files
committed
Auto merge of #111570 - compiler-errors:ct-err, r=BoxyUwU
Rename const error methods for consistency renames `ty::Const`'s methods for creating a `ConstKind::Error` to be in the same naming style as `ty::Ty`'s equivalent methods. r? `@BoxyUwU`
2 parents a14d696 + 8e163f9 commit 8d18c32

File tree

11 files changed

+24
-32
lines changed

11 files changed

+24
-32
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
464464
self.astconv.ct_infer(ty, Some(param), inf.span).into()
465465
} else {
466466
self.inferred_params.push(inf.span);
467-
tcx.const_error(ty).into()
467+
tcx.const_error_misc(ty).into()
468468
}
469469
}
470470
_ => unreachable!(),
@@ -518,7 +518,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
518518
.no_bound_vars()
519519
.expect("const parameter types cannot be generic");
520520
if let Err(guar) = ty.error_reported() {
521-
return tcx.const_error_with_guaranteed(ty, guar).into();
521+
return tcx.const_error(ty, guar).into();
522522
}
523523
if !infer_args && has_default {
524524
tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
@@ -527,7 +527,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
527527
self.astconv.ct_infer(ty, Some(param), self.span).into()
528528
} else {
529529
// We've already errored above about the mismatch.
530-
tcx.const_error(ty).into()
530+
tcx.const_error_misc(ty).into()
531531
}
532532
}
533533
}
@@ -1387,7 +1387,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
13871387
term = match def_kind {
13881388
hir::def::DefKind::AssocTy => tcx.ty_error(reported).into(),
13891389
hir::def::DefKind::AssocConst => tcx
1390-
.const_error_with_guaranteed(
1390+
.const_error(
13911391
tcx.type_of(assoc_item_def_id)
13921392
.subst(tcx, projection_ty.skip_binder().substs),
13931393
reported,

compiler/rustc_hir_typeck/src/writeback.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
836836
debug!("Resolver::fold_const: input const `{:?}` not fully resolvable", ct);
837837
let e = self.report_error(ct);
838838
self.replaced_with_error = Some(e);
839-
self.interner().const_error_with_guaranteed(ct.ty(), e)
839+
self.interner().const_error(ct.ty(), e)
840840
}
841841
}
842842
}

compiler/rustc_infer/src/infer/combine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,11 @@ impl<'tcx> InferCtxt<'tcx> {
209209
// HACK: equating both sides with `[const error]` eagerly prevents us
210210
// from leaving unconstrained inference vars during things like impl
211211
// matching in the solver.
212-
let a_error = self.tcx.const_error_with_guaranteed(a.ty(), guar);
212+
let a_error = self.tcx.const_error(a.ty(), guar);
213213
if let ty::ConstKind::Infer(InferConst::Var(vid)) = a.kind() {
214214
return self.unify_const_variable(vid, a_error);
215215
}
216-
let b_error = self.tcx.const_error_with_guaranteed(b.ty(), guar);
216+
let b_error = self.tcx.const_error(b.ty(), guar);
217217
if let ty::ConstKind::Infer(InferConst::Var(vid)) = b.kind() {
218218
return self.unify_const_variable(vid, b_error);
219219
}

compiler/rustc_middle/src/mir/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,7 @@ impl<'tcx> ConstantKind<'tcx> {
23302330
if let Some(val) = c.kind().try_eval_for_mir(tcx, param_env) {
23312331
match val {
23322332
Ok(val) => Self::Val(val, c.ty()),
2333-
Err(_) => Self::Ty(tcx.const_error(self.ty())),
2333+
Err(guar) => Self::Ty(tcx.const_error(self.ty(), guar)),
23342334
}
23352335
} else {
23362336
self
@@ -2342,9 +2342,7 @@ impl<'tcx> ConstantKind<'tcx> {
23422342
match tcx.const_eval_resolve(param_env, uneval, None) {
23432343
Ok(val) => Self::Val(val, ty),
23442344
Err(ErrorHandled::TooGeneric) => self,
2345-
Err(ErrorHandled::Reported(guar)) => {
2346-
Self::Ty(tcx.const_error_with_guaranteed(ty, guar))
2347-
}
2345+
Err(ErrorHandled::Reported(guar)) => Self::Ty(tcx.const_error(ty, guar)),
23482346
}
23492347
}
23502348
}

compiler/rustc_middle/src/ty/abstract_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'tcx> TyCtxt<'tcx> {
5353
fn fold_const(&mut self, c: Const<'tcx>) -> Const<'tcx> {
5454
let ct = match c.kind() {
5555
ty::ConstKind::Unevaluated(uv) => match self.tcx.thir_abstract_const(uv.def) {
56-
Err(e) => self.tcx.const_error_with_guaranteed(c.ty(), e),
56+
Err(e) => self.tcx.const_error(c.ty(), e),
5757
Ok(Some(bac)) => {
5858
let substs = self.tcx.erase_regions(uv.substs);
5959
let bac = bac.subst(self.tcx, substs);

compiler/rustc_middle/src/ty/consts.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ impl<'tcx> Const<'tcx> {
142142
ty::ConstKind::Bound(debruijn, ty::BoundVar::from_u32(index)),
143143
param_ty,
144144
)),
145-
Some(rbv::ResolvedArg::Error(guar)) => {
146-
Some(tcx.const_error_with_guaranteed(param_ty, guar))
147-
}
145+
Some(rbv::ResolvedArg::Error(guar)) => Some(tcx.const_error(param_ty, guar)),
148146
arg => bug!("unexpected bound var resolution for {:?}: {arg:?}", expr.hir_id),
149147
}
150148
}
@@ -228,7 +226,7 @@ impl<'tcx> Const<'tcx> {
228226
if let Some(val) = self.kind().try_eval_for_typeck(tcx, param_env) {
229227
match val {
230228
Ok(val) => tcx.mk_const(val, self.ty()),
231-
Err(guar) => tcx.const_error_with_guaranteed(self.ty(), guar),
229+
Err(guar) => tcx.const_error(self.ty(), guar),
232230
}
233231
} else {
234232
// Either the constant isn't evaluatable or ValTree creation failed.

compiler/rustc_middle/src/ty/context.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -732,17 +732,13 @@ impl<'tcx> TyCtxt<'tcx> {
732732

733733
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`
734734
#[track_caller]
735-
pub fn const_error_with_guaranteed(
736-
self,
737-
ty: Ty<'tcx>,
738-
reported: ErrorGuaranteed,
739-
) -> Const<'tcx> {
735+
pub fn const_error(self, ty: Ty<'tcx>, reported: ErrorGuaranteed) -> Const<'tcx> {
740736
self.mk_const(ty::ConstKind::Error(reported), ty)
741737
}
742738

743739
/// Like [TyCtxt::ty_error] but for constants.
744740
#[track_caller]
745-
pub fn const_error(self, ty: Ty<'tcx>) -> Const<'tcx> {
741+
pub fn const_error_misc(self, ty: Ty<'tcx>) -> Const<'tcx> {
746742
self.const_error_with_message(
747743
ty,
748744
DUMMY_SP,

compiler/rustc_middle/src/ty/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl GenericParamDef {
103103
ty::GenericParamDefKind::Lifetime => tcx.mk_re_error_misc().into(),
104104
ty::GenericParamDefKind::Type { .. } => tcx.ty_error_misc().into(),
105105
ty::GenericParamDefKind::Const { .. } => {
106-
tcx.const_error(tcx.type_of(self.def_id).subst(tcx, preceding_substs)).into()
106+
tcx.const_error_misc(tcx.type_of(self.def_id).subst(tcx, preceding_substs)).into()
107107
}
108108
}
109109
}

compiler/rustc_middle/src/ty/opaque_types.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -207,14 +207,16 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
207207
Some(GenericArgKind::Const(c1)) => c1,
208208
Some(u) => panic!("const mapped to unexpected kind: {:?}", u),
209209
None => {
210-
if !self.ignore_errors {
211-
self.tcx.sess.emit_err(ConstNotUsedTraitAlias {
210+
let guar = self
211+
.tcx
212+
.sess
213+
.create_err(ConstNotUsedTraitAlias {
212214
ct: ct.to_string(),
213215
span: self.span,
214-
});
215-
}
216+
})
217+
.emit_unless(self.ignore_errors);
216218

217-
self.interner().const_error(ct.ty())
219+
self.interner().const_error(ct.ty(), guar)
218220
}
219221
}
220222
}

compiler/rustc_mir_build/src/build/expr/as_constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub fn as_constant_inner<'tcx>(
5252
match lit_to_mir_constant(tcx, LitToConstInput { lit: &lit.node, ty, neg }) {
5353
Ok(c) => c,
5454
Err(LitToConstError::Reported(guar)) => {
55-
ConstantKind::Ty(tcx.const_error_with_guaranteed(ty, guar))
55+
ConstantKind::Ty(tcx.const_error(ty, guar))
5656
}
5757
Err(LitToConstError::TypeError) => {
5858
bug!("encountered type error in `lit_to_mir_constant`")

compiler/rustc_ty_utils/src/consts.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ fn recurse_build<'tcx>(
115115
let sp = node.span;
116116
match tcx.at(sp).lit_to_const(LitToConstInput { lit: &lit.node, ty: node.ty, neg }) {
117117
Ok(c) => c,
118-
Err(LitToConstError::Reported(guar)) => {
119-
tcx.const_error_with_guaranteed(node.ty, guar)
120-
}
118+
Err(LitToConstError::Reported(guar)) => tcx.const_error(node.ty, guar),
121119
Err(LitToConstError::TypeError) => {
122120
bug!("encountered type error in lit_to_const")
123121
}

0 commit comments

Comments
 (0)