Skip to content

Commit 4bbd781

Browse files
authored
Rollup merge of #113832 - WaffleLapkin:track_lint_caller, r=compiler-errors
Add `#[track_caller]` to lint related diagnostic functions This fixes locations reported by `-Ztrack-diagnostics`.
2 parents dd8fabb + 3dd5413 commit 4bbd781

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

compiler/rustc_lint/src/levels.rs

+4
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
978978
/// Returns `true` if the lint's feature is enabled.
979979
// FIXME only emit this once for each attribute, instead of repeating it 4 times for
980980
// pre-expansion lints, post-expansion lints, `shallow_lint_levels_on` and `lint_expectations`.
981+
#[track_caller]
981982
fn check_gated_lint(&self, lint_id: LintId, span: Span) -> bool {
982983
if let Some(feature) = lint_id.lint.feature_gate {
983984
if !self.sess.features_untracked().enabled(feature) {
@@ -1015,6 +1016,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
10151016
///
10161017
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
10171018
#[rustc_lint_diagnostics]
1019+
#[track_caller]
10181020
pub(crate) fn struct_lint(
10191021
&self,
10201022
lint: &'static Lint,
@@ -1028,6 +1030,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
10281030
struct_lint_level(self.sess, lint, level, src, span, msg, decorate)
10291031
}
10301032

1033+
#[track_caller]
10311034
pub fn emit_spanned_lint(
10321035
&self,
10331036
lint: &'static Lint,
@@ -1040,6 +1043,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
10401043
});
10411044
}
10421045

1046+
#[track_caller]
10431047
pub fn emit_lint(&self, lint: &'static Lint, decorate: impl for<'a> DecorateLint<'a, ()>) {
10441048
let (level, src) = self.lint_level(lint);
10451049
struct_lint_level(self.sess, lint, level, src, None, decorate.msg(), |lint| {

compiler/rustc_middle/src/lint.rs

+2
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ pub fn explain_lint_level_source(
278278
/// // ^^^^^^^^^^^^^^^^^^^^^ returns `&mut DiagnosticBuilder` by default
279279
/// )
280280
/// ```
281+
#[track_caller]
281282
pub fn struct_lint_level(
282283
sess: &Session,
283284
lint: &'static Lint,
@@ -291,6 +292,7 @@ pub fn struct_lint_level(
291292
) {
292293
// Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to
293294
// the "real" work.
295+
#[track_caller]
294296
fn struct_lint_level_impl(
295297
sess: &Session,
296298
lint: &'static Lint,

compiler/rustc_middle/src/ty/context.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1860,6 +1860,7 @@ impl<'tcx> TyCtxt<'tcx> {
18601860

18611861
/// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`,
18621862
/// typically generated by `#[derive(LintDiagnostic)]`).
1863+
#[track_caller]
18631864
pub fn emit_spanned_lint(
18641865
self,
18651866
lint: &'static Lint,
@@ -1880,6 +1881,7 @@ impl<'tcx> TyCtxt<'tcx> {
18801881
///
18811882
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
18821883
#[rustc_lint_diagnostics]
1884+
#[track_caller]
18831885
pub fn struct_span_lint_hir(
18841886
self,
18851887
lint: &'static Lint,
@@ -1896,6 +1898,7 @@ impl<'tcx> TyCtxt<'tcx> {
18961898

18971899
/// Emit a lint from a lint struct (some type that implements `DecorateLint`, typically
18981900
/// generated by `#[derive(LintDiagnostic)]`).
1901+
#[track_caller]
18991902
pub fn emit_lint(
19001903
self,
19011904
lint: &'static Lint,
@@ -1911,6 +1914,7 @@ impl<'tcx> TyCtxt<'tcx> {
19111914
///
19121915
/// [`struct_lint_level`]: rustc_middle::lint::struct_lint_level#decorate-signature
19131916
#[rustc_lint_diagnostics]
1917+
#[track_caller]
19141918
pub fn struct_lint_node(
19151919
self,
19161920
lint: &'static Lint,

compiler/rustc_session/src/parse.rs

+9
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub fn feature_err_issue(
117117
/// Construct a future incompatibility diagnostic for a feature gate.
118118
///
119119
/// This diagnostic is only a warning and *does not cause compilation to fail*.
120+
#[track_caller]
120121
pub fn feature_warn(sess: &ParseSess, feature: Symbol, span: Span, explain: &'static str) {
121122
feature_warn_issue(sess, feature, span, GateIssue::Language, explain);
122123
}
@@ -129,6 +130,7 @@ pub fn feature_warn(sess: &ParseSess, feature: Symbol, span: Span, explain: &'st
129130
/// Almost always, you want to use this for a language feature. If so, prefer `feature_warn`.
130131
#[allow(rustc::diagnostic_outside_of_impl)]
131132
#[allow(rustc::untranslatable_diagnostic)]
133+
#[track_caller]
132134
pub fn feature_warn_issue(
133135
sess: &ParseSess,
134136
feature: Symbol,
@@ -351,24 +353,28 @@ impl ParseSess {
351353
self.create_warning(warning).emit()
352354
}
353355

356+
#[track_caller]
354357
pub fn create_note<'a>(
355358
&'a self,
356359
note: impl IntoDiagnostic<'a, Noted>,
357360
) -> DiagnosticBuilder<'a, Noted> {
358361
note.into_diagnostic(&self.span_diagnostic)
359362
}
360363

364+
#[track_caller]
361365
pub fn emit_note<'a>(&'a self, note: impl IntoDiagnostic<'a, Noted>) -> Noted {
362366
self.create_note(note).emit()
363367
}
364368

369+
#[track_caller]
365370
pub fn create_fatal<'a>(
366371
&'a self,
367372
fatal: impl IntoDiagnostic<'a, !>,
368373
) -> DiagnosticBuilder<'a, !> {
369374
fatal.into_diagnostic(&self.span_diagnostic)
370375
}
371376

377+
#[track_caller]
372378
pub fn emit_fatal<'a>(&'a self, fatal: impl IntoDiagnostic<'a, !>) -> ! {
373379
self.create_fatal(fatal).emit()
374380
}
@@ -383,16 +389,19 @@ impl ParseSess {
383389
}
384390

385391
#[rustc_lint_diagnostics]
392+
#[track_caller]
386393
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
387394
self.span_diagnostic.struct_warn(msg)
388395
}
389396

390397
#[rustc_lint_diagnostics]
398+
#[track_caller]
391399
pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> {
392400
self.span_diagnostic.struct_fatal(msg)
393401
}
394402

395403
#[rustc_lint_diagnostics]
404+
#[track_caller]
396405
pub fn struct_diagnostic<G: EmissionGuarantee>(
397406
&self,
398407
msg: impl Into<DiagnosticMessage>,

0 commit comments

Comments
 (0)