Migrate "constant pattern depends on generic parameter" diagnostic
This commit is contained in:
parent
b694e6649e
commit
d5f821eeb0
3 changed files with 14 additions and 3 deletions
|
@ -466,3 +466,10 @@ pub struct UnreachablePattern {
|
|||
#[label(mir_build::catchall_label)]
|
||||
pub catchall: Option<Span>,
|
||||
}
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[diag(mir_build::const_pattern_depends_on_generic_parameter)]
|
||||
pub struct ConstPatternDependsOnGenericParameter {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ mod usefulness;
|
|||
pub(crate) use self::check_match::check_match;
|
||||
pub(crate) use self::usefulness::MatchCheckCtxt;
|
||||
|
||||
use crate::errors::ConstPatternDependsOnGenericParameter;
|
||||
use crate::thir::util::UserAnnotatedTyHelpers;
|
||||
|
||||
use rustc_errors::struct_span_err;
|
||||
|
@ -549,7 +550,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
Err(ErrorHandled::TooGeneric) => {
|
||||
// While `Reported | Linted` cases will have diagnostics emitted already
|
||||
// it is not true for TooGeneric case, so we need to give user more information.
|
||||
self.tcx.sess.span_err(span, "constant pattern depends on a generic parameter");
|
||||
self.tcx.sess.emit_err(ConstPatternDependsOnGenericParameter { span });
|
||||
pat_from_kind(PatKind::Wild)
|
||||
}
|
||||
Err(_) => {
|
||||
|
@ -583,9 +584,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
|
|||
_ => bug!("Expected ConstKind::Param"),
|
||||
},
|
||||
mir::ConstantKind::Val(_, _) => self.const_to_pat(value, id, span, false).kind,
|
||||
mir::ConstantKind::Unevaluated(..) => {
|
||||
mir::ConstKind::Unevaluated(_) => {
|
||||
// If we land here it means the const can't be evaluated because it's `TooGeneric`.
|
||||
self.tcx.sess.span_err(span, "constant pattern depends on a generic parameter");
|
||||
self.tcx.sess.emit_err(ConstPatternDependsOnGenericParameter { span });
|
||||
return PatKind::Wild;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue