various: add rustc_lint_diagnostics
to diag fns
The `rustc_lint_diagnostics` attribute is used by the diagnostic translation/struct migration lints to identify calls where non-translatable diagnostics or diagnostics outwith impls are being created. Any function used in creating a diagnostic should be annotated with this attribute so this commit adds the attribute to many more functions. Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
871c879bff
commit
ae612241dc
@ -1,4 +1,6 @@
|
||||
use rustc_errors::{struct_span_err, DiagnosticBuilder, DiagnosticId, ErrorGuaranteed, MultiSpan};
|
||||
use rustc_errors::{
|
||||
struct_span_err, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, ErrorGuaranteed, MultiSpan,
|
||||
};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_span::Span;
|
||||
|
||||
@ -476,10 +478,11 @@ pub(crate) fn temporary_value_borrowed_for_too_long(
|
||||
struct_span_err!(self, span, E0716, "temporary value dropped while borrowed",)
|
||||
}
|
||||
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
fn struct_span_err_with_code<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
msg: &str,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
code: DiagnosticId,
|
||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||
self.infcx.tcx.sess.struct_span_err_with_code(sp, msg, code)
|
||||
|
@ -6,6 +6,7 @@
|
||||
#![feature(let_else)]
|
||||
#![feature(min_specialization)]
|
||||
#![feature(never_type)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
#![feature(trusted_step)]
|
||||
#![feature(try_blocks)]
|
||||
|
@ -1077,6 +1077,7 @@ pub fn expansion_cause(&self) -> Option<Span> {
|
||||
self.current_expansion.id.expansion_cause()
|
||||
}
|
||||
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_span_err<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
@ -1101,9 +1102,11 @@ pub fn emit_err(&self, err: impl SessionDiagnostic<'a>) -> ErrorGuaranteed {
|
||||
///
|
||||
/// Compilation will be stopped in the near future (at the end of
|
||||
/// the macro expansion phase).
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
|
||||
self.sess.parse_sess.span_diagnostic.span_err(sp, msg);
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
|
||||
self.sess.parse_sess.span_diagnostic.span_warn(sp, msg);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
#![feature(proc_macro_diagnostic)]
|
||||
#![feature(proc_macro_internals)]
|
||||
#![feature(proc_macro_span)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(try_blocks)]
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#![feature(let_chains)]
|
||||
#![feature(let_else)]
|
||||
#![feature(never_type)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
#[macro_use]
|
||||
|
@ -357,6 +357,7 @@ fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
}
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub(super) fn span_err<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
@ -365,6 +366,7 @@ pub(super) fn span_err<S: Into<MultiSpan>>(
|
||||
err.span_err(sp, self.diagnostic())
|
||||
}
|
||||
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_span_err<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
|
@ -280,6 +280,7 @@ pub fn init_crate_types(&self, crate_types: Vec<CrateType>) {
|
||||
self.crate_types.set(crate_types).expect("`crate_types` was initialized twice")
|
||||
}
|
||||
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_span_warn<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
@ -287,6 +288,7 @@ pub fn struct_span_warn<S: Into<MultiSpan>>(
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
self.diagnostic().struct_span_warn(sp, msg)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_span_warn_with_expectation<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
@ -295,6 +297,7 @@ pub fn struct_span_warn_with_expectation<S: Into<MultiSpan>>(
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
self.diagnostic().struct_span_warn_with_expectation(sp, msg, id)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_span_warn_with_code<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
@ -303,9 +306,11 @@ pub fn struct_span_warn_with_code<S: Into<MultiSpan>>(
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
self.diagnostic().struct_span_warn_with_code(sp, msg, code)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
|
||||
self.diagnostic().struct_warn(msg)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_warn_with_expectation(
|
||||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
@ -313,6 +318,7 @@ pub fn struct_warn_with_expectation(
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
self.diagnostic().struct_warn_with_expectation(msg, id)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_span_allow<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
@ -320,9 +326,11 @@ pub fn struct_span_allow<S: Into<MultiSpan>>(
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
self.diagnostic().struct_span_allow(sp, msg)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_allow(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
|
||||
self.diagnostic().struct_allow(msg)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_expect(
|
||||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
@ -330,6 +338,7 @@ pub fn struct_expect(
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
self.diagnostic().struct_expect(msg, id)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_span_err<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
@ -337,6 +346,7 @@ pub fn struct_span_err<S: Into<MultiSpan>>(
|
||||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
self.diagnostic().struct_span_err(sp, msg)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_span_err_with_code<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
@ -346,12 +356,14 @@ pub fn struct_span_err_with_code<S: Into<MultiSpan>>(
|
||||
self.diagnostic().struct_span_err_with_code(sp, msg, code)
|
||||
}
|
||||
// FIXME: This method should be removed (every error should have an associated error code).
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_err(
|
||||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
self.parse_sess.struct_err(msg)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_err_with_code(
|
||||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
@ -359,6 +371,7 @@ pub fn struct_err_with_code(
|
||||
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
|
||||
self.diagnostic().struct_err_with_code(msg, code)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_warn_with_code(
|
||||
&self,
|
||||
msg: impl Into<DiagnosticMessage>,
|
||||
@ -366,6 +379,7 @@ pub fn struct_warn_with_code(
|
||||
) -> DiagnosticBuilder<'_, ()> {
|
||||
self.diagnostic().struct_warn_with_code(msg, code)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_span_fatal<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
@ -373,6 +387,7 @@ pub fn struct_span_fatal<S: Into<MultiSpan>>(
|
||||
) -> DiagnosticBuilder<'_, !> {
|
||||
self.diagnostic().struct_span_fatal(sp, msg)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_span_fatal_with_code<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
@ -381,13 +396,16 @@ pub fn struct_span_fatal_with_code<S: Into<MultiSpan>>(
|
||||
) -> DiagnosticBuilder<'_, !> {
|
||||
self.diagnostic().struct_span_fatal_with_code(sp, msg, code)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> {
|
||||
self.diagnostic().struct_fatal(msg)
|
||||
}
|
||||
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) -> ! {
|
||||
self.diagnostic().span_fatal(sp, msg)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn span_fatal_with_code<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
@ -396,9 +414,11 @@ pub fn span_fatal_with_code<S: Into<MultiSpan>>(
|
||||
) -> ! {
|
||||
self.diagnostic().span_fatal_with_code(sp, msg, code)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> ! {
|
||||
self.diagnostic().fatal(msg).raise()
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn span_err_or_warn<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
is_warning: bool,
|
||||
@ -411,6 +431,7 @@ pub fn span_err_or_warn<S: Into<MultiSpan>>(
|
||||
self.span_err(sp, msg);
|
||||
}
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn span_err<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
@ -418,6 +439,7 @@ pub fn span_err<S: Into<MultiSpan>>(
|
||||
) -> ErrorGuaranteed {
|
||||
self.diagnostic().span_err(sp, msg)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn span_err_with_code<S: Into<MultiSpan>>(
|
||||
&self,
|
||||
sp: S,
|
||||
@ -426,6 +448,7 @@ pub fn span_err_with_code<S: Into<MultiSpan>>(
|
||||
) {
|
||||
self.diagnostic().span_err_with_code(sp, msg, code)
|
||||
}
|
||||
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
|
||||
pub fn err(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
|
||||
self.diagnostic().err(msg)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user