Skip to content

Commit 06bc4fc

Browse files
committed
Remove LintDiagnostic::msg
* instead simply set the primary message inside the lint decorator functions * it used to be this way before [#]101986 which introduced `msg` to prevent good path delayed bugs (which no longer exist) from firing under certain circumstances when lints were suppressed / silenced * this is no longer necessary for various reasons I presume * it shaves off complexity and makes further changes easier to implement
1 parent 366ef95 commit 06bc4fc

File tree

44 files changed

+430
-488
lines changed

Some content is hidden

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

44 files changed

+430
-488
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, |lint| {
50+
lint.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
@@ -1164,33 +1164,28 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
11641164
let ty = self.lower_assoc_ty(span, assoc_ty_did, assoc_segment, bound);
11651165

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

1183-
could_refer_to(DefKind::Variant, variant_def_id, "");
1184-
could_refer_to(DefKind::AssocTy, assoc_ty_did, " also");
1179+
could_refer_to(DefKind::Variant, variant_def_id, "");
1180+
could_refer_to(DefKind::AssocTy, assoc_ty_did, " also");
11851181

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

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)