Skip to content

Commit ae61224

Browse files
committed
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 <[email protected]>
1 parent 871c879 commit ae61224

File tree

7 files changed

+36
-2
lines changed

7 files changed

+36
-2
lines changed

compiler/rustc_borrowck/src/borrowck_errors.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use rustc_errors::{struct_span_err, DiagnosticBuilder, DiagnosticId, ErrorGuaranteed, MultiSpan};
1+
use rustc_errors::{
2+
struct_span_err, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, ErrorGuaranteed, MultiSpan,
3+
};
24
use rustc_middle::ty::{self, Ty, TyCtxt};
35
use rustc_span::Span;
46

@@ -476,10 +478,11 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
476478
struct_span_err!(self, span, E0716, "temporary value dropped while borrowed",)
477479
}
478480

481+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
479482
fn struct_span_err_with_code<S: Into<MultiSpan>>(
480483
&self,
481484
sp: S,
482-
msg: &str,
485+
msg: impl Into<DiagnosticMessage>,
483486
code: DiagnosticId,
484487
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
485488
self.infcx.tcx.sess.struct_span_err_with_code(sp, msg, code)

compiler/rustc_borrowck/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(let_else)]
77
#![feature(min_specialization)]
88
#![feature(never_type)]
9+
#![feature(rustc_attrs)]
910
#![feature(stmt_expr_attributes)]
1011
#![feature(trusted_step)]
1112
#![feature(try_blocks)]

compiler/rustc_expand/src/base.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ impl<'a> ExtCtxt<'a> {
10771077
self.current_expansion.id.expansion_cause()
10781078
}
10791079

1080+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
10801081
pub fn struct_span_err<S: Into<MultiSpan>>(
10811082
&self,
10821083
sp: S,
@@ -1101,9 +1102,11 @@ impl<'a> ExtCtxt<'a> {
11011102
///
11021103
/// Compilation will be stopped in the near future (at the end of
11031104
/// the macro expansion phase).
1105+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
11041106
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
11051107
self.sess.parse_sess.span_diagnostic.span_err(sp, msg);
11061108
}
1109+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
11071110
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: &str) {
11081111
self.sess.parse_sess.span_diagnostic.span_warn(sp, msg);
11091112
}

compiler/rustc_expand/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#![feature(proc_macro_diagnostic)]
1010
#![feature(proc_macro_internals)]
1111
#![feature(proc_macro_span)]
12+
#![feature(rustc_attrs)]
1213
#![feature(try_blocks)]
1314
#![recursion_limit = "256"]
1415

compiler/rustc_parse/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(let_chains)]
77
#![feature(let_else)]
88
#![feature(never_type)]
9+
#![feature(rustc_attrs)]
910
#![recursion_limit = "256"]
1011

1112
#[macro_use]

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ impl<'a> DerefMut for SnapshotParser<'a> {
357357
}
358358

