Skip to content

Commit fddff8e

Browse files
committed
warn on unused linker_messages warning attributes
1 parent 5e51d98 commit fddff8e

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-0
lines changed

compiler/rustc_passes/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,9 @@ passes_unused_duplicate =
798798
passes_unused_empty_lints_note =
799799
attribute `{$name}` with an empty list has no effect
800800
801+
passes_unused_linker_warnings_note =
802+
the `linker_warnings` lint can only be controlled at the root of a crate with `--crate-type bin`
803+
801804
passes_unused_multiple =
802805
multiple `{$name}` attributes
803806
.suggestion = remove this attribute

compiler/rustc_passes/src/check_attr.rs

+10
Original file line numberDiff line numberDiff line change
@@ -2271,6 +2271,16 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22712271
&& item.path == sym::reason
22722272
{
22732273
errors::UnusedNote::NoLints { name: attr.name_or_empty() }
2274+
} else if matches!(
2275+
attr.name_or_empty(),
2276+
sym::allow | sym::warn | sym::deny | sym::forbid | sym::expect
2277+
) && let Some(meta) = attr.meta_item_list()
2278+
&& meta.iter().any(|meta| {
2279+
meta.meta_item().map_or(false, |item| item.path == sym::linker_messages)
2280+
})
2281+
&& hir_id != CRATE_HIR_ID
2282+
{
2283+
errors::UnusedNote::LinkerWarningsBinaryCrateOnly
22742284
} else if attr.name_or_empty() == sym::default_method_body_is_const {
22752285
errors::UnusedNote::DefaultMethodBodyConst
22762286
} else {

compiler/rustc_passes/src/errors.rs

+2
Original file line numberDiff line numberDiff line change
@@ -762,6 +762,8 @@ pub(crate) enum UnusedNote {
762762
NoLints { name: Symbol },
763763
#[note(passes_unused_default_method_body_const_note)]
764764
DefaultMethodBodyConst,
765+
#[note(passes_unused_linker_warnings_note)]
766+
LinkerWarningsBinaryCrateOnly,
765767
}
766768

767769
#[derive(LintDiagnostic)]

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,7 @@ symbols! {
11531153
link_section,
11541154
linkage,
11551155
linker,
1156+
linker_messages,
11561157
lint_reasons,
11571158
literal,
11581159
load,

0 commit comments

Comments
 (0)