1
Fork 0

Tweak unevaluated constant in pattern error

Silence errors that are implied by the errors in the `const` item definition.

Add a primary span label.
This commit is contained in:
Esteban Küber 2024-11-20 02:37:56 +00:00
parent c6205055e0
commit cc492edc9d
22 changed files with 37 additions and 165 deletions

View file

@ -92,6 +92,7 @@ mir_build_const_pattern_depends_on_generic_parameter =
constant pattern depends on a generic parameter
mir_build_could_not_eval_const_pattern = could not evaluate constant pattern
.label = could not evaluate constant
mir_build_deref_raw_pointer_requires_unsafe =
dereference of raw pointer is unsafe and requires unsafe block

View file

@ -702,6 +702,7 @@ pub(crate) struct ConstPatternDependsOnGenericParameter {
#[diag(mir_build_could_not_eval_const_pattern)]
pub(crate) struct CouldNotEvalConstPattern {
#[primary_span]
#[label]
pub(crate) span: Span,
}

View file

@ -122,7 +122,16 @@ impl<'tcx> ConstToPat<'tcx> {
Ok(Ok(c)) => c,
Err(ErrorHandled::Reported(_, _)) => {
// Let's tell the use where this failing const occurs.
let err = self.tcx.dcx().create_err(CouldNotEvalConstPattern { span: self.span });
let mut err =
self.tcx.dcx().create_err(CouldNotEvalConstPattern { span: self.span });
// We've emitted an error on the original const, it would be redundant to complain
// on its use as well.
if let ty::ConstKind::Unevaluated(uv) = self.c.kind()
&& let hir::def::DefKind::Const | hir::def::DefKind::AssocConst =
self.tcx.def_kind(uv.def)
{
err.downgrade_to_delayed_bug();
}
return self.mk_err(err, ty);
}
Err(ErrorHandled::TooGeneric(_)) => {