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`
This commit is contained in:
commit
8d18c32b61
11 changed files with 24 additions and 32 deletions
|
@ -464,7 +464,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
self.astconv.ct_infer(ty, Some(param), inf.span).into()
|
self.astconv.ct_infer(ty, Some(param), inf.span).into()
|
||||||
} else {
|
} else {
|
||||||
self.inferred_params.push(inf.span);
|
self.inferred_params.push(inf.span);
|
||||||
tcx.const_error(ty).into()
|
tcx.const_error_misc(ty).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
@ -518,7 +518,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
.no_bound_vars()
|
.no_bound_vars()
|
||||||
.expect("const parameter types cannot be generic");
|
.expect("const parameter types cannot be generic");
|
||||||
if let Err(guar) = ty.error_reported() {
|
if let Err(guar) = ty.error_reported() {
|
||||||
return tcx.const_error_with_guaranteed(ty, guar).into();
|
return tcx.const_error(ty, guar).into();
|
||||||
}
|
}
|
||||||
if !infer_args && has_default {
|
if !infer_args && has_default {
|
||||||
tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
|
tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
|
||||||
|
@ -527,7 +527,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
self.astconv.ct_infer(ty, Some(param), self.span).into()
|
self.astconv.ct_infer(ty, Some(param), self.span).into()
|
||||||
} else {
|
} else {
|
||||||
// We've already errored above about the mismatch.
|
// We've already errored above about the mismatch.
|
||||||
tcx.const_error(ty).into()
|
tcx.const_error_misc(ty).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1387,7 +1387,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
term = match def_kind {
|
term = match def_kind {
|
||||||
hir::def::DefKind::AssocTy => tcx.ty_error(reported).into(),
|
hir::def::DefKind::AssocTy => tcx.ty_error(reported).into(),
|
||||||
hir::def::DefKind::AssocConst => tcx
|
hir::def::DefKind::AssocConst => tcx
|
||||||
.const_error_with_guaranteed(
|
.const_error(
|
||||||
tcx.type_of(assoc_item_def_id)
|
tcx.type_of(assoc_item_def_id)
|
||||||
.subst(tcx, projection_ty.skip_binder().substs),
|
.subst(tcx, projection_ty.skip_binder().substs),
|
||||||
reported,
|
reported,
|
||||||
|
|
|
@ -836,7 +836,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
|
||||||
debug!("Resolver::fold_const: input const `{:?}` not fully resolvable", ct);
|
debug!("Resolver::fold_const: input const `{:?}` not fully resolvable", ct);
|
||||||
let e = self.report_error(ct);
|
let e = self.report_error(ct);
|
||||||
self.replaced_with_error = Some(e);
|
self.replaced_with_error = Some(e);
|
||||||
self.interner().const_error_with_guaranteed(ct.ty(), e)
|
self.interner().const_error(ct.ty(), e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,11 +209,11 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||||
// HACK: equating both sides with `[const error]` eagerly prevents us
|
// HACK: equating both sides with `[const error]` eagerly prevents us
|
||||||
// from leaving unconstrained inference vars during things like impl
|
// from leaving unconstrained inference vars during things like impl
|
||||||
// matching in the solver.
|
// matching in the solver.
|
||||||
let a_error = self.tcx.const_error_with_guaranteed(a.ty(), guar);
|
let a_error = self.tcx.const_error(a.ty(), guar);
|
||||||
if let ty::ConstKind::Infer(InferConst::Var(vid)) = a.kind() {
|
if let ty::ConstKind::Infer(InferConst::Var(vid)) = a.kind() {
|
||||||
return self.unify_const_variable(vid, a_error);
|
return self.unify_const_variable(vid, a_error);
|
||||||
}
|
}
|
||||||
let b_error = self.tcx.const_error_with_guaranteed(b.ty(), guar);
|
let b_error = self.tcx.const_error(b.ty(), guar);
|
||||||
if let ty::ConstKind::Infer(InferConst::Var(vid)) = b.kind() {
|
if let ty::ConstKind::Infer(InferConst::Var(vid)) = b.kind() {
|
||||||
return self.unify_const_variable(vid, b_error);
|
return self.unify_const_variable(vid, b_error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2330,7 +2330,7 @@ impl<'tcx> ConstantKind<'tcx> {
|
||||||
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 {
|
match val {
|
||||||
Ok(val) => Self::Val(val, c.ty()),
|
Ok(val) => Self::Val(val, c.ty()),
|
||||||
Err(_) => Self::Ty(tcx.const_error(self.ty())),
|
Err(guar) => Self::Ty(tcx.const_error(self.ty(), guar)),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
self
|
self
|
||||||
|
@ -2342,9 +2342,7 @@ impl<'tcx> ConstantKind<'tcx> {
|
||||||
match tcx.const_eval_resolve(param_env, uneval, None) {
|
match tcx.const_eval_resolve(param_env, uneval, None) {
|
||||||
Ok(val) => Self::Val(val, ty),
|
Ok(val) => Self::Val(val, ty),
|
||||||
Err(ErrorHandled::TooGeneric) => self,
|
Err(ErrorHandled::TooGeneric) => self,
|
||||||
Err(ErrorHandled::Reported(guar)) => {
|
Err(ErrorHandled::Reported(guar)) => Self::Ty(tcx.const_error(ty, guar)),
|
||||||
Self::Ty(tcx.const_error_with_guaranteed(ty, guar))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
fn fold_const(&mut self, c: Const<'tcx>) -> Const<'tcx> {
|
fn fold_const(&mut self, c: Const<'tcx>) -> Const<'tcx> {
|
||||||
let ct = match c.kind() {
|
let ct = match c.kind() {
|
||||||
ty::ConstKind::Unevaluated(uv) => match self.tcx.thir_abstract_const(uv.def) {
|
ty::ConstKind::Unevaluated(uv) => match self.tcx.thir_abstract_const(uv.def) {
|
||||||
Err(e) => self.tcx.const_error_with_guaranteed(c.ty(), e),
|
Err(e) => self.tcx.const_error(c.ty(), e),
|
||||||
Ok(Some(bac)) => {
|
Ok(Some(bac)) => {
|
||||||
let substs = self.tcx.erase_regions(uv.substs);
|
let substs = self.tcx.erase_regions(uv.substs);
|
||||||
let bac = bac.subst(self.tcx, substs);
|
let bac = bac.subst(self.tcx, substs);
|
||||||
|
|
|
@ -142,9 +142,7 @@ impl<'tcx> Const<'tcx> {
|
||||||
ty::ConstKind::Bound(debruijn, ty::BoundVar::from_u32(index)),
|
ty::ConstKind::Bound(debruijn, ty::BoundVar::from_u32(index)),
|
||||||
param_ty,
|
param_ty,
|
||||||
)),
|
)),
|
||||||
Some(rbv::ResolvedArg::Error(guar)) => {
|
Some(rbv::ResolvedArg::Error(guar)) => Some(tcx.const_error(param_ty, guar)),
|
||||||
Some(tcx.const_error_with_guaranteed(param_ty, guar))
|
|
||||||
}
|
|
||||||
arg => bug!("unexpected bound var resolution for {:?}: {arg:?}", expr.hir_id),
|
arg => bug!("unexpected bound var resolution for {:?}: {arg:?}", expr.hir_id),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,7 +226,7 @@ impl<'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 {
|
match val {
|
||||||
Ok(val) => tcx.mk_const(val, self.ty()),
|
Ok(val) => tcx.mk_const(val, self.ty()),
|
||||||
Err(guar) => tcx.const_error_with_guaranteed(self.ty(), guar),
|
Err(guar) => tcx.const_error(self.ty(), guar),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Either the constant isn't evaluatable or ValTree creation failed.
|
// Either the constant isn't evaluatable or ValTree creation failed.
|
||||||
|
|
|
@ -732,17 +732,13 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`
|
/// Like [TyCtxt::ty_error] but for constants, with current `ErrorGuaranteed`
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn const_error_with_guaranteed(
|
pub fn const_error(self, ty: Ty<'tcx>, reported: ErrorGuaranteed) -> Const<'tcx> {
|
||||||
self,
|
|
||||||
ty: Ty<'tcx>,
|
|
||||||
reported: ErrorGuaranteed,
|
|
||||||
) -> Const<'tcx> {
|
|
||||||
self.mk_const(ty::ConstKind::Error(reported), ty)
|
self.mk_const(ty::ConstKind::Error(reported), ty)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like [TyCtxt::ty_error] but for constants.
|
/// Like [TyCtxt::ty_error] but for constants.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn const_error(self, ty: Ty<'tcx>) -> Const<'tcx> {
|
pub fn const_error_misc(self, ty: Ty<'tcx>) -> Const<'tcx> {
|
||||||
self.const_error_with_message(
|
self.const_error_with_message(
|
||||||
ty,
|
ty,
|
||||||
DUMMY_SP,
|
DUMMY_SP,
|
||||||
|
|
|
@ -103,7 +103,7 @@ impl GenericParamDef {
|
||||||
ty::GenericParamDefKind::Lifetime => tcx.mk_re_error_misc().into(),
|
ty::GenericParamDefKind::Lifetime => tcx.mk_re_error_misc().into(),
|
||||||
ty::GenericParamDefKind::Type { .. } => tcx.ty_error_misc().into(),
|
ty::GenericParamDefKind::Type { .. } => tcx.ty_error_misc().into(),
|
||||||
ty::GenericParamDefKind::Const { .. } => {
|
ty::GenericParamDefKind::Const { .. } => {
|
||||||
tcx.const_error(tcx.type_of(self.def_id).subst(tcx, preceding_substs)).into()
|
tcx.const_error_misc(tcx.type_of(self.def_id).subst(tcx, preceding_substs)).into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,14 +207,16 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReverseMapper<'tcx> {
|
||||||
Some(GenericArgKind::Const(c1)) => c1,
|
Some(GenericArgKind::Const(c1)) => c1,
|
||||||
Some(u) => panic!("const mapped to unexpected kind: {:?}", u),
|
Some(u) => panic!("const mapped to unexpected kind: {:?}", u),
|
||||||
None => {
|
None => {
|
||||||
if !self.ignore_errors {
|
let guar = self
|
||||||
self.tcx.sess.emit_err(ConstNotUsedTraitAlias {
|
.tcx
|
||||||
|
.sess
|
||||||
|
.create_err(ConstNotUsedTraitAlias {
|
||||||
ct: ct.to_string(),
|
ct: ct.to_string(),
|
||||||
span: self.span,
|
span: self.span,
|
||||||
});
|
})
|
||||||
}
|
.emit_unless(self.ignore_errors);
|
||||||
|
|
||||||
self.interner().const_error(ct.ty())
|
self.interner().const_error(ct.ty(), guar)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ pub fn as_constant_inner<'tcx>(
|
||||||
match lit_to_mir_constant(tcx, LitToConstInput { lit: &lit.node, ty, neg }) {
|
match lit_to_mir_constant(tcx, LitToConstInput { lit: &lit.node, ty, neg }) {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(LitToConstError::Reported(guar)) => {
|
Err(LitToConstError::Reported(guar)) => {
|
||||||
ConstantKind::Ty(tcx.const_error_with_guaranteed(ty, guar))
|
ConstantKind::Ty(tcx.const_error(ty, guar))
|
||||||
}
|
}
|
||||||
Err(LitToConstError::TypeError) => {
|
Err(LitToConstError::TypeError) => {
|
||||||
bug!("encountered type error in `lit_to_mir_constant`")
|
bug!("encountered type error in `lit_to_mir_constant`")
|
||||||
|
|
|
@ -115,9 +115,7 @@ fn recurse_build<'tcx>(
|
||||||
let sp = node.span;
|
let sp = node.span;
|
||||||
match tcx.at(sp).lit_to_const(LitToConstInput { lit: &lit.node, ty: node.ty, neg }) {
|
match tcx.at(sp).lit_to_const(LitToConstInput { lit: &lit.node, ty: node.ty, neg }) {
|
||||||
Ok(c) => c,
|
Ok(c) => c,
|
||||||
Err(LitToConstError::Reported(guar)) => {
|
Err(LitToConstError::Reported(guar)) => tcx.const_error(node.ty, guar),
|
||||||
tcx.const_error_with_guaranteed(node.ty, guar)
|
|
||||||
}
|
|
||||||
Err(LitToConstError::TypeError) => {
|
Err(LitToConstError::TypeError) => {
|
||||||
bug!("encountered type error in lit_to_const")
|
bug!("encountered type error in lit_to_const")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue