Move LitKind
logic to session_diagnostics
module
This commit is contained in:
parent
944a3e22ef
commit
afd34765f6
2 changed files with 22 additions and 18 deletions
|
@ -854,6 +854,7 @@ where
|
||||||
sess.emit_err(session_diagnostics::DeprecatedItemSuggestion {
|
sess.emit_err(session_diagnostics::DeprecatedItemSuggestion {
|
||||||
span: mi.span,
|
span: mi.span,
|
||||||
is_nightly: sess.is_nightly_build().then_some(()),
|
is_nightly: sess.is_nightly_build().then_some(()),
|
||||||
|
details: (),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1021,23 +1022,11 @@ pub fn parse_repr_attr(sess: &Session, attr: &Attribute) -> Vec<ReprAttr> {
|
||||||
sess.emit_err(session_diagnostics::IncorrectReprFormatGeneric {
|
sess.emit_err(session_diagnostics::IncorrectReprFormatGeneric {
|
||||||
span: item.span(),
|
span: item.span(),
|
||||||
repr_arg: &name,
|
repr_arg: &name,
|
||||||
cause: match value.kind {
|
cause: IncorrectReprFormatGenericCause::from_lit_kind(
|
||||||
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
|
item.span(),
|
||||||
Some(IncorrectReprFormatGenericCause::Int {
|
&value.kind,
|
||||||
span: item.span(),
|
&name,
|
||||||
name: &name,
|
),
|
||||||
int,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
ast::LitKind::Str(symbol, _) => {
|
|
||||||
Some(IncorrectReprFormatGenericCause::Symbol {
|
|
||||||
span: item.span(),
|
|
||||||
name: &name,
|
|
||||||
symbol,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if matches!(
|
if matches!(
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
use std::num::IntErrorKind;
|
use std::num::IntErrorKind;
|
||||||
|
|
||||||
|
use rustc_ast as ast;
|
||||||
use rustc_errors::{error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed};
|
use rustc_errors::{error_code, fluent, Applicability, DiagnosticBuilder, ErrorGuaranteed};
|
||||||
use rustc_macros::SessionDiagnostic;
|
use rustc_macros::SessionDiagnostic;
|
||||||
use rustc_session::{parse::ParseSess, SessionDiagnostic};
|
use rustc_session::{parse::ParseSess, SessionDiagnostic};
|
||||||
|
@ -303,6 +304,18 @@ pub(crate) enum IncorrectReprFormatGenericCause<'a> {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> IncorrectReprFormatGenericCause<'a> {
|
||||||
|
pub fn from_lit_kind(span: Span, kind: &ast::LitKind, name: &'a str) -> Option<Self> {
|
||||||
|
match kind {
|
||||||
|
ast::LitKind::Int(int, ast::LitIntType::Unsuffixed) => {
|
||||||
|
Some(Self::Int { span, name, int: *int })
|
||||||
|
}
|
||||||
|
ast::LitKind::Str(symbol, _) => Some(Self::Symbol { span, name, symbol: *symbol }),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(SessionDiagnostic)]
|
#[derive(SessionDiagnostic)]
|
||||||
#[diag(attr::rustc_promotable_pairing, code = "E0717")]
|
#[diag(attr::rustc_promotable_pairing, code = "E0717")]
|
||||||
pub(crate) struct RustcPromotablePairing {
|
pub(crate) struct RustcPromotablePairing {
|
||||||
|
@ -326,13 +339,15 @@ pub(crate) struct CfgPredicateIdentifier {
|
||||||
|
|
||||||
#[derive(SessionDiagnostic)]
|
#[derive(SessionDiagnostic)]
|
||||||
#[diag(attr::deprecated_item_suggestion)]
|
#[diag(attr::deprecated_item_suggestion)]
|
||||||
#[note]
|
|
||||||
pub(crate) struct DeprecatedItemSuggestion {
|
pub(crate) struct DeprecatedItemSuggestion {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
|
|
||||||
#[help]
|
#[help]
|
||||||
pub is_nightly: Option<()>,
|
pub is_nightly: Option<()>,
|
||||||
|
|
||||||
|
#[note]
|
||||||
|
pub details: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(SessionDiagnostic)]
|
#[derive(SessionDiagnostic)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue