Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c2769b7

Browse files
committed
Auto merge of rust-lang#125410 - fmease:adj-lint-diag-api, r=<try>
[perf] Delay construction of early lint diag structs cc rust-lang#124417 (comment) r? ghost
2 parents f0038a7 + 7ef19da commit c2769b7

File tree

31 files changed

+451
-638
lines changed

31 files changed

+451
-638
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,8 +564,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
564564
lint::builtin::INLINE_NO_SANITIZE,
565565
hir_id,
566566
no_sanitize_span,
567-
"`no_sanitize` will have no effect after inlining",
568567
|lint| {
568+
lint.primary_message("`no_sanitize` will have no effect after inlining");
569569
lint.span_note(inline_span, "inlining requested here");
570570
},
571571
)

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ pub trait SubdiagMessageOp<G: EmissionGuarantee> =
200200
pub trait LintDiagnostic<'a, G: EmissionGuarantee> {
201201
/// Decorate and emit a lint.
202202
fn decorate_lint<'b>(self, diag: &'b mut Diag<'a, G>);
203-
204-
fn msg(&self) -> DiagMessage;
205203
}
206204

207205
#[derive(Clone, Debug, Encodable, Decodable)]

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,9 @@ pub fn check_abi(tcx: TyCtxt<'_>, hir_id: hir::HirId, span: Span, abi: Abi) {
4646
.emit();
4747
}
4848
None => {
49-
tcx.node_span_lint(
50-
UNSUPPORTED_CALLING_CONVENTIONS,
51-
hir_id,
52-
span,
53-
"use of calling convention not supported on this target",
54-
|_| {},
55-
);
49+
tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |diag| {
50+
diag.primary_message("use of calling convention not supported on this target");
51+
});
5652
}
5753
}
5854

