Skip to content

Commit 98442b6

Browse files
lzcuntmejrs
authored andcommitted
Migrate pattern inlining error diagnostics
1 parent c7bfd00 commit 98442b6

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;
@@ -109,28 +109,20 @@ impl PatCtxt<'_, '_> {
109109
for error in &self.errors {
110110
match *error {
111111
PatternError::StaticInPattern(span) => {
112-
self.span_e0158(span, "statics cannot be referenced in patterns")
112+
self.tcx.sess.emit_err(StaticInPattern { span });
113113
}
114114
PatternError::AssocConstInPattern(span) => {
115-
self.span_e0158(span, "associated consts cannot be referenced in patterns")
115+
self.tcx.sess.emit_err(AssocConstInPattern { span });
116116
}
117117
PatternError::ConstParamInPattern(span) => {
118-
self.span_e0158(span, "const parameters cannot be referenced in patterns")
118+
self.tcx.sess.emit_err(ConstParamInPattern { span });
119119
}
120120
PatternError::NonConstPath(span) => {
121-
rustc_middle::mir::interpret::struct_error(
122-
self.tcx.at(span),
123-
"runtime values cannot be referenced in patterns",
124-
)
125-
.emit();
121+
self.tcx.sess.emit_err(NonConstPath { span });
126122
}
127123
}
128124
}
129125
}
130-
131-
fn span_e0158(&self, span: Span, text: &str) {
132-
struct_span_err!(self.tcx.sess, span, E0158, "{}", text).emit();
133-
}
134126
}
135127

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

0 commit comments

Comments
 (0)