Skip to content

Commit 967e380

Browse files
committed
Auto merge of #152811 - GuillaumeGomez:rm-lintdiag, r=<try>
Remove `LintDiagnostic`
2 parents 59fd4ef + 8165375 commit 967e380

File tree

203 files changed

+3781
-2782
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

203 files changed

+3781
-2782
lines changed

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_abi::ExternAbi;
44
use rustc_ast::ParamKindOrd;
55
use rustc_errors::codes::*;
66
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic};
7-
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
7+
use rustc_macros::{Diagnostic, Subdiagnostic};
88
use rustc_span::{Ident, Span, Symbol};
99

1010
#[derive(Diagnostic)]
@@ -671,7 +671,7 @@ pub(crate) struct MissingUnsafeOnExtern {
671671
pub span: Span,
672672
}
673673

674-
#[derive(LintDiagnostic)]
674+
#[derive(Diagnostic)]
675675
#[diag("extern blocks should be unsafe")]
676676
pub(crate) struct MissingUnsafeOnExternLint {
677677
#[suggestion(
@@ -1027,7 +1027,7 @@ pub(crate) struct MissingAbi {
10271027
pub span: Span,
10281028
}
10291029

1030-
#[derive(LintDiagnostic)]
1030+
#[derive(Diagnostic)]
10311031
#[diag("`extern` declarations without an explicit ABI are deprecated")]
10321032
pub(crate) struct MissingAbiSugg {
10331033
#[suggestion(

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ mod opaque_types;
5656
mod region_errors;
5757

5858
pub(crate) use bound_region_errors::{ToUniverseInfo, UniverseInfo};
59+
pub(crate) use explain_borrow::BorrowExplanation;
5960
pub(crate) use move_errors::{IllegalMoveOriginKind, MoveError};
6061
pub(crate) use mutability_errors::AccessKind;
6162
pub(crate) use outlives_suggestion::OutlivesSuggestionBuilder;

compiler/rustc_borrowck/src/lib.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_abi::FieldIdx;
2727
use rustc_data_structures::frozen::Frozen;
2828
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
2929
use rustc_data_structures::graph::dominators::Dominators;
30-
use rustc_errors::LintDiagnostic;
30+
use rustc_errors::Diagnostic;
3131
use rustc_hir as hir;
3232
use rustc_hir::CRATE_HIR_ID;
3333
use rustc_hir::def_id::LocalDefId;
@@ -1397,6 +1397,26 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
13971397
place: Place<'tcx>,
13981398
state: &BorrowckDomain,
13991399
) {
1400+
struct Borrowed<'a, 'b, 'infcx, 'tcx> {
1401+
borrowed: Span,
1402+
this: &'a MirBorrowckCtxt<'b, 'infcx, 'tcx>,
1403+
explain: crate::diagnostics::BorrowExplanation<'tcx>,
1404+
}
1405+
1406+
impl<'a, 'b, 'c, 'infcx, 'tcx: 'c> Diagnostic<'a, ()> for Borrowed<'b, 'c, 'infcx, 'tcx> {
1407+
fn into_diag(
1408+
self,
1409+
dcx: rustc_errors::DiagCtxtHandle<'a>,
1410+
level: rustc_errors::Level,
1411+
) -> rustc_errors::Diag<'a, ()> {
1412+
let Self { borrowed, this, explain } = self;
1413+
let mut diag =
1414+
session_diagnostics::TailExprDropOrder { borrowed }.into_diag(dcx, level);
1415+
explain.add_explanation_to_diagnostic(this, &mut diag, "", None, None);
1416+
diag
1417+
}
1418+
}
1419+
14001420
let tcx = self.infcx.tcx;
14011421
// If this type does not need `Drop`, then treat it like a `StorageDead`.
14021422
// This is needed because we track the borrows of refs to thread locals,
@@ -1428,14 +1448,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, '_, 'tcx> {
14281448
borrow,
14291449
Some((WriteKind::StorageDeadOrDrop, place)),
14301450
);
1431-
this.infcx.tcx.node_span_lint(
1451+
this.infcx.tcx.emit_node_span_lint(
14321452
TAIL_EXPR_DROP_ORDER,
14331453
CRATE_HIR_ID,
14341454
borrowed,
1435-
|diag| {
1436-
session_diagnostics::TailExprDropOrder { borrowed }.decorate_lint(diag);
1437-
explain.add_explanation_to_diagnostic(&this, diag, "", None, None);
1438-
},
1455+
Borrowed { borrowed, this, explain },
14391456
);
14401457
// We may stop at the first case
14411458
ControlFlow::Break(())

compiler/rustc_borrowck/src/session_diagnostics.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_errors::MultiSpan;
22
use rustc_errors::codes::*;
3-
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
3+
use rustc_macros::{Diagnostic, Subdiagnostic};
44
use rustc_middle::ty::{GenericArg, Ty};
55
use rustc_span::Span;
66

@@ -47,7 +47,7 @@ pub(crate) struct GenericDoesNotLiveLongEnough {
4747
pub span: Span,
4848
}
4949

50-
#[derive(LintDiagnostic)]
50+
#[derive(Diagnostic)]
5151
#[diag("variable does not need to be mutable")]
5252
pub(crate) struct VarNeedNotMut {
5353
#[suggestion(
@@ -595,7 +595,7 @@ pub(crate) struct SimdIntrinsicArgConst {
595595
pub intrinsic: String,
596596
}
597597

598-
#[derive(LintDiagnostic)]
598+
#[derive(Diagnostic)]
599599
#[diag("relative drop order changing in Rust 2024")]
600600
pub(crate) struct TailExprDropOrder {
601601
#[label("this temporary value will be dropped at the end of the block")]

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@ use rustc_errors::{
33
Diag, DiagCtxtHandle, Diagnostic, EmissionGuarantee, Level, MultiSpan, SingleLabelManySpans,
44
Subdiagnostic, msg,
55
};
6-
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
6+
use rustc_macros::{Diagnostic, Subdiagnostic};
77
use rustc_span::{Ident, Span, Symbol};
88

9-
#[derive(LintDiagnostic)]
9+
#[derive(Diagnostic)]
1010
#[diag("avoid using `.intel_syntax`, Intel syntax is the default")]
1111
pub(crate) struct AvoidIntelSyntax;
1212

13-
#[derive(LintDiagnostic)]
13+
#[derive(Diagnostic)]
1414
#[diag("avoid using `.att_syntax`, prefer using `options(att_syntax)` instead")]
1515
pub(crate) struct AvoidAttSyntax;
1616

17-
#[derive(LintDiagnostic)]
17+
#[derive(Diagnostic)]
1818
#[diag("include macro expected single expression in source")]
1919
pub(crate) struct IncompleteInclude;
2020

21-
#[derive(LintDiagnostic)]
21+
#[derive(Diagnostic)]
2222
#[diag("cannot test inner items")]
2323
pub(crate) struct UnnameableTestItems;
2424

25-
#[derive(LintDiagnostic)]
25+
#[derive(Diagnostic)]
2626
#[diag("duplicated attribute")]
2727
pub(crate) struct DuplicateMacroAttribute;
2828

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ use rustc_attr_parsing::eval_config_entry;
1818
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
1919
use rustc_data_structures::memmap::Mmap;
2020
use rustc_data_structures::temp_dir::MaybeTempDir;
21-
use rustc_errors::{DiagCtxtHandle, LintDiagnostic};
21+
use rustc_errors::DiagCtxtHandle;
2222
use rustc_fs_util::{TempDirBuilder, fix_windows_verbatim_for_gcc, try_canonicalize};
2323
use rustc_hir::attrs::NativeLibKind;
2424
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
25-
use rustc_macros::LintDiagnostic;
25+
use rustc_macros::Diagnostic;
2626
use rustc_metadata::fs::{METADATA_FILENAME, copy_to_stdout, emit_wrapper_file};
2727
use rustc_metadata::{
2828
EncodedMetadata, NativeLibSearchFallback, find_native_static_library,
@@ -662,7 +662,7 @@ fn link_dwarf_object(sess: &Session, cg_results: &CodegenResults, executable_out
662662
}
663663
}
664664

665-
#[derive(LintDiagnostic)]
665+
#[derive(Diagnostic)]
666666
#[diag("{$inner}")]
667667
/// Translating this is kind of useless. We don't pass translation flags to the linker, so we'd just
668668
/// end up with inconsistent languages within the same diagnostic.
@@ -937,11 +937,8 @@ fn link_natively(
937937
}
938938

939939
let level = codegen_results.crate_info.lint_levels.linker_messages;
940-
let lint = |msg| {
941-
lint_level(sess, LINKER_MESSAGES, level, None, |diag| {
942-
LinkerOutput { inner: msg }.decorate_lint(diag)
943-
})
944-
};
940+
let lint =
941+
|msg| lint_level(sess, LINKER_MESSAGES, level, None, LinkerOutput { inner: msg });
945942

946943
if !prog.stderr.is_empty() {
947944
// We already print `warning:` at the start of the diagnostic. Remove it from the linker output if present.

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_hir::attrs::{
99
use rustc_hir::def::DefKind;
1010
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
1111
use rustc_hir::{self as hir, Attribute, find_attr};
12+
use rustc_macros::Diagnostic;
1213
use rustc_middle::middle::codegen_fn_attrs::{
1314
CodegenFnAttrFlags, CodegenFnAttrs, PatchableFunctionEntry, SanitizerFnAttrs,
1415
};
@@ -393,6 +394,17 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code
393394
}
394395
}
395396

397+
#[derive(Diagnostic)]
398+
#[diag("non-default `sanitize` will have no effect after inlining")]
399+
struct NonDefaultSanitize {
400+
#[note("inlining requested here")]
401+
inline_span: Span,
402+
}
403+
404+
#[derive(Diagnostic)]
405+
#[diag("the async executor can run blocking code, without realtime sanitizer catching it")]
406+
struct AsyncExecutorRunningBlockingCode;
407+
396408
fn check_result(
397409
tcx: TyCtxt<'_>,
398410
did: LocalDefId,
@@ -433,10 +445,12 @@ fn check_result(
433445
(interesting_spans.sanitize, interesting_spans.inline)
434446
{
435447
let hir_id = tcx.local_def_id_to_hir_id(did);
436-
tcx.node_span_lint(lint::builtin::INLINE_NO_SANITIZE, hir_id, sanitize_span, |lint| {
437-
lint.primary_message("non-default `sanitize` will have no effect after inlining");
438-
lint.span_note(inline_span, "inlining requested here");
439-
})
448+
tcx.emit_node_span_lint(
449+
lint::builtin::INLINE_NO_SANITIZE,
450+
hir_id,
451+
sanitize_span,
452+
NonDefaultSanitize { inline_span },
453+
);
440454
}
441455

442456
// warn for nonblocking async functions, blocks and closures.
@@ -453,13 +467,11 @@ fn check_result(
453467
!= rustc_hir::ClosureKind::Closure))
454468
{
455469
let hir_id = tcx.local_def_id_to_hir_id(did);
456-
tcx.node_span_lint(
470+
tcx.emit_node_span_lint(
457471
lint::builtin::RTSAN_NONBLOCKING_ASYNC,
458472
hir_id,
459473
sanitize_span,
460-
|lint| {
461-
lint.primary_message(r#"the async executor can run blocking code, without realtime sanitizer catching it"#);
462-
}
474+
AsyncExecutorRunningBlockingCode,
463475
);
464476
}
465477

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_errors::codes::*;
1010
use rustc_errors::{
1111
Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, Level, msg,
1212
};
13-
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
13+
use rustc_macros::{Diagnostic, Subdiagnostic};
1414
use rustc_middle::ty::layout::LayoutError;
1515
use rustc_middle::ty::{FloatTy, Ty};
1616
use rustc_span::{Span, Symbol};
@@ -1164,7 +1164,7 @@ pub(crate) struct XcrunSdkPathWarning {
11641164
pub stderr: String,
11651165
}
11661166

1167-
#[derive(LintDiagnostic)]
1167+
#[derive(Diagnostic)]
11681168
#[diag("enabling the `neon` target feature on the current target is unsound due to ABI issues")]
11691169
pub(crate) struct Aarch64SoftfloatNeon;
11701170

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,13 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
905905
kind: CallKind,
906906
mergeable_succ: bool,
907907
) -> MergingSucc {
908+
#[derive(rustc_macros::Diagnostic)]
909+
#[diag("tail calling a function marked with `#[track_caller]` has no special effect")]
910+
struct TailCallingTrackCallerFn {
911+
#[primary_span]
912+
fn_span: Span,
913+
}
914+
908915
let source_info = mir::SourceInfo { span: fn_span, ..terminator.source_info };
909916

910917
// Create the callee. This is a fn ptr or zero-sized and hence a kind of scalar.
@@ -1020,10 +1027,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10201027
if let Some(hir_id) =
10211028
terminator.source_info.scope.lint_root(&self.mir.source_scopes)
10221029
{
1023-
let msg = "tail calling a function marked with `#[track_caller]` has no special effect";
1024-
bx.tcx().node_lint(TAIL_CALL_TRACK_CALLER, hir_id, |d| {
1025-
_ = d.primary_message(msg).span(fn_span)
1026-
});
1030+
bx.tcx().node_lint(
1031+
TAIL_CALL_TRACK_CALLER,
1032+
hir_id,
1033+
TailCallingTrackCallerFn { fn_span },
1034+
);
10271035
}
10281036

10291037
let instance = ty::Instance::resolve_for_fn_ptr(

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ pub(super) fn lint<'tcx, L>(
252252
lint: &'static rustc_session::lint::Lint,
253253
decorator: impl FnOnce(Vec<errors::FrameNote>) -> L,
254254
) where
255-
L: for<'a> rustc_errors::LintDiagnostic<'a, ()>,
255+
L: for<'a> rustc_errors::Diagnostic<'a, ()>,
256256
{
257257
let (span, frames) = get_span_and_frames(tcx, &machine.stack);
258258

0 commit comments

Comments
 (0)