Migrate pattern inlining error diagnostics

This commit is contained in:
TheOddGarlic 2022-08-26 19:30:33 +03:00 committed by mejrs
parent c7bfd00719
commit 98442b6905
3 changed files with 41 additions and 13 deletions

View File

@ -183,3 +183,11 @@ mir_build_non_exhaustive_patterns_type_not_empty = non-exhaustive patterns: type
.reference_note = references are always considered inhabited
.suggestion = ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
.help = ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
mir_build_static_in_pattern = statics cannot be referenced in patterns
mir_build_assoc_const_in_pattern = associated consts cannot be referenced in patterns
mir_build_const_param_in_pattern = const parameters cannot be referenced in patterns
mir_build_non_const_path = runtime values cannot be referenced in patterns

View File

@ -429,3 +429,31 @@ impl<'a> SessionDiagnostic<'a> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_>
diag
}
}
#[derive(SessionDiagnostic)]
#[diag(mir_build::static_in_pattern, code = "E0158")]
pub struct StaticInPattern {
#[primary_span]
pub span: Span,
}
#[derive(SessionDiagnostic)]
#[diag(mir_build::assoc_const_in_pattern, code = "E0158")]
pub struct AssocConstInPattern {
#[primary_span]
pub span: Span,
}
#[derive(SessionDiagnostic)]
#[diag(mir_build::const_param_in_pattern, code = "E0158")]
pub struct ConstParamInPattern {
#[primary_span]
pub span: Span,
}
#[derive(SessionDiagnostic)]
#[diag(mir_build::non_const_path, code = "E0080")]
pub struct NonConstPath {
#[primary_span]
pub span: Span,
}

View File

@ -4,7 +4,7 @@ use super::usefulness::{
};
use super::{PatCtxt, PatternError};
use crate::errors::NonExhaustivePatternsTypeNotEmpty;
use crate::errors::*;
use rustc_arena::TypedArena;
use rustc_ast::Mutability;
@ -109,28 +109,20 @@ impl PatCtxt<'_, '_> {
for error in &self.errors {
match *error {
PatternError::StaticInPattern(span) => {
self.span_e0158(span, "statics cannot be referenced in patterns")
self.tcx.sess.emit_err(StaticInPattern { span });
}
PatternError::AssocConstInPattern(span) => {
self.span_e0158(span, "associated consts cannot be referenced in patterns")
self.tcx.sess.emit_err(AssocConstInPattern { span });
}
PatternError::ConstParamInPattern(span) => {
self.span_e0158(span, "const parameters cannot be referenced in patterns")
self.tcx.sess.emit_err(ConstParamInPattern { span });
}
PatternError::NonConstPath(span) => {
rustc_middle::mir::interpret::struct_error(
self.tcx.at(span),
"runtime values cannot be referenced in patterns",
)
.emit();
self.tcx.sess.emit_err(NonConstPath { span });
}
}
}
}
fn span_e0158(&self, span: Span, text: &str) {
struct_span_err!(self.tcx.sess, span, E0158, "{}", text).emit();
}
}
impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {