Skip to content

Commit

Permalink
warn on unused linker_messages warning attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jyn514 committed Oct 28, 2024
1 parent 2cd3a7f commit 1fd35a1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,9 @@ passes_unused_duplicate =
passes_unused_empty_lints_note =
attribute `{$name}` with an empty list has no effect
passes_unused_linker_warnings_note =
the `linker_warnings` lint can only controlled at the root of a crate with `--crate-type bin`
passes_unused_multiple =
multiple `{$name}` attributes
.suggestion = remove this attribute
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2195,6 +2195,16 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
&& item.path == sym::reason
{
errors::UnusedNote::NoLints { name: attr.name_or_empty() }
} else if matches!(
attr.name_or_empty(),
sym::allow | sym::warn | sym::deny | sym::forbid | sym::expect
) && let Some(meta) = attr.meta_item_list()
&& meta.iter().any(|meta| {
meta.meta_item().map_or(false, |item| item.path == sym::linker_messages)
})
&& hir_id != CRATE_HIR_ID
{
errors::UnusedNote::LinkerWarningsBinaryCrateOnly
} else if attr.name_or_empty() == sym::default_method_body_is_const {
errors::UnusedNote::DefaultMethodBodyConst
} else {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,8 @@ pub(crate) enum UnusedNote {
NoLints { name: Symbol },
#[note(passes_unused_default_method_body_const_note)]
DefaultMethodBodyConst,
#[note(passes_unused_linker_warnings_note)]
LinkerWarningsBinaryCrateOnly,
}

#[derive(LintDiagnostic)]
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,7 @@ symbols! {
link_section,
linkage,
linker,
linker_messages,
lint_reasons,
literal,
load,
Expand Down

0 comments on commit 1fd35a1

Please sign in to comment.