1
Fork 0

make it possible to silence linker warnings with a crate-level attribute

this was slightly complicated because codegen_ssa doesn't have access to a tcx.
This commit is contained in:
jyn 2024-10-16 01:14:10 -04:00
parent c0822ed9b8
commit 537218afb2
5 changed files with 85 additions and 11 deletions

View file

@ -60,6 +60,7 @@ declare_lint_pass! {
LARGE_ASSIGNMENTS,
LATE_BOUND_LIFETIME_ARGUMENTS,
LEGACY_DERIVE_HELPERS,
LINKER_MESSAGES,
LONG_RUNNING_CONST_EVAL,
LOSSY_PROVENANCE_CASTS,
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
@ -4085,6 +4086,39 @@ declare_lint! {
"call to foreign functions or function pointers with FFI-unwind ABI"
}
declare_lint! {
/// The `linker_messages` lint forwards warnings from the linker.
///
/// ### Example
///
/// ```rust,ignore (needs CLI args, platform-specific)
/// extern "C" {
/// fn foo();
/// }
/// fn main () { unsafe { foo(); } }
/// ```
///
/// On Linux, using `gcc -Wl,--warn-unresolved-symbols` as a linker, this will produce
///
/// ```text
/// warning: linker stderr: rust-lld: undefined symbol: foo
/// >>> referenced by rust_out.69edbd30df4ae57d-cgu.0
/// >>> rust_out.rust_out.69edbd30df4ae57d-cgu.0.rcgu.o:(rust_out::main::h3a90094b06757803)
/// |
/// = note: `#[warn(linker_messages)]` on by default
///
/// warning: 1 warning emitted
/// ```
///
/// ### Explanation
///
/// Linkers emit platform-specific and program-specific warnings that cannot be predicted in advance by the rust compiler.
/// They are forwarded by default, but can be disabled by adding `#![allow(linker_messages)]` at the crate root.
pub LINKER_MESSAGES,
Warn,
"warnings emitted at runtime by the target-specific linker program"
}
declare_lint! {
/// The `named_arguments_used_positionally` lint detects cases where named arguments are only
/// used positionally in format strings. This usage is valid but potentially very confusing.

View file

@ -161,7 +161,19 @@ impl<HCX: rustc_hir::HashStableContext> ToStableHashKey<HCX> for LintExpectation
/// Setting for how to handle a lint.
///
/// See: <https://doc.rust-lang.org/rustc/lints/levels.html>
#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash, HashStable_Generic)]
#[derive(
Clone,
Copy,
PartialEq,
PartialOrd,
Eq,
Ord,
Debug,
Hash,
Encodable,
Decodable,
HashStable_Generic
)]
pub enum Level {
/// The `allow` level will not issue any message.
Allow,