File tree Expand file tree Collapse file tree 6 files changed +32
-10
lines changed
compiler/rustc_lint_defs/src
rust-lld-by-default-beta-stable
rust-lld-by-default-nightly Expand file tree Collapse file tree 6 files changed +32
-10
lines changed Original file line number Diff line number Diff line change @@ -4091,6 +4091,7 @@ declare_lint! {
4091
4091
/// ### Example
4092
4092
///
4093
4093
/// ```rust,ignore (needs CLI args, platform-specific)
4094
+ /// #[warn(linker_messages)]
4094
4095
/// extern "C" {
4095
4096
/// fn foo();
4096
4097
/// }
@@ -4104,17 +4105,24 @@ declare_lint! {
4104
4105
/// >>> referenced by rust_out.69edbd30df4ae57d-cgu.0
4105
4106
/// >>> rust_out.rust_out.69edbd30df4ae57d-cgu.0.rcgu.o:(rust_out::main::h3a90094b06757803)
4106
4107
/// |
4107
- /// = note: `#[warn(linker_messages)]` on by default
4108
- ///
4108
+ /// note: the lint level is defined here
4109
+ /// --> warn.rs:1:9
4110
+ /// |
4111
+ /// 1 | #![warn(linker_messages)]
4112
+ /// | ^^^^^^^^^^^^^^^
4109
4113
/// warning: 1 warning emitted
4110
4114
/// ```
4111
4115
///
4112
4116
/// ### Explanation
4113
4117
///
4114
- /// Linkers emit platform-specific and program-specific warnings that cannot be predicted in advance by the rust compiler.
4115
- /// They are forwarded by default, but can be disabled by adding `#![allow(linker_messages)]` at the crate root.
4118
+ /// Linkers emit platform-specific and program-specific warnings that cannot be predicted in
4119
+ /// advance by the Rust compiler. Such messages are ignored by default for now. While linker
4120
+ /// warnings could be very useful they have been ignored for many years by essentially all
4121
+ /// users, so we need to do a bit more work than just surfacing their text to produce a clear
4122
+ /// and actionable warning of similar quality to our other diagnostics. See this tracking
4123
+ /// issue for more details: <https://github.com/rust-lang/rust/issues/136096>.
4116
4124
pub LINKER_MESSAGES,
4117
- Warn ,
4125
+ Allow ,
4118
4126
"warnings emitted at runtime by the target-specific linker program"
4119
4127
}
4120
4128
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ fn run_rustc() -> Rustc {
8
8
// Make sure we use a consistent value.
9
9
.arg("-Clink-self-contained=-linker")
10
10
.arg("-Zunstable-options")
11
+ .arg("-Wlinker-messages")
11
12
.output("main")
12
13
.linker("./fake-linker");
13
14
if run_make_support::target() == "x86_64-unknown-linux-gnu" {
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ use run_make_support::rustc;
12
12
fn main() {
13
13
// A regular compilation should not use rust-lld by default. We'll check that by asking the
14
14
// linker to display its version number with a link-arg.
15
- let output = rustc().link_arg("-Wl,-v").input("main.rs").run();
15
+ let output = rustc().arg("-Wlinker-messages"). link_arg("-Wl,-v").input("main.rs").run();
16
16
assert!(
17
17
!find_lld_version_in_logs(output.stderr_utf8()),
18
18
"the LLD version string should not be present in the output logs:\n{}",
Original file line number Diff line number Diff line change @@ -12,15 +12,20 @@ use run_make_support::rustc;
12
12
fn main() {
13
13
// A regular compilation should use rust-lld by default. We'll check that by asking the linker
14
14
// to display its version number with a link-arg.
15
- let output = rustc().link_arg("-Wl,-v").input("main.rs").run();
15
+ let output = rustc().arg("-Wlinker-messages"). link_arg("-Wl,-v").input("main.rs").run();
16
16
assert!(
17
17
find_lld_version_in_logs(output.stderr_utf8()),
18
18
"the LLD version string should be present in the output logs:\n{}",
19
19
output.stderr_utf8()
20
20
);
21
21
22
22
// But it can still be disabled by turning the linker feature off.
23
- let output = rustc().link_arg("-Wl,-v").arg("-Zlinker-features=-lld").input("main.rs").run();
23
+ let output = rustc()
24
+ .arg("-Wlinker-messages")
25
+ .link_arg("-Wl,-v")
26
+ .arg("-Zlinker-features=-lld")
27
+ .input("main.rs")
28
+ .run();
24
29
assert!(
25
30
!find_lld_version_in_logs(output.stderr_utf8()),
26
31
"the LLD version string should not be present in the output logs:\n{}",
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ fn main() {
16
16
// the linker to display its version number with a link-arg.
17
17
let output = rustc()
18
18
.crate_type("cdylib")
19
+ .arg("-Wlinker-messages")
19
20
.target("custom-target.json")
20
21
.link_arg("-Wl,-v")
21
22
.input("lib.rs")
@@ -29,6 +30,7 @@ fn main() {
29
30
// But it can also be disabled via linker features.
30
31
let output = rustc()
31
32
.crate_type("cdylib")
33
+ .arg("-Wlinker-messages")
32
34
.target("custom-target.json")
33
35
.arg("-Zlinker-features=-lld")
34
36
.link_arg("-Wl,-v")
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ fn main() {
17
17
.arg("-Zlinker-features=+lld")
18
18
.arg("-Clink-self-contained=+linker")
19
19
.arg("-Zunstable-options")
20
+ .arg("-Wlinker-messages")
20
21
.link_arg(linker_version_flag)
21
22
.input("main.rs")
22
23
.run();
@@ -27,8 +28,12 @@ fn main() {
27
28
);
28
29
29
30
// It should not be used when we explicitly opt-out of lld.
30
- let output =
31
- rustc().link_arg(linker_version_flag).arg("-Zlinker-features=-lld").input("main.rs").run();
31
+ let output = rustc()
32
+ .link_arg(linker_version_flag)
33
+ .arg("-Zlinker-features=-lld")
34
+ .arg("-Wlinker-messages")
35
+ .input("main.rs")
36
+ .run();
32
37
assert!(
33
38
!find_lld_version_in_logs(output.stderr_utf8()),
34
39
"the LLD version string should not be present in the output logs:\n{}",
@@ -44,6 +49,7 @@ fn main() {
44
49
.arg("-Zlinker-features=-lld")
45
50
.arg("-Zlinker-features=+lld")
46
51
.arg("-Zlinker-features=-lld,+lld")
52
+ .arg("-Wlinker-messages")
47
53
.input("main.rs")
48
54
.run();
49
55
assert!(
You can’t perform that action at this time.
0 commit comments