359359
impl<'a> Parser<'a> {
360+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
360361
pub(super) fn span_err<S: Into<MultiSpan>>(
361362
&self,
362363
sp: S,
@@ -365,6 +366,7 @@ impl<'a> Parser<'a> {
365366
err.span_err(sp, self.diagnostic())
366367
}
367368

369+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
368370
pub fn struct_span_err<S: Into<MultiSpan>>(
369371
&self,
370372
sp: S,

compiler/rustc_session/src/session.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,15 @@ impl Session {
280280
self.crate_types.set(crate_types).expect("`crate_types` was initialized twice")
281281
}
282282

283+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
283284
pub fn struct_span_warn<S: Into<MultiSpan>>(
284285
&self,
285286
sp: S,
286287
msg: impl Into<DiagnosticMessage>,
287288
) -> DiagnosticBuilder<'_, ()> {
288289
self.diagnostic().struct_span_warn(sp, msg)
289290
}
291+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
290292
pub fn struct_span_warn_with_expectation<S: Into<MultiSpan>>(
291293
&self,
292294
sp: S,
@@ -295,6 +297,7 @@ impl Session {
295297
) -> DiagnosticBuilder<'_, ()> {
296298
self.diagnostic().struct_span_warn_with_expectation(sp, msg, id)
297299
}
300+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
298301
pub fn struct_span_warn_with_code<S: Into<MultiSpan>>(
299302
&self,
300303
sp: S,
@@ -303,40 +306,47 @@ impl Session {
303306
) -> DiagnosticBuilder<'_, ()> {
304307
self.diagnostic().struct_span_warn_with_code(sp, msg, code)
305308
}
309+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
306310
pub fn struct_warn(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
307311
self.diagnostic().struct_warn(msg)
308312
}
313+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
309314
pub fn struct_warn_with_expectation(
310315
&self,
311316
msg: impl Into<DiagnosticMessage>,
312317
id: lint::LintExpectationId,
313318
) -> DiagnosticBuilder<'_, ()> {
314319
self.diagnostic().struct_warn_with_expectation(msg, id)
315320
}
321+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
316322
pub fn struct_span_allow<S: Into<MultiSpan>>(
317323
&self,
318324
sp: S,
319325
msg: impl Into<DiagnosticMessage>,
320326
) -> DiagnosticBuilder<'_, ()> {
321327
self.diagnostic().struct_span_allow(sp, msg)
322328
}
329+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
323330
pub fn struct_allow(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, ()> {
324331
self.diagnostic().struct_allow(msg)
325332
}
333+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
326334
pub fn struct_expect(
327335
&self,
328336
msg: impl Into<DiagnosticMessage>,
329337
id: lint::LintExpectationId,
330338
) -> DiagnosticBuilder<'_, ()> {
331339
self.diagnostic().struct_expect(msg, id)
332340
}
341+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
333342
pub fn struct_span_err<S: Into<MultiSpan>>(
334343
&self,
335344
sp: S,
336345
msg: impl Into<DiagnosticMessage>,
337346
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
338347
self.diagnostic().struct_span_err(sp, msg)
339348
}
349+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
340350
pub fn struct_span_err_with_code<S: Into<MultiSpan>>(
341351
&self,
342352
sp: S,
@@ -346,33 +356,38 @@ impl Session {
346356
self.diagnostic().struct_span_err_with_code(sp, msg, code)
347357
}
348358
// FIXME: This method should be removed (every error should have an associated error code).
359+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
349360
pub fn struct_err(
350361
&self,
351362
msg: impl Into<DiagnosticMessage>,
352363
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
353364
self.parse_sess.struct_err(msg)
354365
}
366+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
355367
pub fn struct_err_with_code(
356368
&self,
357369
msg: impl Into<DiagnosticMessage>,
358370
code: DiagnosticId,
359371
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
360372
self.diagnostic().struct_err_with_code(msg, code)
361373
}
374+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
362375
pub fn struct_warn_with_code(
363376
&self,
364377
msg: impl Into<DiagnosticMessage>,
365378
code: DiagnosticId,
366379
) -> DiagnosticBuilder<'_, ()> {
367380
self.diagnostic().struct_warn_with_code(msg, code)
368381
}
382+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
369383
pub fn struct_span_fatal<S: Into<MultiSpan>>(
370384
&self,
371385
sp: S,
372386
msg: impl Into<DiagnosticMessage>,
373387
) -> DiagnosticBuilder<'_, !> {
374388
self.diagnostic().struct_span_fatal(sp, msg)
375389
}
390+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
376391
pub fn struct_span_fatal_with_code<S: Into<MultiSpan>>(
377392
&self,
378393
sp: S,
@@ -381,13 +396,16 @@ impl Session {
381396
) -> DiagnosticBuilder<'_, !> {
382397
self.diagnostic().struct_span_fatal_with_code(sp, msg, code)
383398
}
399+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
384400
pub fn struct_fatal(&self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'_, !> {
385401
self.diagnostic().struct_fatal(msg)
386402
}
387403

404+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
388405
pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) -> ! {
389406
self.diagnostic().span_fatal(sp, msg)
390407
}
408+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
391409
pub fn span_fatal_with_code<S: Into<MultiSpan>>(
392410
&self,
393411
sp: S,
@@ -396,9 +414,11 @@ impl Session {
396414
) -> ! {
397415
self.diagnostic().span_fatal_with_code(sp, msg, code)
398416
}
417+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
399418
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> ! {
400419
self.diagnostic().fatal(msg).raise()
401420
}
421+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
402422
pub fn span_err_or_warn<S: Into<MultiSpan>>(
403423
&self,
404424
is_warning: bool,
@@ -411,13 +431,15 @@ impl Session {
411431
self.span_err(sp, msg);
412432
}
413433
}
434+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
414435
pub fn span_err<S: Into<MultiSpan>>(
415436
&self,
416437
sp: S,
417438
msg: impl Into<DiagnosticMessage>,
418439
) -> ErrorGuaranteed {
419440
self.diagnostic().span_err(sp, msg)
420441
}
442+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
421443
pub fn span_err_with_code<S: Into<MultiSpan>>(
422444
&self,
423445
sp: S,
@@ -426,6 +448,7 @@ impl Session {
426448
) {
427449
self.diagnostic().span_err_with_code(sp, msg, code)
428450
}
451+
#[cfg_attr(not(bootstrap), rustc_lint_diagnostics)]
429452
pub fn err(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
430453
self.diagnostic().err(msg)
431454
}

0 commit comments

Comments
 (0)