Skip to content

Commit 59b91ae

Browse files
committed
Break complex conditional into separate statements
1 parent 3bdef53 commit 59b91ae

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+22-15
Original file line numberDiff line numberDiff line change
@@ -1197,22 +1197,29 @@ fn add_sanitizer_libraries(
11971197
crate_type: CrateType,
11981198
linker: &mut dyn Linker,
11991199
) {
1200-
// On macOS and Windows using MSVC the runtimes are distributed as dylibs
1201-
// which should be linked to both executables and dynamic libraries.
1202-
// Everywhere else the runtimes are currently distributed as static
1203-
// libraries which should be linked to executables only.
1204-
let needs_runtime = !sess.target.is_like_android
1205-
&& (!sess.opts.cg.link_self_contained.is_sanitizers_disabled()
1206-
|| sess.opts.cg.link_self_contained.is_sanitizers_enabled())
1207-
&& match crate_type {
1208-
CrateType::Executable => true,
1209-
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => {
1210-
sess.target.is_like_osx || sess.target.is_like_msvc
1211-
}
1212-
CrateType::Rlib | CrateType::Staticlib => false,
1213-
};
1200+
if sess.target.is_like_android {
1201+
// Sanitizer runtime libraries are provided dynamically on Android
1202+
// targets.
1203+
return;
1204+
}
1205+
1206+
if sess.opts.cg.link_self_contained.is_sanitizers_disabled() {
1207+
// Linking against in-tree sanitizer runtimes is disabled via
1208+
// `-C link-self-contained=-sanitizers`
1209+
return;
1210+
}
1211+
1212+
// On macOS the runtimes are distributed as dylibs which should be linked to
1213+
// both executables and dynamic shared objects. On most other platforms the
1214+
// runtimes are currently distributed as static libraries which should be
1215+
// linked to executables only.
1216+
if matches!(crate_type, CrateType::Rlib, crate_type == CrateType::StaticLib) {
1217+
return;
1218+
}
1219+
1220+
if matches!(crate_type, CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro) &&
1221+
(sess.target.is_like_osx || sess.target.is_like_msvc) {
12141222

1215-
if !needs_runtime {
12161223
return;
12171224
}
12181225

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl LinkSelfContained {
295295
self.enabled_components.contains(LinkSelfContainedComponents::SANITIZERS)
296296
}
297297

298-
/// Returns whether the self-contained linker component was disabled on the CLI, using the
298+
/// Returns whether the self-contained sanitizer component was disabled on the CLI, using the
299299
/// `-C link-self-contained=-sanitizers` syntax, or one of the `false` shortcuts.
300300
pub fn is_sanitizers_disabled(&self) -> bool {
301301
self.disabled_components.contains(LinkSelfContainedComponents::SANITIZERS)

0 commit comments

Comments
 (0)