ast_passes: use derive more
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
2a4b587a68
commit
ea5d258a75
2 changed files with 6 additions and 20 deletions
|
@ -14,6 +14,7 @@ use rustc_ast::*;
|
||||||
use rustc_ast_pretty::pprust::{self, State};
|
use rustc_ast_pretty::pprust::{self, State};
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_errors::{error_code, fluent, pluralize, struct_span_err, Applicability};
|
use rustc_errors::{error_code, fluent, pluralize, struct_span_err, Applicability};
|
||||||
|
use rustc_macros::Subdiagnostic;
|
||||||
use rustc_parse::validate_attr;
|
use rustc_parse::validate_attr;
|
||||||
use rustc_session::lint::builtin::{
|
use rustc_session::lint::builtin::{
|
||||||
DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, PATTERNS_IN_FNS_WITHOUT_BODY,
|
DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, PATTERNS_IN_FNS_WITHOUT_BODY,
|
||||||
|
@ -1782,15 +1783,17 @@ pub fn check_crate(session: &Session, krate: &Crate, lints: &mut LintBuffer) ->
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used to forbid `let` expressions in certain syntactic locations.
|
/// Used to forbid `let` expressions in certain syntactic locations.
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy, Subdiagnostic)]
|
||||||
pub(crate) enum ForbiddenLetReason {
|
pub(crate) enum ForbiddenLetReason {
|
||||||
/// `let` is not valid and the source environment is not important
|
/// `let` is not valid and the source environment is not important
|
||||||
GenericForbidden,
|
GenericForbidden,
|
||||||
/// A let chain with the `||` operator
|
/// A let chain with the `||` operator
|
||||||
NotSupportedOr(Span),
|
#[note(ast_passes::not_supported_or)]
|
||||||
|
NotSupportedOr(#[primary_span] Span),
|
||||||
/// A let chain with invalid parentheses
|
/// A let chain with invalid parentheses
|
||||||
///
|
///
|
||||||
/// For example, `let 1 = 1 && (expr && expr)` is allowed
|
/// For example, `let 1 = 1 && (expr && expr)` is allowed
|
||||||
/// but `(let 1 = 1 && (let 1 = 1 && (let 1 = 1))) && let a = 1` is not
|
/// but `(let 1 = 1 && (let 1 = 1 && (let 1 = 1))) && let a = 1` is not
|
||||||
NotSupportedParentheses(Span),
|
#[note(ast_passes::not_supported_parentheses)]
|
||||||
|
NotSupportedParentheses(#[primary_span] Span),
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,23 +16,6 @@ pub struct ForbiddenLet {
|
||||||
pub(crate) reason: ForbiddenLetReason,
|
pub(crate) reason: ForbiddenLetReason,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddToDiagnostic for ForbiddenLetReason {
|
|
||||||
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
|
|
||||||
where
|
|
||||||
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
|
|
||||||
{
|
|
||||||
match self {
|
|
||||||
Self::GenericForbidden => {}
|
|
||||||
Self::NotSupportedOr(span) => {
|
|
||||||
diag.span_note(span, fluent::ast_passes::not_supported_or);
|
|
||||||
}
|
|
||||||
Self::NotSupportedParentheses(span) => {
|
|
||||||
diag.span_note(span, fluent::ast_passes::not_supported_parentheses);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(ast_passes::forbidden_let_stable)]
|
#[diag(ast_passes::forbidden_let_stable)]
|
||||||
#[note]
|
#[note]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue