Skip to content

Commit ea5d258

Browse files
committed
ast_passes: use derive more
Signed-off-by: David Wood <david.wood@huawei.com>
1 parent 2a4b587 commit ea5d258

File tree

2 files changed

+6
-20
lines changed

2 files changed

+6
-20
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_ast::*;
1414
use rustc_ast_pretty::pprust::{self, State};
1515
use rustc_data_structures::fx::FxHashMap;
1616
use rustc_errors::{error_code, fluent, pluralize, struct_span_err, Applicability};
17+
use rustc_macros::Subdiagnostic;
1718
use rustc_parse::validate_attr;
1819
use rustc_session::lint::builtin::{
1920
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) ->
17821783
}
17831784

17841785
/// Used to forbid `let` expressions in certain syntactic locations.
1785-
#[derive(Clone, Copy)]
1786+
#[derive(Clone, Copy, Subdiagnostic)]
17861787
pub(crate) enum ForbiddenLetReason {
17871788
/// `let` is not valid and the source environment is not important
17881789
GenericForbidden,
17891790
/// A let chain with the `||` operator
1790-
NotSupportedOr(Span),
1791+
#[note(ast_passes::not_supported_or)]
1792+
NotSupportedOr(#[primary_span] Span),
17911793
/// A let chain with invalid parentheses
17921794
///
17931795
/// For example, `let 1 = 1 && (expr && expr)` is allowed
17941796
/// but `(let 1 = 1 && (let 1 = 1 && (let 1 = 1))) && let a = 1` is not
1795-
NotSupportedParentheses(Span),
1797+
#[note(ast_passes::not_supported_parentheses)]
1798+
NotSupportedParentheses(#[primary_span] Span),
17961799
}

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,6 @@ pub struct ForbiddenLet {
1616
pub(crate) reason: ForbiddenLetReason,
1717
}
1818

19-
impl AddToDiagnostic for ForbiddenLetReason {
20-
fn add_to_diagnostic_with<F>(self, diag: &mut Diagnostic, _: F)
21-
where
22-
F: Fn(&mut Diagnostic, SubdiagnosticMessage) -> SubdiagnosticMessage,
23-
{
24-
match self {
25-
Self::GenericForbidden => {}
26-
Self::NotSupportedOr(span) => {
27-
diag.span_note(span, fluent::ast_passes::not_supported_or);
28-
}
29-
Self::NotSupportedParentheses(span) => {
30-
diag.span_note(span, fluent::ast_passes::not_supported_parentheses);
31-
}
32-
}
33-
}
34-
}
35-
3619
#[derive(Diagnostic)]
3720
#[diag(ast_passes::forbidden_let_stable)]
3821
#[note]

0 commit comments

Comments
 (0)