Skip to content

Commit c59b708

Browse files
committed
Emit warning while outputs is not exe and prints linkage info
Signed-off-by: xizheyin <[email protected]>
1 parent 6e23095 commit c59b708

File tree

6 files changed

+38
-0
lines changed

6 files changed

+38
-0
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,23 @@ pub fn ensure_removed(dcx: DiagCtxtHandle<'_>, path: &Path) {
6868
}
6969
}
7070

71+
fn check_link_info_print_request(sess: &Session, crate_type: CrateType) {
72+
let print_native_static_libs =
73+
sess.opts.prints.iter().any(|p| p.kind == PrintKind::NativeStaticLibs);
74+
if print_native_static_libs {
75+
if crate_type != CrateType::Staticlib {
76+
sess.dcx()
77+
.warn(format!("cannot output linkage information without staticlib crate-type"));
78+
sess.dcx()
79+
.note(format!("consider `--crate-type staticlib` to print linkage information"));
80+
} else if !sess.opts.output_types.should_link() {
81+
sess.dcx().warn(format!(
82+
"skipping link step due to conflict: cannot output linkage information without emitting link"
83+
));
84+
}
85+
}
86+
}
87+
7188
/// Performs the linkage portion of the compilation phase. This will generate all
7289
/// of the requested outputs for this compilation session.
7390
pub fn link_binary(
@@ -178,6 +195,8 @@ pub fn link_binary(
178195
tempfiles_for_stdout_output.push(out_filename);
179196
}
180197
}
198+
199+
check_link_info_print_request(sess, crate_type);
181200
}
182201

183202
// Remove the temporary object file and metadata if we aren't saving temps.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
//@ compile-flags: --print native-static-libs
2+
//@ check-pass
3+
//~? WARN cannot output linkage information without staticlib crate-type
4+
5+
fn main() {}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: cannot output linkage information without staticlib crate-type
2+
3+
note: consider `--crate-type staticlib` to print linkage information
4+
5+
warning: 1 warning emitted
6+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//@ compile-flags: --print native-static-libs --crate-type staticlib --emit metadata
2+
//@ check-pass
3+
//~? WARN skipping link step due to conflict: cannot output linkage information without emitting link
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
warning: skipping link step due to conflict: cannot output linkage information without emitting link
2+
3+
warning: 1 warning emitted
4+

tests/ui/print-request/stability.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,4 @@ fn main() {}
110110
//[check_cfg]~? ERROR the `-Z unstable-options` flag must also be passed to enable the `check-cfg` print option
111111
//[supported_crate_types]~? ERROR the `-Z unstable-options` flag must also be passed to enable the `supported-crate-types` print option
112112
//[target_spec_json]~? ERROR the `-Z unstable-options` flag must also be passed to enable the `target-spec-json` print option
113+
//[native_static_libs]~? WARNING cannot output linkage information without staticlib crate-type

0 commit comments

Comments
 (0)