Skip to content

Commit 01acfef

Browse files
committed
Migrate stable let_chains error to session diagnostics
1 parent d1ef818 commit 01acfef

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

Diff for: compiler/rustc_ast_passes/src/ast_validation.rs

+2-23
Original file line numberDiff line numberDiff line change
@@ -121,30 +121,9 @@ impl<'a> AstValidator<'a> {
121121
fn ban_let_expr(&self, expr: &'a Expr, forbidden_let_reason: ForbiddenLetReason) {
122122
let sess = &self.session;
123123
if sess.opts.unstable_features.is_nightly_build() {
124-
let err = "`let` expressions are not supported here";
125-
let mut diag = sess.struct_span_err(expr.span, err);
126-
diag.note("only supported directly in conditions of `if` and `while` expressions");
127-
match forbidden_let_reason {
128-
ForbiddenLetReason::GenericForbidden => {}
129-
ForbiddenLetReason::NotSupportedOr(span) => {
130-
diag.span_note(
131-
span,
132-
"`||` operators are not supported in let chain expressions",
133-
);
134-
}
135-
ForbiddenLetReason::NotSupportedParentheses(span) => {
136-
diag.span_note(
137-
span,
138-
"`let`s wrapped in parentheses are not supported in a context with let \
139-
chains",
140-
);
141-
}
142-
}
143-
diag.emit();
124+
sess.emit_err(ForbiddenLet { span: expr.span, reason: forbidden_let_reason });
144125
} else {
145-
sess.struct_span_err(expr.span, "expected expression, found statement (`let`)")
146-
.note("variable declaration using `let` is a statement")
147-
.emit();
126+
sess.emit_err(ForbiddenLetStable { span: expr.span });
148127
}
149128
}
150129

Diff for: compiler/rustc_ast_passes/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ impl AddSubdiagnostic for ForbiddenLetReason {
3030
}
3131
}
3232

33+
#[derive(SessionDiagnostic)]
34+
#[diag(ast_passes::forbidden_let_stable)]
35+
#[note]
36+
pub struct ForbiddenLetStable {
37+
#[primary_span]
38+
pub span: Span,
39+
}
40+
3341
#[derive(SessionDiagnostic)]
3442
#[diag(ast_passes::forbidden_assoc_constraint)]
3543
pub struct ForbiddenAssocConstraint {

Diff for: compiler/rustc_error_messages/locales/en-US/ast_passes.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ ast_passes_forbidden_let =
44
.not_supported_or = `||` operators are not supported in let chain expressions
55
.not_supported_parentheses = `let`s wrapped in parentheses are not supported in a context with let chains
66
7+
ast_passes_forbidden_let_stable =
8+
expected expression, found statement (`let`)
9+
.note = variable declaration using `let` is a statement
10+
711
ast_passes_deprecated_where_clause_location =
812
where clause not allowed here
913

0 commit comments

Comments
 (0)