Skip to content

Commit afd3476

Browse files
committed
Move LitKind logic to session_diagnostics module
1 parent 944a3e2 commit afd3476

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

compiler/rustc_attr/src/builtin.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,7 @@ where
854854
sess.emit_err(session_diagnostics::DeprecatedItemSuggestion {
855855
span: mi.span,
856856
is_nightly: sess.is_nightly_build().then_some(()),
857+
details: (),
857858
});
858859
}
859860

@@ -1021,23 +1022,11 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
10211022
sess.emit_err(session_diagnostics::IncorrectReprFormatGeneric {
10221023
span: item.span(),
10231024
repr_arg: &name,
1024-
cause: match value.kind {
1025-
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
1026-
Some(IncorrectReprFormatGenericCause::Int {
1027-
span: item.span(),
1028-
name: &name,
1029-
int,
1030-
})
1031-
}
1032-
ast::LitKind::Str(symbol, _) => {
1033-
Some(IncorrectReprFormatGenericCause::Symbol {
1034-
span: item.span(),
1035-
name: &name,
1036-
symbol,
1037-
})
1038-
}
1039-
_ => None,
1040-
},
1025+
cause: IncorrectReprFormatGenericCause::from_lit_kind(
1026+
item.span(),
1027+
&value.kind,
1028+
&name,
1029+
),
10411030
});
10421031
} else {
10431032
if matches!(

compiler/rustc_attr/src/session_diagnostics.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::num::IntErrorKind;
22

3+
use rustc_ast as ast;
34
use rustc_errors::{error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed};
45
use rustc_macros::SessionDiagnostic;
56
use rustc_session::{parse::ParseSess, SessionDiagnostic};
@@ -303,6 +304,18 @@ pub(crate) enum IncorrectReprFormatGenericCause<'a> {
303304
},
304305
}
305306

307+
impl<'a> IncorrectReprFormatGenericCause<'a> {
308+
pub fn from_lit_kind(span: Span, kind: &ast::LitKind, name: &'a str) -> Option<Self> {
309+
match kind {
310+
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
311+
Some(Self::Int { span, name, int: *int })
312+
}
313+
ast::LitKind::Str(symbol, _) => Some(Self::Symbol { span, name, symbol: *symbol }),
314+
_ => None,
315+
}
316+
}
317+
}
318+
306319
#[derive(SessionDiagnostic)]
307320
#[diag(attr::rustc_promotable_pairing, code = "E0717")]
308321
pub(crate) struct RustcPromotablePairing {
@@ -326,13 +339,15 @@ pub(crate) struct CfgPredicateIdentifier {
326339

327340
#[derive(SessionDiagnostic)]
328341
#[diag(attr::deprecated_item_suggestion)]
329-
#[note]
330342
pub(crate) struct DeprecatedItemSuggestion {
331343
#[primary_span]
332344
pub span: Span,
333345

334346
#[help]
335347
pub is_nightly: Option<()>,
348+
349+
#[note]
350+
pub details: (),
336351
}
337352

338353
#[derive(SessionDiagnostic)]

0 commit comments

Comments
 (0)