@@ -243,8 +239,8 @@ fn check_static_inhabited(tcx: TyCtxt<'_>, def_id: LocalDefId) {
243239
UNINHABITED_STATIC,
244240
tcx.local_def_id_to_hir_id(def_id),
245241
span,
246-
"static of uninhabited type",
247242
|lint| {
243+
lint.primary_message("static of uninhabited type");
248244
lint
249245
.note("uninhabited statics cannot be initialized, and any access would be an immediate error");
250246
},
@@ -1315,9 +1311,11 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
13151311
REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS,
13161312
tcx.local_def_id_to_hir_id(adt.did().expect_local()),
13171313
span,
1318-
"zero-sized fields in `repr(transparent)` cannot \
1319-
contain external non-exhaustive types",
13201314
|lint| {
1315+
lint.primary_message(
1316+
"zero-sized fields in `repr(transparent)` cannot \
1317+
contain external non-exhaustive types",
1318+
);
13211319
let note = if non_exhaustive {
13221320
"is marked with `#[non_exhaustive]`"
13231321
} else {

compiler/rustc_hir_analysis/src/check/intrinsicck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,8 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
281281
lint::builtin::ASM_SUB_REGISTER,
282282
expr.hir_id,
283283
spans,
284-
"formatting may not be suitable for sub-register argument",
285284
|lint| {
285+
lint.primary_message("formatting may not be suitable for sub-register argument");
286286
lint.span_label(expr.span, "for this argument");
287287
lint.help(format!(
288288
"use `{{{idx}:{suggested_modifier}}}` to have the register formatted as `{suggested_result}` (for {suggested_size}-bit values)",

compiler/rustc_hir_analysis/src/check_unused.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ fn check_unused_traits(tcx: TyCtxt<'_>, (): ()) {
3535
continue;
3636
}
3737
let (path, _) = item.expect_use();
38-
let msg = if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(path.span) {
39-
format!("unused import: `{snippet}`")
40-
} else {
41-
"unused import".to_owned()
42-
};
43-
tcx.node_span_lint(lint::builtin::UNUSED_IMPORTS, item.hir_id(), path.span, msg, |_| {});
38+
tcx.node_span_lint(lint::builtin::UNUSED_IMPORTS, item.hir_id(), path.span, |lint| {
39+
if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(path.span) {
40+
lint.primary_message(format!("unused import: `{snippet}`"));
41+
} else {
42+
lint.primary_message("unused import");
43+
}
44+
});
4445
}
4546
}

compiler/rustc_hir_analysis/src/collect/generics_of.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,9 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
317317
lint::builtin::INVALID_TYPE_PARAM_DEFAULT,
318318
param.hir_id,
319319
param.span,
320-
TYPE_DEFAULT_NOT_ALLOWED,
321-
|_| {},
320+
|lint| {
321+
lint.primary_message(TYPE_DEFAULT_NOT_ALLOWED);
322+
},
322323
);
323324
}
324325
Defaults::Deny => {

compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,9 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes(
646646
LATE_BOUND_LIFETIME_ARGUMENTS,
647647
args.args[0].hir_id(),
648648
multispan,
649-
msg,
650-
|_| {},
649+
|lint| {
650+
lint.primary_message(msg);
651+
},
651652
);
652653
}
653654

compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
7272
self.maybe_suggest_assoc_ty_bound(self_ty, &mut diag);
7373
diag.stash(self_ty.span, StashKey::TraitMissingMethod);
7474
} else {
75-
let msg = "trait objects without an explicit `dyn` are deprecated";
76-
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, msg, |lint| {
75+
tcx.node_span_lint(BARE_TRAIT_OBJECTS, self_ty.hir_id, self_ty.span, |lint| {
76+
lint.primary_message("trait objects without an explicit `dyn` are deprecated");
7777
if self_ty.span.can_be_used_for_suggestions() {
7878
lint.multipart_suggestion_verbose(
7979
"if this is an object-safe trait, use `dyn`",

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,33 +1165,28 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
11651165
let ty = self.lower_assoc_ty(span, assoc_ty_did, assoc_segment, bound);
11661166

11671167
if let Some(variant_def_id) = variant_resolution {
1168-
tcx.node_span_lint(
1169-
AMBIGUOUS_ASSOCIATED_ITEMS,
1170-
hir_ref_id,
1171-
span,
1172-
"ambiguous associated item",
1173-
|lint| {
1174-
let mut could_refer_to = |kind: DefKind, def_id, also| {
1175-
let note_msg = format!(
1176-
"`{}` could{} refer to the {} defined here",
1177-
assoc_ident,
1178-
also,
1179-
tcx.def_kind_descr(kind, def_id)
1180-
);
1181-
lint.span_note(tcx.def_span(def_id), note_msg);
1182-
};
1168+
tcx.node_span_lint(AMBIGUOUS_ASSOCIATED_ITEMS, hir_ref_id, span, |lint| {
1169+
lint.primary_message("ambiguous associated item");
1170+
let mut could_refer_to = |kind: DefKind, def_id, also| {
1171+
let note_msg = format!(
1172+
"`{}` could{} refer to the {} defined here",
1173+
assoc_ident,
1174+
also,
1175+
tcx.def_kind_descr(kind, def_id)
1176+
);
1177+
lint.span_note(tcx.def_span(def_id), note_msg);
1178+
};
11831179

1184-
could_refer_to(DefKind::Variant, variant_def_id, "");
1185-
could_refer_to(DefKind::AssocTy, assoc_ty_did, " also");
1180+
could_refer_to(DefKind::Variant, variant_def_id, "");
1181+
could_refer_to(DefKind::AssocTy, assoc_ty_did, " also");
11861182

1187-
lint.span_suggestion(
1188-
span,
1189-
"use fully-qualified syntax",
1190-
format!("<{} as {}>::{}", qself_ty, tcx.item_name(trait_did), assoc_ident),
1191-
Applicability::MachineApplicable,
1192-
);
1193-
},
1194-
);
1183+
lint.span_suggestion(
1184+
span,
1185+
"use fully-qualified syntax",
1186+
format!("<{} as {}>::{}", qself_ty, tcx.item_name(trait_did), assoc_ident),
1187+
Applicability::MachineApplicable,
1188+
);
1189+
});
11951190
}
11961191
Ok((ty, DefKind::AssocTy, assoc_ty_did))
11971192
}

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
6363
debug!("warn_if_unreachable: id={:?} span={:?} kind={}", id, span, kind);
6464

6565
let msg = format!("unreachable {kind}");
66-
self.tcx().node_span_lint(
67-
lint::builtin::UNREACHABLE_CODE,
68-
id,
69-
span,
70-
msg.clone(),
71-
|lint| {
72-
lint.span_label(span, msg).span_label(
73-
orig_span,
74-
custom_note
75-
.unwrap_or("any code following this expression is unreachable"),
76-
);
77-
},
78-
)
66+
self.tcx().node_span_lint(lint::builtin::UNREACHABLE_CODE, id, span, |lint| {
67+
lint.primary_message(msg.clone());
68+
lint.span_label(span, msg).span_label(
69+
orig_span,
70+
custom_note.unwrap_or("any code following this expression is unreachable"),
71+
);
72+
})
7973
}
8074
}
8175
}

0 commit comments

Comments
 (0)