Migrate stable let_chains error to session diagnostics
This commit is contained in:
parent
d1ef8180f9
commit
01acfef1a4
@ -121,30 +121,9 @@ impl<'a> AstValidator<'a> {
|
|||||||
fn ban_let_expr(&self, expr: &'a Expr, forbidden_let_reason: ForbiddenLetReason) {
|
fn ban_let_expr(&self, expr: &'a Expr, forbidden_let_reason: ForbiddenLetReason) {
|
||||||
let sess = &self.session;
|
let sess = &self.session;
|
||||||
if sess.opts.unstable_features.is_nightly_build() {
|
if sess.opts.unstable_features.is_nightly_build() {
|
||||||
let err = "`let` expressions are not supported here";
|
sess.emit_err(ForbiddenLet { span: expr.span, reason: forbidden_let_reason });
|
||||||
let mut diag = sess.struct_span_err(expr.span, err);
|
|
||||||
diag.note("only supported directly in conditions of `if` and `while` expressions");
|
|
||||||
match forbidden_let_reason {
|
|
||||||
ForbiddenLetReason::GenericForbidden => {}
|
|
||||||
ForbiddenLetReason::NotSupportedOr(span) => {
|
|
||||||
diag.span_note(
|
|
||||||
span,
|
|
||||||
"`||` operators are not supported in let chain expressions",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
ForbiddenLetReason::NotSupportedParentheses(span) => {
|
|
||||||
diag.span_note(
|
|
||||||
span,
|
|
||||||
"`let`s wrapped in parentheses are not supported in a context with let \
|
|
||||||
chains",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
diag.emit();
|
|
||||||
} else {
|
} else {
|
||||||
sess.struct_span_err(expr.span, "expected expression, found statement (`let`)")
|
sess.emit_err(ForbiddenLetStable { span: expr.span });
|
||||||
.note("variable declaration using `let` is a statement")
|
|
||||||
.emit();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,6 +30,14 @@ impl AddSubdiagnostic for ForbiddenLetReason {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(SessionDiagnostic)]
|
||||||
|
#[diag(ast_passes::forbidden_let_stable)]
|
||||||
|
#[note]
|
||||||
|
pub struct ForbiddenLetStable {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(SessionDiagnostic)]
|
#[derive(SessionDiagnostic)]
|
||||||
#[diag(ast_passes::forbidden_assoc_constraint)]
|
#[diag(ast_passes::forbidden_assoc_constraint)]
|
||||||
pub struct ForbiddenAssocConstraint {
|
pub struct ForbiddenAssocConstraint {
|
||||||
|
@ -4,6 +4,10 @@ ast_passes_forbidden_let =
|
|||||||
.not_supported_or = `||` operators are not supported in let chain expressions
|
.not_supported_or = `||` operators are not supported in let chain expressions
|
||||||
.not_supported_parentheses = `let`s wrapped in parentheses are not supported in a context with let chains
|
.not_supported_parentheses = `let`s wrapped in parentheses are not supported in a context with let chains
|
||||||
|
|
||||||
|
ast_passes_forbidden_let_stable =
|
||||||
|
expected expression, found statement (`let`)
|
||||||
|
.note = variable declaration using `let` is a statement
|
||||||
|
|
||||||
ast_passes_deprecated_where_clause_location =
|
ast_passes_deprecated_where_clause_location =
|
||||||
where clause not allowed here
|
where clause not allowed here
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user