Add #[track_caller] to lint related diagnostic functions

This commit is contained in:
Maybe Waffle 2023-07-18 15:48:07 +00:00
parent f0580df0d5
commit 3dd5413bfd
4 changed files with 19 additions and 0 deletions

View File

@ -978,6 +978,7 @@ fn add(&mut self, attrs: &[ast::Attribute], is_crate_node: bool, source_hir_id:
/// Returns `true` if the lint's feature is enabled. /// Returns `true` if the lint's feature is enabled.
// FIXME only emit this once for each attribute, instead of repeating it 4 times for // FIXME only emit this once for each attribute, instead of repeating it 4 times for
// pre-expansion lints, post-expansion lints, `shallow_lint_levels_on` and `lint_expectations`. // pre-expansion lints, post-expansion lints, `shallow_lint_levels_on` and `lint_expectations`.
#[track_caller]
fn check_gated_lint(&self, lint_id: LintId, span: Span) -> bool { fn check_gated_lint(&self, lint_id: LintId, span: Span) -> bool {
if let Some(feature) = lint_id.lint.feature_gate { if let Some(feature) = lint_id.lint.feature_gate {
if !self.sess.features_untracked().enabled(feature) { if !self.sess.features_untracked().enabled(feature) {
@ -1015,6 +1016,7 @@ pub fn lint_level(&self, lint: &'static Lint) -> LevelAndSource {
/// ///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature /// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
#[track_caller]
pub(crate) fn struct_lint( pub(crate) fn struct_lint(
&self, &self,
lint: &'static Lint, lint: &'static Lint,
@ -1028,6 +1030,7 @@ pub(crate) fn struct_lint(
struct_lint_level(self.sess, lint, level, src, span, msg, decorate) struct_lint_level(self.sess, lint, level, src, span, msg, decorate)
} }
#[track_caller]
pub fn emit_spanned_lint( pub fn emit_spanned_lint(
&self, &self,
lint: &'static Lint, lint: &'static Lint,
@ -1040,6 +1043,7 @@ pub fn emit_spanned_lint(
}); });
} }
#[track_caller]
pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> DecorateLint<'a, ()>) { pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> DecorateLint<'a, ()>) {
let (level, src) = self.lint_level(lint); let (level, src) = self.lint_level(lint);
struct_lint_level(self.sess, lint, level, src, None, decorate.msg(), |lint| { struct_lint_level(self.sess, lint, level, src, None, decorate.msg(), |lint| {

View File

@ -278,6 +278,7 @@ pub fn explain_lint_level_source(
/// // ^^^^^^^^^^^^^^^^^^^^^ returns `&mut DiagnosticBuilder` by default /// // ^^^^^^^^^^^^^^^^^^^^^ returns `&mut DiagnosticBuilder` by default
/// ) /// )
/// ``` /// ```
#[track_caller]
pub fn struct_lint_level( pub fn struct_lint_level(
sess: &Session, sess: &Session,
lint: &'static Lint, lint: &'static Lint,
@ -291,6 +292,7 @@ pub fn struct_lint_level(
) { ) {
// Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to // Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to
// the "real" work. // the "real" work.
#[track_caller]
fn struct_lint_level_impl( fn struct_lint_level_impl(
sess: &Session, sess: &Session,
lint: &'static Lint, lint: &'static Lint,

View File

@ -1860,6 +1860,7 @@ pub fn mk_bound_variable_kinds_from_iter<I, T>(self, iter: I) -> T::Output
/// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`, /// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`,
/// typically generated by `#[derive(LintDiagnostic)]`). /// typically generated by `#[derive(LintDiagnostic)]`).
#[track_caller]
pub fn emit_spanned_lint( pub fn emit_spanned_lint(
self, self,
lint: &'static Lint, lint: &'static Lint,
@ -1880,6 +1881,7 @@ pub fn emit_spanned_lint(
/// ///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature /// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
#[track_caller]
pub fn struct_span_lint_hir( pub fn struct_span_lint_hir(
self, self,
lint: &'static Lint, lint: &'static Lint,
@ -1896,6 +1898,7 @@ pub fn struct_span_lint_hir(
/// Emit a lint from a lint struct (some type that implements `DecorateLint`, typically /// Emit a lint from a lint struct (some type that implements `DecorateLint`, typically
/// generated by `#[derive(LintDiagnostic)]`). /// generated by `#[derive(LintDiagnostic)]`).
#[track_caller]
pub fn emit_lint( pub fn emit_lint(
self, self,
lint: &'static Lint, lint: &'static Lint,
@ -1911,6 +1914,7 @@ pub fn emit_lint(
/// ///
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature /// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
#[track_caller]
pub fn struct_lint_node( pub fn struct_lint_node(
self, self,
lint: &'static Lint, lint: &'static Lint,

View File

@ -117,6 +117,7 @@ pub fn feature_err_issue(
/// Construct a future incompatibility diagnostic for a feature gate. /// Construct a future incompatibility diagnostic for a feature gate.
/// ///
/// This diagnostic is only a warning and *does not cause compilation to fail*. /// This diagnostic is only a warning and *does not cause compilation to fail*.
#[track_caller]
pub fn feature_warn(sess: &ParseSess, feature: Symbol, span: Span, explain: &'static str) { pub fn feature_warn(sess: &ParseSess, feature: Symbol, span: Span, explain: &'static str) {
feature_warn_issue(sess, feature, span, GateIssue::Language, explain); feature_warn_issue(sess, feature, span, GateIssue::Language, explain);
} }
@ -129,6 +130,7 @@ pub fn feature_warn(sess: &ParseSess, feature: Symbol, span: Span, explain: &'st
/// Almost always, you want to use this for a language feature. If so, prefer `feature_warn`. /// Almost always, you want to use this for a language feature. If so, prefer `feature_warn`.
#[allow(rustc::diagnostic_outside_of_impl)] #[allow(rustc::diagnostic_outside_of_impl)]
#[allow(rustc::untranslatable_diagnostic)] #[allow(rustc::untranslatable_diagnostic)]
#[track_caller]
pub fn feature_warn_issue( pub fn feature_warn_issue(
sess: &ParseSess, sess: &ParseSess,
feature: Symbol, feature: Symbol,
@ -351,6 +353,7 @@ pub fn emit_warning<'a>(&'a self, warning: impl IntoDiagnostic<'a, ()>) {
self.create_warning(warning).emit() self.create_warning(warning).emit()
} }
#[track_caller]
pub fn create_note<'a>( pub fn create_note<'a>(
&'a self, &'a self,
note: impl IntoDiagnostic<'a, Noted>, note: impl IntoDiagnostic<'a, Noted>,
@ -358,10 +361,12 @@ pub fn create_note<'a>(
note.into_diagnostic(&self.span_diagnostic) note.into_diagnostic(&self.span_diagnostic)
} }
#[track_caller]
pub fn emit_note<'a>(&'a self, note: impl IntoDiagnostic<'a, Noted>) -> Noted { pub fn emit_note<'a>(&'a self, note: impl IntoDiagnostic<'a, Noted>) -> Noted {
self.create_note(note).emit() self.create_note(note).emit()
} }
#[track_caller]
pub fn create_fatal<'a>( pub fn create_fatal<'a>(
&'a self, &'a self,
fatal: impl IntoDiagnostic<'a, !>, fatal: impl IntoDiagnostic<'a, !>,
@ -369,6 +374,7 @@ pub fn create_fatal<'a>(
fatal.into_diagnostic(&self.span_diagnostic) fatal.into_diagnostic(&self.span_diagnostic)
} }
#[track_caller]
pub fn emit_fatal<'a>(&'a self, fatal: impl IntoDiagnostic<'a, !>) -> ! { pub fn emit_fatal<'a>(&'a self, fatal: impl IntoDiagnostic<'a, !>) -> ! {
self.create_fatal(fatal).emit() self.create_fatal(fatal).emit()
} }
@ -383,16 +389,19 @@ pub fn struct_err(
} }
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
#[track_caller]
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> { pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
self.span_diagnostic.struct_warn(msg) self.span_diagnostic.struct_warn(msg)
} }
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
#[track_caller]
pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> { pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> {
self.span_diagnostic.struct_fatal(msg) self.span_diagnostic.struct_fatal(msg)
} }
#[rustc_lint_diagnostics] #[rustc_lint_diagnostics]
#[track_caller]
pub fn struct_diagnostic<G: EmissionGuarantee>( pub fn struct_diagnostic<G: EmissionGuarantee>(
&self, &self,
msg: impl Into<DiagnosticMessage>, msg: impl Into<DiagnosticMessage>,