Skip to content

Commit 6adcc31

Browse files
committed
Migrate pattern inlining error diagnostics
1 parent 59c0b8d commit 6adcc31

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

compiler/rustc_error_messages/locales/en-US/mir_build.ftl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,11 @@ mir_build_non_exhaustive_patterns_type_not_empty = non-exhaustive patterns: type
183183
.reference_note = references are always considered inhabited
184184
.suggestion = ensure that all possible cases are being handled by adding a match arm with a wildcard pattern as shown
185185
.help = ensure that all possible cases are being handled by adding a match arm with a wildcard pattern
186+
187+
mir_build_static_in_pattern = statics cannot be referenced in patterns
188+
189+
mir_build_assoc_const_in_pattern = associated consts cannot be referenced in patterns
190+
191+
mir_build_const_param_in_pattern = const parameters cannot be referenced in patterns
192+
193+
mir_build_non_const_path = runtime values cannot be referenced in patterns

compiler/rustc_mir_build/src/errors.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,3 +429,31 @@ impl<'a> SessionDiagnostic<'a> for NonExhaustivePatternsTypeNotEmpty<'_, '_, '_>
429429
diag
430430
}
431431
}
432+
433+
#[derive(SessionDiagnostic)]
434+
#[diag(mir_build::static_in_pattern, code = "E0158")]
435+
pub struct StaticInPattern {
436+
#[primary_span]
437+
pub span: Span,
438+
}
439+
440+
#[derive(SessionDiagnostic)]
441+
#[diag(mir_build::assoc_const_in_pattern, code = "E0158")]
442+
pub struct AssocConstInPattern {
443+
#[primary_span]
444+
pub span: Span,
445+
}
446+
447+
#[derive(SessionDiagnostic)]
448+
#[diag(mir_build::const_param_in_pattern, code = "E0158")]
449+
pub struct ConstParamInPattern {
450+
#[primary_span]
451+
pub span: Span,
452+
}
453+
454+
#[derive(SessionDiagnostic)]
455+
#[diag(mir_build::non_const_path, code = "E0080")]
456+
pub struct NonConstPath {
457+
#[primary_span]
458+
pub span: Span,
459+
}

compiler/rustc_mir_build/src/thir/pattern/check_match.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use super::usefulness::{
44
};
55
use super::{PatCtxt, PatternError};
66

7-
use crate::errors::NonExhaustivePatternsTypeNotEmpty;
7+
use crate::errors::*;
88

99
use rustc_arena::TypedArena;
1010
use rustc_ast::Mutability;
@@ -106,28 +106,20 @@ impl PatCtxt<'_, '_> {
106106
for error in &self.errors {
107107
match *error {
108108
PatternError::StaticInPattern(span) => {
109-
self.span_e0158(span, "statics cannot be referenced in patterns")
109+
self.tcx.sess.emit_err(StaticInPattern { span });
110110
}
111111
PatternError::AssocConstInPattern(span) => {
112-
self.span_e0158(span, "associated consts cannot be referenced in patterns")
112+
self.tcx.sess.emit_err(AssocConstInPattern { span });
113113
}
114114
PatternError::ConstParamInPattern(span) => {
115-
self.span_e0158(span, "const parameters cannot be referenced in patterns")
115+
self.tcx.sess.emit_err(ConstParamInPattern { span });
116116
}
117117
PatternError::NonConstPath(span) => {
118-
rustc_middle::mir::interpret::struct_error(
119-
self.tcx.at(span),
120-
"runtime values cannot be referenced in patterns",
121-
)
122-
.emit();
118+
self.tcx.sess.emit_err(NonConstPath { span });
123119
}
124120
}
125121
}
126122
}
127-
128-
fn span_e0158(&self, span: Span, text: &str) {
129-
struct_span_err!(self.tcx.sess, span, E0158, "{}", text).emit();
130-
}
131123
}
132124

133125
impl<'p, 'tcx> MatchVisitor<'_, 'p, 'tcx> {

0 commit comments

Comments
 (0)